Fix ConcurrentModificationException in DhcpWorkaround

This commit is contained in:
Mygod
2019-09-19 11:43:36 +08:00
parent 20592ab9e9
commit ae3dc81aba

View File

@@ -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()
}
}
}