diff --git a/app/build.gradle.kts b/app/build.gradle.kts index d8e183b..4d9341f 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -37,8 +37,8 @@ android { applicationId = "com.ericlowry.dnstoggle" minSdk = 28 targetSdk = 37 - versionCode = 38 - versionName = "3.2.0" + versionCode = 39 + versionName = "3.2.1" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/java/com/ericlowry/dnstoggle/data/Constants.kt b/app/src/main/java/com/ericlowry/dnstoggle/data/Constants.kt index 55e6b46..c4df67d 100644 --- a/app/src/main/java/com/ericlowry/dnstoggle/data/Constants.kt +++ b/app/src/main/java/com/ericlowry/dnstoggle/data/Constants.kt @@ -91,6 +91,7 @@ object Constants { const val VPN_DUMP_IN_PROCESS_TIMEOUT_MS = 1500L const val VPN_DUMP_SERVICE_TIMEOUT_MS = 3000L const val VPN_DUMP_ROOT_TIMEOUT_MS = 2500L + const val VPN_PACKAGE_RESOLVE_RETRY_DELAY_MS = 350L const val ROOT_VERIFY_TIMEOUT_MS = 15000L // Thresholds diff --git a/app/src/main/java/com/ericlowry/dnstoggle/data/DnsPolicyEvaluator.kt b/app/src/main/java/com/ericlowry/dnstoggle/data/DnsPolicyEvaluator.kt index b32f954..ae8424e 100644 --- a/app/src/main/java/com/ericlowry/dnstoggle/data/DnsPolicyEvaluator.kt +++ b/app/src/main/java/com/ericlowry/dnstoggle/data/DnsPolicyEvaluator.kt @@ -109,7 +109,11 @@ object DnsPolicyEvaluator { if (network.vpnNetworkHandle != null && network.vpnNetworkHandle == cachedVpnNetworkHandle && cachedVpnPackage != null) { cachedVpnPackage } else { - val pkg = vpnPackageResolver(context) + var pkg = vpnPackageResolver(context) + if (pkg == null) { + delay(Constants.VPN_PACKAGE_RESOLVE_RETRY_DELAY_MS.milliseconds) + pkg = vpnPackageResolver(context) + } if (pkg != null) { cachedVpnNetworkHandle = network.vpnNetworkHandle cachedVpnPackage = pkg @@ -142,8 +146,10 @@ object DnsPolicyEvaluator { if (matchedVpnProfile != null && matchedVpnProfile.isBypassMode()) { isCurrentVpnBypassed = true dnsSettleJob?.cancel() + isTransitioning = false val targetKey = matchedVpnProfile.toOverrideKey() if (isInVpnOverride || activeVpnProfileKey != targetKey) { + lastBssid = null prefs.edit { putBoolean(Constants.PREF_IS_IN_VPN_OVERRIDE, false) putString(Constants.PREF_ACTIVE_VPN_PROFILE_OVERRIDE, targetKey) @@ -280,9 +286,16 @@ object DnsPolicyEvaluator { val profiles = NetworkProfileRepository.networkProfiles.value ?: emptyList() val profile = profiles.find { it.ssid == validSsid } + val preferredMode = prefs.getString( + Constants.PREF_PREFERRED_DNS_MODE, + Constants.DNS_MODE_HOSTNAME + ) ?: Constants.DNS_MODE_HOSTNAME val targetHostname = profile?.targetHostname ?: getGlobalPreferredHostname(context) - val isApplyingHostname = - (profile == null) || (profile.isEnabled && targetHostname != null) + val isApplyingHostname = if (profile == null) { + preferredMode == Constants.DNS_MODE_HOSTNAME && targetHostname != null + } else { + profile.isEnabled && targetHostname != null + } val isRoam = currentBssid != null && lastBssid != null && currentBssid != lastBssid if (isApplyingHostname && (!isValidated || !hasInternet)) { diff --git a/app/src/main/java/com/ericlowry/dnstoggle/util/ShizukuUtils.kt b/app/src/main/java/com/ericlowry/dnstoggle/util/ShizukuUtils.kt index f66f489..a931dc1 100644 --- a/app/src/main/java/com/ericlowry/dnstoggle/util/ShizukuUtils.kt +++ b/app/src/main/java/com/ericlowry/dnstoggle/util/ShizukuUtils.kt @@ -186,7 +186,6 @@ object ShizukuUtils { val userId = android.os.Process.myUid() / 100000 - var dumpSucceeded = false val fastPathResult = try { val vpnDump: String? = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) { @@ -199,24 +198,16 @@ object ShizukuUtils { } if (pkg != null) { - dumpSucceeded = true pkg } else { - var uidResolutionFailed = false val connDump: String? = executeInProcessDump("connectivity") - val connPkg = if (connDump != null) { + if (connDump != null) { VpnDumpParser.parseActiveVpnPackage(vpnDump, connDump, userId) { uid -> - val resolved = context.packageManager.getPackagesForUid(uid)?.firstOrNull() - if (resolved == null) { - uidResolutionFailed = true - } - resolved + context.packageManager.getPackagesForUid(uid)?.firstOrNull() } } else { null } - dumpSucceeded = (connDump != null) && !uidResolutionFailed - connPkg } } catch (e: CancellationException) { throw e @@ -229,10 +220,7 @@ object ShizukuUtils { return fastPathResult } - if (!dumpSucceeded) { - return fetchViaShizukuUserService(context, userId) - } - return null + return fetchViaShizukuUserService(context, userId) } private fun userServiceArgs(context: Context): Shizuku.UserServiceArgs = diff --git a/app/src/main/java/com/ericlowry/dnstoggle/util/VpnDumpParser.kt b/app/src/main/java/com/ericlowry/dnstoggle/util/VpnDumpParser.kt index 695cafb..4f6b99d 100644 --- a/app/src/main/java/com/ericlowry/dnstoggle/util/VpnDumpParser.kt +++ b/app/src/main/java/com/ericlowry/dnstoggle/util/VpnDumpParser.kt @@ -6,18 +6,18 @@ package com.ericlowry.dnstoggle.util */ object VpnDumpParser { private val userHeaderRegex = - Regex("""(?:VPN for user|User)\s+(\d+)""", RegexOption.IGNORE_CASE) + Regex("""(?:VPN for user|User|mUserId)\s*[=:]?\s*(\d+)""", RegexOption.IGNORE_CASE) private val userColonPackageRegex = Regex("""^\s*(\d+)\s*:\s*(\S+)""") private val activePackageRegex = Regex( - """\b(?:Active package name|mPackage|Package)\s*[=:]\s*(\S+)""", + """\b(?:Active package name|mPackage|Package|ownerPackage)\s*[=:]\s*(\S+)""", RegexOption.IGNORE_CASE ) private val extraPackageRegex = Regex("""extra:\s*(?:VPN:)?([a-zA-Z][a-zA-Z0-9_]*(?:\.[a-zA-Z0-9_]+)+)""") private val ownerUidRegex = - Regex("""(?:ownerUid|OwnerUid)\s*[=:]\s*(\d+)""") + Regex("""(?:ownerUid|OwnerUid|mOwnerUid)\s*[=:]\s*(\d+)""") private val adminUidsRegex = Regex("""(?:adminUids|AdminUids|administratorUids)\s*[=:]\s*\[\s*(\d+)""") private val packageNamePattern = @@ -76,6 +76,10 @@ object VpnDumpParser { var inVpnBlock = false var currentBlockExtraPkg: String? = null var currentBlockUid: Int? = null + var inCandidateAgentBlock = false + var candidateIsConnected = false + var candidateHasVpn = false + var candidateHasNotVpn = false fun processCurrentBlock(): String? { if (!inVpnBlock) { @@ -102,28 +106,38 @@ object VpnDumpParser { val isNetworkAgentLine = trimmed.startsWith("NetworkAgentInfo[") || trimmed.startsWith("NetworkAgentInfo") if (isNetworkAgentLine || trimmed.isEmpty()) { + if (inCandidateAgentBlock && candidateHasVpn && candidateIsConnected && !candidateHasNotVpn) { + inVpnBlock = true + } val result = processCurrentBlock() if (result != null) { return result } inVpnBlock = false + inCandidateAgentBlock = isNetworkAgentLine + candidateIsConnected = false + candidateHasVpn = false + candidateHasNotVpn = false currentBlockExtraPkg = null currentBlockUid = null } - if (isNetworkAgentLine) { - val hasVpnType = line.contains("type: VPN[") || - line.contains("TRANSPORT_VPN") || - line.contains("ni{VPN ") || - line.contains("ni{VPN[") || - line.contains("Transports: VPN") - val isConnected = connectedStateRegex.containsMatchIn(line) - val hasNotVpn = line.contains("NOT_VPN") - if (hasVpnType && isConnected && (!hasNotVpn || line.contains("TRANSPORT_VPN"))) { - inVpnBlock = true + if (inCandidateAgentBlock) { + if (line.contains("type: VPN[") || + line.contains("TRANSPORT_VPN") || + line.contains("ni{VPN ") || + line.contains("ni{VPN[") || + line.contains("Transports: VPN") + ) { + candidateHasVpn = true } - } - if (inVpnBlock) { + if (connectedStateRegex.containsMatchIn(line)) { + candidateIsConnected = true + } + if (line.contains("NOT_VPN") && !line.contains("TRANSPORT_VPN")) { + candidateHasNotVpn = true + } + val extraMatch = extraPackageRegex.find(line) if (extraMatch != null) { currentBlockExtraPkg = extraMatch.groupValues[1] @@ -139,6 +153,9 @@ object VpnDumpParser { } } } + if (inCandidateAgentBlock && candidateHasVpn && candidateIsConnected && !candidateHasNotVpn) { + inVpnBlock = true + } val result = processCurrentBlock() if (result != null) { return result diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index b7eaff7..fa8a802 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -1,62 +1,62 @@ - Versione app: %s - Novità - Novità nel v%s - GitHub (codice sorgente) - OK - Annulla - Riprova - Chiudi - Impostazioni - Attivo - Disattivato - Altre opzioni - Autorizzazione richiesta - L\'app richiede un\'autorizzazione speciale per modificare le impostazioni del DNS privato. - Aggiusta - Apri impostazioni - DNS privato - Salta test di connessione - Attiva questa opzione solo se il DNS funziona ma l\'app lo mostra come non raggiungibile. - Provider DNS personalizzati - Aggiungi hostname - Salva questo hostname attivo - Modifica hostname - Server DNS - dns.nextdns.io - Nome (facoltativo) - Rimuovere questo hostname? - Impossibile attivare il DNS privato se l\'indirizzo del l\'host è vuoto - Ricevi supporto - Per usare questa opzione, devi concedere le autorizzazioni delle impostazioni tramite root, Shizuku oppure eseguire questo comando ADB sul computer con il debug USB attivato: - Comando ADB - Comando ADB: %s - Copia comando ADB - Comando copiato negli appunti - Concedi tramite Shizuku - Concedi tramite root - Richiedi autorizzazione - Richiesta autorizzazione tramite Shizuku… - Richiesta autorizzazione tramite root… - Richiesta autorizzazione automatica… - Autorizzazione Shizuku/Root non riuscita o negata - Autorizzazione concessa - Autorizzazione impostazioni di sistema richiesta - Formato dell\'indirizzo host DNS non valido - Verifica connessione… - Attuale (non salvato) - Non attivo (non salvato) - Attivo e raggiungibile - Predefinita - PREDEFINITO - Bloccato automaticamente: - Server DNS non raggiungibile nella porta 853 (DoT). Android potrebbe essere comunque connesso correttamente tramite altri metodi. - Sovrascrittura VPN attiva - Profilo Wi-Fi attivo (%s) - Sovrascrittura SSID attiva: %1$s è impostata su %2$s - Disattivato (%s) - Attiva DNS privato - Profili Wi-Fi - Imposta regole o eccezioni specifiche del DNS privato per le singole reti Wi-Fi. + Versione app: %s + Novità + Novità nel v%s + GitHub (codice sorgente) + OK + Annulla + Riprova + Chiudi + Impostazioni + Attivo + Disattivato + Altre opzioni + Autorizzazione richiesta + L\'app richiede un\'autorizzazione speciale per modificare le impostazioni del DNS privato. + Aggiusta + Apri impostazioni + DNS privato + Salta test di connessione + Attiva questa opzione solo se il DNS funziona ma l\'app lo mostra come non raggiungibile. + Provider DNS personalizzati + Aggiungi hostname + Salva questo hostname attivo + Modifica hostname + Server DNS + dns.nextdns.io + Nome (facoltativo) + Rimuovere questo hostname? + Impossibile attivare il DNS privato se l\'indirizzo del l\'host è vuoto + Ricevi supporto + Per usare questa opzione, devi concedere le autorizzazioni delle impostazioni tramite root, Shizuku oppure eseguire questo comando ADB sul computer con il debug USB attivato: + Comando ADB + Comando ADB: %s + Copia comando ADB + Comando copiato negli appunti + Concedi tramite Shizuku + Concedi tramite root + Richiedi autorizzazione + Richiesta autorizzazione tramite Shizuku… + Richiesta autorizzazione tramite root… + Richiesta autorizzazione automatica… + Autorizzazione Shizuku/Root non riuscita o negata + Autorizzazione concessa + Autorizzazione impostazioni di sistema richiesta + Formato dell\'indirizzo host DNS non valido + Verifica connessione… + Attuale (non salvato) + Non attivo (non salvato) + Attivo e raggiungibile + Predefinita + PREDEFINITO + Bloccato automaticamente: + Server DNS non raggiungibile nella porta 853 (DoT). Android potrebbe essere comunque connesso correttamente tramite altri metodi. + Sovrascrittura VPN attiva + Profilo Wi-Fi attivo (%s) + Sovrascrittura SSID attiva: %1$s è impostata su %2$s + Disattivato (%s) + Attiva DNS privato + Profili Wi-Fi + Imposta regole o eccezioni specifiche del DNS privato per le singole reti Wi-Fi. diff --git a/fastlane/metadata/android/en-US/changelogs/39.txt b/fastlane/metadata/android/en-US/changelogs/39.txt new file mode 100644 index 0000000..06623da --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/39.txt @@ -0,0 +1 @@ +- Made VPN app detection more robust. \ No newline at end of file diff --git a/fastlane/metadata/android/fr-FR/changelogs/39.txt b/fastlane/metadata/android/fr-FR/changelogs/39.txt new file mode 100644 index 0000000..7c93fa1 --- /dev/null +++ b/fastlane/metadata/android/fr-FR/changelogs/39.txt @@ -0,0 +1 @@ +- La détéction d'applications VPN est maintenant plus robuste. \ No newline at end of file