From ae3dc81abaab43bef91c0e9d664ac1b0be52192a Mon Sep 17 00:00:00 2001 From: Mygod Date: Thu, 19 Sep 2019 11:43:36 +0800 Subject: [PATCH] Fix ConcurrentModificationException in DhcpWorkaround --- .../be/mygod/vpnhotspot/net/DhcpWorkaround.kt | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 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 59520207..9b998950 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/DhcpWorkaround.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/DhcpWorkaround.kt @@ -28,19 +28,21 @@ 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" - try { - RootSession.use { 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@launch - Timber.w(IOException("Failed to tweak dhcp workaround rule", e)) - SmartSnackbar.make(e).show() - } catch (e: Exception) { - Timber.w(e) - SmartSnackbar.make(e).show() + 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() + } } }