From d6da72e43cf777a33b1b0609ec30b3ce2a632204 Mon Sep 17 00:00:00 2001 From: Mygod Date: Thu, 19 Sep 2019 12:29:04 +0800 Subject: [PATCH] Fix catastrophic error --- .../be/mygod/vpnhotspot/net/DhcpWorkaround.kt | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/DhcpWorkaround.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/DhcpWorkaround.kt index 9b998950..52ada7f7 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/DhcpWorkaround.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/DhcpWorkaround.kt @@ -28,21 +28,23 @@ object DhcpWorkaround : SharedPreferences.OnSharedPreferenceChangeListener { val shouldEnable get() = app.pref.getBoolean(KEY_ENABLED, false) fun enable(enabled: Boolean) = GlobalScope.launch { val action = if (enabled) "add" else "del" - RootSession.use { - try { - it.exec("ip rule $action iif lo uidrange 0-0 lookup local_network priority 11000") - } catch (e: RootSession.UnexpectedOutputException) { - if (e.result.out.isEmpty() && (e.result.code == 2 || e.result.code == 254) && if (enabled) { - e.result.err.joinToString("\n") == "RTNETLINK answers: File exists" - } else { - e.result.err.joinToString("\n") == "RTNETLINK answers: No such file or directory" - }) return@use - Timber.w(IOException("Failed to tweak dhcp workaround rule", e)) - SmartSnackbar.make(e).show() - } catch (e: Exception) { - Timber.w(e) - SmartSnackbar.make(e).show() + try { + RootSession.use { + try { + it.exec("ip rule $action iif lo uidrange 0-0 lookup local_network priority 11000") + } catch (e: RootSession.UnexpectedOutputException) { + if (e.result.out.isEmpty() && (e.result.code == 2 || e.result.code == 254) && if (enabled) { + e.result.err.joinToString("\n") == "RTNETLINK answers: File exists" + } else { + e.result.err.joinToString("\n") == "RTNETLINK answers: No such file or directory" + }) return@use + Timber.w(IOException("Failed to tweak dhcp workaround rule", e)) + SmartSnackbar.make(e).show() + } } + } catch (e: Exception) { + Timber.w(e) + SmartSnackbar.make(e).show() } }