native fixes

* call sendFd() before tun2socks start
This commit is contained in:
Rurirei
2020-10-08 15:50:51 +08:00
committed by GitHub
parent 24d105a53c
commit 030b9a3900
7 changed files with 18 additions and 41 deletions

View File

@@ -27,6 +27,7 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:extractNativeLibs="true"
android:theme="@style/AppTheme">
<activity
android:name=".ui.MainActivity"

View File

@@ -11,5 +11,4 @@ interface ServiceControl {
fun vpnProtect(socket: Int): Boolean
fun vpnSendFd()
}

View File

@@ -37,10 +37,6 @@ class V2RayProxyOnlyService : Service(), ServiceControl {
return true
}
override fun vpnSendFd() {
// do nothing
}
override fun onBind(intent: Intent?): IBinder? {
return null
}

View File

@@ -111,16 +111,6 @@ object V2RayServiceManager {
}
}
override fun sendFd(): Long {
val serviceControl = serviceControl?.get() ?: return -1
try {
serviceControl.vpnSendFd()
} catch (e: Exception) {
Log.d(serviceControl.getService().packageName, e.toString())
return -1
}
return 0
}
}
fun startV2rayPoint() {

View File

@@ -172,6 +172,8 @@ class V2RayVpnService : VpnService(), ServiceControl {
e.printStackTrace()
stopV2Ray()
}
sendFd()
}
private fun sendFd() {
@@ -181,7 +183,7 @@ class V2RayVpnService : VpnService(), ServiceControl {
GlobalScope.launch(Dispatchers.IO) {
var tries = 0
while (true) try {
Thread.sleep(50L shl tries)
Thread.sleep(1000L shl tries)
Log.d(packageName, "sendFd tries: $tries")
LocalSocket().use { localSocket ->
localSocket.connect(LocalSocketAddress(path, LocalSocketAddress.Namespace.FILESYSTEM))
@@ -251,7 +253,4 @@ class V2RayVpnService : VpnService(), ServiceControl {
return protect(socket)
}
override fun vpnSendFd() {
sendFd()
}
}