summaryrefslogtreecommitdiffhomepage
path: root/android
diff options
context:
space:
mode:
Diffstat (limited to 'android')
-rw-r--r--android/lib/endpoint/src/debug/kotlin/net/mullvad/mullvadvpn/lib/endpoint/CustomApiEndpointConfiguration.kt8
-rw-r--r--android/lib/endpoint/src/main/kotlin/net/mullvad/mullvadvpn/lib/endpoint/CustomApiEndpointConfiguration.kt23
-rw-r--r--android/service/build.gradle.kts15
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt19
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/di/ApiEndpointModule.kt19
-rw-r--r--android/test/mockapi/src/main/kotlin/net/mullvad/mullvadvpn/test/mockapi/MockApiTest.kt18
6 files changed, 76 insertions, 26 deletions
diff --git a/android/lib/endpoint/src/debug/kotlin/net/mullvad/mullvadvpn/lib/endpoint/CustomApiEndpointConfiguration.kt b/android/lib/endpoint/src/debug/kotlin/net/mullvad/mullvadvpn/lib/endpoint/CustomApiEndpointConfiguration.kt
deleted file mode 100644
index 5fb8db5fe1..0000000000
--- a/android/lib/endpoint/src/debug/kotlin/net/mullvad/mullvadvpn/lib/endpoint/CustomApiEndpointConfiguration.kt
+++ /dev/null
@@ -1,8 +0,0 @@
-package net.mullvad.mullvadvpn.lib.endpoint
-
-import kotlinx.parcelize.Parcelize
-
-@Parcelize
-data class CustomApiEndpointConfiguration(val apiEndpoint: ApiEndpoint) : ApiEndpointConfiguration {
- override fun apiEndpoint() = apiEndpoint
-}
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
new file mode 100644
index 0000000000..9d2ba2420f
--- /dev/null
+++ b/android/lib/endpoint/src/main/kotlin/net/mullvad/mullvadvpn/lib/endpoint/CustomApiEndpointConfiguration.kt
@@ -0,0 +1,23 @@
+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,
+ val port: Int,
+ val disableAddressCache: Boolean = false,
+ val disableTls: Boolean = false,
+ val forceDirectConnection: Boolean = false
+) : ApiEndpointConfiguration {
+ override fun apiEndpoint() =
+ ApiEndpoint(
+ address = InetSocketAddress(hostname, port),
+ disableAddressCache = disableAddressCache,
+ disableTls = disableTls,
+ forceDirectConnection = forceDirectConnection
+ )
+}
diff --git a/android/service/build.gradle.kts b/android/service/build.gradle.kts
index bbdb862cf3..6b9c76f0b3 100644
--- a/android/service/build.gradle.kts
+++ b/android/service/build.gradle.kts
@@ -24,10 +24,25 @@ android {
}
flavorDimensions += FlavorDimensions.BILLING
+ flavorDimensions += FlavorDimensions.INFRASTRUCTURE
productFlavors {
create(Flavors.OSS) { dimension = FlavorDimensions.BILLING }
create(Flavors.PLAY) { dimension = FlavorDimensions.BILLING }
+ 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\"")
+ }
}
}
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
+}
diff --git a/android/test/mockapi/src/main/kotlin/net/mullvad/mullvadvpn/test/mockapi/MockApiTest.kt b/android/test/mockapi/src/main/kotlin/net/mullvad/mullvadvpn/test/mockapi/MockApiTest.kt
index bb5c20eebb..f699b3cadc 100644
--- a/android/test/mockapi/src/main/kotlin/net/mullvad/mullvadvpn/test/mockapi/MockApiTest.kt
+++ b/android/test/mockapi/src/main/kotlin/net/mullvad/mullvadvpn/test/mockapi/MockApiTest.kt
@@ -9,8 +9,6 @@ import androidx.test.rule.GrantPermissionRule
import androidx.test.runner.AndroidJUnit4
import androidx.test.uiautomator.UiDevice
import java.net.InetAddress
-import java.net.InetSocketAddress
-import net.mullvad.mullvadvpn.lib.endpoint.ApiEndpoint
import net.mullvad.mullvadvpn.lib.endpoint.CustomApiEndpointConfiguration
import net.mullvad.mullvadvpn.test.common.interactor.AppInteractor
import net.mullvad.mullvadvpn.test.common.rule.CaptureScreenshotOnFailedTestRule
@@ -57,14 +55,12 @@ abstract class MockApiTest {
}
private fun createEndpoint(port: Int): CustomApiEndpointConfiguration {
- val mockApiSocket = InetSocketAddress(InetAddress.getLocalHost(), port)
- val api =
- ApiEndpoint(
- address = mockApiSocket,
- disableAddressCache = true,
- disableTls = true,
- forceDirectConnection = true
- )
- return CustomApiEndpointConfiguration(api)
+ return CustomApiEndpointConfiguration(
+ InetAddress.getLocalHost().hostName,
+ port,
+ disableAddressCache = true,
+ disableTls = true,
+ forceDirectConnection = true
+ )
}
}