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 004732e5d0b0..99fafcab4377 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 @@ -28,6 +28,7 @@ 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.endpoint.ApiEndpointFromIntentHolder +import net.mullvad.mullvadvpn.lib.endpoint.getApiEndpointConfigurationExtras import net.mullvad.mullvadvpn.lib.model.PrepareError import net.mullvad.mullvadvpn.lib.model.Prepared import net.mullvad.mullvadvpn.lib.theme.AppTheme @@ -84,7 +85,7 @@ class MainActivity : ComponentActivity(), AndroidScopeComponent { window.decorView.filterTouchesWhenObscured = true // Needs to be before we start the service, since we need to access the intent there - setUpIntentListener() + lifecycleScope.launch { intents().collect(::handleIntent) } // We use lifecycleScope here to get less start service in background exceptions // Se this article for more information: @@ -129,15 +130,13 @@ class MainActivity : ComponentActivity(), AndroidScopeComponent { super.onDestroy() } - private fun setUpIntentListener() { - lifecycleScope.launch { - intents().collect { - if (it.action == KEY_REQUEST_VPN_PROFILE) { - handleRequestVpnProfileIntent() - } else { - apiEndpointFromIntentHolder.handleIntent(it) - } - } + private fun handleIntent(intent: Intent) { + if (intent.action == KEY_REQUEST_VPN_PROFILE) { + handleRequestVpnProfileIntent() + } else { + apiEndpointFromIntentHolder.setApiEndpointOverride( + intent.getApiEndpointConfigurationExtras() + ) } } 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 index 4561c08ff813..2de7e829dda6 100644 --- 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 @@ -1,12 +1,10 @@ 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() + fun setApiEndpointOverride(apiEndpointOverride: ApiEndpointOverride?) { + this.apiEndpointOverride = apiEndpointOverride } } 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 index 2e3d514db17f..9fa617276b5d 100644 --- 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 @@ -1,12 +1,11 @@ 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) { + @Suppress("UnusedParameter") + fun setApiEndpointOverride(apiEndpointOverride: ApiEndpointOverride?) { // No-op } }