summaryrefslogtreecommitdiffhomepage
path: root/android
diff options
context:
space:
mode:
authorKalle Lindström <karl.lindstrom@mullvad.net>2025-08-07 09:12:51 +0200
committerKalle Lindström <karl.lindstrom@mullvad.net>2025-08-14 10:11:48 +0200
commit4e489750035e5d153cd833fbc6d50782df66241a (patch)
tree47cccac589c921c5c9b1c22a1a4a8c968df52dd3 /android
parentfe53ad976eb77fffbc845710804e0abd53e99904 (diff)
downloadmullvadvpn-4e489750035e5d153cd833fbc6d50782df66241a.tar.xz
mullvadvpn-4e489750035e5d153cd833fbc6d50782df66241a.zip
Set relay to current country on first start
Sets the default relay selection to the current country (as determined by am.i.mullvad.net). If the current country does not have any relays the country with the closest relay is choosen instead. In non-release builds of the Android app we do not bundle a relay list in the APK, and the relay list is fetched when the user logs in. So one of the following can happen: 1. Geolocation request returns, we have a relay list. 2. Geolocation request returns, we do not yet have a relay list. 3. Relay list request returns, we have a geolocation. 4. Relay list request returns, we do not have a geolocation. In 1. and 3. we can update the default location. In 2. we have to wait until the relay list is fetched from the api until we can update the default location. 4. is unlikely to happen but could happen if am.i.mullvad is down.
Diffstat (limited to 'android')
-rw-r--r--android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/DefaultLocationTest.kt44
1 files changed, 44 insertions, 0 deletions
diff --git a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/DefaultLocationTest.kt b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/DefaultLocationTest.kt
new file mode 100644
index 0000000000..935e1a28a5
--- /dev/null
+++ b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/DefaultLocationTest.kt
@@ -0,0 +1,44 @@
+package net.mullvad.mullvadvpn.test.e2e
+
+import java.io.File
+import net.mullvad.mullvadvpn.test.common.page.ConnectPage
+import net.mullvad.mullvadvpn.test.common.page.LoginPage
+import net.mullvad.mullvadvpn.test.common.page.on
+import net.mullvad.mullvadvpn.test.e2e.misc.AccountTestRule
+import org.json.JSONObject
+import org.junit.jupiter.api.Assertions.assertFalse
+import org.junit.jupiter.api.Test
+import org.junit.jupiter.api.extension.RegisterExtension
+
+class DefaultLocationTest : EndToEndTest() {
+
+ @RegisterExtension @JvmField val accountTestRule = AccountTestRule()
+
+ @Test
+ fun testUpdateDefaultLocationFlag() {
+ app.launchAndEnsureOnLoginPage()
+
+ // The update_default_location flag should be set to true when first starting the app
+ assert(readUpdateDefaultLocationKeyFromSettings())
+
+ on<LoginPage> {
+ enterAccountNumber(accountTestRule.validAccountNumber)
+ clickLoginButton()
+ }
+
+ on<ConnectPage>()
+
+ // After we have logged in the daemon will have set the new default location so the
+ // flag should be false.
+ assertFalse(readUpdateDefaultLocationKeyFromSettings())
+ }
+
+ private fun readUpdateDefaultLocationKeyFromSettings(): Boolean {
+ val settings = File(targetApplication.filesDir, "settings.json")
+ if (!settings.isFile()) error("settings.json does not exist")
+
+ val text = settings.readText()
+ val json = JSONObject(text)
+ return json.getBoolean("update_default_location")
+ }
+}