Merge "Note network interfaces based on transport"
This commit is contained in:
@@ -6196,7 +6196,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
nai.networkAgentPortalData = lp.getCaptivePortalData();
|
nai.networkAgentPortalData = lp.getCaptivePortalData();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateLinkProperties(NetworkAgentInfo networkAgent, LinkProperties newLp,
|
private void updateLinkProperties(NetworkAgentInfo networkAgent, @NonNull LinkProperties newLp,
|
||||||
@NonNull LinkProperties oldLp) {
|
@NonNull LinkProperties oldLp) {
|
||||||
int netId = networkAgent.network.getNetId();
|
int netId = networkAgent.network.getNetId();
|
||||||
|
|
||||||
@@ -6205,8 +6205,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
// the LinkProperties for the network are accurate.
|
// the LinkProperties for the network are accurate.
|
||||||
networkAgent.clatd.fixupLinkProperties(oldLp, newLp);
|
networkAgent.clatd.fixupLinkProperties(oldLp, newLp);
|
||||||
|
|
||||||
updateInterfaces(newLp, oldLp, netId, networkAgent.networkCapabilities,
|
updateInterfaces(newLp, oldLp, netId, networkAgent.networkCapabilities);
|
||||||
networkAgent.networkInfo.getType());
|
|
||||||
|
|
||||||
// update filtering rules, need to happen after the interface update so netd knows about the
|
// update filtering rules, need to happen after the interface update so netd knows about the
|
||||||
// new interface (the interface name -> index map becomes initialized)
|
// new interface (the interface name -> index map becomes initialized)
|
||||||
@@ -6345,7 +6344,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
private void updateInterfaces(final @Nullable LinkProperties newLp,
|
private void updateInterfaces(final @Nullable LinkProperties newLp,
|
||||||
final @Nullable LinkProperties oldLp, final int netId,
|
final @Nullable LinkProperties oldLp, final int netId,
|
||||||
final @Nullable NetworkCapabilities caps, final int legacyType) {
|
final @NonNull NetworkCapabilities caps) {
|
||||||
final CompareResult<String> interfaceDiff = new CompareResult<>(
|
final CompareResult<String> interfaceDiff = new CompareResult<>(
|
||||||
oldLp != null ? oldLp.getAllInterfaceNames() : null,
|
oldLp != null ? oldLp.getAllInterfaceNames() : null,
|
||||||
newLp != null ? newLp.getAllInterfaceNames() : null);
|
newLp != null ? newLp.getAllInterfaceNames() : null);
|
||||||
@@ -6356,7 +6355,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
if (DBG) log("Adding iface " + iface + " to network " + netId);
|
if (DBG) log("Adding iface " + iface + " to network " + netId);
|
||||||
mNetd.networkAddInterface(netId, iface);
|
mNetd.networkAddInterface(netId, iface);
|
||||||
wakeupModifyInterface(iface, caps, true);
|
wakeupModifyInterface(iface, caps, true);
|
||||||
bs.noteNetworkInterfaceType(iface, legacyType);
|
bs.noteNetworkInterfaceForTransports(iface, caps.getTransportTypes());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
loge("Exception adding interface: " + e);
|
loge("Exception adding interface: " + e);
|
||||||
}
|
}
|
||||||
@@ -6628,6 +6627,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
* maintained here that the NetworkAgent is not aware of (e.g., validated, captive portal,
|
* maintained here that the NetworkAgent is not aware of (e.g., validated, captive portal,
|
||||||
* and foreground status).
|
* and foreground status).
|
||||||
*/
|
*/
|
||||||
|
@NonNull
|
||||||
private NetworkCapabilities mixInCapabilities(NetworkAgentInfo nai, NetworkCapabilities nc) {
|
private NetworkCapabilities mixInCapabilities(NetworkAgentInfo nai, NetworkCapabilities nc) {
|
||||||
// Once a NetworkAgent is connected, complain if some immutable capabilities are removed.
|
// Once a NetworkAgent is connected, complain if some immutable capabilities are removed.
|
||||||
// Don't complain for VPNs since they're not driven by requests and there is no risk of
|
// Don't complain for VPNs since they're not driven by requests and there is no risk of
|
||||||
|
|||||||
@@ -329,7 +329,7 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
|
|||||||
private final QosCallbackTracker mQosCallbackTracker;
|
private final QosCallbackTracker mQosCallbackTracker;
|
||||||
|
|
||||||
public NetworkAgentInfo(INetworkAgent na, Network net, NetworkInfo info,
|
public NetworkAgentInfo(INetworkAgent na, Network net, NetworkInfo info,
|
||||||
LinkProperties lp, NetworkCapabilities nc, int score, Context context,
|
@NonNull LinkProperties lp, @NonNull NetworkCapabilities nc, int score, Context context,
|
||||||
Handler handler, NetworkAgentConfig config, ConnectivityService connService, INetd netd,
|
Handler handler, NetworkAgentConfig config, ConnectivityService connService, INetd netd,
|
||||||
IDnsResolver dnsResolver, INetworkManagementService nms, int factorySerialNumber,
|
IDnsResolver dnsResolver, INetworkManagementService nms, int factorySerialNumber,
|
||||||
int creatorUid, QosCallbackTracker qosCallbackTracker) {
|
int creatorUid, QosCallbackTracker qosCallbackTracker) {
|
||||||
|
|||||||
@@ -7358,7 +7358,6 @@ public class ConnectivityServiceTest {
|
|||||||
mCm.unregisterNetworkCallback(trustedCallback);
|
mCm.unregisterNetworkCallback(trustedCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore // 40%+ flakiness : figure out why and re-enable.
|
|
||||||
@Test
|
@Test
|
||||||
public final void testBatteryStatsNetworkType() throws Exception {
|
public final void testBatteryStatsNetworkType() throws Exception {
|
||||||
final LinkProperties cellLp = new LinkProperties();
|
final LinkProperties cellLp = new LinkProperties();
|
||||||
@@ -7366,8 +7365,8 @@ public class ConnectivityServiceTest {
|
|||||||
mCellNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_CELLULAR, cellLp);
|
mCellNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_CELLULAR, cellLp);
|
||||||
mCellNetworkAgent.connect(true);
|
mCellNetworkAgent.connect(true);
|
||||||
waitForIdle();
|
waitForIdle();
|
||||||
verify(mBatteryStatsService).noteNetworkInterfaceType(cellLp.getInterfaceName(),
|
verify(mBatteryStatsService).noteNetworkInterfaceForTransports(cellLp.getInterfaceName(),
|
||||||
TYPE_MOBILE);
|
new int[] { TRANSPORT_CELLULAR });
|
||||||
reset(mBatteryStatsService);
|
reset(mBatteryStatsService);
|
||||||
|
|
||||||
final LinkProperties wifiLp = new LinkProperties();
|
final LinkProperties wifiLp = new LinkProperties();
|
||||||
@@ -7375,18 +7374,20 @@ public class ConnectivityServiceTest {
|
|||||||
mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI, wifiLp);
|
mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI, wifiLp);
|
||||||
mWiFiNetworkAgent.connect(true);
|
mWiFiNetworkAgent.connect(true);
|
||||||
waitForIdle();
|
waitForIdle();
|
||||||
verify(mBatteryStatsService).noteNetworkInterfaceType(wifiLp.getInterfaceName(),
|
verify(mBatteryStatsService).noteNetworkInterfaceForTransports(wifiLp.getInterfaceName(),
|
||||||
TYPE_WIFI);
|
new int[] { TRANSPORT_WIFI });
|
||||||
reset(mBatteryStatsService);
|
reset(mBatteryStatsService);
|
||||||
|
|
||||||
mCellNetworkAgent.disconnect();
|
mCellNetworkAgent.disconnect();
|
||||||
|
mWiFiNetworkAgent.disconnect();
|
||||||
|
|
||||||
cellLp.setInterfaceName("wifi0");
|
cellLp.setInterfaceName("wifi0");
|
||||||
mCellNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_CELLULAR, cellLp);
|
mCellNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_CELLULAR, cellLp);
|
||||||
mCellNetworkAgent.connect(true);
|
mCellNetworkAgent.connect(true);
|
||||||
waitForIdle();
|
waitForIdle();
|
||||||
verify(mBatteryStatsService).noteNetworkInterfaceType(cellLp.getInterfaceName(),
|
verify(mBatteryStatsService).noteNetworkInterfaceForTransports(cellLp.getInterfaceName(),
|
||||||
TYPE_MOBILE);
|
new int[] { TRANSPORT_CELLULAR });
|
||||||
|
mCellNetworkAgent.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -7459,8 +7460,8 @@ public class ConnectivityServiceTest {
|
|||||||
assertRoutesAdded(cellNetId, ipv6Subnet, defaultRoute);
|
assertRoutesAdded(cellNetId, ipv6Subnet, defaultRoute);
|
||||||
verify(mMockDnsResolver, times(1)).createNetworkCache(eq(cellNetId));
|
verify(mMockDnsResolver, times(1)).createNetworkCache(eq(cellNetId));
|
||||||
verify(mMockNetd, times(1)).networkAddInterface(cellNetId, MOBILE_IFNAME);
|
verify(mMockNetd, times(1)).networkAddInterface(cellNetId, MOBILE_IFNAME);
|
||||||
verify(mBatteryStatsService).noteNetworkInterfaceType(cellLp.getInterfaceName(),
|
verify(mBatteryStatsService).noteNetworkInterfaceForTransports(cellLp.getInterfaceName(),
|
||||||
TYPE_MOBILE);
|
new int[] { TRANSPORT_CELLULAR });
|
||||||
|
|
||||||
networkCallback.expectAvailableThenValidatedCallbacks(mCellNetworkAgent);
|
networkCallback.expectAvailableThenValidatedCallbacks(mCellNetworkAgent);
|
||||||
verify(mMockDnsResolver, times(1)).startPrefix64Discovery(cellNetId);
|
verify(mMockDnsResolver, times(1)).startPrefix64Discovery(cellNetId);
|
||||||
@@ -7480,7 +7481,8 @@ public class ConnectivityServiceTest {
|
|||||||
// Make sure BatteryStats was not told about any v4- interfaces, as none should have
|
// Make sure BatteryStats was not told about any v4- interfaces, as none should have
|
||||||
// come online yet.
|
// come online yet.
|
||||||
waitForIdle();
|
waitForIdle();
|
||||||
verify(mBatteryStatsService, never()).noteNetworkInterfaceType(startsWith("v4-"), anyInt());
|
verify(mBatteryStatsService, never()).noteNetworkInterfaceForTransports(startsWith("v4-"),
|
||||||
|
any());
|
||||||
|
|
||||||
verifyNoMoreInteractions(mMockNetd);
|
verifyNoMoreInteractions(mMockNetd);
|
||||||
verifyNoMoreInteractions(mMockDnsResolver);
|
verifyNoMoreInteractions(mMockDnsResolver);
|
||||||
@@ -7533,8 +7535,8 @@ public class ConnectivityServiceTest {
|
|||||||
assertTrue(ArrayUtils.contains(resolvrParams.servers, "8.8.8.8"));
|
assertTrue(ArrayUtils.contains(resolvrParams.servers, "8.8.8.8"));
|
||||||
|
|
||||||
for (final LinkProperties stackedLp : stackedLpsAfterChange) {
|
for (final LinkProperties stackedLp : stackedLpsAfterChange) {
|
||||||
verify(mBatteryStatsService).noteNetworkInterfaceType(stackedLp.getInterfaceName(),
|
verify(mBatteryStatsService).noteNetworkInterfaceForTransports(
|
||||||
TYPE_MOBILE);
|
stackedLp.getInterfaceName(), new int[] { TRANSPORT_CELLULAR });
|
||||||
}
|
}
|
||||||
reset(mMockNetd);
|
reset(mMockNetd);
|
||||||
when(mMockNetd.interfaceGetCfg(CLAT_PREFIX + MOBILE_IFNAME))
|
when(mMockNetd.interfaceGetCfg(CLAT_PREFIX + MOBILE_IFNAME))
|
||||||
|
|||||||
Reference in New Issue
Block a user