-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PIA-625: Introduce DNS option to enable system resolver (#30)
* Introduce DNS option to enable system resolver * update subnet utils * Update translations with crowdin-provided files * update dns option selection logic to avoid a potential out of bounds exception * review: add parenthesis to make the operation more explicit * PIA-625: Fix edge case where 32 bitmasks were being wrongly processed as being contained in some cidr ranges --------- Co-authored-by: Aldo Pedromingo <[email protected]>
- Loading branch information
1 parent
21ac50f
commit 4624f9c
Showing
26 changed files
with
580 additions
and
255 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
app/src/main/java/com/privateinternetaccess/android/pia/providers/DnsProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.privateinternetaccess.android.pia.providers | ||
|
||
import android.content.Context | ||
import android.net.ConnectivityManager | ||
import android.os.Build | ||
import com.privateinternetaccess.android.pia.handlers.PiaPrefHandler | ||
|
||
object DnsProvider { | ||
|
||
private const val MACE_DNS = "10.0.0.241" | ||
private const val PIA_DNS = "10.0.0.242" | ||
|
||
fun getTargetDns(context: Context, defaultDns: String? = null): Pair<String, String?> { | ||
var primaryDns: String = defaultDns ?: PIA_DNS | ||
var secondaryDns: String? = null | ||
|
||
if (PiaPrefHandler.isMaceEnabled(context)) { | ||
primaryDns = MACE_DNS | ||
} else if (PiaPrefHandler.isCustomDnsSelected(context)) { | ||
PiaPrefHandler.getPrimaryDns(context)?.let { | ||
primaryDns = it | ||
} | ||
PiaPrefHandler.getSecondaryDns(context)?.let { | ||
secondaryDns = it | ||
} | ||
} else if ( | ||
PiaPrefHandler.isSystemDnsResolverSelected(context) && | ||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M | ||
) { | ||
val connectivityManager: ConnectivityManager = | ||
context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager | ||
val network = connectivityManager.activeNetwork | ||
connectivityManager.getLinkProperties(network)?.dnsServers?.let { dnsServers -> | ||
dnsServers.firstOrNull()?.hostAddress?.let { | ||
primaryDns = it | ||
} | ||
if (dnsServers.size > 1) { | ||
dnsServers.lastOrNull()?.hostAddress?.let { | ||
secondaryDns = it | ||
} | ||
} | ||
} | ||
} | ||
|
||
return Pair(primaryDns, secondaryDns) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.