From 7c72b9a235c3eaf8864381f200c21e1a0a6e7eeb Mon Sep 17 00:00:00 2001 From: Mygod Date: Tue, 1 Jan 2019 12:27:49 +0800 Subject: [PATCH] Caller already has an active LocalOnlyHotspot request is now unexpected --- .../be/mygod/vpnhotspot/LocalOnlyHotspotService.kt | 10 +++++++--- .../src/main/java/be/mygod/vpnhotspot/net/Routing.kt | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt index 4fa6b5c1..3d102387 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt @@ -12,6 +12,7 @@ import be.mygod.vpnhotspot.net.wifi.WifiDoubleLock import be.mygod.vpnhotspot.util.StickyEvent1 import be.mygod.vpnhotspot.util.broadcastReceiver import be.mygod.vpnhotspot.widget.SmartSnackbar +import timber.log.Timber @RequiresApi(26) class LocalOnlyHotspotService : IpNeighbourMonitoringService() { @@ -63,6 +64,7 @@ class LocalOnlyHotspotService : IpNeighbourMonitoringService() { override fun onBind(intent: Intent?) = binder override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { + if (binder.iface != null) return START_STICKY binder.iface = "" // show invisible foreground notification on television to avoid being killed if (app.uiMode.currentModeType == Configuration.UI_MODE_TYPE_TELEVISION) updateNotification() @@ -106,9 +108,11 @@ class LocalOnlyHotspotService : IpNeighbourMonitoringService() { startFailure() } }, app.handler) - // assuming IllegalStateException will be thrown only if - // "Caller already has an active LocalOnlyHotspot request" - } catch (_: IllegalStateException) { } catch (e: SecurityException) { + } catch (e: IllegalStateException) { + Timber.w(e) + SmartSnackbar.make(e).show() + startFailure() + } catch (e: SecurityException) { SmartSnackbar.make(e).show() startFailure() } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt index 01f04caf..3f61d02b 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt @@ -257,7 +257,7 @@ class Routing(val downstream: String, ownerAddress: InterfaceAddress? = null) : fun revert() { stop() TrafficRecorder.update() // record stats before exiting to prevent stats losing - clients.forEach { (_, subroute) -> subroute.close() } + clients.values.forEach { it.close() } fallbackUpstream.subrouting?.transaction?.revert() upstream.subrouting?.transaction?.revert() transaction.revert()