diff options
| author | Albin <albin@mullvad.net> | 2023-10-16 09:17:32 +0200 |
|---|---|---|
| committer | Albin <albin@mullvad.net> | 2023-10-16 11:19:41 +0200 |
| commit | 55099af85627d4898b54e2ec48da6bdffa68c302 (patch) | |
| tree | 66a8b40cbe80e16dadbce59e9440c08b51b4ee3e /android | |
| parent | 65c8c9544fe5ef26960be51643e8d48eff07692c (diff) | |
| download | mullvadvpn-55099af85627d4898b54e2ec48da6bdffa68c302.tar.xz mullvadvpn-55099af85627d4898b54e2ec48da6bdffa68c302.zip | |
Use flavor configuration to set api endpoint
Diffstat (limited to 'android')
4 files changed, 43 insertions, 9 deletions
diff --git a/android/lib/endpoint/src/main/kotlin/net/mullvad/mullvadvpn/lib/endpoint/CustomApiEndpointConfiguration.kt b/android/lib/endpoint/src/main/kotlin/net/mullvad/mullvadvpn/lib/endpoint/CustomApiEndpointConfiguration.kt index ba79bdff62..9d2ba2420f 100644 --- a/android/lib/endpoint/src/main/kotlin/net/mullvad/mullvadvpn/lib/endpoint/CustomApiEndpointConfiguration.kt +++ b/android/lib/endpoint/src/main/kotlin/net/mullvad/mullvadvpn/lib/endpoint/CustomApiEndpointConfiguration.kt @@ -3,6 +3,8 @@ package net.mullvad.mullvadvpn.lib.endpoint import java.net.InetSocketAddress import kotlinx.parcelize.Parcelize +const val CUSTOM_ENDPOINT_HTTPS_PORT = 443 + @Parcelize data class CustomApiEndpointConfiguration( val hostname: String, diff --git a/android/service/build.gradle.kts b/android/service/build.gradle.kts index 156a35a3d8..6b9c76f0b3 100644 --- a/android/service/build.gradle.kts +++ b/android/service/build.gradle.kts @@ -32,9 +32,17 @@ android { create(Flavors.PROD) { dimension = FlavorDimensions.INFRASTRUCTURE isDefault = true + // Not used for production builds. + buildConfigField("String", "API_ENDPOINT", "\"\"") + } + create(Flavors.DEVMOLE) { + dimension = FlavorDimensions.INFRASTRUCTURE + buildConfigField("String", "API_ENDPOINT", "\"api.devmole.eu\"") + } + create(Flavors.STAGEMOLE) { + dimension = FlavorDimensions.INFRASTRUCTURE + buildConfigField("String", "API_ENDPOINT", "\"api.stagemole.eu\"") } - create(Flavors.DEVMOLE) { dimension = FlavorDimensions.INFRASTRUCTURE } - create(Flavors.STAGEMOLE) { dimension = FlavorDimensions.INFRASTRUCTURE } } } 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 cd05d5cc71..e714295d9c 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,14 +17,15 @@ import net.mullvad.mullvadvpn.lib.common.constant.KEY_DISCONNECT_ACTION import net.mullvad.mullvadvpn.lib.common.constant.KEY_QUIT_ACTION import net.mullvad.mullvadvpn.lib.common.constant.MAIN_ACTIVITY_CLASS import net.mullvad.mullvadvpn.lib.endpoint.ApiEndpointConfiguration -import net.mullvad.mullvadvpn.lib.endpoint.DefaultApiEndpointConfiguration import net.mullvad.mullvadvpn.lib.endpoint.getApiEndpointConfigurationExtras import net.mullvad.mullvadvpn.model.Settings import net.mullvad.mullvadvpn.model.TunnelState +import net.mullvad.mullvadvpn.service.di.apiEndpointModule import net.mullvad.mullvadvpn.service.di.vpnServiceModule import net.mullvad.mullvadvpn.service.endpoint.ServiceEndpoint import net.mullvad.mullvadvpn.service.notifications.AccountExpiryNotification import net.mullvad.talpid.TalpidVpnService +import org.koin.android.ext.android.get import org.koin.core.context.loadKoinModules class MullvadVpnService : TalpidVpnService() { @@ -58,8 +59,7 @@ class MullvadVpnService : TalpidVpnService() { endpoint.settingsListener.settings?.let { settings -> handlePendingAction(settings) } } - private var apiEndpointConfiguration: ApiEndpointConfiguration = - DefaultApiEndpointConfiguration() + private lateinit var apiEndpointConfiguration: ApiEndpointConfiguration // Suppressing since the tunnel state pref should be writted immediately. @SuppressLint("ApplySharedPref") @@ -67,7 +67,7 @@ class MullvadVpnService : TalpidVpnService() { super.onCreate() Log.d(TAG, "Initializing service") - loadKoinModules(vpnServiceModule) + loadKoinModules(listOf(vpnServiceModule, apiEndpointModule)) daemonInstance = DaemonInstance(this) keyguardManager = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager @@ -103,9 +103,14 @@ class MullvadVpnService : TalpidVpnService() { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { Log.d(TAG, "Starting service") - if (BuildConfig.DEBUG) { - intent?.getApiEndpointConfigurationExtras()?.let { apiEndpointConfiguration = it } - } + val intentProvidedConfiguration = + if (BuildConfig.DEBUG) { + intent?.getApiEndpointConfigurationExtras() + } else { + null + } + + apiEndpointConfiguration = intentProvidedConfiguration ?: get() daemonInstance.apply { intermittentDaemon.registerListener(this@MullvadVpnService) { daemon -> diff --git a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/di/ApiEndpointModule.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/di/ApiEndpointModule.kt new file mode 100644 index 0000000000..4d86559bc6 --- /dev/null +++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/di/ApiEndpointModule.kt @@ -0,0 +1,19 @@ +package net.mullvad.mullvadvpn.service.di + +import net.mullvad.mullvadvpn.lib.endpoint.ApiEndpointConfiguration +import net.mullvad.mullvadvpn.lib.endpoint.CUSTOM_ENDPOINT_HTTPS_PORT +import net.mullvad.mullvadvpn.lib.endpoint.CustomApiEndpointConfiguration +import net.mullvad.mullvadvpn.lib.endpoint.DefaultApiEndpointConfiguration +import net.mullvad.mullvadvpn.service.BuildConfig +import org.koin.dsl.bind +import org.koin.dsl.module + +val apiEndpointModule = module { + single { + if (BuildConfig.FLAVOR_infrastructure != "prod") { + CustomApiEndpointConfiguration(BuildConfig.API_ENDPOINT, CUSTOM_ENDPOINT_HTTPS_PORT) + } else { + DefaultApiEndpointConfiguration() + } + } bind ApiEndpointConfiguration::class +} |
