diff --git a/README.md b/README.md index ebba4873..1cc6e58b 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,7 @@ Greylisted/blacklisted APIs or internal constants: (some constants are hardcoded * (prior to API 30) `Landroid/net/ConnectivityManager;->getLastTetherError(Ljava/lang/String;)I,max-target-r` * (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,blocked` +* (since API 31) `Landroid/net/TetheringManager$TetheringEventCallback;->onSupportedTetheringTypes(Ljava/util/Set;)V,blocked` * (since API 31) `Landroid/net/wifi/SoftApCapability;->getCountryCode()Ljava/lang/String;,blocked` * (since API 33) `Landroid/net/wifi/SoftApConfiguration$Builder;->setRandomizedMacAddress(Landroid/net/MacAddress;)Landroid/net/wifi/SoftApConfiguration$Builder;,blocked` * (since API 31) `Landroid/net/wifi/SoftApConfiguration;->BAND_TYPES:[I,blocked` @@ -222,6 +223,7 @@ Greylisted/blacklisted APIs or internal constants: (some constants are hardcoded * (since API 30) `Landroid/net/TetheringManager;->TETHERING_ETHERNET:I,sdk,system-api,test-api` * `Landroid/net/TetheringManager;->TETHERING_USB:I,sdk,system-api,test-api` * `Landroid/net/TetheringManager;->TETHERING_WIFI:I,sdk,system-api,test-api` +* (since API 31) `Landroid/net/TetheringManager;->TETHERING_WIFI_P2P:I,sdk,system-api,test-api` * `Landroid/net/TetheringManager;->TETHER_ERROR_*:I,sdk,system-api,test-api` * (since API 30) `Landroid/net/TetheringManager;->TETHER_ERROR_NO_CHANGE_TETHERING_PERMISSION:I,sdk,system-api,test-api` * (since API 30) `Landroid/net/TetheringManager;->TETHER_HARDWARE_OFFLOAD_FAILED:I,sdk,system-api,test-api` 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 acf3f46c..32accdb8 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/TetheringManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/TetheringManager.kt @@ -33,6 +33,7 @@ import java.lang.reflect.Proxy import java.util.concurrent.CancellationException import java.util.concurrent.Executor + /** * Heavily based on: * https://github.com/aegis1980/WifiHotSpot @@ -153,6 +154,8 @@ object TetheringManager { */ @RequiresApi(30) const val TETHERING_ETHERNET = 5 + @RequiresApi(31) // TETHERING_WIFI_P2P + private val expectedTypes = setOf(TETHERING_WIFI, TETHERING_USB, TETHERING_BLUETOOTH, 3, TETHERING_ETHERNET) @get:RequiresApi(30) private val clazz by lazy { Class.forName("android.net.TetheringManager") } @@ -397,6 +400,23 @@ object TetheringManager { */ fun onTetheringSupported(supported: Boolean) {} + /** + * Called when tethering supported status changed. + * + * This will be called immediately after the callback is registered, and may be called + * multiple times later upon changes. + * + * Tethering may be disabled via system properties, device configuration, or device + * policy restrictions. + * + * @param supportedTypes a set of @TetheringType which is supported. + */ + @TargetApi(31) + fun onSupportedTetheringTypes(supportedTypes: Set) { + if ((supportedTypes - expectedTypes).isNotEmpty()) Timber.w(Exception( + "Unexpected supported tethering types: ${supportedTypes.joinToString()}")) + } + /** * Called when tethering upstream changed. * @@ -519,6 +539,10 @@ object TetheringManager { method.matches("onTetheringSupported", Boolean::class.java) -> { callback?.onTetheringSupported(args!![0] as Boolean) } + method.matches1>("onSupportedTetheringTypes") -> { + @Suppress("UNCHECKED_CAST") + callback?.onSupportedTetheringTypes(args!![0] as Set) + } method.matches1("onUpstreamChanged") -> { callback?.onUpstreamChanged(args!![0] as Network?) }