Skip to content

Commit 5e8dfc2

Browse files
committedMar 7, 2025
Merge branch 'improve-error-text-for-android-12-and-above-when-we-are-droid-1857'
2 parents 32fd95f + 8354eb4 commit 5e8dfc2

File tree

25 files changed

+45
-51
lines changed

25 files changed

+45
-51
lines changed
 

‎android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModel.kt

+2
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ class ConnectViewModel(
160160
if (hasVpnPermission) {
161161
connectionProxy.connect()
162162
} else {
163+
// Either the user denied the permission or another always-on-vpn is active (if
164+
// Android 11+ and run from Android Studio)
163165
_uiSideEffect.send(UiSideEffect.ConnectError.PermissionDenied)
164166
}
165167
}

‎android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/ContextExtensions.kt

-13
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@ package net.mullvad.mullvadvpn.lib.common.util
33
import android.content.Context
44
import android.content.Intent
55
import android.net.Uri
6-
import android.provider.Settings
76
import net.mullvad.mullvadvpn.lib.model.WebsiteAuthToken
87

9-
private const val ALWAYS_ON_VPN_APP = "always_on_vpn_app"
10-
118
fun createAccountUri(accountUri: String, websiteAuthToken: WebsiteAuthToken?): Uri {
129
val urlString = buildString {
1310
append(accountUri)
@@ -19,16 +16,6 @@ fun createAccountUri(accountUri: String, websiteAuthToken: WebsiteAuthToken?): U
1916
return Uri.parse(urlString)
2017
}
2118

22-
// NOTE: This function will return the current Always-on VPN package's name. In case of either
23-
// Always-on VPN being disabled or not being able to read the state, NULL will be returned.
24-
fun Context.resolveAlwaysOnVpnPackageName(): String? {
25-
return try {
26-
Settings.Secure.getString(contentResolver, ALWAYS_ON_VPN_APP)
27-
} catch (ex: SecurityException) {
28-
null
29-
}
30-
}
31-
3219
fun Context.openVpnSettings() {
3320
val intent = Intent("android.settings.VPN_SETTINGS")
3421
startActivity(intent)

‎android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/VpnServiceUtils.kt

+39-16
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import android.content.Context
44
import android.content.Intent
55
import android.net.VpnService
66
import android.net.VpnService.prepare
7+
import android.os.Build
78
import android.os.ParcelFileDescriptor
9+
import android.provider.Settings
10+
import androidx.annotation.DeprecatedSinceApi
811
import arrow.core.Either
912
import arrow.core.flatMap
1013
import arrow.core.left
@@ -22,8 +25,9 @@ import net.mullvad.mullvadvpn.lib.model.Prepared
2225
* Invoking VpnService.prepare() can result in 3 out comes:
2326
* 1. IllegalStateException - There is a legacy VPN profile marked as always on
2427
* 2. Intent
25-
* - A: Can-prepare - Create Vpn profile
26-
* - B: Always-on-VPN - Another Vpn Profile is marked as always on
28+
* - A: Can-prepare - Create Vpn profile or Always-on-VPN is not detected in case of Android 11+
29+
* - B: Always-on-VPN - Another Vpn Profile is marked as always on (Only available up to Android
30+
* 11 or where testOnly is set, e.g builds from Android Studio)
2731
* 3. null - The app has the VPN permission
2832
*
2933
* In case 1 and 2b, you don't know if you have a VPN profile or not.
@@ -44,25 +48,44 @@ fun Context.prepareVpnSafe(): Either<PrepareError, Prepared> =
4448
if (intent == null) {
4549
Prepared.right()
4650
} else {
47-
val alwaysOnVpnApp = getAlwaysOnVpnAppName()
48-
if (alwaysOnVpnApp == null) {
49-
PrepareError.NotPrepared(intent).left()
50-
} else {
51-
PrepareError.OtherAlwaysOnApp(alwaysOnVpnApp).left()
51+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
52+
val alwaysOnVpnApp = getOtherAlwaysOnVpnAppName()
53+
if (alwaysOnVpnApp != null) {
54+
return@flatMap PrepareError.OtherAlwaysOnApp(alwaysOnVpnApp).left()
55+
}
5256
}
57+
return@flatMap PrepareError.NotPrepared(intent).left()
5358
}
5459
}
5560

56-
fun Context.getAlwaysOnVpnAppName(): String? {
57-
return resolveAlwaysOnVpnPackageName()
58-
?.let { currentAlwaysOnVpn ->
59-
packageManager.getInstalledPackagesList(0).singleOrNull {
60-
it.packageName == currentAlwaysOnVpn && it.packageName != packageName
61-
}
61+
private const val ALWAYS_ON_VPN_APP = "always_on_vpn_app"
62+
63+
// NOTE: This function will return the current Always-on VPN package's name. In case of either
64+
// Always-on VPN being disabled or not being able to read the state, null will be returned.
65+
//
66+
// Caveat: For Android 11+ it will always return null unless the app is a test build (e.g running
67+
// from Android Studio).
68+
@DeprecatedSinceApi(Build.VERSION_CODES.S)
69+
fun Context.getOtherAlwaysOnVpnAppName(): String? {
70+
val currentAlwaysOnPackageName =
71+
try {
72+
Settings.Secure.getString(contentResolver, ALWAYS_ON_VPN_APP)
73+
} catch (ex: SecurityException) {
74+
return null
6275
}
63-
?.applicationInfo
64-
?.loadLabel(packageManager)
65-
?.toString()
76+
77+
// If we are the current Always-on VPN app, we return null
78+
return if (currentAlwaysOnPackageName == packageName) {
79+
null
80+
} else {
81+
// Resolve package name to app name
82+
packageManager
83+
.getInstalledPackagesList(0)
84+
.firstOrNull { it.packageName == currentAlwaysOnPackageName }
85+
?.applicationInfo
86+
?.loadLabel(packageManager)
87+
?.toString()
88+
}
6689
}
6790

6891
/**

‎android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/PrepareError.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ sealed interface PrepareError : PrepareResult {
88
// Legacy VPN profile is active as Always-on
99
data object OtherLegacyAlwaysOnVpn : PrepareError
1010

11-
// Another VPN app is active as Always-on
11+
// Another VPN app is active as Always-on (Only works up to Android 11 or debug builds)
1212
data class OtherAlwaysOnApp(val appName: String) : PrepareError
1313

14+
// VPN profile can be created or Always-on VPN is active but not detected
1415
data class NotPrepared(val prepareIntent: Intent) : PrepareError
1516
}
1617

‎android/lib/resource/src/main/res/values-da/strings.xml

-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@
378378
<string name="voucher_already_used">Kuponkode er allerede brugt.</string>
379379
<string name="voucher_is_account_number">Det ser ud til, at du har indtastet et kontonummer i stedet for en rabatkuponkode. Hvis du vil ændre den aktive konto, skal du først logge ud.</string>
380380
<string name="voucher_success_title">Indløsning af kuponen lykkedes.</string>
381-
<string name="vpn_permission_denied_error">VPN-tilladelse blev nægtet, da tunnelen blev oprettet. Prøv at oprette forbindelse igen.</string>
382381
<string name="vpn_permission_error_notification_message">Tryk på Opret forbindelse for at anmode om VPN-tilladelse</string>
383382
<string name="vpn_permission_error_notification_title">VPN-tilladelsesfejl</string>
384383
<string name="we_will_look_into_this">Vi vil undersøge dette.</string>

‎android/lib/resource/src/main/res/values-de/strings.xml

-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@
378378
<string name="voucher_already_used">Der Gutscheincode wurde bereits verwendet.</string>
379379
<string name="voucher_is_account_number">Anscheinend haben Sie eine Kontonummer statt eines Gutscheincodes eingegeben. Wenn Sie das aktive Konto wechseln möchten, melden Sie sich bitte zuerst ab.</string>
380380
<string name="voucher_success_title">Der Gutschein wurde erfolgreich eingelöst.</string>
381-
<string name="vpn_permission_denied_error">VPN-Berechtigungen wurden beim Erstellen des Tunnels abgelehnt.</string>
382381
<string name="vpn_permission_error_notification_message">Drücken Sie auf „Verbinden“, um die VPN-Berechtigung anzufordern</string>
383382
<string name="vpn_permission_error_notification_title">VPN-Berechtigungsfehler</string>
384383
<string name="we_will_look_into_this">Wir werden uns das anschauen.</string>

‎android/lib/resource/src/main/res/values-es/strings.xml

-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@
378378
<string name="voucher_already_used">El código del cupón ya se ha usado.</string>
379379
<string name="voucher_is_account_number">Parece que ha introducido un número de cuenta en lugar de un código de cupón. Si desea cambiar la cuenta activa, cierre primero la sesión.</string>
380380
<string name="voucher_success_title">El cupón se canjeó correctamente.</string>
381-
<string name="vpn_permission_denied_error">Se denegó el permiso para usar una conexión VPN al crear el túnel. Intente volver a establecer la conexión.</string>
382381
<string name="vpn_permission_error_notification_message">Pulse conectar para solicitar el permiso de VPN</string>
383382
<string name="vpn_permission_error_notification_title">Error en la autorización de la VPN</string>
384383
<string name="we_will_look_into_this">Revisaremos esto.</string>

‎android/lib/resource/src/main/res/values-fi/strings.xml

-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@
378378
<string name="voucher_already_used">Kuponkikoodi on jo käytetty.</string>
379379
<string name="voucher_is_account_number">Näytät syöttäneen tilin numeron etusetelin koodin sijaan. Jos haluat vaihtaa tiliä, kirjaudu ensin ulos nykyiseltä tililtä.</string>
380380
<string name="voucher_success_title">Kupongin lunastus onnistui.</string>
381-
<string name="vpn_permission_denied_error">VPN-lupa evättiin tunnelia luotaessa. Yritä muodostaa yhteys uudelleen.</string>
382381
<string name="vpn_permission_error_notification_message">Pyydä VPN:n käyttölupa yhteydenluontipainiketta painamalla</string>
383382
<string name="vpn_permission_error_notification_title">VPN-lupavirhe</string>
384383
<string name="we_will_look_into_this">Tutkimme asiaa.</string>

‎android/lib/resource/src/main/res/values-fr/strings.xml

-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@
378378
<string name="voucher_already_used">Le code du bon a déjà été utilisé.</string>
379379
<string name="voucher_is_account_number">Vous semblez avoir saisi un numéro de compte plutôt qu\'un code de bon. Si vous souhaitez modifier le compte actif, veuillez d\'abord vous déconnecter.</string>
380380
<string name="voucher_success_title">Le bon a bien été échangé.</string>
381-
<string name="vpn_permission_denied_error">La permission VPN a été refusée lors de la création du tunnel. Veuillez essayer de vous reconnecter.</string>
382381
<string name="vpn_permission_error_notification_message">Veuillez appuyer sur connexion pour demander l\'autorisation VPN</string>
383382
<string name="vpn_permission_error_notification_title">Erreur de permission VPN</string>
384383
<string name="we_will_look_into_this">Nous allons nous pencher dessus.</string>

‎android/lib/resource/src/main/res/values-it/strings.xml

-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@
378378
<string name="voucher_already_used">Il codice voucher è già stato utilizzato.</string>
379379
<string name="voucher_is_account_number">Sembra che tu abbia inserito un numero di account anziché un codice voucher. Se desideri modificare l\'account attivo, effettua prima la disconnessione.</string>
380380
<string name="voucher_success_title">Il voucher è stato riscattato correttamente.</string>
381-
<string name="vpn_permission_denied_error">L\'autorizzazione VPN è stata negata durante la creazione del tunnel. Prova a connetterti di nuovo.</string>
382381
<string name="vpn_permission_error_notification_message">Premi Connetti per richiedere l\'autorizzazione VPN</string>
383382
<string name="vpn_permission_error_notification_title">Errore di autorizzazione VPN</string>
384383
<string name="we_will_look_into_this">Verificheremo.</string>

‎android/lib/resource/src/main/res/values-ja/strings.xml

-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@
378378
<string name="voucher_already_used">バウチャーコードはすでに使用されています。</string>
379379
<string name="voucher_is_account_number">バウチャーコードではなくアカウント番号を入力したようです。有効なアカウントを変更する場合は、先にログアウトしてください。</string>
380380
<string name="voucher_success_title">バウチャーを正常に使用しました。</string>
381-
<string name="vpn_permission_denied_error">トンネルを作成中にVPNへのアクセスが拒否されました。もう一度接続してみてください。</string>
382381
<string name="vpn_permission_error_notification_message">[接続] を押してVPNへのアクセス許可をリクエストしてください</string>
383382
<string name="vpn_permission_error_notification_title">VPN許可エラー</string>
384383
<string name="we_will_look_into_this">この問題を調査いたします。</string>

‎android/lib/resource/src/main/res/values-ko/strings.xml

-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@
378378
<string name="voucher_already_used">이미 사용된 바우처 코드입니다.</string>
379379
<string name="voucher_is_account_number">바우처 코드 대신 계정 번호를 입력한 것 같습니다. 활성 계정을 변경하려면 먼저 로그아웃하세요.</string>
380380
<string name="voucher_success_title">바우처가 성공적으로 사용되었습니다.</string>
381-
<string name="vpn_permission_denied_error">터널을 만드는 동안 VPN 사용 권한이 거부되었습니다. 다시 연결해 보세요.</string>
382381
<string name="vpn_permission_error_notification_message">VPN 권한을 요청하려면 연결을 누르세요</string>
383382
<string name="vpn_permission_error_notification_title">VPN 권한 오류</string>
384383
<string name="we_will_look_into_this">조사해보겠습니다.</string>

‎android/lib/resource/src/main/res/values-my/strings.xml

-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@
378378
<string name="voucher_already_used">ဘောက်ချာကုဒ် သုံးထားပြီးသား ဖြစ်ပါသည်။</string>
379379
<string name="voucher_is_account_number">ဘောက်ချာကုဒ်အစား အကောင့်နံပါတ်တစ်ခုကို ထည့်သွင်းထားပုံရသည်။ အသုံးပြုနေသောအကောင့်ကို ပြောင်းလဲလိုပါက ဦးစွာ အကောင့်မှထွက်ပါ။</string>
380380
<string name="voucher_success_title">ဘောက်ချာကို အောင်မြင်စွာ လဲယူခဲ့ပါသည်။</string>
381-
<string name="vpn_permission_denied_error">Tunnel ဖန်တီးနေစဉ် VPN ခွင့်ပြုချက်ကို ပယ်ချခဲ့ပါသည်။ ထပ်မံချိတ်ဆက်ပေးပါ။</string>
382381
<string name="vpn_permission_error_notification_message">VPN ခွင့်ပြုချက်တောင်းရန် ချိတ်ဆက်ရန်ကို နှိပ်ပေးပါ</string>
383382
<string name="vpn_permission_error_notification_title">VPN ခွင့်ပြုချက် ချို့ယွင်းချက်</string>
384383
<string name="we_will_look_into_this">ဤသည်ကို စစ်ဆေးလိုက်ပါမည်။</string>

‎android/lib/resource/src/main/res/values-nb/strings.xml

-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@
378378
<string name="voucher_already_used">Kupongkoden er allerede brukt.</string>
379379
<string name="voucher_is_account_number">Det ser ut til at du har oppgitt et kontonummer i stedet for en kupongkode. Hvis du vil endre den aktive kontoen, må du først logge ut.</string>
380380
<string name="voucher_success_title">Kupongkoden er løst inn.</string>
381-
<string name="vpn_permission_denied_error">VPN-tillatelse ble avvist under opprettelsen av tunnelen. Prøv å koble til igjen.</string>
382381
<string name="vpn_permission_error_notification_message">Trykk på koble til for å be om VPN-tillatelse</string>
383382
<string name="vpn_permission_error_notification_title">Feil med VPN-tillatelse</string>
384383
<string name="we_will_look_into_this">Dette skal vi følge opp.</string>

‎android/lib/resource/src/main/res/values-nl/strings.xml

-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@
378378
<string name="voucher_already_used">Vouchercode is al gebruikt.</string>
379379
<string name="voucher_is_account_number">Het lijkt erop dat u een accountnummer hebt ingevoerd in plaats van een vouchercode. Als u het actieve account wilt wijzigen, meld u dan eerst af.</string>
380380
<string name="voucher_success_title">Voucher is ingewisseld.</string>
381-
<string name="vpn_permission_denied_error">VPN-toestemming is geweigerd tijdens maken van de tunnel. Probeer opnieuw verbinding te maken.</string>
382381
<string name="vpn_permission_error_notification_message">Druk op Verbinding maken om VPN-toestemming te verzoeken</string>
383382
<string name="vpn_permission_error_notification_title">VPN-machtigingsfout</string>
384383
<string name="we_will_look_into_this">We gaan het bekijken.</string>

‎android/lib/resource/src/main/res/values-pl/strings.xml

-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@
378378
<string name="voucher_already_used">Kod z tego kuponu został już użyty.</string>
379379
<string name="voucher_is_account_number">Wygląda na to, że wpisano numer konta zamiast kodu kuponu. Jeśli chcesz zmienić aktywne konto, najpierw się wyloguj.</string>
380380
<string name="voucher_success_title">Kupon został zrealizowany.</string>
381-
<string name="vpn_permission_denied_error">Uprawnienie VPN zostało odrzucone podczas tworzenia tunelu. Spróbuj połączyć się ponownie.</string>
382381
<string name="vpn_permission_error_notification_message">Naciśnij przycisk Połącz, aby zażądać uprawnienia VPN</string>
383382
<string name="vpn_permission_error_notification_title">Błąd uprawnienia VPN</string>
384383
<string name="we_will_look_into_this">Sprawdzimy to.</string>

‎android/lib/resource/src/main/res/values-pt/strings.xml

-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@
378378
<string name="voucher_already_used">O código do voucher já foi utilizado.</string>
379379
<string name="voucher_is_account_number">Parece que introduziu um número de conta em vez de um código de voucher. Se pretender alterar a conta ativa, termine a sessão primeiro.</string>
380380
<string name="voucher_success_title">O voucher foi reclamado com sucesso.</string>
381-
<string name="vpn_permission_denied_error">A transmissão foi negada durante a criação do túnel. Tente fazer novamente a ligação.</string>
382381
<string name="vpn_permission_error_notification_message">Prima \"ligar\" para solicitar a permissão de VPN</string>
383382
<string name="vpn_permission_error_notification_title">Erro de permissão da VPN</string>
384383
<string name="we_will_look_into_this">Vamos analisar esta situação.</string>

‎android/lib/resource/src/main/res/values-ru/strings.xml

-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@
378378
<string name="voucher_already_used">Этот код ваучера уже использовался.</string>
379379
<string name="voucher_is_account_number">Вы ввели номер учетной записи вместо кода ваучера. Чтобы изменить активную учетную запись, сначала выйдите из системы.</string>
380380
<string name="voucher_success_title">Ваучер погашен.</string>
381-
<string name="vpn_permission_denied_error">При создании туннеля в доступе к VPN было отказано. Попробуйте подключиться снова.</string>
382381
<string name="vpn_permission_error_notification_message">Чтобы запросить разрешение для VPN, нажмите «Подключить»</string>
383382
<string name="vpn_permission_error_notification_title">Ошибка разрешения для VPN</string>
384383
<string name="we_will_look_into_this">Мы рассмотрим эту проблему.</string>

‎android/lib/resource/src/main/res/values-sv/strings.xml

-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@
378378
<string name="voucher_already_used">Kupongkoden har redan använts.</string>
379379
<string name="voucher_is_account_number">Det verkar som om du angett ett kontonummer istället för en kupongkod. Logga först ut om du vill ändra den aktiva koden.</string>
380380
<string name="voucher_success_title">Kupongen har lösts in.</string>
381-
<string name="vpn_permission_denied_error">VPN-behörighet nekades när tunneln skapades. Försök att ansluta igen.</string>
382381
<string name="vpn_permission_error_notification_message">Tryck på anslut för att begära VPN-behörighet</string>
383382
<string name="vpn_permission_error_notification_title">Behörighetsfel med VPN</string>
384383
<string name="we_will_look_into_this">Vi kommer att undersöka detta.</string>

‎android/lib/resource/src/main/res/values-th/strings.xml

-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@
378378
<string name="voucher_already_used">รหัสบัตรกำนัลถูกใช้ไปแล้ว</string>
379379
<string name="voucher_is_account_number">ดูเหมือนว่า คุณได้ป้อนหมายเลขบัญชีแทนรหัสบัตรกำนัล หากคุณต้องการเปลี่ยนบัญชีที่ใช้งานอยู่ โปรดออกจากระบบก่อน</string>
380380
<string name="voucher_success_title">แลกบัตรกำนัลสำเร็จแล้ว</string>
381-
<string name="vpn_permission_denied_error">การให้สิทธิ์ VPN ถูกปฏิเสธ ในขณะที่สร้างอุโมงค์ โปรดลองเชื่อมต่อใหม่อีกครั้ง</string>
382381
<string name="vpn_permission_error_notification_message">กรุณากดเชื่อมต่อ เพื่อขออนุญาตสิทธิ์ VPN</string>
383382
<string name="vpn_permission_error_notification_title">เกิดข้อผิดพลาดในการอนุญาต VPN</string>
384383
<string name="we_will_look_into_this">เราจะตรวจสอบปัญหานี้</string>

0 commit comments

Comments
 (0)