diff options
| author | Markus Pettersson <markus.pettersson@mullvad.net> | 2024-06-11 15:37:43 +0200 |
|---|---|---|
| committer | Markus Pettersson <markus.pettersson@mullvad.net> | 2024-06-17 09:49:52 +0200 |
| commit | 5c16eff4b48c6e14b720b81e0b548c8b31d5a22e (patch) | |
| tree | 6a17f4c00b1997d4906fdbbea00700ef7d89ed4b /android | |
| parent | 9cba0d84ca508a7ac69442cb32b1660691704653 (diff) | |
| download | mullvadvpn-5c16eff4b48c6e14b720b81e0b548c8b31d5a22e.tar.xz mullvadvpn-5c16eff4b48c6e14b720b81e0b548c8b31d5a22e.zip | |
Get value of data directory value at app startup
Remove `APP_PATH` from `mullvad-paths` on Android since it should
not be a constant value. Instead, it is passed down from the Android app
startup. As it turns out, it is really ever used for pointing to the RPC
socket in use.
Diffstat (limited to 'android')
7 files changed, 32 insertions, 12 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/constant/PathConstant.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/constant/PathConstant.kt deleted file mode 100644 index 755e076721..0000000000 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/constant/PathConstant.kt +++ /dev/null @@ -1,3 +0,0 @@ -package net.mullvad.mullvadvpn.constant - -const val GRPC_SOCKET_FILE_NAME = "rpc-socket" diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/AppModule.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/AppModule.kt index a9853250f2..6af9ff57cb 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/AppModule.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/AppModule.kt @@ -1,8 +1,10 @@ package net.mullvad.mullvadvpn.di +import java.io.File import kotlinx.coroutines.MainScope import net.mullvad.mullvadvpn.BuildConfig -import net.mullvad.mullvadvpn.constant.GRPC_SOCKET_FILE_NAME +import net.mullvad.mullvadvpn.lib.common.constant.GRPC_SOCKET_FILE_NAME +import net.mullvad.mullvadvpn.lib.common.constant.GRPC_SOCKET_FILE_NAMED_ARGUMENT import net.mullvad.mullvadvpn.lib.daemon.grpc.ManagementService import net.mullvad.mullvadvpn.lib.intent.IntentProvider import net.mullvad.mullvadvpn.lib.model.BuildVersion @@ -15,10 +17,12 @@ import org.koin.core.qualifier.named import org.koin.dsl.module val appModule = module { - single(named(RPC_SOCKET_PATH)) { "${androidContext().dataDir.path}/$GRPC_SOCKET_FILE_NAME" } + single(named(GRPC_SOCKET_FILE_NAMED_ARGUMENT)) { + File(androidContext().noBackupFilesDir, GRPC_SOCKET_FILE_NAME) + } single { ManagementService( - rpcSocketPath = get(named(RPC_SOCKET_PATH)), + rpcSocketFile = get(named(GRPC_SOCKET_FILE_NAMED_ARGUMENT)), extensiveLogging = BuildConfig.DEBUG, scope = MainScope(), ) @@ -30,5 +34,3 @@ val appModule = module { single { VpnPermissionRepository(androidContext()) } single { ConnectionProxy(get(), get()) } } - -const val RPC_SOCKET_PATH = "RPC_SOCKET" diff --git a/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/constant/DiConstant.kt b/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/constant/DiConstant.kt new file mode 100644 index 0000000000..0acd41c7ec --- /dev/null +++ b/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/constant/DiConstant.kt @@ -0,0 +1,3 @@ +package net.mullvad.mullvadvpn.lib.common.constant + +const val GRPC_SOCKET_FILE_NAMED_ARGUMENT = "RPC_SOCKET" diff --git a/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/constant/PathConstant.kt b/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/constant/PathConstant.kt new file mode 100644 index 0000000000..4ad0471c86 --- /dev/null +++ b/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/constant/PathConstant.kt @@ -0,0 +1,3 @@ +package net.mullvad.mullvadvpn.lib.common.constant + +const val GRPC_SOCKET_FILE_NAME = "rpc-socket" diff --git a/android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/ManagementService.kt b/android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/ManagementService.kt index 987b7e56ea..10c2406850 100644 --- a/android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/ManagementService.kt +++ b/android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/ManagementService.kt @@ -16,6 +16,7 @@ import io.grpc.ConnectivityState import io.grpc.Status import io.grpc.StatusException import io.grpc.android.UdsChannelBuilder +import java.io.File import java.net.InetAddress import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -127,14 +128,19 @@ import net.mullvad.mullvadvpn.lib.model.wireguardConstraints @Suppress("TooManyFunctions") class ManagementService( - rpcSocketPath: String, + rpcSocketFile: File, private val extensiveLogging: Boolean, private val scope: CoroutineScope, ) { private var job: Job? = null + // We expect daemon to create the rpc socket file on the path provided on initialisation private val channel = - UdsChannelBuilder.forPath(rpcSocketPath, LocalSocketAddress.Namespace.FILESYSTEM).build() + UdsChannelBuilder.forPath( + rpcSocketFile.absolutePath, + LocalSocketAddress.Namespace.FILESYSTEM + ) + .build() val connectionState: StateFlow<GrpcConnectivityState> = channel 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 aa6f07e9bb..2c441483f6 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 @@ -17,6 +17,7 @@ private const val RELAYS_FILE = "relays.json" @SuppressLint("SdCardPath") class MullvadDaemon( vpnService: MullvadVpnService, + rpcSocketFile: File, apiEndpointConfiguration: ApiEndpointConfiguration, migrateSplitTunneling: MigrateSplitTunneling ) { @@ -34,8 +35,9 @@ class MullvadDaemon( initialize( vpnService = vpnService, + rpcSocketPath = rpcSocketFile.absolutePath, + filesDirectory = vpnService.filesDir.absolutePath, cacheDirectory = vpnService.cacheDir.absolutePath, - resourceDirectory = vpnService.filesDir.absolutePath, apiEndpoint = apiEndpointConfiguration.apiEndpoint() ) } @@ -69,8 +71,9 @@ class MullvadDaemon( private external fun initialize( vpnService: MullvadVpnService, + rpcSocketPath: String, + filesDirectory: String, cacheDirectory: String, - resourceDirectory: String, apiEndpoint: ApiEndpoint? ) diff --git a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt index e3940c8166..87f6076c3f 100644 --- a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt +++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt @@ -9,6 +9,7 @@ import android.util.Log import androidx.core.content.getSystemService import androidx.lifecycle.lifecycleScope import arrow.atomic.AtomicInt +import java.io.File import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow @@ -17,6 +18,7 @@ import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking +import net.mullvad.mullvadvpn.lib.common.constant.GRPC_SOCKET_FILE_NAMED_ARGUMENT import net.mullvad.mullvadvpn.lib.common.constant.KEY_CONNECT_ACTION import net.mullvad.mullvadvpn.lib.common.constant.KEY_DISCONNECT_ACTION import net.mullvad.mullvadvpn.lib.common.constant.TAG @@ -36,6 +38,7 @@ import net.mullvad.mullvadvpn.service.notifications.ShouldBeOnForegroundProvider import net.mullvad.talpid.TalpidVpnService import org.koin.android.ext.android.getKoin import org.koin.core.context.loadKoinModules +import org.koin.core.qualifier.named class MullvadVpnService : TalpidVpnService(), ShouldBeOnForegroundProvider { private val _shouldBeOnForeground = MutableStateFlow(false) @@ -49,6 +52,7 @@ class MullvadVpnService : TalpidVpnService(), ShouldBeOnForegroundProvider { private lateinit var migrateSplitTunneling: MigrateSplitTunneling private lateinit var intentProvider: IntentProvider private lateinit var connectionProxy: ConnectionProxy + private lateinit var rpcSocketFile: File private lateinit var foregroundNotificationHandler: ForegroundNotificationManager @@ -75,6 +79,7 @@ class MullvadVpnService : TalpidVpnService(), ShouldBeOnForegroundProvider { migrateSplitTunneling = get() intentProvider = get() connectionProxy = get() + rpcSocketFile = get(named(GRPC_SOCKET_FILE_NAMED_ARGUMENT)) } keyguardManager = getSystemService<KeyguardManager>()!! @@ -88,6 +93,7 @@ class MullvadVpnService : TalpidVpnService(), ShouldBeOnForegroundProvider { daemonInstance = MullvadDaemon( vpnService = this@MullvadVpnService, + rpcSocketFile = rpcSocketFile, apiEndpointConfiguration = intentProvider.getLatestIntent()?.getApiEndpointConfigurationExtras() ?: apiEndpointConfiguration, |
