From 91592e5a259ccb3dbbcd74c1614c29afaa9fec5c Mon Sep 17 00:00:00 2001 From: Mygod Date: Sat, 23 Jun 2018 17:58:27 +0800 Subject: [PATCH] Suppress errors when stopping --- .../mygod/vpnhotspot/LocalOnlyInterfaceManager.kt | 4 ++-- .../java/be/mygod/vpnhotspot/TetheringService.kt | 14 ++++---------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyInterfaceManager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyInterfaceManager.kt index 83b9f04b..85fac1a2 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyInterfaceManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyInterfaceManager.kt @@ -27,7 +27,7 @@ class LocalOnlyInterfaceManager(val downstream: String) : UpstreamMonitor.Callba } override fun onLost() { val routing = routing ?: return - if (!routing.stop()) app.toast(R.string.noisy_su_failure) + routing.stop() initRouting(null, routing.hostAddress, emptyList()) } @@ -59,6 +59,6 @@ class LocalOnlyInterfaceManager(val downstream: String) : UpstreamMonitor.Callba fun stop() { UpstreamMonitor.unregisterCallback(this) app.cleanRoutings -= this - if (routing?.stop() == false) app.toast(R.string.noisy_su_failure) + routing?.stop() } } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/TetheringService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/TetheringService.kt index ee8cdcb5..c95169b2 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/TetheringService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/TetheringService.kt @@ -2,7 +2,6 @@ package be.mygod.vpnhotspot import android.content.Intent import android.content.IntentFilter -import android.widget.Toast import be.mygod.vpnhotspot.App.Companion.app import be.mygod.vpnhotspot.manage.TetheringFragment import be.mygod.vpnhotspot.net.IpNeighbourMonitor @@ -33,9 +32,8 @@ class TetheringService : IpNeighbourMonitoringService(), UpstreamMonitor.Callbac private var receiverRegistered = false private val receiver = broadcastReceiver { _, intent -> synchronized(routings) { - val failed = (routings.keys - TetheringManager.getTetheredIfaces(intent.extras)) - .any { routings.remove(it)?.stop() == false } - if (failed) Toast.makeText(this, getText(R.string.noisy_su_failure), Toast.LENGTH_SHORT).show() + for (iface in routings.keys - TetheringManager.getTetheredIfaces(intent.extras)) + routings.remove(iface)?.stop() updateRoutingsLocked() } } @@ -48,7 +46,6 @@ class TetheringService : IpNeighbourMonitoringService(), UpstreamMonitor.Callbac var failed = false for ((downstream, value) in routings) if (value == null || value.upstream != upstream) try { - if (value?.stop() == false) failed = true // system tethering already has working forwarding rules // so it doesn't make sense to add additional forwarding rules val routing = Routing(upstream, downstream).rule().forward() @@ -92,8 +89,7 @@ class TetheringService : IpNeighbourMonitoringService(), UpstreamMonitor.Callbac val iface = intent.getStringExtra(EXTRA_ADD_INTERFACE) synchronized(routings) { if (iface != null) routings[iface] = null - if (routings.remove(intent.getStringExtra(EXTRA_REMOVE_INTERFACE))?.stop() == false) - Toast.makeText(this, getText(R.string.noisy_su_failure), Toast.LENGTH_SHORT).show() + routings.remove(intent.getStringExtra(EXTRA_REMOVE_INTERFACE))?.stop() updateRoutingsLocked() } return START_NOT_STICKY @@ -109,14 +105,12 @@ class TetheringService : IpNeighbourMonitoringService(), UpstreamMonitor.Callbac override fun onLost() { upstream = null this.dns = emptyList() - var failed = false synchronized(routings) { for ((iface, routing) in routings) { - if (routing?.stop() == false) failed = true + routing?.stop() routings[iface] = null } } - if (failed) Toast.makeText(this, getText(R.string.noisy_su_failure), Toast.LENGTH_SHORT).show() } override fun onDestroy() {