From 7e8deb120f962209129c9496c674784586eba8c6 Mon Sep 17 00:00:00 2001 From: Mygod Date: Tue, 21 Jan 2020 06:29:43 +0800 Subject: [PATCH] Prevent crash by buggy OS --- .../vpnhotspot/preference/UpstreamsPreference.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/preference/UpstreamsPreference.kt b/mobile/src/main/java/be/mygod/vpnhotspot/preference/UpstreamsPreference.kt index e8bde193..cf853730 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/preference/UpstreamsPreference.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/preference/UpstreamsPreference.kt @@ -15,6 +15,8 @@ import be.mygod.vpnhotspot.net.monitor.FallbackUpstreamMonitor import be.mygod.vpnhotspot.net.monitor.UpstreamMonitor import be.mygod.vpnhotspot.util.SpanFormatter import be.mygod.vpnhotspot.util.parseNumericAddress +import timber.log.Timber +import java.lang.RuntimeException class UpstreamsPreference(context: Context, attrs: AttributeSet) : Preference(context, attrs), DefaultLifecycleObserver { @@ -32,7 +34,14 @@ class UpstreamsPreference(context: Context, attrs: AttributeSet) : Preference(co } ?: "∅" override fun onAvailable(ifname: String, properties: LinkProperties) { - currentInterface = Interface(ifname, properties.routes.any { it.matches(internetAddress) }) + currentInterface = Interface(ifname, properties.routes.any { + try { + it.matches(internetAddress) + } catch (e: RuntimeException) { + Timber.w(e) + false + } + }) onUpdate() }