Allow use of bindProcessToNetwork only to change private DNS bypass.
Currently it is not possible to change private DNS bypass by doing: setProcessDefaultNetwork(network.getPrivateDnsBypassingCopy()); setProcessDefaultNetwork(network); because the code will ignore the change. Fix this by ensuring that we always call bindProcessToNetwork (which does not have side effects) and then only performing the expensive operations (flushing DNS cache, upating socket pools) if the netId changed. Bug: 112869080 Test: None Change-Id: I5e8999cb11d8b8c1e9eb583fa8b3932f212accff
This commit is contained in:
@@ -3970,13 +3970,17 @@ public class ConnectivityManager {
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
public static boolean setProcessDefaultNetwork(@Nullable Network network) {
|
public static boolean setProcessDefaultNetwork(@Nullable Network network) {
|
||||||
int netId = (network == null) ? NETID_UNSET : network.netId;
|
int netId = (network == null) ? NETID_UNSET : network.netId;
|
||||||
if (netId == NetworkUtils.getBoundNetworkForProcess()) {
|
boolean isSameNetId = (netId == NetworkUtils.getBoundNetworkForProcess());
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (netId != NETID_UNSET) {
|
if (netId != NETID_UNSET) {
|
||||||
netId = network.getNetIdForResolv();
|
netId = network.getNetIdForResolv();
|
||||||
}
|
}
|
||||||
if (NetworkUtils.bindProcessToNetwork(netId)) {
|
|
||||||
|
if (!NetworkUtils.bindProcessToNetwork(netId)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isSameNetId) {
|
||||||
// Set HTTP proxy system properties to match network.
|
// Set HTTP proxy system properties to match network.
|
||||||
// TODO: Deprecate this static method and replace it with a non-static version.
|
// TODO: Deprecate this static method and replace it with a non-static version.
|
||||||
try {
|
try {
|
||||||
@@ -3990,10 +3994,9 @@ public class ConnectivityManager {
|
|||||||
// Must flush socket pool as idle sockets will be bound to previous network and may
|
// Must flush socket pool as idle sockets will be bound to previous network and may
|
||||||
// cause subsequent fetches to be performed on old network.
|
// cause subsequent fetches to be performed on old network.
|
||||||
NetworkEventDispatcher.getInstance().onNetworkConfigurationChanged();
|
NetworkEventDispatcher.getInstance().onNetworkConfigurationChanged();
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user