diff options
| author | Jonatan Rhodin <jonatan.rhodin@mullvad.net> | 2024-02-07 23:23:41 +0100 |
|---|---|---|
| committer | Jonatan Rhodin <jonatan.rhodin@mullvad.net> | 2024-02-08 10:50:58 +0100 |
| commit | a969af0ed6c820d47f15d66009ec38926159288b (patch) | |
| tree | 108cae0406c0881575e17eb55a79cdb943d25142 /android | |
| parent | 066742e2ba964b9b651c6b88e2ca840bdf47d89a (diff) | |
| download | mullvadvpn-a969af0ed6c820d47f15d66009ec38926159288b.tar.xz mullvadvpn-a969af0ed6c820d47f15d66009ec38926159288b.zip | |
Add custom lists to the service
Diffstat (limited to 'android')
4 files changed, 72 insertions, 7 deletions
diff --git a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt index 52e662c771..d09287fbf2 100644 --- a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt +++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt @@ -5,6 +5,7 @@ import kotlinx.coroutines.flow.asSharedFlow import net.mullvad.mullvadvpn.lib.endpoint.ApiEndpoint import net.mullvad.mullvadvpn.lib.endpoint.ApiEndpointConfiguration import net.mullvad.mullvadvpn.model.AppVersionInfo +import net.mullvad.mullvadvpn.model.CustomList import net.mullvad.mullvadvpn.model.Device import net.mullvad.mullvadvpn.model.DeviceEvent import net.mullvad.mullvadvpn.model.DeviceListEvent @@ -189,6 +190,18 @@ class MullvadDaemon( setQuantumResistantTunnel(daemonInterfaceAddress, quantumResistant) } + fun createCustomList(name: String): String { + return createCustomList(daemonInterfaceAddress, name) + } + + fun deleteCustomList(id: String) { + deleteCustomList(daemonInterfaceAddress, id) + } + + fun updateCustomList(customList: CustomList) { + updateCustomList(daemonInterfaceAddress, customList) + } + fun onDestroy() { onSettingsChange.unsubscribeAll() onTunnelStateChange.unsubscribeAll() @@ -297,6 +310,13 @@ class MullvadDaemon( ) // Used by JNI + + private external fun createCustomList(daemonInterfaceAddress: Long, name: String): String + + private external fun deleteCustomList(daemonInterfaceAddress: Long, id: String) + + private external fun updateCustomList(daemonInterfaceAddress: Long, customList: CustomList) + @Suppress("unused") private fun notifyAppVersionInfoEvent(appVersionInfo: AppVersionInfo) { onAppVersionInfoChange?.invoke(appVersionInfo) diff --git a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/CustomLists.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/CustomLists.kt new file mode 100644 index 0000000000..d80bcf04ff --- /dev/null +++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/CustomLists.kt @@ -0,0 +1,49 @@ +package net.mullvad.mullvadvpn.service.endpoint + +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.SupervisorJob +import kotlinx.coroutines.cancel +import kotlinx.coroutines.flow.filterIsInstance +import kotlinx.coroutines.launch +import net.mullvad.mullvadvpn.lib.ipc.Event +import net.mullvad.mullvadvpn.lib.ipc.Request + +class CustomLists( + private val endpoint: ServiceEndpoint, + dispatcher: CoroutineDispatcher = Dispatchers.IO +) { + private val scope: CoroutineScope = CoroutineScope(SupervisorJob() + dispatcher) + private val daemon + get() = endpoint.intermittentDaemon + + init { + scope.launch { + endpoint.dispatcher.parsedMessages + .filterIsInstance<Request.CreateCustomList>() + .collect { createCustomList(it.name) } + } + + scope.launch { + endpoint.dispatcher.parsedMessages + .filterIsInstance<Request.DeleteCustomList>() + .collect { daemon.await().deleteCustomList(it.id) } + } + + scope.launch { + endpoint.dispatcher.parsedMessages + .filterIsInstance<Request.UpdateCustomList>() + .collect { daemon.await().updateCustomList(it.customList) } + } + } + + private suspend fun createCustomList(name: String) { + val result = daemon.await().createCustomList(name) + endpoint.sendEvent(Event.CreateCustomListResult(result)) + } + + fun onDestroy() { + scope.cancel() + } +} diff --git a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/RelayListListener.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/RelayListListener.kt index 2f18c09064..8ba6234cf6 100644 --- a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/RelayListListener.kt +++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/RelayListListener.kt @@ -11,7 +11,6 @@ import kotlinx.coroutines.launch import net.mullvad.mullvadvpn.lib.ipc.Event import net.mullvad.mullvadvpn.lib.ipc.Request import net.mullvad.mullvadvpn.model.Constraint -import net.mullvad.mullvadvpn.model.LocationConstraint import net.mullvad.mullvadvpn.model.RelayConstraints import net.mullvad.mullvadvpn.model.RelayList import net.mullvad.mullvadvpn.model.RelaySettings @@ -45,12 +44,7 @@ class RelayListListener( .collect { request -> val update = getCurrentRelayConstraints() - .copy( - location = - Constraint.Only( - LocationConstraint.Location(request.relayLocation) - ) - ) + .copy(location = Constraint.Only(request.locationConstraint)) daemon.await().setRelaySettings(RelaySettings.Normal(update)) } } diff --git a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ServiceEndpoint.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ServiceEndpoint.kt index 09fc73e5d3..5485c528b0 100644 --- a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ServiceEndpoint.kt +++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ServiceEndpoint.kt @@ -51,6 +51,7 @@ class ServiceEndpoint( val voucherRedeemer = VoucherRedeemer(this, accountCache) private val playPurchaseHandler = PlayPurchaseHandler(this) + private val customLists = CustomLists(this) private val deviceRepositoryBackend = DaemonDeviceDataSource(this) @@ -81,6 +82,7 @@ class ServiceEndpoint( splitTunneling.onDestroy() voucherRedeemer.onDestroy() playPurchaseHandler.onDestroy() + customLists.onDestroy() } internal fun sendEvent(event: Event) { |
