Fix ConcurrentModificationException

This commit is contained in:
Mygod
2018-09-03 14:21:29 +08:00
parent fc7731c4ed
commit 0342d97fb0

View File

@@ -45,7 +45,10 @@ class TetheringService : IpNeighbourMonitoringService(), UpstreamMonitor.Callbac
val upstream = upstream val upstream = upstream
if (upstream != null) { if (upstream != null) {
var failed = false var failed = false
for ((downstream, value) in routings) if (value == null || value.upstream != upstream) val iterator = routings.iterator()
while (iterator.hasNext()) {
val (downstream, value) = iterator.next()
if (value != null && value.upstream == upstream) continue
try { try {
routings[downstream] = Routing(upstream, downstream).apply { routings[downstream] = Routing(upstream, downstream).apply {
if (app.dhcpWorkaround) dhcpWorkaround() if (app.dhcpWorkaround) dhcpWorkaround()
@@ -61,9 +64,10 @@ class TetheringService : IpNeighbourMonitoringService(), UpstreamMonitor.Callbac
} catch (e: SocketException) { } catch (e: SocketException) {
e.printStackTrace() e.printStackTrace()
Crashlytics.logException(e) Crashlytics.logException(e)
routings.remove(downstream) iterator.remove()
failed = true failed = true
} }
}
if (failed) SmartSnackbar.make(R.string.noisy_su_failure).show() if (failed) SmartSnackbar.make(R.string.noisy_su_failure).show()
} else if (!receiverRegistered) { } else if (!receiverRegistered) {
registerReceiver(receiver, IntentFilter(TetheringManager.ACTION_TETHER_STATE_CHANGED)) registerReceiver(receiver, IntentFilter(TetheringManager.ACTION_TETHER_STATE_CHANGED))