diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2021-01-28 18:54:48 +0000 |
|---|---|---|
| committer | Aleksandr Granin <aleksandr@mullvad.net> | 2021-04-08 13:26:19 +0200 |
| commit | a74f982e7d6f65c264babc059d2a3cd2475668dc (patch) | |
| tree | b152ce1fb60131479e69251418c525a157f4bdf9 /android | |
| parent | 5007aac3ed193b07cc637d1931363a9352ee6458 (diff) | |
| download | mullvadvpn-a74f982e7d6f65c264babc059d2a3cd2475668dc.tar.xz mullvadvpn-a74f982e7d6f65c264babc059d2a3cd2475668dc.zip | |
Reduce exposed `SplitTunneling` service-side API
Diffstat (limited to 'android')
| -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() } |
