Check for unsupported tethering types
This commit is contained in:
@@ -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`
|
* (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/ConnectivityModuleConnector;->IN_PROCESS_SUFFIX:Ljava/lang/String;`
|
||||||
* (since API 30) `Landroid/net/TetheringManager$TetheringEventCallback;->onTetherableInterfaceRegexpsChanged(Landroid/net/TetheringManager$TetheringInterfaceRegexps;)V,blocked`
|
* (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 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 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`
|
* (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`
|
* (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_USB:I,sdk,system-api,test-api`
|
||||||
* `Landroid/net/TetheringManager;->TETHERING_WIFI: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`
|
* `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_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`
|
* (since API 30) `Landroid/net/TetheringManager;->TETHER_HARDWARE_OFFLOAD_FAILED:I,sdk,system-api,test-api`
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import java.lang.reflect.Proxy
|
|||||||
import java.util.concurrent.CancellationException
|
import java.util.concurrent.CancellationException
|
||||||
import java.util.concurrent.Executor
|
import java.util.concurrent.Executor
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Heavily based on:
|
* Heavily based on:
|
||||||
* https://github.com/aegis1980/WifiHotSpot
|
* https://github.com/aegis1980/WifiHotSpot
|
||||||
@@ -153,6 +154,8 @@ object TetheringManager {
|
|||||||
*/
|
*/
|
||||||
@RequiresApi(30)
|
@RequiresApi(30)
|
||||||
const val TETHERING_ETHERNET = 5
|
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)
|
@get:RequiresApi(30)
|
||||||
private val clazz by lazy { Class.forName("android.net.TetheringManager") }
|
private val clazz by lazy { Class.forName("android.net.TetheringManager") }
|
||||||
@@ -397,6 +400,23 @@ object TetheringManager {
|
|||||||
*/
|
*/
|
||||||
fun onTetheringSupported(supported: Boolean) {}
|
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<Int?>) {
|
||||||
|
if ((supportedTypes - expectedTypes).isNotEmpty()) Timber.w(Exception(
|
||||||
|
"Unexpected supported tethering types: ${supportedTypes.joinToString()}"))
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when tethering upstream changed.
|
* Called when tethering upstream changed.
|
||||||
*
|
*
|
||||||
@@ -519,6 +539,10 @@ object TetheringManager {
|
|||||||
method.matches("onTetheringSupported", Boolean::class.java) -> {
|
method.matches("onTetheringSupported", Boolean::class.java) -> {
|
||||||
callback?.onTetheringSupported(args!![0] as Boolean)
|
callback?.onTetheringSupported(args!![0] as Boolean)
|
||||||
}
|
}
|
||||||
|
method.matches1<java.util.Set<*>>("onSupportedTetheringTypes") -> {
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
callback?.onSupportedTetheringTypes(args!![0] as Set<Int?>)
|
||||||
|
}
|
||||||
method.matches1<Network>("onUpstreamChanged") -> {
|
method.matches1<Network>("onUpstreamChanged") -> {
|
||||||
callback?.onUpstreamChanged(args!![0] as Network?)
|
callback?.onUpstreamChanged(args!![0] as Network?)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user