diff --git a/app/src/main/java/io/nekohasekai/sfa/bg/PlatformInterfaceWrapper.kt b/app/src/main/java/io/nekohasekai/sfa/bg/PlatformInterfaceWrapper.kt index 850b202..c417ace 100644 --- a/app/src/main/java/io/nekohasekai/sfa/bg/PlatformInterfaceWrapper.kt +++ b/app/src/main/java/io/nekohasekai/sfa/bg/PlatformInterfaceWrapper.kt @@ -2,7 +2,6 @@ package io.nekohasekai.sfa.bg import android.annotation.SuppressLint import android.content.pm.PackageManager -import android.net.Network import android.net.NetworkCapabilities import android.os.Build import android.os.Process @@ -13,8 +12,6 @@ import io.nekohasekai.libbox.InterfaceUpdateListener import io.nekohasekai.libbox.Libbox import io.nekohasekai.libbox.NetworkInterfaceIterator import io.nekohasekai.libbox.PlatformInterface -import io.nekohasekai.libbox.RawNetwork -import io.nekohasekai.libbox.RawNetworkIterator import io.nekohasekai.libbox.StringIterator import io.nekohasekai.libbox.TunOptions import io.nekohasekai.libbox.WIFIState @@ -147,15 +144,11 @@ interface PlatformInterfaceWrapper : PlatformInterface { boxInterface.flags = dumpFlags boxInterface.metered = !networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED) - boxInterface.rawNetwork = NetworkWrapper(network) interfaces.add(boxInterface) } return InterfaceArray(interfaces.iterator()) } - override fun setUnderlyingNetworks(networks: RawNetworkIterator) { - } - override fun underNetworkExtension(): Boolean { return false } @@ -209,8 +202,6 @@ interface PlatformInterfaceWrapper : PlatformInterface { } } - data class NetworkWrapper(val network: Network) : RawNetwork - private fun InterfaceAddress.toPrefix(): String { return if (address is Inet6Address) { "${Inet6Address.getByAddress(address.address).hostAddress}/${networkPrefixLength}" diff --git a/app/src/main/java/io/nekohasekai/sfa/bg/VPNService.kt b/app/src/main/java/io/nekohasekai/sfa/bg/VPNService.kt index 0db1cb4..4973c70 100644 --- a/app/src/main/java/io/nekohasekai/sfa/bg/VPNService.kt +++ b/app/src/main/java/io/nekohasekai/sfa/bg/VPNService.kt @@ -2,13 +2,11 @@ package io.nekohasekai.sfa.bg import android.content.Intent import android.content.pm.PackageManager.NameNotFoundException -import android.net.Network import android.net.ProxyInfo import android.net.VpnService import android.os.Build import android.os.IBinder import io.nekohasekai.libbox.Notification -import io.nekohasekai.libbox.RawNetworkIterator import io.nekohasekai.libbox.TunOptions import io.nekohasekai.sfa.database.Settings import io.nekohasekai.sfa.ktx.toIpPrefix @@ -183,51 +181,10 @@ class VPNService : VpnService(), PlatformInterfaceWrapper { systemProxyEnabled = false } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { - synchronized(this) { - val underlyingNetworks = underlyingNetworksCache - if (underlyingNetworks != null) { - builder.setUnderlyingNetworks(underlyingNetworks) - underlyingNetworksCache = null - } - val pfd = - builder.establish() - ?: error("android: the application is not prepared or is revoked") - service.fileDescriptor = pfd - return pfd.fd - } - } else { - val pfd = - builder.establish() - ?: error("android: the application is not prepared or is revoked") - service.fileDescriptor = pfd - return pfd.fd - } - } - - @Volatile - private var underlyingNetworksCache: Array? = null - - override fun setUnderlyingNetworks(networkIterator: RawNetworkIterator) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { - synchronized(this) { - val defaultNetwork = runBlocking { DefaultNetworkListener.get() } - var networks = mutableListOf() - while (networkIterator.hasNext()) { - val network = - (networkIterator.next() as PlatformInterfaceWrapper.NetworkWrapper).network - if (network == defaultNetwork) { - networks.add(0, network) - } else { - networks.add(network) - } - } - val newNetworks = networks.toTypedArray() - if (!setUnderlyingNetworks(newNetworks)) { - underlyingNetworksCache = newNetworks - } - } - } + val pfd = + builder.establish() ?: error("android: the application is not prepared or is revoked") + service.fileDescriptor = pfd + return pfd.fd } override fun writeLog(message: String) = service.writeLog(message)