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

Improve error text for other always on apps #7754

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ class ConnectViewModel(
if (hasVpnPermission) {
connectionProxy.connect()
} else {
// Either the user denied the permission or another always-on-vpn is active (if
// Android 11+ and run from Android Studio)
_uiSideEffect.send(UiSideEffect.ConnectError.PermissionDenied)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ package net.mullvad.mullvadvpn.lib.common.util
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.provider.Settings
import net.mullvad.mullvadvpn.lib.model.WebsiteAuthToken

private const val ALWAYS_ON_VPN_APP = "always_on_vpn_app"

fun createAccountUri(accountUri: String, websiteAuthToken: WebsiteAuthToken?): Uri {
val urlString = buildString {
append(accountUri)
Expand All @@ -19,16 +16,6 @@ fun createAccountUri(accountUri: String, websiteAuthToken: WebsiteAuthToken?): U
return Uri.parse(urlString)
}

// NOTE: This function will return the current Always-on VPN package's name. In case of either
// Always-on VPN being disabled or not being able to read the state, NULL will be returned.
fun Context.resolveAlwaysOnVpnPackageName(): String? {
return try {
Settings.Secure.getString(contentResolver, ALWAYS_ON_VPN_APP)
} catch (ex: SecurityException) {
null
}
}

fun Context.openVpnSettings() {
val intent = Intent("android.settings.VPN_SETTINGS")
startActivity(intent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import android.content.Context
import android.content.Intent
import android.net.VpnService
import android.net.VpnService.prepare
import android.os.Build
import android.os.ParcelFileDescriptor
import android.provider.Settings
import androidx.annotation.DeprecatedSinceApi
import arrow.core.Either
import arrow.core.flatMap
import arrow.core.left
Expand All @@ -22,8 +25,9 @@ import net.mullvad.mullvadvpn.lib.model.Prepared
* Invoking VpnService.prepare() can result in 3 out comes:
* 1. IllegalStateException - There is a legacy VPN profile marked as always on
* 2. Intent
* - A: Can-prepare - Create Vpn profile
* - B: Always-on-VPN - Another Vpn Profile is marked as always on
* - A: Can-prepare - Create Vpn profile or Always-on-VPN is not detected in case of Android 11+
* - B: Always-on-VPN - Another Vpn Profile is marked as always on (Only available up to Android
* 11 or where testOnly is set, e.g builds from Android Studio)
* 3. null - The app has the VPN permission
*
* In case 1 and 2b, you don't know if you have a VPN profile or not.
Expand All @@ -44,25 +48,44 @@ fun Context.prepareVpnSafe(): Either<PrepareError, Prepared> =
if (intent == null) {
Prepared.right()
} else {
val alwaysOnVpnApp = getAlwaysOnVpnAppName()
if (alwaysOnVpnApp == null) {
PrepareError.NotPrepared(intent).left()
} else {
PrepareError.OtherAlwaysOnApp(alwaysOnVpnApp).left()
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
val alwaysOnVpnApp = getOtherAlwaysOnVpnAppName()
if (alwaysOnVpnApp != null) {
return@flatMap PrepareError.OtherAlwaysOnApp(alwaysOnVpnApp).left()
}
}
return@flatMap PrepareError.NotPrepared(intent).left()
}
}

fun Context.getAlwaysOnVpnAppName(): String? {
return resolveAlwaysOnVpnPackageName()
?.let { currentAlwaysOnVpn ->
packageManager.getInstalledPackagesList(0).singleOrNull {
it.packageName == currentAlwaysOnVpn && it.packageName != packageName
}
private const val ALWAYS_ON_VPN_APP = "always_on_vpn_app"

// NOTE: This function will return the current Always-on VPN package's name. In case of either
// Always-on VPN being disabled or not being able to read the state, null will be returned.
//
// Caveat: For Android 11+ it will always return null unless the app is a test build (e.g running
// from Android Studio).
@DeprecatedSinceApi(Build.VERSION_CODES.S)
fun Context.getOtherAlwaysOnVpnAppName(): String? {
val currentAlwaysOnPackageName =
try {
Settings.Secure.getString(contentResolver, ALWAYS_ON_VPN_APP)
} catch (ex: SecurityException) {
return null
}
?.applicationInfo
?.loadLabel(packageManager)
?.toString()

// If we are the current Always-on VPN app, we return null
return if (currentAlwaysOnPackageName == packageName) {
null
} else {
// Resolve package name to app name
packageManager
.getInstalledPackagesList(0)
.firstOrNull { it.packageName == currentAlwaysOnPackageName }
?.applicationInfo
?.loadLabel(packageManager)
?.toString()
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ sealed interface PrepareError : PrepareResult {
// Legacy VPN profile is active as Always-on
data object OtherLegacyAlwaysOnVpn : PrepareError

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

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

Expand Down
1 change: 0 additions & 1 deletion android/lib/resource/src/main/res/values-da/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@
<string name="voucher_already_used">Kuponkode er allerede brugt.</string>
<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>
<string name="voucher_success_title">Indløsning af kuponen lykkedes.</string>
<string name="vpn_permission_denied_error">VPN-tilladelse blev nægtet, da tunnelen blev oprettet. Prøv at oprette forbindelse igen.</string>
<string name="vpn_permission_error_notification_message">Tryk på Opret forbindelse for at anmode om VPN-tilladelse</string>
<string name="vpn_permission_error_notification_title">VPN-tilladelsesfejl</string>
<string name="we_will_look_into_this">Vi vil undersøge dette.</string>
Expand Down
1 change: 0 additions & 1 deletion android/lib/resource/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@
<string name="voucher_already_used">Der Gutscheincode wurde bereits verwendet.</string>
<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>
<string name="voucher_success_title">Der Gutschein wurde erfolgreich eingelöst.</string>
<string name="vpn_permission_denied_error">VPN-Berechtigungen wurden beim Erstellen des Tunnels abgelehnt.</string>
<string name="vpn_permission_error_notification_message">Drücken Sie auf „Verbinden“, um die VPN-Berechtigung anzufordern</string>
<string name="vpn_permission_error_notification_title">VPN-Berechtigungsfehler</string>
<string name="we_will_look_into_this">Wir werden uns das anschauen.</string>
Expand Down
1 change: 0 additions & 1 deletion android/lib/resource/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@
<string name="voucher_already_used">El código del cupón ya se ha usado.</string>
<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>
<string name="voucher_success_title">El cupón se canjeó correctamente.</string>
<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>
<string name="vpn_permission_error_notification_message">Pulse conectar para solicitar el permiso de VPN</string>
<string name="vpn_permission_error_notification_title">Error en la autorización de la VPN</string>
<string name="we_will_look_into_this">Revisaremos esto.</string>
Expand Down
1 change: 0 additions & 1 deletion android/lib/resource/src/main/res/values-fi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@
<string name="voucher_already_used">Kuponkikoodi on jo käytetty.</string>
<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>
<string name="voucher_success_title">Kupongin lunastus onnistui.</string>
<string name="vpn_permission_denied_error">VPN-lupa evättiin tunnelia luotaessa. Yritä muodostaa yhteys uudelleen.</string>
<string name="vpn_permission_error_notification_message">Pyydä VPN:n käyttölupa yhteydenluontipainiketta painamalla</string>
<string name="vpn_permission_error_notification_title">VPN-lupavirhe</string>
<string name="we_will_look_into_this">Tutkimme asiaa.</string>
Expand Down
1 change: 0 additions & 1 deletion android/lib/resource/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@
<string name="voucher_already_used">Le code du bon a déjà été utilisé.</string>
<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>
<string name="voucher_success_title">Le bon a bien été échangé.</string>
<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>
<string name="vpn_permission_error_notification_message">Veuillez appuyer sur connexion pour demander l\'autorisation VPN</string>
<string name="vpn_permission_error_notification_title">Erreur de permission VPN</string>
<string name="we_will_look_into_this">Nous allons nous pencher dessus.</string>
Expand Down
1 change: 0 additions & 1 deletion android/lib/resource/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@
<string name="voucher_already_used">Il codice voucher è già stato utilizzato.</string>
<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>
<string name="voucher_success_title">Il voucher è stato riscattato correttamente.</string>
<string name="vpn_permission_denied_error">L\'autorizzazione VPN è stata negata durante la creazione del tunnel. Prova a connetterti di nuovo.</string>
<string name="vpn_permission_error_notification_message">Premi Connetti per richiedere l\'autorizzazione VPN</string>
<string name="vpn_permission_error_notification_title">Errore di autorizzazione VPN</string>
<string name="we_will_look_into_this">Verificheremo.</string>
Expand Down
1 change: 0 additions & 1 deletion android/lib/resource/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@
<string name="voucher_already_used">バウチャーコードはすでに使用されています。</string>
<string name="voucher_is_account_number">バウチャーコードではなくアカウント番号を入力したようです。有効なアカウントを変更する場合は、先にログアウトしてください。</string>
<string name="voucher_success_title">バウチャーを正常に使用しました。</string>
<string name="vpn_permission_denied_error">トンネルを作成中にVPNへのアクセスが拒否されました。もう一度接続してみてください。</string>
<string name="vpn_permission_error_notification_message">[接続] を押してVPNへのアクセス許可をリクエストしてください</string>
<string name="vpn_permission_error_notification_title">VPN許可エラー</string>
<string name="we_will_look_into_this">この問題を調査いたします。</string>
Expand Down
1 change: 0 additions & 1 deletion android/lib/resource/src/main/res/values-ko/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@
<string name="voucher_already_used">이미 사용된 바우처 코드입니다.</string>
<string name="voucher_is_account_number">바우처 코드 대신 계정 번호를 입력한 것 같습니다. 활성 계정을 변경하려면 먼저 로그아웃하세요.</string>
<string name="voucher_success_title">바우처가 성공적으로 사용되었습니다.</string>
<string name="vpn_permission_denied_error">터널을 만드는 동안 VPN 사용 권한이 거부되었습니다. 다시 연결해 보세요.</string>
<string name="vpn_permission_error_notification_message">VPN 권한을 요청하려면 연결을 누르세요</string>
<string name="vpn_permission_error_notification_title">VPN 권한 오류</string>
<string name="we_will_look_into_this">조사해보겠습니다.</string>
Expand Down
1 change: 0 additions & 1 deletion android/lib/resource/src/main/res/values-my/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@
<string name="voucher_already_used">ဘောက်ချာကုဒ် သုံးထားပြီးသား ဖြစ်ပါသည်။</string>
<string name="voucher_is_account_number">ဘောက်ချာကုဒ်အစား အကောင့်နံပါတ်တစ်ခုကို ထည့်သွင်းထားပုံရသည်။ အသုံးပြုနေသောအကောင့်ကို ပြောင်းလဲလိုပါက ဦးစွာ အကောင့်မှထွက်ပါ။</string>
<string name="voucher_success_title">ဘောက်ချာကို အောင်မြင်စွာ လဲယူခဲ့ပါသည်။</string>
<string name="vpn_permission_denied_error">Tunnel ဖန်တီးနေစဉ် VPN ခွင့်ပြုချက်ကို ပယ်ချခဲ့ပါသည်။ ထပ်မံချိတ်ဆက်ပေးပါ။</string>
<string name="vpn_permission_error_notification_message">VPN ခွင့်ပြုချက်တောင်းရန် ချိတ်ဆက်ရန်ကို နှိပ်ပေးပါ</string>
<string name="vpn_permission_error_notification_title">VPN ခွင့်ပြုချက် ချို့ယွင်းချက်</string>
<string name="we_will_look_into_this">ဤသည်ကို စစ်ဆေးလိုက်ပါမည်။</string>
Expand Down
1 change: 0 additions & 1 deletion android/lib/resource/src/main/res/values-nb/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@
<string name="voucher_already_used">Kupongkoden er allerede brukt.</string>
<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>
<string name="voucher_success_title">Kupongkoden er løst inn.</string>
<string name="vpn_permission_denied_error">VPN-tillatelse ble avvist under opprettelsen av tunnelen. Prøv å koble til igjen.</string>
<string name="vpn_permission_error_notification_message">Trykk på koble til for å be om VPN-tillatelse</string>
<string name="vpn_permission_error_notification_title">Feil med VPN-tillatelse</string>
<string name="we_will_look_into_this">Dette skal vi følge opp.</string>
Expand Down
1 change: 0 additions & 1 deletion android/lib/resource/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@
<string name="voucher_already_used">Vouchercode is al gebruikt.</string>
<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>
<string name="voucher_success_title">Voucher is ingewisseld.</string>
<string name="vpn_permission_denied_error">VPN-toestemming is geweigerd tijdens maken van de tunnel. Probeer opnieuw verbinding te maken.</string>
<string name="vpn_permission_error_notification_message">Druk op Verbinding maken om VPN-toestemming te verzoeken</string>
<string name="vpn_permission_error_notification_title">VPN-machtigingsfout</string>
<string name="we_will_look_into_this">We gaan het bekijken.</string>
Expand Down
1 change: 0 additions & 1 deletion android/lib/resource/src/main/res/values-pl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@
<string name="voucher_already_used">Kod z tego kuponu został już użyty.</string>
<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>
<string name="voucher_success_title">Kupon został zrealizowany.</string>
<string name="vpn_permission_denied_error">Uprawnienie VPN zostało odrzucone podczas tworzenia tunelu. Spróbuj połączyć się ponownie.</string>
<string name="vpn_permission_error_notification_message">Naciśnij przycisk Połącz, aby zażądać uprawnienia VPN</string>
<string name="vpn_permission_error_notification_title">Błąd uprawnienia VPN</string>
<string name="we_will_look_into_this">Sprawdzimy to.</string>
Expand Down
1 change: 0 additions & 1 deletion android/lib/resource/src/main/res/values-pt/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@
<string name="voucher_already_used">O código do voucher já foi utilizado.</string>
<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>
<string name="voucher_success_title">O voucher foi reclamado com sucesso.</string>
<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>
<string name="vpn_permission_error_notification_message">Prima \"ligar\" para solicitar a permissão de VPN</string>
<string name="vpn_permission_error_notification_title">Erro de permissão da VPN</string>
<string name="we_will_look_into_this">Vamos analisar esta situação.</string>
Expand Down
1 change: 0 additions & 1 deletion android/lib/resource/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@
<string name="voucher_already_used">Этот код ваучера уже использовался.</string>
<string name="voucher_is_account_number">Вы ввели номер учетной записи вместо кода ваучера. Чтобы изменить активную учетную запись, сначала выйдите из системы.</string>
<string name="voucher_success_title">Ваучер погашен.</string>
<string name="vpn_permission_denied_error">При создании туннеля в доступе к VPN было отказано. Попробуйте подключиться снова.</string>
<string name="vpn_permission_error_notification_message">Чтобы запросить разрешение для VPN, нажмите «Подключить»</string>
<string name="vpn_permission_error_notification_title">Ошибка разрешения для VPN</string>
<string name="we_will_look_into_this">Мы рассмотрим эту проблему.</string>
Expand Down
1 change: 0 additions & 1 deletion android/lib/resource/src/main/res/values-sv/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@
<string name="voucher_already_used">Kupongkoden har redan använts.</string>
<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>
<string name="voucher_success_title">Kupongen har lösts in.</string>
<string name="vpn_permission_denied_error">VPN-behörighet nekades när tunneln skapades. Försök att ansluta igen.</string>
<string name="vpn_permission_error_notification_message">Tryck på anslut för att begära VPN-behörighet</string>
<string name="vpn_permission_error_notification_title">Behörighetsfel med VPN</string>
<string name="we_will_look_into_this">Vi kommer att undersöka detta.</string>
Expand Down
1 change: 0 additions & 1 deletion android/lib/resource/src/main/res/values-th/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@
<string name="voucher_already_used">รหัสบัตรกำนัลถูกใช้ไปแล้ว</string>
<string name="voucher_is_account_number">ดูเหมือนว่า คุณได้ป้อนหมายเลขบัญชีแทนรหัสบัตรกำนัล หากคุณต้องการเปลี่ยนบัญชีที่ใช้งานอยู่ โปรดออกจากระบบก่อน</string>
<string name="voucher_success_title">แลกบัตรกำนัลสำเร็จแล้ว</string>
<string name="vpn_permission_denied_error">การให้สิทธิ์ VPN ถูกปฏิเสธ ในขณะที่สร้างอุโมงค์ โปรดลองเชื่อมต่อใหม่อีกครั้ง</string>
<string name="vpn_permission_error_notification_message">กรุณากดเชื่อมต่อ เพื่อขออนุญาตสิทธิ์ VPN</string>
<string name="vpn_permission_error_notification_title">เกิดข้อผิดพลาดในการอนุญาต VPN</string>
<string name="we_will_look_into_this">เราจะตรวจสอบปัญหานี้</string>
Expand Down
Loading
Loading