Merge "Make DNS cache lifecycle management explicit"
This commit is contained in:
commit
a6d5664819
@ -362,18 +362,6 @@ interface INetworkManagementService
|
||||
*/
|
||||
boolean isNetworkActive();
|
||||
|
||||
/**
|
||||
* Setup a new physical network.
|
||||
* @param permission PERMISSION_NONE if no permissions required to access this network.
|
||||
* PERMISSION_NETWORK or PERMISSION_SYSTEM to set respective permission.
|
||||
*/
|
||||
void createPhysicalNetwork(int netId, int permission);
|
||||
|
||||
/**
|
||||
* Setup a new VPN.
|
||||
*/
|
||||
void createVirtualNetwork(int netId, boolean secure);
|
||||
|
||||
/**
|
||||
* Add an interface to a network.
|
||||
*/
|
||||
|
@ -3070,11 +3070,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
// fallback network the default or requested a new network from the
|
||||
// NetworkFactories, so network traffic isn't interrupted for an unnecessarily
|
||||
// long time.
|
||||
try {
|
||||
mNetd.networkDestroy(nai.network.netId);
|
||||
} catch (RemoteException | ServiceSpecificException e) {
|
||||
loge("Exception destroying network: " + e);
|
||||
}
|
||||
destroyNativeNetwork(nai);
|
||||
mDnsManager.removeNetwork(nai.network);
|
||||
}
|
||||
synchronized (mNetworkForNetId) {
|
||||
@ -3082,6 +3078,35 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
}
|
||||
}
|
||||
|
||||
private boolean createNativeNetwork(@NonNull NetworkAgentInfo networkAgent) {
|
||||
try {
|
||||
// This should never fail. Specifying an already in use NetID will cause failure.
|
||||
if (networkAgent.isVPN()) {
|
||||
mNetd.networkCreateVpn(networkAgent.network.netId,
|
||||
(networkAgent.networkMisc == null
|
||||
|| !networkAgent.networkMisc.allowBypass));
|
||||
} else {
|
||||
mNetd.networkCreatePhysical(networkAgent.network.netId,
|
||||
getNetworkPermission(networkAgent.networkCapabilities));
|
||||
}
|
||||
mDnsResolver.createNetworkCache(networkAgent.network.netId);
|
||||
return true;
|
||||
} catch (RemoteException | ServiceSpecificException e) {
|
||||
loge("Error creating network " + networkAgent.network.netId + ": "
|
||||
+ e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void destroyNativeNetwork(@NonNull NetworkAgentInfo networkAgent) {
|
||||
try {
|
||||
mNetd.networkDestroy(networkAgent.network.netId);
|
||||
mDnsResolver.destroyNetworkCache(networkAgent.network.netId);
|
||||
} catch (RemoteException | ServiceSpecificException e) {
|
||||
loge("Exception destroying network: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
// If this method proves to be too slow then we can maintain a separate
|
||||
// pendingIntent => NetworkRequestInfo map.
|
||||
// This method assumes that every non-null PendingIntent maps to exactly 1 NetworkRequestInfo.
|
||||
@ -6482,21 +6507,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
// A network that has just connected has zero requests and is thus a foreground network.
|
||||
networkAgent.networkCapabilities.addCapability(NET_CAPABILITY_FOREGROUND);
|
||||
|
||||
try {
|
||||
// This should never fail. Specifying an already in use NetID will cause failure.
|
||||
if (networkAgent.isVPN()) {
|
||||
mNMS.createVirtualNetwork(networkAgent.network.netId,
|
||||
(networkAgent.networkMisc == null ||
|
||||
!networkAgent.networkMisc.allowBypass));
|
||||
} else {
|
||||
mNMS.createPhysicalNetwork(networkAgent.network.netId,
|
||||
getNetworkPermission(networkAgent.networkCapabilities));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
loge("Error creating network " + networkAgent.network.netId + ": "
|
||||
+ e.getMessage());
|
||||
return;
|
||||
}
|
||||
if (!createNativeNetwork(networkAgent)) return;
|
||||
networkAgent.created = true;
|
||||
}
|
||||
|
||||
|
@ -2044,28 +2044,6 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
||||
pw.println("]");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createPhysicalNetwork(int netId, int permission) {
|
||||
mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
|
||||
|
||||
try {
|
||||
mNetdService.networkCreatePhysical(netId, permission);
|
||||
} catch (RemoteException | ServiceSpecificException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createVirtualNetwork(int netId, boolean secure) {
|
||||
mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
|
||||
|
||||
try {
|
||||
mNetdService.networkCreateVpn(netId, secure);
|
||||
} catch (RemoteException | ServiceSpecificException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInterfaceToNetwork(String iface, int netId) {
|
||||
modifyInterfaceInNetwork(MODIFY_OPERATION_ADD, netId, iface);
|
||||
|
@ -263,12 +263,6 @@ public class DnsManager {
|
||||
}
|
||||
|
||||
public void removeNetwork(Network network) {
|
||||
try {
|
||||
mDnsResolver.clearResolverConfiguration(network.netId);
|
||||
} catch (RemoteException | ServiceSpecificException e) {
|
||||
Slog.e(TAG, "Error clearing DNS configuration: " + e);
|
||||
return;
|
||||
}
|
||||
mPrivateDnsMap.remove(network.netId);
|
||||
mPrivateDnsValidationMap.remove(network.netId);
|
||||
}
|
||||
|
@ -4919,7 +4919,10 @@ public class ConnectivityServiceTest {
|
||||
mCellNetworkAgent.sendLinkProperties(cellLp);
|
||||
mCellNetworkAgent.connect(false);
|
||||
waitForIdle();
|
||||
// CS tells netd about the empty DNS config for this network.
|
||||
|
||||
verify(mMockDnsResolver, times(1)).createNetworkCache(
|
||||
eq(mCellNetworkAgent.getNetwork().netId));
|
||||
// CS tells dnsresolver about the empty DNS config for this network.
|
||||
verify(mMockDnsResolver, atLeastOnce()).setResolverConfiguration(any());
|
||||
reset(mMockDnsResolver);
|
||||
|
||||
@ -5003,6 +5006,8 @@ public class ConnectivityServiceTest {
|
||||
mCellNetworkAgent.sendLinkProperties(cellLp);
|
||||
mCellNetworkAgent.connect(false);
|
||||
waitForIdle();
|
||||
verify(mMockDnsResolver, times(1)).createNetworkCache(
|
||||
eq(mCellNetworkAgent.getNetwork().netId));
|
||||
verify(mMockDnsResolver, atLeastOnce()).setResolverConfiguration(
|
||||
mResolverParamsParcelCaptor.capture());
|
||||
ResolverParamsParcel resolvrParams = mResolverParamsParcelCaptor.getValue();
|
||||
@ -5876,12 +5881,17 @@ public class ConnectivityServiceTest {
|
||||
cellLp.addRoute(new RouteInfo(myIpv6, null, MOBILE_IFNAME));
|
||||
reset(mNetworkManagementService);
|
||||
reset(mMockDnsResolver);
|
||||
reset(mMockNetd);
|
||||
when(mNetworkManagementService.getInterfaceConfig(CLAT_PREFIX + MOBILE_IFNAME))
|
||||
.thenReturn(getClatInterfaceConfig(myIpv4));
|
||||
|
||||
// Connect with ipv6 link properties. Expect prefix discovery to be started.
|
||||
mCellNetworkAgent.sendLinkProperties(cellLp);
|
||||
mCellNetworkAgent.connect(true);
|
||||
|
||||
verify(mMockNetd, times(1)).networkCreatePhysical(eq(cellNetId), anyInt());
|
||||
verify(mMockDnsResolver, times(1)).createNetworkCache(eq(cellNetId));
|
||||
|
||||
networkCallback.expectAvailableThenValidatedCallbacks(mCellNetworkAgent);
|
||||
verify(mMockDnsResolver, times(1)).startPrefix64Discovery(cellNetId);
|
||||
|
||||
@ -6073,7 +6083,7 @@ public class ConnectivityServiceTest {
|
||||
verify(mNetworkManagementService, times(0)).removeIdleTimer(eq(MOBILE_IFNAME));
|
||||
verify(mMockNetd, times(1)).networkDestroy(eq(mCellNetworkAgent.getNetwork().netId));
|
||||
verify(mMockDnsResolver, times(1))
|
||||
.clearResolverConfiguration(eq(mCellNetworkAgent.getNetwork().netId));
|
||||
.destroyNetworkCache(eq(mCellNetworkAgent.getNetwork().netId));
|
||||
|
||||
// Disconnect wifi
|
||||
ConditionVariable cv = waitForConnectivityBroadcasts(1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user