diff options
Diffstat (limited to 'android/src')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/SplitTunneling.kt | 30 |
1 files changed, 8 insertions, 22 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/SplitTunneling.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/SplitTunneling.kt index 906b5f2a2a..2a704c74a2 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/SplitTunneling.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/SplitTunneling.kt @@ -19,12 +19,12 @@ class SplitTunneling(context: Context, endpoint: ServiceEndpoint) { private val excludedApps = HashSet<String>() private val preferences = context.getSharedPreferences(SHARED_PREFERENCES, Context.MODE_PRIVATE) - val onChange = EventNotifier<List<String>?>(null) - - var enabled by observable(preferences.getBoolean(KEY_ENABLED, false)) { _, _, _ -> + private var enabled by observable(preferences.getBoolean(KEY_ENABLED, false)) { _, _, _ -> enabledChanged() } + val onChange = EventNotifier<List<String>?>(null) + init { if (appListFile.exists()) { excludedApps.addAll(appListFile.readLines()) @@ -37,11 +37,13 @@ class SplitTunneling(context: Context, endpoint: ServiceEndpoint) { endpoint.dispatcher.apply { registerHandler(Request.IncludeApp::class) { request -> - includeApp(request.packageName) + excludedApps.remove(request.packageName) + update() } registerHandler(Request.ExcludeApp::class) { request -> - excludeApp(request.packageName) + excludedApps.add(request.packageName) + update() } registerHandler(Request.SetEnableSplitTunneling::class) { request -> @@ -49,27 +51,11 @@ class SplitTunneling(context: Context, endpoint: ServiceEndpoint) { } registerHandler(Request.PersistExcludedApps::class) { _ -> - persist() + appListFile.writeText(excludedApps.joinToString(separator = "\n")) } } } - fun isAppExcluded(appPackageName: String) = excludedApps.contains(appPackageName) - - fun excludeApp(appPackageName: String) { - excludedApps.add(appPackageName) - update() - } - - fun includeApp(appPackageName: String) { - excludedApps.remove(appPackageName) - update() - } - - fun persist() { - appListFile.writeText(excludedApps.joinToString(separator = "\n")) - } - fun onDestroy() { onChange.unsubscribeAll() } |
