diff --git a/README.md b/README.md index f46d65f0..14c0014f 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,7 @@ This is only meant to be an index. You can read more in the source code. Greylisted/blacklisted APIs or internal constants: (some constants are hardcoded or implicitly used) * [`Landroid/net/ConnectivityManager;->getLastTetherError(Ljava/lang/String;)I,greylist`](https://android.googlesource.com/platform/prebuilts/runtime/+/4601d91/appcompat/hiddenapi-flags.csv#144306) +* (since API 30) `Landroid/net/ConnectivityModuleConnector;->IN_PROCESS_SUFFIX:Ljava/lang/String;` * (since API 30) [`Landroid/net/TetheringManager$TetheringEventCallback;->onTetherableInterfaceRegexpsChanged(Landroid/net/TetheringManager$TetheringInterfaceRegexps;)V,blacklist`](https://android.googlesource.com/platform/prebuilts/runtime/+/4601d91/appcompat/hiddenapi-flags.csv#148899) * (since API 30) `Landroid/net/TetheringManager;->TETHERING_WIGIG:I` * (prior to API 30) [`Landroid/net/wifi/WifiConfiguration$KeyMgmt;->FT_PSK:I,greylist-max-o`](https://android.googlesource.com/platform/prebuilts/runtime/+/4601d91/appcompat/hiddenapi-flags.csv#153923) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/TetheringManager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/TetheringManager.kt index 29e9c4f4..874e9188 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/TetheringManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/TetheringManager.kt @@ -7,6 +7,7 @@ import android.content.Context import android.content.Intent import android.content.IntentFilter import android.content.pm.PackageManager +import android.content.pm.ResolveInfo import android.net.ConnectivityManager import android.net.Network import android.os.Build @@ -69,6 +70,8 @@ object TetheringManager { @RequiresApi(30) private const val TETHERING_CONNECTOR_CLASS = "android.net.ITetheringConnector" + @RequiresApi(30) + private const val IN_PROCESS_SUFFIX = ".InProcess" /** * This is a sticky broadcast since almost forever. @@ -165,9 +168,17 @@ object TetheringManager { val service = Services.context.getSystemService(TETHERING_SERVICE) service } + + private fun resolveSystemService(action: String): ResolveInfo? { + val result = app.packageManager.queryIntentServices(Intent(action), PackageManager.MATCH_SYSTEM_ONLY) + check(result.size <= 1) { "Multiple system services handle $action: ${result.joinToString()}" } + return result.firstOrNull() + } @get:RequiresApi(30) - val resolvedService get() = app.packageManager.queryIntentServices(Intent(TETHERING_CONNECTOR_CLASS), - PackageManager.MATCH_SYSTEM_ONLY).single() + val resolvedService get() = sequence { + resolveSystemService(TETHERING_CONNECTOR_CLASS + IN_PROCESS_SUFFIX)?.let { yield(it) } + resolveSystemService(TETHERING_CONNECTOR_CLASS)?.let { yield(it) } + }.single() @get:RequiresApi(24) private val classOnStartTetheringCallback by lazy {