Suppport in-process tethering module

This commit is contained in:
Mygod
2020-08-10 22:02:47 +08:00
parent ffe087cc3b
commit 27e93b2a78
2 changed files with 14 additions and 2 deletions

View File

@@ -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) 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) * [`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$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` * (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) * (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)

View File

@@ -7,6 +7,7 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.IntentFilter import android.content.IntentFilter
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.content.pm.ResolveInfo
import android.net.ConnectivityManager import android.net.ConnectivityManager
import android.net.Network import android.net.Network
import android.os.Build import android.os.Build
@@ -69,6 +70,8 @@ object TetheringManager {
@RequiresApi(30) @RequiresApi(30)
private const val TETHERING_CONNECTOR_CLASS = "android.net.ITetheringConnector" 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. * This is a sticky broadcast since almost forever.
@@ -165,9 +168,17 @@ object TetheringManager {
val service = Services.context.getSystemService(TETHERING_SERVICE) val service = Services.context.getSystemService(TETHERING_SERVICE)
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) @get:RequiresApi(30)
val resolvedService get() = app.packageManager.queryIntentServices(Intent(TETHERING_CONNECTOR_CLASS), val resolvedService get() = sequence {
PackageManager.MATCH_SYSTEM_ONLY).single() resolveSystemService(TETHERING_CONNECTOR_CLASS + IN_PROCESS_SUFFIX)?.let { yield(it) }
resolveSystemService(TETHERING_CONNECTOR_CLASS)?.let { yield(it) }
}.single()
@get:RequiresApi(24) @get:RequiresApi(24)
private val classOnStartTetheringCallback by lazy { private val classOnStartTetheringCallback by lazy {