[NS A14] Move code notifying battery stats in its right place

This should be done once every time an interface comes online.
Doing this in updateLinkProperties guarantees this happens every
time a new interface comes online, but it doesn't do it more
often than needed.

Test: FrameworksNetTests NetworkStackTests
Change-Id: I0613c23f44192944266d76107308da8d1c541d1c
This commit is contained in:
Chalard Jean
2019-11-19 19:03:53 +09:00
parent f01b2efc13
commit 9589e72241
2 changed files with 24 additions and 49 deletions

View File

@@ -5664,14 +5664,6 @@ public class ConnectivityServiceTest {
TYPE_WIFI);
reset(mBatteryStatsService);
// TODO : In the current code, ConnectivityService only tells BatteryStatsService about
// the type of networks that satisfy a request. That is a bug in a sense, but it has no
// consequences because a network that never satisfies any request gets torn down right
// away. Because of this, in the context of this test, the cell network agent does not
// satisfy any request as long as WiFi is connected, so the test below would fail if
// the WiFi network agent is not disconnected first. When this bug is fixed, remove the
// WiFi disconnect for more precise testing.
mWiFiNetworkAgent.disconnect();
mCellNetworkAgent.disconnect();
cellLp.setInterfaceName("wifi0");
@@ -5722,13 +5714,12 @@ public class ConnectivityServiceTest {
mCm.registerNetworkCallback(networkRequest, networkCallback);
// Prepare ipv6 only link properties.
mCellNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_CELLULAR);
final int cellNetId = mCellNetworkAgent.getNetwork().netId;
final LinkProperties cellLp = new LinkProperties();
cellLp.setInterfaceName(MOBILE_IFNAME);
cellLp.addLinkAddress(myIpv6);
cellLp.addRoute(new RouteInfo((IpPrefix) null, myIpv6.getAddress(), MOBILE_IFNAME));
cellLp.addRoute(new RouteInfo(myIpv6, null, MOBILE_IFNAME));
mCellNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_CELLULAR, cellLp);
reset(mNetworkManagementService);
reset(mMockDnsResolver);
reset(mMockNetd);
@@ -5737,8 +5728,8 @@ public class ConnectivityServiceTest {
.thenReturn(getClatInterfaceConfig(myIpv4));
// Connect with ipv6 link properties. Expect prefix discovery to be started.
mCellNetworkAgent.sendLinkProperties(cellLp);
mCellNetworkAgent.connect(true);
final int cellNetId = mCellNetworkAgent.getNetwork().netId;
waitForIdle();
verify(mMockNetd, times(1)).networkCreatePhysical(eq(cellNetId), anyInt());
@@ -5811,14 +5802,10 @@ public class ConnectivityServiceTest {
assertEquals(1, resolvrParams.servers.length);
assertTrue(ArrayUtils.contains(resolvrParams.servers, "8.8.8.8"));
// TODO : this should be invoked but in the current code there is no path to invoke
// it. In practice, it will be invoked next time this network changes what requests it
// satisfies through rematchNetworkAndRequests, which may in fact be too late. This code
// should be reinstated when the bug is fixed.
// for (final LinkProperties stackedLp : stackedLpsAfterChange) {
// verify(mBatteryStatsService).noteNetworkInterfaceType(stackedLp.getInterfaceName(),
// TYPE_MOBILE);
// }
for (final LinkProperties stackedLp : stackedLpsAfterChange) {
verify(mBatteryStatsService).noteNetworkInterfaceType(stackedLp.getInterfaceName(),
TYPE_MOBILE);
}
// Add ipv4 address, expect that clatd and prefix discovery are stopped and stacked
// linkproperties are cleaned up.