From 9b6464561a8a7c06d657504ba51a35f96517830a Mon Sep 17 00:00:00 2001 From: Jonatan Rhodin Date: Tue, 10 Dec 2024 22:57:56 +0100 Subject: [PATCH] Replace intentholder with api override intent holder --- android/app/build.gradle.kts | 1 - .../net/mullvad/mullvadvpn/di/AppModule.kt | 4 +-- .../net/mullvad/mullvadvpn/ui/MainActivity.kt | 6 ++-- .../endpoint/ApiEndpointFromIntentHolder.kt | 12 +++++++ .../endpoint/ApiEndpointFromIntentHolder.kt | 12 +++++++ android/lib/intent-provider/build.gradle.kts | 35 ------------------- .../src/main/AndroidManifest.xml | 1 - .../mullvadvpn/lib/intent/IntentProvider.kt | 14 -------- android/service/build.gradle.kts | 1 - .../mullvadvpn/service/MullvadVpnService.kt | 10 +++--- android/settings.gradle.kts | 1 - 11 files changed, 33 insertions(+), 64 deletions(-) create mode 100644 android/lib/endpoint/src/debug/kotlin/net/mullvad/mullvadvpn/lib/endpoint/ApiEndpointFromIntentHolder.kt create mode 100644 android/lib/endpoint/src/release/kotlin/net/mullvad/mullvadvpn/lib/endpoint/ApiEndpointFromIntentHolder.kt delete mode 100644 android/lib/intent-provider/build.gradle.kts delete mode 100644 android/lib/intent-provider/src/main/AndroidManifest.xml delete mode 100644 android/lib/intent-provider/src/main/kotlin/net/mullvad/mullvadvpn/lib/intent/IntentProvider.kt diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index d62df346450f..8e252e1fc6a5 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -328,7 +328,6 @@ dependencies { implementation(projects.lib.common) implementation(projects.lib.daemonGrpc) implementation(projects.lib.endpoint) - implementation(projects.lib.intentProvider) implementation(projects.lib.map) implementation(projects.lib.model) implementation(projects.lib.payment) 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 9c52677dce8d..d7a1bfc8cb56 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 @@ -6,7 +6,7 @@ import net.mullvad.mullvadvpn.BuildConfig 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.endpoint.ApiEndpointFromIntentHolder import net.mullvad.mullvadvpn.lib.model.BuildVersion import net.mullvad.mullvadvpn.lib.shared.AccountRepository import net.mullvad.mullvadvpn.lib.shared.ConnectionProxy @@ -33,7 +33,7 @@ val appModule = module { single { PrepareVpnUseCase(androidContext()) } single { BuildVersion(BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE) } - single { IntentProvider() } + single { ApiEndpointFromIntentHolder() } single { AccountRepository(get(), get(), MainScope()) } single { DeviceRepository(get()) } single { ConnectionProxy(get(), get(), get()) } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt index 134816417f64..004732e5d0b0 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt @@ -27,7 +27,7 @@ import net.mullvad.mullvadvpn.lib.common.util.SdkUtils.requestNotificationPermis import net.mullvad.mullvadvpn.lib.common.util.prepareVpnSafe import net.mullvad.mullvadvpn.lib.daemon.grpc.GrpcConnectivityState import net.mullvad.mullvadvpn.lib.daemon.grpc.ManagementService -import net.mullvad.mullvadvpn.lib.intent.IntentProvider +import net.mullvad.mullvadvpn.lib.endpoint.ApiEndpointFromIntentHolder import net.mullvad.mullvadvpn.lib.model.PrepareError import net.mullvad.mullvadvpn.lib.model.Prepared import net.mullvad.mullvadvpn.lib.theme.AppTheme @@ -51,7 +51,7 @@ class MainActivity : ComponentActivity(), AndroidScopeComponent { private val launchVpnPermission = registerForActivityResult(CreateVpnProfile()) { _ -> mullvadAppViewModel.connect() } - private val intentProvider by inject() + private val apiEndpointFromIntentHolder by inject() private val mullvadAppViewModel by inject() private val privacyDisclaimerRepository by inject() private val serviceConnectionManager by inject() @@ -135,7 +135,7 @@ class MainActivity : ComponentActivity(), AndroidScopeComponent { if (it.action == KEY_REQUEST_VPN_PROFILE) { handleRequestVpnProfileIntent() } else { - intentProvider.setStartIntent(it) + apiEndpointFromIntentHolder.handleIntent(it) } } } diff --git a/android/lib/endpoint/src/debug/kotlin/net/mullvad/mullvadvpn/lib/endpoint/ApiEndpointFromIntentHolder.kt b/android/lib/endpoint/src/debug/kotlin/net/mullvad/mullvadvpn/lib/endpoint/ApiEndpointFromIntentHolder.kt new file mode 100644 index 000000000000..4561c08ff813 --- /dev/null +++ b/android/lib/endpoint/src/debug/kotlin/net/mullvad/mullvadvpn/lib/endpoint/ApiEndpointFromIntentHolder.kt @@ -0,0 +1,12 @@ +package net.mullvad.mullvadvpn.lib.endpoint + +import android.content.Intent + +class ApiEndpointFromIntentHolder { + var apiEndpointOverride: ApiEndpointOverride? = null + private set + + fun handleIntent(intent: Intent) { + apiEndpointOverride = intent.getApiEndpointConfigurationExtras() + } +} diff --git a/android/lib/endpoint/src/release/kotlin/net/mullvad/mullvadvpn/lib/endpoint/ApiEndpointFromIntentHolder.kt b/android/lib/endpoint/src/release/kotlin/net/mullvad/mullvadvpn/lib/endpoint/ApiEndpointFromIntentHolder.kt new file mode 100644 index 000000000000..2e3d514db17f --- /dev/null +++ b/android/lib/endpoint/src/release/kotlin/net/mullvad/mullvadvpn/lib/endpoint/ApiEndpointFromIntentHolder.kt @@ -0,0 +1,12 @@ +package net.mullvad.mullvadvpn.lib.endpoint + +import android.content.Intent + +// Overridding the API endpoint is not supported in release builds +class ApiEndpointFromIntentHolder { + val apiEndpointOverride: ApiEndpointOverride? = null + + fun handleIntent(intent: Intent) { + // No-op + } +} diff --git a/android/lib/intent-provider/build.gradle.kts b/android/lib/intent-provider/build.gradle.kts deleted file mode 100644 index 66c9b6ff7490..000000000000 --- a/android/lib/intent-provider/build.gradle.kts +++ /dev/null @@ -1,35 +0,0 @@ -plugins { - alias(libs.plugins.android.library) - alias(libs.plugins.kotlin.android) - alias(libs.plugins.kotlin.parcelize) -} - -android { - namespace = "net.mullvad.mullvadvpn.lib.intent" - compileSdk = Versions.compileSdkVersion - buildToolsVersion = Versions.buildToolsVersion - - defaultConfig { minSdk = Versions.minSdkVersion } - - compileOptions { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 - } - - kotlinOptions { - jvmTarget = Versions.jvmTarget - allWarningsAsErrors = true - } - - lint { - lintConfig = file("${rootProject.projectDir}/config/lint.xml") - abortOnError = true - warningsAsErrors = true - } - buildFeatures { buildConfig = true } -} - -dependencies { - implementation(libs.kotlin.stdlib) - implementation(libs.kotlinx.coroutines.android) -} diff --git a/android/lib/intent-provider/src/main/AndroidManifest.xml b/android/lib/intent-provider/src/main/AndroidManifest.xml deleted file mode 100644 index cc947c567995..000000000000 --- a/android/lib/intent-provider/src/main/AndroidManifest.xml +++ /dev/null @@ -1 +0,0 @@ - diff --git a/android/lib/intent-provider/src/main/kotlin/net/mullvad/mullvadvpn/lib/intent/IntentProvider.kt b/android/lib/intent-provider/src/main/kotlin/net/mullvad/mullvadvpn/lib/intent/IntentProvider.kt deleted file mode 100644 index bd6e716d8dbd..000000000000 --- a/android/lib/intent-provider/src/main/kotlin/net/mullvad/mullvadvpn/lib/intent/IntentProvider.kt +++ /dev/null @@ -1,14 +0,0 @@ -package net.mullvad.mullvadvpn.lib.intent - -import android.content.Intent -import kotlinx.coroutines.flow.MutableStateFlow - -class IntentProvider { - private val _intents = MutableStateFlow(null) - - fun setStartIntent(intent: Intent?) { - _intents.tryEmit(intent) - } - - fun getLatestIntent(): Intent? = _intents.value -} diff --git a/android/service/build.gradle.kts b/android/service/build.gradle.kts index 8d8ffd22194b..717e2c6ef781 100644 --- a/android/service/build.gradle.kts +++ b/android/service/build.gradle.kts @@ -56,7 +56,6 @@ dependencies { implementation(projects.lib.common) implementation(projects.lib.daemonGrpc) implementation(projects.lib.endpoint) - implementation(projects.lib.intentProvider) implementation(projects.lib.model) implementation(projects.lib.shared) implementation(projects.lib.talpid) 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 458f592f1b85..e4c8eba3c60c 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 @@ -17,8 +17,7 @@ import kotlinx.coroutines.runBlocking 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.daemon.grpc.ManagementService -import net.mullvad.mullvadvpn.lib.endpoint.getApiEndpointConfigurationExtras -import net.mullvad.mullvadvpn.lib.intent.IntentProvider +import net.mullvad.mullvadvpn.lib.endpoint.ApiEndpointFromIntentHolder import net.mullvad.mullvadvpn.lib.model.TunnelState import net.mullvad.mullvadvpn.lib.shared.ConnectionProxy import net.mullvad.mullvadvpn.service.di.vpnServiceModule @@ -39,7 +38,7 @@ class MullvadVpnService : TalpidVpnService() { private lateinit var managementService: ManagementService private lateinit var migrateSplitTunneling: MigrateSplitTunneling - private lateinit var intentProvider: IntentProvider + private lateinit var apiEndpointFromIntentHolder: ApiEndpointFromIntentHolder private lateinit var connectionProxy: ConnectionProxy private lateinit var daemonConfig: DaemonConfig @@ -66,7 +65,7 @@ class MullvadVpnService : TalpidVpnService() { daemonConfig = get() migrateSplitTunneling = get() - intentProvider = get() + apiEndpointFromIntentHolder = get() connectionProxy = get() } @@ -77,8 +76,7 @@ class MullvadVpnService : TalpidVpnService() { // If it is a debug build and we have an api override in the intent, use it // This is for injecting hostname and port for our mock api tests - val intentApiOverride = - intentProvider.getLatestIntent()?.getApiEndpointConfigurationExtras() + val intentApiOverride = apiEndpointFromIntentHolder.apiEndpointOverride val updatedConfig = if (BuildConfig.DEBUG && intentApiOverride != null) { daemonConfig.copy(apiEndpointOverride = intentApiOverride) diff --git a/android/settings.gradle.kts b/android/settings.gradle.kts index 7aa90a373f49..7e49d4cb9294 100644 --- a/android/settings.gradle.kts +++ b/android/settings.gradle.kts @@ -21,7 +21,6 @@ include( ":lib:common-test", ":lib:daemon-grpc", ":lib:endpoint", - ":lib:intent-provider", ":lib:map", ":lib:model", ":lib:payment",