Fix android service revoke

This commit is contained in:
problematicconsumer
2023-11-09 16:48:51 +03:30
parent c1491ffe0b
commit 9bea38f605

View File

@@ -6,8 +6,12 @@ import android.content.pm.PackageManager.NameNotFoundException
import android.net.ProxyInfo import android.net.ProxyInfo
import android.net.VpnService import android.net.VpnService
import android.os.Build import android.os.Build
import android.os.IBinder
import com.hiddify.hiddify.constant.PerAppProxyMode import com.hiddify.hiddify.constant.PerAppProxyMode
import io.nekohasekai.libbox.TunOptions import io.nekohasekai.libbox.TunOptions
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
class VPNService : VpnService(), PlatformInterfaceWrapper { class VPNService : VpnService(), PlatformInterfaceWrapper {
@@ -20,14 +24,24 @@ class VPNService : VpnService(), PlatformInterfaceWrapper {
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int) = override fun onStartCommand(intent: Intent?, flags: Int, startId: Int) =
service.onStartCommand(intent, flags, startId) service.onStartCommand(intent, flags, startId)
override fun onBind(intent: Intent) = service.onBind(intent) override fun onBind(intent: Intent): IBinder {
val binder = super.onBind(intent)
if (binder != null) {
return binder
}
return service.onBind(intent)
}
override fun onDestroy() { override fun onDestroy() {
service.onDestroy() service.onDestroy()
} }
override fun onRevoke() { override fun onRevoke() {
runBlocking {
withContext(Dispatchers.Main) {
service.onRevoke() service.onRevoke()
} }
}
}
override fun autoDetectInterfaceControl(fd: Int) { override fun autoDetectInterfaceControl(fd: Int) {
protect(fd) protect(fd)