Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use custom flavor endpoints #5294

Merged
merged 3 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/android-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ jobs:
arguments: |
testDebugUnitTest -x :test:arch:testDebugUnitTest
:app:testOssProdDebugUnitTest
:service:testOssDebugUnitTest
:service:testOssProdDebugUnitTest
gradle-version: wrapper
build-root-directory: android
execution-only-caches: true
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
)
}
15 changes: 15 additions & 0 deletions android/service/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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\"")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -58,16 +59,15 @@ 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")
override fun onCreate() {
super.onCreate()
Log.d(TAG, "Initializing service")

loadKoinModules(vpnServiceModule)
loadKoinModules(listOf(vpnServiceModule, apiEndpointModule))

daemonInstance = DaemonInstance(this)
keyguardManager = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
Expand Down Expand Up @@ -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 ->
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
}
}
Loading