From c276642161d0f2a283c9a254b1b60f97f09cb2ea Mon Sep 17 00:00:00 2001 From: Mygod Date: Fri, 2 Oct 2020 07:05:20 +0800 Subject: [PATCH] Suppress more CancellationException --- .../java/be/mygod/vpnhotspot/manage/TetherManager.kt | 3 +-- .../mygod/vpnhotspot/manage/TetheringTileService.kt | 3 +-- .../java/be/mygod/vpnhotspot/net/TetheringManager.kt | 12 +++++++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetherManager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetherManager.kt index bec59e21..7036a4c8 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetherManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetherManager.kt @@ -23,7 +23,6 @@ import be.mygod.vpnhotspot.net.TetheringManager import be.mygod.vpnhotspot.net.wifi.SoftApConfigurationCompat import be.mygod.vpnhotspot.net.wifi.WifiApManager import be.mygod.vpnhotspot.root.WifiApCommands -import be.mygod.vpnhotspot.util.getRootCause import be.mygod.vpnhotspot.util.readableMessage import be.mygod.vpnhotspot.widget.SmartSnackbar import kotlinx.coroutines.Dispatchers @@ -102,7 +101,7 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(), data.notifyChange() } override fun onException(e: Exception) { - if (e.getRootCause() !is SecurityException) Timber.w(e) + super.onException(e) GlobalScope.launch(Dispatchers.Main.immediate) { val context = parent.context ?: app Toast.makeText(context, e.readableMessage, Toast.LENGTH_LONG).show() diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringTileService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringTileService.kt index e27d6013..5a57f4ea 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringTileService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringTileService.kt @@ -18,7 +18,6 @@ import be.mygod.vpnhotspot.net.TetheringManager import be.mygod.vpnhotspot.net.TetheringManager.tetheredIfaces import be.mygod.vpnhotspot.net.wifi.WifiApManager import be.mygod.vpnhotspot.util.broadcastReceiver -import be.mygod.vpnhotspot.util.getRootCause import be.mygod.vpnhotspot.util.readableMessage import be.mygod.vpnhotspot.util.stopAndUnbind import kotlinx.coroutines.Dispatchers @@ -125,7 +124,7 @@ sealed class TetheringTileService : IpNeighbourMonitoringTileService(), Tetherin updateTile() } override fun onException(e: Exception) { - if (e.getRootCause() !is SecurityException) Timber.w(e) + super.onException(e) GlobalScope.launch(Dispatchers.Main.immediate) { Toast.makeText(this@TetheringTileService, e.readableMessage, Toast.LENGTH_LONG).show() } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/TetheringManager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/TetheringManager.kt index 9dc296d4..4125b9a5 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/TetheringManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/TetheringManager.kt @@ -29,6 +29,7 @@ import java.lang.reflect.InvocationHandler import java.lang.reflect.InvocationTargetException import java.lang.reflect.Method import java.lang.reflect.Proxy +import java.util.concurrent.CancellationException import java.util.concurrent.Executor /** @@ -56,7 +57,12 @@ object TetheringManager { /** * ADDED: Called when a local Exception occurred. */ - fun onException(e: Exception) { } + fun onException(e: Exception) { + when (e.getRootCause()) { + is SecurityException, is CancellationException -> { } + else -> Timber.w(e) + } + } } /** @@ -320,7 +326,7 @@ object TetheringManager { } catch (eRoot: Exception) { try { // last resort: start tethering without trying to bypass entitlement check startTethering(type, false, showProvisioningUi, executor, proxy(callback)) - Timber.w(eRoot) + if (eRoot !is CancellationException) Timber.w(eRoot) } catch (e: Exception) { e.addSuppressed(eRoot) callback.onException(e) @@ -356,7 +362,7 @@ object TetheringManager { }.value } catch (eRoot: Exception) { eRoot.addSuppressed(e) - Timber.w(eRoot) + if (eRoot !is CancellationException) Timber.w(eRoot) callback.onException(eRoot) return@launch }