Handle failure to resolve service gracefully
This commit is contained in:
@@ -104,13 +104,20 @@ enum class TetherType(@DrawableRes val icon: Int) {
|
|||||||
*
|
*
|
||||||
* Based on: https://android.googlesource.com/platform/frameworks/base/+/5d36f01/packages/Tethering/src/com/android/networkstack/tethering/Tethering.java#479
|
* Based on: https://android.googlesource.com/platform/frameworks/base/+/5d36f01/packages/Tethering/src/com/android/networkstack/tethering/Tethering.java#479
|
||||||
*/
|
*/
|
||||||
fun ofInterface(iface: String?, p2pDev: String? = null) = synchronized(this) { ofInterfaceImpl(iface, p2pDev) }
|
fun ofInterface(iface: String?, p2pDev: String? = null) = when (iface) {
|
||||||
private tailrec fun ofInterfaceImpl(iface: String?, p2pDev: String?): TetherType = when {
|
null -> NONE
|
||||||
iface == null -> NONE
|
p2pDev -> WIFI_P2P
|
||||||
iface == p2pDev -> WIFI_P2P
|
else -> try {
|
||||||
|
synchronized(this) { ofInterfaceImpl(iface) }
|
||||||
|
} catch (e: RuntimeException) {
|
||||||
|
Timber.w(e)
|
||||||
|
NONE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private tailrec fun ofInterfaceImpl(iface: String): TetherType = when {
|
||||||
requiresUpdate -> {
|
requiresUpdate -> {
|
||||||
if (Build.VERSION.SDK_INT >= 30) updateRegexs() else error("unexpected requiresUpdate")
|
if (Build.VERSION.SDK_INT >= 30) updateRegexs() else error("unexpected requiresUpdate")
|
||||||
ofInterfaceImpl(iface, p2pDev)
|
ofInterfaceImpl(iface)
|
||||||
}
|
}
|
||||||
wifiRegexs.any { it.matcher(iface).matches() } -> WIFI
|
wifiRegexs.any { it.matcher(iface).matches() } -> WIFI
|
||||||
wigigRegexs.any { it.matcher(iface).matches() } -> WIGIG
|
wigigRegexs.any { it.matcher(iface).matches() } -> WIGIG
|
||||||
|
|||||||
Reference in New Issue
Block a user