From 5a98778a3b4d6d5b5a3d41971e864838fa3e20d5 Mon Sep 17 00:00:00 2001 From: Mygod Date: Sat, 13 Jan 2018 22:28:37 +0800 Subject: [PATCH] Various bugfixes for TetheringService --- .../java/be/mygod/vpnhotspot/TetheringService.kt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/TetheringService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/TetheringService.kt index 6ef112a4..b5925a06 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/TetheringService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/TetheringService.kt @@ -13,8 +13,12 @@ class TetheringService : Service(), VpnListener.Callback { const val EXTRA_REMOVE_INTERFACE = "interface.remove" private const val KEY_ACTIVE = "persist.service.tether.active" + private var alive = false var active: Set - get() = app.pref.getStringSet(KEY_ACTIVE, null) ?: emptySet() + get() = if (alive) app.pref.getStringSet(KEY_ACTIVE, null) ?: emptySet() else { + app.pref.edit().remove(KEY_ACTIVE).apply() + emptySet() + } private set(value) { app.pref.edit().putStringSet(KEY_ACTIVE, value).apply() LocalBroadcastManager.getInstance(app).sendBroadcast(Intent(ACTION_ACTIVE_INTERFACES_CHANGED)) @@ -33,7 +37,6 @@ class TetheringService : Service(), VpnListener.Callback { } private fun updateRoutings() { - active = routings.keys if (routings.isEmpty()) { unregisterReceiver() stopSelf() @@ -56,6 +59,12 @@ class TetheringService : Service(), VpnListener.Callback { receiverRegistered = true } } + active = routings.keys + } + + override fun onCreate() { + super.onCreate() + alive = true } override fun onBind(intent: Intent?) = null @@ -90,6 +99,7 @@ class TetheringService : Service(), VpnListener.Callback { override fun onDestroy() { unregisterReceiver() + alive = false super.onDestroy() }