Implement displaying tethering errors
This commit is contained in:
@@ -41,10 +41,36 @@ object TetheringManager {
|
||||
*/
|
||||
const val ACTION_TETHER_STATE_CHANGED = "android.net.conn.TETHER_STATE_CHANGED"
|
||||
private const val EXTRA_ACTIVE_TETHER_LEGACY = "activeArray"
|
||||
/**
|
||||
* gives a String[] listing all the interfaces currently in local-only
|
||||
* mode (ie, has DHCPv4+IPv6-ULA support and no packet forwarding)
|
||||
*/
|
||||
@RequiresApi(26)
|
||||
private const val EXTRA_ACTIVE_LOCAL_ONLY = "localOnlyArray"
|
||||
/**
|
||||
* gives a String[] listing all the interfaces currently tethered
|
||||
* (ie, has DHCPv4 support and packets potentially forwarded/NATed)
|
||||
*/
|
||||
@RequiresApi(26)
|
||||
private const val EXTRA_ACTIVE_TETHER = "tetherArray"
|
||||
/**
|
||||
* gives a String[] listing all the interfaces we tried to tether and
|
||||
* failed. Use {@link #getLastTetherError} to find the error code
|
||||
* for any interfaces listed here.
|
||||
*/
|
||||
const val EXTRA_ERRORED_TETHER = "erroredArray"
|
||||
const val TETHER_ERROR_NO_ERROR = 0
|
||||
const val TETHER_ERROR_UNKNOWN_IFACE = 1
|
||||
const val TETHER_ERROR_SERVICE_UNAVAIL = 2
|
||||
const val TETHER_ERROR_UNSUPPORTED = 3
|
||||
const val TETHER_ERROR_UNAVAIL_IFACE = 4
|
||||
const val TETHER_ERROR_MASTER_ERROR = 5
|
||||
const val TETHER_ERROR_TETHER_IFACE_ERROR = 6
|
||||
const val TETHER_ERROR_UNTETHER_IFACE_ERROR = 7
|
||||
const val TETHER_ERROR_ENABLE_NAT_ERROR = 8
|
||||
const val TETHER_ERROR_DISABLE_NAT_ERROR = 9
|
||||
const val TETHER_ERROR_IFACE_CFG_ERROR = 10
|
||||
const val TETHER_ERROR_PROVISION_FAILED = 11
|
||||
|
||||
const val TETHERING_WIFI = 0
|
||||
/**
|
||||
@@ -68,6 +94,9 @@ object TetheringManager {
|
||||
private val stopTethering by lazy {
|
||||
ConnectivityManager::class.java.getDeclaredMethod("stopTethering", Int::class.java)
|
||||
}
|
||||
private val getLastTetherError by lazy {
|
||||
ConnectivityManager::class.java.getDeclaredMethod("getLastTetherError", String::class.java)
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs tether provisioning for the given type if needed and then starts tethering if
|
||||
@@ -126,6 +155,16 @@ object TetheringManager {
|
||||
stopTethering.invoke(app.connectivity, type)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a more detailed error code after a Tethering or Untethering
|
||||
* request asynchronously failed.
|
||||
*
|
||||
* @param iface The name of the interface of interest
|
||||
* @return error The error code of the last error tethering or untethering the named
|
||||
* interface
|
||||
*/
|
||||
fun getLastTetherError(iface: String): Int = getLastTetherError.invoke(app.connectivity, iface) as Int
|
||||
|
||||
fun getTetheredIfaces(extras: Bundle) = extras.getStringArrayList(
|
||||
if (Build.VERSION.SDK_INT >= 26) EXTRA_ACTIVE_TETHER else EXTRA_ACTIVE_TETHER_LEGACY)!!
|
||||
fun getLocalOnlyTetheredIfaces(extras: Bundle) =
|
||||
|
||||
Reference in New Issue
Block a user