51 lines
1.1 KiB
Kotlin
51 lines
1.1 KiB
Kotlin
package net.bluemangoo.indpjsk.vpn
|
|
|
|
import android.util.Log
|
|
|
|
object VpnBridge {
|
|
|
|
private const val TAG = "VpnBridge"
|
|
private var loaded = false
|
|
|
|
@Volatile
|
|
var stepListener: ((String, String?) -> Unit)? = null
|
|
|
|
init {
|
|
loaded = try {
|
|
System.loadLibrary("core_vpn")
|
|
true
|
|
} catch (t: Throwable) {
|
|
Log.e(TAG, "loadLibrary core_vpn failed", t)
|
|
false
|
|
}
|
|
}
|
|
|
|
fun isAvailable(): Boolean = loaded
|
|
|
|
@JvmStatic
|
|
external fun boot(tunFd: Int, stepsJson: String, proxy: String?): Boolean
|
|
|
|
@JvmStatic
|
|
external fun stopSession()
|
|
|
|
@JvmStatic
|
|
external fun shutdownSession()
|
|
|
|
@Suppress("unused")
|
|
@JvmStatic
|
|
fun nativeStepResult(stepId: String, url: String?) {
|
|
stepListener?.invoke(stepId, url)
|
|
}
|
|
|
|
@Suppress("unused")
|
|
@JvmStatic
|
|
fun nativeLog(level: String, msg: String) {
|
|
when (level) {
|
|
"error" -> VpnLog.error(msg)
|
|
"warn" -> VpnLog.warn(msg)
|
|
"info" -> VpnLog.info(msg)
|
|
else -> VpnLog.info(msg)
|
|
}
|
|
}
|
|
}
|