Skip to content
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
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ By long-pressing the Quick Settings tile, you can access the configuration menu
> _Note: For security, your encrypted hostnames and Wi-Fi profiles are excluded from cloud backups and must be transferred manually._
- **Dynamic Tile Labeling**:
Rename the Quick Settings tile.
- **App Authentication**:
Optionally require biometric or device credential authentication when manually toggling Private DNS or opening the app.
- **Hide App Icon**:
Optionally hide the app from your launcher drawer to keep your home screen clean.
- **USB Debugging Tile**:
Expand Down Expand Up @@ -83,10 +85,10 @@ If you encounter issues not covered here, please [open a support ticket](https:/
This usually means the permission was not granted correctly. See the warning above.
- **Custom DNS is marked as "Unreachable"**:
Some strict DNS providers block automatic connection tests. If you are certain the address is correct, you can enable the `Skip connection test` option.
- **"Unknown SSID" or Automation fails**:
- Ensure **Location Permissions** are set to "Allow all the time". Android requires this to identify Wi-Fi networks in the background.
- Active **VPNs** or "Private DNS" settings on some devices can mask the SSID.
- Some devices aggressively kill background apps. If automation stops working, you may need to disable `Battery Optimizations` or enable `Autostart` for DNS Toggle in your system settings.
- **"Unknown SSID" or Automation fails**:
- Ensure **Location Permissions** are set to "Allow all the time". Android requires this to identify Wi-Fi networks in the background.
- Active **VPNs** or "Private DNS" settings on some devices can mask the SSID.
- Some devices aggressively kill background apps. If automation stops working, you may need to disable `Battery Optimizations` or enable `Autostart` for DNS Toggle in your system settings.

## Permissions

Expand Down
15 changes: 13 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ android {
applicationId = "com.ericlowry.dnstoggle"
minSdk = 28
targetSdk = 37
versionCode = 27
versionName = "2.2.0"
versionCode = 28
versionName = "3.0.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -99,6 +99,16 @@ androidComponents {
}
}

tasks.configureEach {
if (name.startsWith("assemble")) {
val variantName = name.removePrefix("assemble")
if (variantName.isNotEmpty()) {
val testTaskName = "test${variantName}UnitTest"
dependsOn(tasks.matching { it.name == testTaskName })
}
}
}

dependencies {
implementation(libs.androidx.core.ktx)
implementation(libs.kotlinx.serialization.json)
Expand All @@ -110,6 +120,7 @@ dependencies {
implementation(libs.shizuku.api)
implementation(libs.shizuku.provider)
implementation(libs.androidx.dynamicanimation)
implementation(libs.androidx.biometric)
testImplementation(libs.junit)
testImplementation(libs.robolectric)
testImplementation(libs.kotlinx.coroutines.test)
Expand Down
10 changes: 7 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@
android:taskAffinity=""
android:theme="@android:style/Theme.NoDisplay" />

<activity
android:name=".ui.QsAuthActivity"
android:excludeFromRecents="true"
android:exported="false"
android:taskAffinity=""
android:theme="@android:style/Theme.Translucent.NoTitleBar" />

<activity-alias
android:name=".LauncherActivity"
android:enabled="true"
Expand Down Expand Up @@ -222,9 +229,6 @@
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<!-- START_LEGACY_MIGRATION_CODE -->
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
<!-- END_LEGACY_MIGRATION_CODE -->
</intent-filter>
</receiver>
</application>
Expand Down
43 changes: 21 additions & 22 deletions app/src/main/java/com/ericlowry/dnstoggle/DnsToggleApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import android.os.Handler
import android.os.Looper
import android.provider.Settings
import android.util.Log
import androidx.core.content.ContextCompat
import androidx.core.content.edit
import com.ericlowry.dnstoggle.data.Constants
import com.ericlowry.dnstoggle.data.repository.AppSettingsRepository
Expand Down Expand Up @@ -146,7 +147,7 @@ class DnsToggleApplication : Application() {
override fun onActivityDestroyed(activity: Activity) {}
})

SecurityRepository.initialize(this)
SecurityRepository.initialize()
AppSettingsRepository.initialize(this)
VpnRepository.initialize(this)
NetworkProfileRepository.initialize(this)
Expand Down Expand Up @@ -206,29 +207,27 @@ class DnsToggleApplication : Application() {
}

fun updateWifiMonitoringRegistration() {
applicationScope.launch(Dispatchers.Default) {
val serviceIntent = Intent(this@DnsToggleApplication, WifiMonitoringService::class.java)

if (isWifiMonitoringRequired()) {
try {
androidx.core.content.ContextCompat.startForegroundService(
this@DnsToggleApplication,
serviceIntent
)
} catch (e: Exception) {
Log.e("DnsToggleApplication", "Failed to start foreground service", e)
}
} else {
stopService(serviceIntent)
detectedSsid = null
}
val serviceIntent = Intent(this@DnsToggleApplication, WifiMonitoringService::class.java)

// Tile resync
TileServiceCompat.requestListeningState(
this@DnsToggleApplication,
ComponentName(this@DnsToggleApplication, DnsToggleService::class.java)
)
if (isWifiMonitoringRequired()) {
try {
ContextCompat.startForegroundService(
this@DnsToggleApplication,
serviceIntent
)
} catch (e: Exception) {
Log.e("DnsToggleApplication", "Failed to start foreground service", e)
}
} else {
stopService(serviceIntent)
detectedSsid = null
}

// Tile resync
TileServiceCompat.requestListeningState(
this@DnsToggleApplication,
ComponentName(this@DnsToggleApplication, DnsToggleService::class.java)
)
}

fun updateUsbDebuggingTileAvailability() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@ data class BackupConfig(
val showToast: Boolean = false,
@SerialName("eso") val enableStrictOff: Boolean = false,
@SerialName("dom") val defaultOffMode: String = Constants.DNS_MODE_OPPORTUNISTIC,
@SerialName("vdm") val vpnDnsMode: String = Constants.DNS_MODE_OPPORTUNISTIC
@SerialName("vdm") val vpnDnsMode: String = Constants.DNS_MODE_OPPORTUNISTIC,
@SerialName("am") val authMode: Constants.AuthMode = Constants.AuthMode.NONE,
@SerialName("cwe") val watchdogEnabled: Boolean = false,
@SerialName("cwd") val watchdogDebounceSeconds: Int = Constants.CONNECTIVITY_WATCHDOG_DEFAULT_DEBOUNCE_SECONDS,
@SerialName("cwt") val watchdogProbeTargets: String = Constants.CONNECTIVITY_WATCHDOG_DEFAULT_PROBE_TARGETS
)
24 changes: 19 additions & 5 deletions app/src/main/java/com/ericlowry/dnstoggle/data/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ object Constants {
const val DNS_MODE_HOSTNAME = "hostname"
const val DNS_MODE_OFF = "off"

// START_LEGACY_MIGRATION_CODE: Old shared preference keys
const val PREF_SSID_BLACKLIST = "ssid_blacklist"
const val PREF_SSID_AUTO_DETECTED_BLACKLIST = "ssid_auto_detected_blacklist"
// END_LEGACY_MIGRATION_CODE

// Shared Preferences Keys
const val PREF_NETWORK_PROFILES = "network_profiles"
const val PREF_AUTO_SAVE_STATE = "pref_auto_save_state"
Expand All @@ -29,6 +24,25 @@ object Constants {
const val PREF_USB_DEBUGGING_TILE_UNLOCKED = "usb_debugging_tile_unlocked"
const val PREF_ENABLE_STRICT_OFF_OPTION = "enable_strict_off_option"
const val PREF_DEFAULT_OFF_MODE = "default_off_mode"
const val PREF_AUTH_MODE = "pref_auth_mode"

/**
* Enum representing the authentication requirements for various app actions.
*/
enum class AuthMode {
/** No authentication required. */
NONE,

/** Authentication required when manually toggling DNS or changing security settings. */
ACTION_ONLY,

/** Authentication required both on app startup/resume and for manual actions. */
ALWAYS
}

// Actions
const val ACTION_TOGGLE = "com.ericlowry.dnstoggle.ACTION_TOGGLE"
const val ACTION_SELECT_DNS = "com.ericlowry.dnstoggle.ACTION_SELECT_DNS"

// Connectivity Watchdog Keys
const val PREF_CONNECTIVITY_WATCHDOG_ENABLED = "connectivity_watchdog_enabled"
Expand Down
16 changes: 8 additions & 8 deletions app/src/main/java/com/ericlowry/dnstoggle/data/DnsManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -223,33 +223,33 @@ object DnsManager {
if (enabled) {
if (previousMode != Constants.DNS_MODE_HOSTNAME) {
Toast.makeText(
context,
"${context.getString(R.string.private_dns)}: ${context.getString(R.string.on_label)}",
app,
"${app.getString(R.string.private_dns)}: ${app.getString(R.string.on_label)}",
Toast.LENGTH_SHORT
).show()
} else if (previousHostname != effectiveHostname) {
val displayName =
HostnameRepository.dnsHostnames.value?.find { it.hostname == effectiveHostname }
?.getDisplayName() ?: effectiveHostname
Toast.makeText(
context,
context.getString(R.string.toast_dns_changed, displayName),
app,
app.getString(R.string.toast_dns_changed, displayName),
Toast.LENGTH_SHORT
).show()
}
} else if (previousMode == Constants.DNS_MODE_HOSTNAME) {
val label = when (newMode) {
Constants.DNS_MODE_OFF -> {
context.getString(R.string.off_strict_label)
app.getString(R.string.off_strict_label)
}

else -> {
context.getString(R.string.off_automatic_label)
app.getString(R.string.off_automatic_label)
}
}
Toast.makeText(
context,
"${context.getString(R.string.private_dns)}: $label",
app,
"${app.getString(R.string.private_dns)}: $label",
Toast.LENGTH_SHORT
).show()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ object DnsPolicyEvaluator {
watchdogManager.cancelAll()

if (!isInVpnOverride) {
prefs.edit(commit = true) {
prefs.edit {
putBoolean(Constants.PREF_IS_IN_VPN_OVERRIDE, true)
putString(Constants.PREF_ACTIVE_SSID_OVERRIDE, null)
}
Expand All @@ -95,7 +95,7 @@ object DnsPolicyEvaluator {
}
return@withLock
} else if (!isVpnActive && isInVpnOverride) {
prefs.edit(commit = true) {
prefs.edit {
putBoolean(Constants.PREF_IS_IN_VPN_OVERRIDE, false)
}
dispatchStatusNotification(
Expand All @@ -111,7 +111,7 @@ object DnsPolicyEvaluator {
lastNotifiedSsid = null
watchdogManager.cancelAll()
if (prefs.getString(Constants.PREF_ACTIVE_SSID_OVERRIDE, null) != null) {
prefs.edit(commit = true) {
prefs.edit {
putString(Constants.PREF_ACTIVE_SSID_OVERRIDE, null)
}
}
Expand Down Expand Up @@ -179,7 +179,7 @@ object DnsPolicyEvaluator {
null
) != currentSsid
) {
prefs.edit(commit = true) {
prefs.edit {
putString(Constants.PREF_ACTIVE_SSID_OVERRIDE, currentSsid)
}
}
Expand Down Expand Up @@ -240,7 +240,7 @@ object DnsPolicyEvaluator {
null
) != null
) {
prefs.edit(commit = true) {
prefs.edit {
putString(Constants.PREF_ACTIVE_SSID_OVERRIDE, null)
}
}
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/com/ericlowry/dnstoggle/data/DnsViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import kotlinx.coroutines.withContext
class DnsViewModel(application: Application) : AndroidViewModel(application) {

var ioDispatcher = Dispatchers.IO
var isUnlockedForSession: Boolean = false

private val _privateDnsMode = MutableLiveData<String?>()
val privateDnsMode: LiveData<String?> = _privateDnsMode
Expand Down Expand Up @@ -78,6 +79,9 @@ class DnsViewModel(application: Application) : AndroidViewModel(application) {
private val _showToastEnabled = MutableLiveData<Boolean>()
val showToastEnabled: LiveData<Boolean> = _showToastEnabled

private val _authMode = MutableLiveData<Constants.AuthMode>()
val authMode: LiveData<Constants.AuthMode> = _authMode

private val _vpnOverrideEnabled = MutableLiveData<Boolean>()
val vpnOverrideEnabled: LiveData<Boolean> = _vpnOverrideEnabled

Expand Down Expand Up @@ -160,6 +164,9 @@ class DnsViewModel(application: Application) : AndroidViewModel(application) {
viewModelScope.launch {
AppSettingsRepository.showToastEnabled.collect { _showToastEnabled.postValue(it) }
}
viewModelScope.launch {
AppSettingsRepository.authMode.collect { _authMode.postValue(it) }
}
viewModelScope.launch {
AppSettingsRepository.isInVpnOverride.collect { _isInVpnOverride.postValue(it) }
}
Expand Down Expand Up @@ -333,6 +340,10 @@ class DnsViewModel(application: Application) : AndroidViewModel(application) {
AppSettingsRepository.setShowToast(enabled)
}

fun setAuthMode(mode: Constants.AuthMode) {
AppSettingsRepository.setAuthMode(mode)
}

fun setAutoSaveState(enabled: Boolean) {
AppSettingsRepository.setAutoSaveState(enabled)
}
Expand Down
Loading
Loading