diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/TetherType.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/TetherType.kt index aad28004..319a07bc 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/TetherType.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/TetherType.kt @@ -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 */ - fun ofInterface(iface: String?, p2pDev: String? = null) = synchronized(this) { ofInterfaceImpl(iface, p2pDev) } - private tailrec fun ofInterfaceImpl(iface: String?, p2pDev: String?): TetherType = when { - iface == null -> NONE - iface == p2pDev -> WIFI_P2P + fun ofInterface(iface: String?, p2pDev: String? = null) = when (iface) { + null -> NONE + 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 -> { if (Build.VERSION.SDK_INT >= 30) updateRegexs() else error("unexpected requiresUpdate") - ofInterfaceImpl(iface, p2pDev) + ofInterfaceImpl(iface) } wifiRegexs.any { it.matcher(iface).matches() } -> WIFI wigigRegexs.any { it.matcher(iface).matches() } -> WIGIG