Remove all static members from NetworkStatsFactory.
NetworkStatsFactory is owned by NetworkStatsService, and any accesses to NSF data should go through NSS. Test: atest FrameworksNetTests Change-Id: Idbd0dbbaeb11313f63474e7ec0e01f974349fc89
This commit is contained in:
@@ -192,7 +192,6 @@ import com.android.server.net.BaseNetdEventCallback;
|
|||||||
import com.android.server.net.BaseNetworkObserver;
|
import com.android.server.net.BaseNetworkObserver;
|
||||||
import com.android.server.net.LockdownVpnTracker;
|
import com.android.server.net.LockdownVpnTracker;
|
||||||
import com.android.server.net.NetworkPolicyManagerInternal;
|
import com.android.server.net.NetworkPolicyManagerInternal;
|
||||||
import com.android.server.net.NetworkStatsFactory;
|
|
||||||
import com.android.server.utils.PriorityDump;
|
import com.android.server.utils.PriorityDump;
|
||||||
|
|
||||||
import com.google.android.collect.Lists;
|
import com.google.android.collect.Lists;
|
||||||
@@ -6800,8 +6799,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify NetworkStatsService and NetworkStatsFactory that the set of active ifaces has changed,
|
* Notify NetworkStatsService that the set of active ifaces has changed, or that one of the
|
||||||
* or that one of the active iface's trackedproperties has changed.
|
* active iface's tracked properties has changed.
|
||||||
*/
|
*/
|
||||||
private void notifyIfacesChangedForNetworkStats() {
|
private void notifyIfacesChangedForNetworkStats() {
|
||||||
ensureRunningOnConnectivityServiceThread();
|
ensureRunningOnConnectivityServiceThread();
|
||||||
@@ -6811,16 +6810,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
activeIface = activeLinkProperties.getInterfaceName();
|
activeIface = activeLinkProperties.getInterfaceName();
|
||||||
}
|
}
|
||||||
|
|
||||||
// CAUTION: Ordering matters between updateVpnInfos() and forceUpdateIfaces(), which
|
final VpnInfo[] vpnInfos = getAllVpnInfo();
|
||||||
// triggers a new poll. Trigger the poll first to ensure a snapshot is taken before
|
|
||||||
// switching to the new state. This ensures that traffic does not get mis-attributed to
|
|
||||||
// incorrect apps (including VPN app).
|
|
||||||
try {
|
try {
|
||||||
mStatsService.forceUpdateIfaces(
|
mStatsService.forceUpdateIfaces(
|
||||||
getDefaultNetworks(), getAllNetworkState(), activeIface);
|
getDefaultNetworks(), getAllNetworkState(), activeIface, vpnInfos);
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
NetworkStatsFactory.updateVpnInfos(getAllVpnInfo());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -205,7 +205,6 @@ import com.android.server.connectivity.Tethering;
|
|||||||
import com.android.server.connectivity.Vpn;
|
import com.android.server.connectivity.Vpn;
|
||||||
import com.android.server.net.NetworkPinner;
|
import com.android.server.net.NetworkPinner;
|
||||||
import com.android.server.net.NetworkPolicyManagerInternal;
|
import com.android.server.net.NetworkPolicyManagerInternal;
|
||||||
import com.android.server.net.NetworkStatsFactory;
|
|
||||||
import com.android.testutils.HandlerUtilsKt;
|
import com.android.testutils.HandlerUtilsKt;
|
||||||
import com.android.testutils.ThrowingConsumer;
|
import com.android.testutils.ThrowingConsumer;
|
||||||
|
|
||||||
@@ -4882,11 +4881,8 @@ public class ConnectivityServiceTest {
|
|||||||
mCellNetworkAgent.sendLinkProperties(cellLp);
|
mCellNetworkAgent.sendLinkProperties(cellLp);
|
||||||
waitForIdle();
|
waitForIdle();
|
||||||
verify(mStatsService, atLeastOnce())
|
verify(mStatsService, atLeastOnce())
|
||||||
.forceUpdateIfaces(
|
.forceUpdateIfaces(eq(onlyCell), any(NetworkState[].class), eq(MOBILE_IFNAME),
|
||||||
eq(onlyCell),
|
eq(new VpnInfo[0]));
|
||||||
any(NetworkState[].class),
|
|
||||||
eq(MOBILE_IFNAME));
|
|
||||||
assertEquals(new VpnInfo[0], NetworkStatsFactory.getVpnInfos());
|
|
||||||
reset(mStatsService);
|
reset(mStatsService);
|
||||||
|
|
||||||
// Default network switch should update ifaces.
|
// Default network switch should update ifaces.
|
||||||
@@ -4895,65 +4891,47 @@ public class ConnectivityServiceTest {
|
|||||||
waitForIdle();
|
waitForIdle();
|
||||||
assertEquals(wifiLp, mService.getActiveLinkProperties());
|
assertEquals(wifiLp, mService.getActiveLinkProperties());
|
||||||
verify(mStatsService, atLeastOnce())
|
verify(mStatsService, atLeastOnce())
|
||||||
.forceUpdateIfaces(
|
.forceUpdateIfaces(eq(onlyWifi), any(NetworkState[].class), eq(WIFI_IFNAME),
|
||||||
eq(onlyWifi),
|
eq(new VpnInfo[0]));
|
||||||
any(NetworkState[].class),
|
|
||||||
eq(WIFI_IFNAME));
|
|
||||||
assertEquals(new VpnInfo[0], NetworkStatsFactory.getVpnInfos());
|
|
||||||
reset(mStatsService);
|
reset(mStatsService);
|
||||||
|
|
||||||
// Disconnect should update ifaces.
|
// Disconnect should update ifaces.
|
||||||
mWiFiNetworkAgent.disconnect();
|
mWiFiNetworkAgent.disconnect();
|
||||||
waitForIdle();
|
waitForIdle();
|
||||||
verify(mStatsService, atLeastOnce())
|
verify(mStatsService, atLeastOnce())
|
||||||
.forceUpdateIfaces(
|
.forceUpdateIfaces(eq(onlyCell), any(NetworkState[].class),
|
||||||
eq(onlyCell),
|
eq(MOBILE_IFNAME), eq(new VpnInfo[0]));
|
||||||
any(NetworkState[].class),
|
|
||||||
eq(MOBILE_IFNAME));
|
|
||||||
assertEquals(new VpnInfo[0], NetworkStatsFactory.getVpnInfos());
|
|
||||||
reset(mStatsService);
|
reset(mStatsService);
|
||||||
|
|
||||||
// Metered change should update ifaces
|
// Metered change should update ifaces
|
||||||
mCellNetworkAgent.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
|
mCellNetworkAgent.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
|
||||||
waitForIdle();
|
waitForIdle();
|
||||||
verify(mStatsService, atLeastOnce())
|
verify(mStatsService, atLeastOnce())
|
||||||
.forceUpdateIfaces(
|
.forceUpdateIfaces(eq(onlyCell), any(NetworkState[].class), eq(MOBILE_IFNAME),
|
||||||
eq(onlyCell),
|
eq(new VpnInfo[0]));
|
||||||
any(NetworkState[].class),
|
|
||||||
eq(MOBILE_IFNAME));
|
|
||||||
assertEquals(new VpnInfo[0], NetworkStatsFactory.getVpnInfos());
|
|
||||||
reset(mStatsService);
|
reset(mStatsService);
|
||||||
|
|
||||||
mCellNetworkAgent.removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
|
mCellNetworkAgent.removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
|
||||||
waitForIdle();
|
waitForIdle();
|
||||||
verify(mStatsService, atLeastOnce())
|
verify(mStatsService, atLeastOnce())
|
||||||
.forceUpdateIfaces(
|
.forceUpdateIfaces(eq(onlyCell), any(NetworkState[].class), eq(MOBILE_IFNAME),
|
||||||
eq(onlyCell),
|
eq(new VpnInfo[0]));
|
||||||
any(NetworkState[].class),
|
|
||||||
eq(MOBILE_IFNAME));
|
|
||||||
assertEquals(new VpnInfo[0], NetworkStatsFactory.getVpnInfos());
|
|
||||||
reset(mStatsService);
|
reset(mStatsService);
|
||||||
|
|
||||||
// Captive portal change shouldn't update ifaces
|
// Captive portal change shouldn't update ifaces
|
||||||
mCellNetworkAgent.addCapability(NetworkCapabilities.NET_CAPABILITY_CAPTIVE_PORTAL);
|
mCellNetworkAgent.addCapability(NetworkCapabilities.NET_CAPABILITY_CAPTIVE_PORTAL);
|
||||||
waitForIdle();
|
waitForIdle();
|
||||||
verify(mStatsService, never())
|
verify(mStatsService, never())
|
||||||
.forceUpdateIfaces(
|
.forceUpdateIfaces(eq(onlyCell), any(NetworkState[].class), eq(MOBILE_IFNAME),
|
||||||
eq(onlyCell),
|
eq(new VpnInfo[0]));
|
||||||
any(NetworkState[].class),
|
|
||||||
eq(MOBILE_IFNAME));
|
|
||||||
assertEquals(new VpnInfo[0], NetworkStatsFactory.getVpnInfos());
|
|
||||||
reset(mStatsService);
|
reset(mStatsService);
|
||||||
|
|
||||||
// Roaming change should update ifaces
|
// Roaming change should update ifaces
|
||||||
mCellNetworkAgent.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_ROAMING);
|
mCellNetworkAgent.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_ROAMING);
|
||||||
waitForIdle();
|
waitForIdle();
|
||||||
verify(mStatsService, atLeastOnce())
|
verify(mStatsService, atLeastOnce())
|
||||||
.forceUpdateIfaces(
|
.forceUpdateIfaces(eq(onlyCell), any(NetworkState[].class), eq(MOBILE_IFNAME),
|
||||||
eq(onlyCell),
|
eq(new VpnInfo[0]));
|
||||||
any(NetworkState[].class),
|
|
||||||
eq(MOBILE_IFNAME));
|
|
||||||
assertEquals(new VpnInfo[0], NetworkStatsFactory.getVpnInfos());
|
|
||||||
reset(mStatsService);
|
reset(mStatsService);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -79,8 +79,7 @@ public class NetworkStatsFactoryTest extends NetworkStatsBaseTest {
|
|||||||
// related to networkStatsFactory is compiled to a minimal native library and loaded here.
|
// related to networkStatsFactory is compiled to a minimal native library and loaded here.
|
||||||
System.loadLibrary("networkstatsfactorytestjni");
|
System.loadLibrary("networkstatsfactorytestjni");
|
||||||
mFactory = new NetworkStatsFactory(mTestProc, false);
|
mFactory = new NetworkStatsFactory(mTestProc, false);
|
||||||
NetworkStatsFactory.updateVpnInfos(new VpnInfo[0]);
|
mFactory.updateVpnInfos(new VpnInfo[0]);
|
||||||
NetworkStatsFactory.clearStackedIfaces();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
@@ -107,7 +106,7 @@ public class NetworkStatsFactoryTest extends NetworkStatsBaseTest {
|
|||||||
@Test
|
@Test
|
||||||
public void vpnRewriteTrafficThroughItself() throws Exception {
|
public void vpnRewriteTrafficThroughItself() throws Exception {
|
||||||
VpnInfo[] vpnInfos = new VpnInfo[] {createVpnInfo(new String[] {TEST_IFACE})};
|
VpnInfo[] vpnInfos = new VpnInfo[] {createVpnInfo(new String[] {TEST_IFACE})};
|
||||||
NetworkStatsFactory.updateVpnInfos(vpnInfos);
|
mFactory.updateVpnInfos(vpnInfos);
|
||||||
|
|
||||||
// create some traffic (assume 10 bytes of MTU for VPN interface and 1 byte encryption
|
// create some traffic (assume 10 bytes of MTU for VPN interface and 1 byte encryption
|
||||||
// overhead per packet):
|
// overhead per packet):
|
||||||
@@ -136,8 +135,8 @@ public class NetworkStatsFactoryTest extends NetworkStatsBaseTest {
|
|||||||
@Test
|
@Test
|
||||||
public void vpnWithClat() throws Exception {
|
public void vpnWithClat() throws Exception {
|
||||||
VpnInfo[] vpnInfos = new VpnInfo[] {createVpnInfo(new String[] {CLAT_PREFIX + TEST_IFACE})};
|
VpnInfo[] vpnInfos = new VpnInfo[] {createVpnInfo(new String[] {CLAT_PREFIX + TEST_IFACE})};
|
||||||
NetworkStatsFactory.updateVpnInfos(vpnInfos);
|
mFactory.updateVpnInfos(vpnInfos);
|
||||||
NetworkStatsFactory.noteStackedIface(CLAT_PREFIX + TEST_IFACE, TEST_IFACE);
|
mFactory.noteStackedIface(CLAT_PREFIX + TEST_IFACE, TEST_IFACE);
|
||||||
|
|
||||||
// create some traffic (assume 10 bytes of MTU for VPN interface and 1 byte encryption
|
// create some traffic (assume 10 bytes of MTU for VPN interface and 1 byte encryption
|
||||||
// overhead per packet):
|
// overhead per packet):
|
||||||
@@ -169,7 +168,7 @@ public class NetworkStatsFactoryTest extends NetworkStatsBaseTest {
|
|||||||
@Test
|
@Test
|
||||||
public void vpnWithOneUnderlyingIface() throws Exception {
|
public void vpnWithOneUnderlyingIface() throws Exception {
|
||||||
VpnInfo[] vpnInfos = new VpnInfo[] {createVpnInfo(new String[] {TEST_IFACE})};
|
VpnInfo[] vpnInfos = new VpnInfo[] {createVpnInfo(new String[] {TEST_IFACE})};
|
||||||
NetworkStatsFactory.updateVpnInfos(vpnInfos);
|
mFactory.updateVpnInfos(vpnInfos);
|
||||||
|
|
||||||
// create some traffic (assume 10 bytes of MTU for VPN interface and 1 byte encryption
|
// create some traffic (assume 10 bytes of MTU for VPN interface and 1 byte encryption
|
||||||
// overhead per packet):
|
// overhead per packet):
|
||||||
@@ -193,7 +192,7 @@ public class NetworkStatsFactoryTest extends NetworkStatsBaseTest {
|
|||||||
public void vpnWithOneUnderlyingIfaceAndOwnTraffic() throws Exception {
|
public void vpnWithOneUnderlyingIfaceAndOwnTraffic() throws Exception {
|
||||||
// WiFi network is connected and VPN is using WiFi (which has TEST_IFACE).
|
// WiFi network is connected and VPN is using WiFi (which has TEST_IFACE).
|
||||||
VpnInfo[] vpnInfos = new VpnInfo[] {createVpnInfo(new String[] {TEST_IFACE})};
|
VpnInfo[] vpnInfos = new VpnInfo[] {createVpnInfo(new String[] {TEST_IFACE})};
|
||||||
NetworkStatsFactory.updateVpnInfos(vpnInfos);
|
mFactory.updateVpnInfos(vpnInfos);
|
||||||
|
|
||||||
// create some traffic (assume 10 bytes of MTU for VPN interface and 1 byte encryption
|
// create some traffic (assume 10 bytes of MTU for VPN interface and 1 byte encryption
|
||||||
// overhead per packet):
|
// overhead per packet):
|
||||||
@@ -221,7 +220,7 @@ public class NetworkStatsFactoryTest extends NetworkStatsBaseTest {
|
|||||||
public void vpnWithOneUnderlyingIface_withCompression() throws Exception {
|
public void vpnWithOneUnderlyingIface_withCompression() throws Exception {
|
||||||
// WiFi network is connected and VPN is using WiFi (which has TEST_IFACE).
|
// WiFi network is connected and VPN is using WiFi (which has TEST_IFACE).
|
||||||
VpnInfo[] vpnInfos = new VpnInfo[] {createVpnInfo(new String[] {TEST_IFACE})};
|
VpnInfo[] vpnInfos = new VpnInfo[] {createVpnInfo(new String[] {TEST_IFACE})};
|
||||||
NetworkStatsFactory.updateVpnInfos(vpnInfos);
|
mFactory.updateVpnInfos(vpnInfos);
|
||||||
|
|
||||||
// create some traffic (assume 10 bytes of MTU for VPN interface and 1 byte encryption
|
// create some traffic (assume 10 bytes of MTU for VPN interface and 1 byte encryption
|
||||||
// overhead per packet):
|
// overhead per packet):
|
||||||
@@ -244,7 +243,7 @@ public class NetworkStatsFactoryTest extends NetworkStatsBaseTest {
|
|||||||
// Cell (which has TEST_IFACE2) and has declared both of them in its underlying network set.
|
// Cell (which has TEST_IFACE2) and has declared both of them in its underlying network set.
|
||||||
// Additionally, VPN is duplicating traffic across both WiFi and Cell.
|
// Additionally, VPN is duplicating traffic across both WiFi and Cell.
|
||||||
VpnInfo[] vpnInfos = new VpnInfo[] {createVpnInfo(new String[] {TEST_IFACE, TEST_IFACE2})};
|
VpnInfo[] vpnInfos = new VpnInfo[] {createVpnInfo(new String[] {TEST_IFACE, TEST_IFACE2})};
|
||||||
NetworkStatsFactory.updateVpnInfos(vpnInfos);
|
mFactory.updateVpnInfos(vpnInfos);
|
||||||
|
|
||||||
// create some traffic (assume 10 bytes of MTU for VPN interface and 1 byte encryption
|
// create some traffic (assume 10 bytes of MTU for VPN interface and 1 byte encryption
|
||||||
// overhead per packet):
|
// overhead per packet):
|
||||||
@@ -270,7 +269,7 @@ public class NetworkStatsFactoryTest extends NetworkStatsBaseTest {
|
|||||||
// Cell (which has TEST_IFACE2) and has declared both of them in its underlying network set.
|
// Cell (which has TEST_IFACE2) and has declared both of them in its underlying network set.
|
||||||
// Additionally, VPN is arbitrarily splitting traffic across WiFi and Cell.
|
// Additionally, VPN is arbitrarily splitting traffic across WiFi and Cell.
|
||||||
VpnInfo[] vpnInfos = new VpnInfo[] {createVpnInfo(new String[] {TEST_IFACE, TEST_IFACE2})};
|
VpnInfo[] vpnInfos = new VpnInfo[] {createVpnInfo(new String[] {TEST_IFACE, TEST_IFACE2})};
|
||||||
NetworkStatsFactory.updateVpnInfos(vpnInfos);
|
mFactory.updateVpnInfos(vpnInfos);
|
||||||
|
|
||||||
// create some traffic (assume 10 bytes of MTU for VPN interface and 1 byte encryption
|
// create some traffic (assume 10 bytes of MTU for VPN interface and 1 byte encryption
|
||||||
// overhead per packet):
|
// overhead per packet):
|
||||||
@@ -297,7 +296,7 @@ public class NetworkStatsFactoryTest extends NetworkStatsBaseTest {
|
|||||||
// Cell (which has TEST_IFACE2) and has declared both of them in its underlying network set.
|
// Cell (which has TEST_IFACE2) and has declared both of them in its underlying network set.
|
||||||
// Additionally, VPN is arbitrarily splitting compressed traffic across WiFi and Cell.
|
// Additionally, VPN is arbitrarily splitting compressed traffic across WiFi and Cell.
|
||||||
VpnInfo[] vpnInfos = new VpnInfo[] {createVpnInfo(new String[] {TEST_IFACE, TEST_IFACE2})};
|
VpnInfo[] vpnInfos = new VpnInfo[] {createVpnInfo(new String[] {TEST_IFACE, TEST_IFACE2})};
|
||||||
NetworkStatsFactory.updateVpnInfos(vpnInfos);
|
mFactory.updateVpnInfos(vpnInfos);
|
||||||
|
|
||||||
// create some traffic (assume 10 bytes of MTU for VPN interface:
|
// create some traffic (assume 10 bytes of MTU for VPN interface:
|
||||||
// 1000 bytes (100 packets) were sent/received by UID_RED over VPN.
|
// 1000 bytes (100 packets) were sent/received by UID_RED over VPN.
|
||||||
@@ -319,7 +318,7 @@ public class NetworkStatsFactoryTest extends NetworkStatsBaseTest {
|
|||||||
// WiFi and Cell networks are connected and VPN is using Cell (which has TEST_IFACE2),
|
// WiFi and Cell networks are connected and VPN is using Cell (which has TEST_IFACE2),
|
||||||
// but has declared only WiFi (TEST_IFACE) in its underlying network set.
|
// but has declared only WiFi (TEST_IFACE) in its underlying network set.
|
||||||
VpnInfo[] vpnInfos = new VpnInfo[] {createVpnInfo(new String[] {TEST_IFACE})};
|
VpnInfo[] vpnInfos = new VpnInfo[] {createVpnInfo(new String[] {TEST_IFACE})};
|
||||||
NetworkStatsFactory.updateVpnInfos(vpnInfos);
|
mFactory.updateVpnInfos(vpnInfos);
|
||||||
|
|
||||||
// create some traffic (assume 10 bytes of MTU for VPN interface and 1 byte encryption
|
// create some traffic (assume 10 bytes of MTU for VPN interface and 1 byte encryption
|
||||||
// overhead per packet):
|
// overhead per packet):
|
||||||
@@ -383,7 +382,7 @@ public class NetworkStatsFactoryTest extends NetworkStatsBaseTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoubleClatAccountingSimple() throws Exception {
|
public void testDoubleClatAccountingSimple() throws Exception {
|
||||||
NetworkStatsFactory.noteStackedIface("v4-wlan0", "wlan0");
|
mFactory.noteStackedIface("v4-wlan0", "wlan0");
|
||||||
|
|
||||||
// xt_qtaguid_with_clat_simple is a synthetic file that simulates
|
// xt_qtaguid_with_clat_simple is a synthetic file that simulates
|
||||||
// - 213 received 464xlat packets of size 200 bytes
|
// - 213 received 464xlat packets of size 200 bytes
|
||||||
@@ -398,7 +397,7 @@ public class NetworkStatsFactoryTest extends NetworkStatsBaseTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoubleClatAccounting() throws Exception {
|
public void testDoubleClatAccounting() throws Exception {
|
||||||
NetworkStatsFactory.noteStackedIface("v4-wlan0", "wlan0");
|
mFactory.noteStackedIface("v4-wlan0", "wlan0");
|
||||||
|
|
||||||
NetworkStats stats = parseDetailedStats(R.raw.xt_qtaguid_with_clat);
|
NetworkStats stats = parseDetailedStats(R.raw.xt_qtaguid_with_clat);
|
||||||
assertEquals(42, stats.size());
|
assertEquals(42, stats.size());
|
||||||
@@ -419,8 +418,6 @@ public class NetworkStatsFactoryTest extends NetworkStatsBaseTest {
|
|||||||
assertStatsEntry(stats, "lo", 0, SET_DEFAULT, 0x0, 1288L, 1288L);
|
assertStatsEntry(stats, "lo", 0, SET_DEFAULT, 0x0, 1288L, 1288L);
|
||||||
|
|
||||||
assertNoStatsEntry(stats, "wlan0", 1029, SET_DEFAULT, 0x0);
|
assertNoStatsEntry(stats, "wlan0", 1029, SET_DEFAULT, 0x0);
|
||||||
|
|
||||||
NetworkStatsFactory.clearStackedIfaces();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -435,7 +432,7 @@ public class NetworkStatsFactoryTest extends NetworkStatsBaseTest {
|
|||||||
long rootRxBytesAfter = 1398634L;
|
long rootRxBytesAfter = 1398634L;
|
||||||
assertEquals("UID 0 traffic should be ~0", 4623, rootRxBytesAfter - rootRxBytesBefore);
|
assertEquals("UID 0 traffic should be ~0", 4623, rootRxBytesAfter - rootRxBytesBefore);
|
||||||
|
|
||||||
NetworkStatsFactory.noteStackedIface("v4-wlan0", "wlan0");
|
mFactory.noteStackedIface("v4-wlan0", "wlan0");
|
||||||
NetworkStats stats;
|
NetworkStats stats;
|
||||||
|
|
||||||
// Stats snapshot before the download
|
// Stats snapshot before the download
|
||||||
@@ -447,8 +444,6 @@ public class NetworkStatsFactoryTest extends NetworkStatsBaseTest {
|
|||||||
stats = parseDetailedStats(R.raw.xt_qtaguid_with_clat_100mb_download_after);
|
stats = parseDetailedStats(R.raw.xt_qtaguid_with_clat_100mb_download_after);
|
||||||
assertStatsEntry(stats, "v4-wlan0", 10106, SET_FOREGROUND, 0x0, appRxBytesAfter, 7867488L);
|
assertStatsEntry(stats, "v4-wlan0", 10106, SET_FOREGROUND, 0x0, appRxBytesAfter, 7867488L);
|
||||||
assertStatsEntry(stats, "wlan0", 0, SET_DEFAULT, 0x0, rootRxBytesAfter, 0L);
|
assertStatsEntry(stats, "wlan0", 0, SET_DEFAULT, 0x0, rootRxBytesAfter, 0L);
|
||||||
|
|
||||||
NetworkStatsFactory.clearStackedIfaces();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ import androidx.test.InstrumentationRegistry;
|
|||||||
import androidx.test.filters.SmallTest;
|
import androidx.test.filters.SmallTest;
|
||||||
import androidx.test.runner.AndroidJUnit4;
|
import androidx.test.runner.AndroidJUnit4;
|
||||||
|
|
||||||
|
import com.android.internal.net.VpnInfo;
|
||||||
import com.android.internal.util.ArrayUtils;
|
import com.android.internal.util.ArrayUtils;
|
||||||
import com.android.internal.util.test.BroadcastInterceptingContext;
|
import com.android.internal.util.test.BroadcastInterceptingContext;
|
||||||
import com.android.server.net.NetworkStatsService.NetworkStatsSettings;
|
import com.android.server.net.NetworkStatsService.NetworkStatsSettings;
|
||||||
@@ -242,7 +243,7 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
|||||||
expectNetworkStatsSummary(buildEmptyStats());
|
expectNetworkStatsSummary(buildEmptyStats());
|
||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
|
|
||||||
mService.forceUpdateIfaces(NETWORKS_WIFI, states, getActiveIface(states));
|
mService.forceUpdateIfaces(NETWORKS_WIFI, states, getActiveIface(states), new VpnInfo[0]);
|
||||||
|
|
||||||
// verify service has empty history for wifi
|
// verify service has empty history for wifi
|
||||||
assertNetworkTotal(sTemplateWifi, 0L, 0L, 0L, 0L, 0);
|
assertNetworkTotal(sTemplateWifi, 0L, 0L, 0L, 0L, 0);
|
||||||
@@ -285,7 +286,7 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
|||||||
expectNetworkStatsSummary(buildEmptyStats());
|
expectNetworkStatsSummary(buildEmptyStats());
|
||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
|
|
||||||
mService.forceUpdateIfaces(NETWORKS_WIFI, states, getActiveIface(states));
|
mService.forceUpdateIfaces(NETWORKS_WIFI, states, getActiveIface(states), new VpnInfo[0]);
|
||||||
|
|
||||||
// verify service has empty history for wifi
|
// verify service has empty history for wifi
|
||||||
assertNetworkTotal(sTemplateWifi, 0L, 0L, 0L, 0L, 0);
|
assertNetworkTotal(sTemplateWifi, 0L, 0L, 0L, 0L, 0);
|
||||||
@@ -358,7 +359,7 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
|||||||
expectNetworkStatsSummary(buildEmptyStats());
|
expectNetworkStatsSummary(buildEmptyStats());
|
||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
|
|
||||||
mService.forceUpdateIfaces(NETWORKS_WIFI, states, getActiveIface(states));
|
mService.forceUpdateIfaces(NETWORKS_WIFI, states, getActiveIface(states), new VpnInfo[0]);
|
||||||
|
|
||||||
// modify some number on wifi, and trigger poll event
|
// modify some number on wifi, and trigger poll event
|
||||||
incrementCurrentTime(2 * HOUR_IN_MILLIS);
|
incrementCurrentTime(2 * HOUR_IN_MILLIS);
|
||||||
@@ -398,7 +399,7 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
|||||||
expectNetworkStatsSummary(buildEmptyStats());
|
expectNetworkStatsSummary(buildEmptyStats());
|
||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
|
|
||||||
mService.forceUpdateIfaces(NETWORKS_MOBILE, states, getActiveIface(states));
|
mService.forceUpdateIfaces(NETWORKS_MOBILE, states, getActiveIface(states), new VpnInfo[0]);
|
||||||
|
|
||||||
// create some traffic on first network
|
// create some traffic on first network
|
||||||
incrementCurrentTime(HOUR_IN_MILLIS);
|
incrementCurrentTime(HOUR_IN_MILLIS);
|
||||||
@@ -432,7 +433,7 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
|||||||
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 512L, 4L, 512L, 4L, 0L)
|
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 512L, 4L, 512L, 4L, 0L)
|
||||||
.addValues(TEST_IFACE, UID_BLUE, SET_DEFAULT, TAG_NONE, 512L, 4L, 0L, 0L, 0L));
|
.addValues(TEST_IFACE, UID_BLUE, SET_DEFAULT, TAG_NONE, 512L, 4L, 0L, 0L, 0L));
|
||||||
|
|
||||||
mService.forceUpdateIfaces(NETWORKS_MOBILE, states, getActiveIface(states));
|
mService.forceUpdateIfaces(NETWORKS_MOBILE, states, getActiveIface(states), new VpnInfo[0]);
|
||||||
forcePollAndWaitForIdle();
|
forcePollAndWaitForIdle();
|
||||||
|
|
||||||
|
|
||||||
@@ -471,7 +472,7 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
|||||||
expectNetworkStatsSummary(buildEmptyStats());
|
expectNetworkStatsSummary(buildEmptyStats());
|
||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
|
|
||||||
mService.forceUpdateIfaces(NETWORKS_WIFI, states, getActiveIface(states));
|
mService.forceUpdateIfaces(NETWORKS_WIFI, states, getActiveIface(states), new VpnInfo[0]);
|
||||||
|
|
||||||
// create some traffic
|
// create some traffic
|
||||||
incrementCurrentTime(HOUR_IN_MILLIS);
|
incrementCurrentTime(HOUR_IN_MILLIS);
|
||||||
@@ -528,7 +529,7 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
|||||||
expectNetworkStatsSummary(buildEmptyStats());
|
expectNetworkStatsSummary(buildEmptyStats());
|
||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
|
|
||||||
mService.forceUpdateIfaces(NETWORKS_MOBILE, states, getActiveIface(states));
|
mService.forceUpdateIfaces(NETWORKS_MOBILE, states, getActiveIface(states), new VpnInfo[0]);
|
||||||
|
|
||||||
// create some traffic
|
// create some traffic
|
||||||
incrementCurrentTime(HOUR_IN_MILLIS);
|
incrementCurrentTime(HOUR_IN_MILLIS);
|
||||||
@@ -554,7 +555,7 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
|||||||
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, 1024L, 8L, 1024L, 8L, 0L)
|
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, 1024L, 8L, 1024L, 8L, 0L)
|
||||||
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 512L, 4L, 512L, 4L, 0L));
|
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 512L, 4L, 512L, 4L, 0L));
|
||||||
|
|
||||||
mService.forceUpdateIfaces(NETWORKS_MOBILE, states, getActiveIface(states));
|
mService.forceUpdateIfaces(NETWORKS_MOBILE, states, getActiveIface(states), new VpnInfo[0]);
|
||||||
forcePollAndWaitForIdle();
|
forcePollAndWaitForIdle();
|
||||||
|
|
||||||
|
|
||||||
@@ -583,7 +584,7 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
|||||||
expectNetworkStatsSummary(buildEmptyStats());
|
expectNetworkStatsSummary(buildEmptyStats());
|
||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
|
|
||||||
mService.forceUpdateIfaces(NETWORKS_WIFI, states, getActiveIface(states));
|
mService.forceUpdateIfaces(NETWORKS_WIFI, states, getActiveIface(states), new VpnInfo[0]);
|
||||||
|
|
||||||
// create some traffic for two apps
|
// create some traffic for two apps
|
||||||
incrementCurrentTime(HOUR_IN_MILLIS);
|
incrementCurrentTime(HOUR_IN_MILLIS);
|
||||||
@@ -640,7 +641,7 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
|||||||
expectNetworkStatsSummary(buildEmptyStats());
|
expectNetworkStatsSummary(buildEmptyStats());
|
||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
|
|
||||||
mService.forceUpdateIfaces(NETWORKS_WIFI, states, getActiveIface(states));
|
mService.forceUpdateIfaces(NETWORKS_WIFI, states, getActiveIface(states), new VpnInfo[0]);
|
||||||
|
|
||||||
NetworkStats.Entry entry1 = new NetworkStats.Entry(
|
NetworkStats.Entry entry1 = new NetworkStats.Entry(
|
||||||
TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, 50L, 5L, 50L, 5L, 0L);
|
TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, 50L, 5L, 50L, 5L, 0L);
|
||||||
@@ -683,7 +684,7 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
|||||||
expectNetworkStatsSummary(buildEmptyStats());
|
expectNetworkStatsSummary(buildEmptyStats());
|
||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
|
|
||||||
mService.forceUpdateIfaces(NETWORKS_WIFI, states, getActiveIface(states));
|
mService.forceUpdateIfaces(NETWORKS_WIFI, states, getActiveIface(states), new VpnInfo[0]);
|
||||||
|
|
||||||
NetworkStats.Entry uidStats = new NetworkStats.Entry(
|
NetworkStats.Entry uidStats = new NetworkStats.Entry(
|
||||||
TEST_IFACE, UID_BLUE, SET_DEFAULT, 0xF00D, 1024L, 8L, 512L, 4L, 0L);
|
TEST_IFACE, UID_BLUE, SET_DEFAULT, 0xF00D, 1024L, 8L, 512L, 4L, 0L);
|
||||||
@@ -695,9 +696,12 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
|||||||
"otherif", UID_BLUE, SET_DEFAULT, 0xF00D, 1024L, 8L, 512L, 4L, 0L);
|
"otherif", UID_BLUE, SET_DEFAULT, 0xF00D, 1024L, 8L, 512L, 4L, 0L);
|
||||||
|
|
||||||
final String[] ifaceFilter = new String[] { TEST_IFACE };
|
final String[] ifaceFilter = new String[] { TEST_IFACE };
|
||||||
|
final String[] augmentedIfaceFilter = new String[] { stackedIface, TEST_IFACE };
|
||||||
incrementCurrentTime(HOUR_IN_MILLIS);
|
incrementCurrentTime(HOUR_IN_MILLIS);
|
||||||
expectDefaultSettings();
|
expectDefaultSettings();
|
||||||
expectNetworkStatsSummary(buildEmptyStats());
|
expectNetworkStatsSummary(buildEmptyStats());
|
||||||
|
when(mStatsFactory.augmentWithStackedInterfaces(eq(ifaceFilter)))
|
||||||
|
.thenReturn(augmentedIfaceFilter);
|
||||||
when(mStatsFactory.readNetworkStatsDetail(eq(UID_ALL), any(), eq(TAG_ALL)))
|
when(mStatsFactory.readNetworkStatsDetail(eq(UID_ALL), any(), eq(TAG_ALL)))
|
||||||
.thenReturn(new NetworkStats(getElapsedRealtime(), 1)
|
.thenReturn(new NetworkStats(getElapsedRealtime(), 1)
|
||||||
.addValues(uidStats));
|
.addValues(uidStats));
|
||||||
@@ -708,15 +712,16 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
|||||||
|
|
||||||
NetworkStats stats = mService.getDetailedUidStats(ifaceFilter);
|
NetworkStats stats = mService.getDetailedUidStats(ifaceFilter);
|
||||||
|
|
||||||
// mNetManager#getNetworkStatsUidDetail(UID_ALL, INTERFACES_ALL) has following invocations:
|
// mStatsFactory#readNetworkStatsDetail() has the following invocations:
|
||||||
// 1) NetworkStatsService#systemReady from #setUp.
|
// 1) NetworkStatsService#systemReady from #setUp.
|
||||||
// 2) mService#forceUpdateIfaces in the test above.
|
// 2) mService#forceUpdateIfaces in the test above.
|
||||||
//
|
//
|
||||||
// Additionally, we should have one call from the above call to mService#getDetailedUidStats
|
// Additionally, we should have one call from the above call to mService#getDetailedUidStats
|
||||||
// with the augmented ifaceFilter
|
// with the augmented ifaceFilter.
|
||||||
verify(mStatsFactory, times(2)).readNetworkStatsDetail(UID_ALL, INTERFACES_ALL, TAG_ALL);
|
verify(mStatsFactory, times(2)).readNetworkStatsDetail(UID_ALL, INTERFACES_ALL, TAG_ALL);
|
||||||
verify(mStatsFactory, times(1)).readNetworkStatsDetail(
|
verify(mStatsFactory, times(1)).readNetworkStatsDetail(
|
||||||
eq(UID_ALL), eq(NetworkStatsFactory.augmentWithStackedInterfaces(ifaceFilter)),
|
eq(UID_ALL),
|
||||||
|
eq(augmentedIfaceFilter),
|
||||||
eq(TAG_ALL));
|
eq(TAG_ALL));
|
||||||
assertTrue(ArrayUtils.contains(stats.getUniqueIfaces(), TEST_IFACE));
|
assertTrue(ArrayUtils.contains(stats.getUniqueIfaces(), TEST_IFACE));
|
||||||
assertTrue(ArrayUtils.contains(stats.getUniqueIfaces(), stackedIface));
|
assertTrue(ArrayUtils.contains(stats.getUniqueIfaces(), stackedIface));
|
||||||
@@ -733,7 +738,7 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
|||||||
expectNetworkStatsSummary(buildEmptyStats());
|
expectNetworkStatsSummary(buildEmptyStats());
|
||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
|
|
||||||
mService.forceUpdateIfaces(NETWORKS_WIFI, states, getActiveIface(states));
|
mService.forceUpdateIfaces(NETWORKS_WIFI, states, getActiveIface(states), new VpnInfo[0]);
|
||||||
|
|
||||||
// create some initial traffic
|
// create some initial traffic
|
||||||
incrementCurrentTime(HOUR_IN_MILLIS);
|
incrementCurrentTime(HOUR_IN_MILLIS);
|
||||||
@@ -789,7 +794,7 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
|||||||
expectNetworkStatsSummary(buildEmptyStats());
|
expectNetworkStatsSummary(buildEmptyStats());
|
||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
|
|
||||||
mService.forceUpdateIfaces(NETWORKS_WIFI, states, getActiveIface(states));
|
mService.forceUpdateIfaces(NETWORKS_WIFI, states, getActiveIface(states), new VpnInfo[0]);
|
||||||
|
|
||||||
// create some initial traffic
|
// create some initial traffic
|
||||||
incrementCurrentTime(HOUR_IN_MILLIS);
|
incrementCurrentTime(HOUR_IN_MILLIS);
|
||||||
@@ -828,7 +833,7 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
|||||||
expectNetworkStatsSummary(buildEmptyStats());
|
expectNetworkStatsSummary(buildEmptyStats());
|
||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
|
|
||||||
mService.forceUpdateIfaces(NETWORKS_MOBILE, states, getActiveIface(states));
|
mService.forceUpdateIfaces(NETWORKS_MOBILE, states, getActiveIface(states), new VpnInfo[0]);
|
||||||
|
|
||||||
// Create some traffic
|
// Create some traffic
|
||||||
incrementCurrentTime(HOUR_IN_MILLIS);
|
incrementCurrentTime(HOUR_IN_MILLIS);
|
||||||
@@ -865,7 +870,7 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
|||||||
expectNetworkStatsSummary(buildEmptyStats());
|
expectNetworkStatsSummary(buildEmptyStats());
|
||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
|
|
||||||
mService.forceUpdateIfaces(NETWORKS_MOBILE, states, getActiveIface(states));
|
mService.forceUpdateIfaces(NETWORKS_MOBILE, states, getActiveIface(states), new VpnInfo[0]);
|
||||||
|
|
||||||
// create some tethering traffic
|
// create some tethering traffic
|
||||||
incrementCurrentTime(HOUR_IN_MILLIS);
|
incrementCurrentTime(HOUR_IN_MILLIS);
|
||||||
@@ -905,7 +910,7 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
|||||||
expectNetworkStatsSummary(buildEmptyStats());
|
expectNetworkStatsSummary(buildEmptyStats());
|
||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
|
|
||||||
mService.forceUpdateIfaces(NETWORKS_WIFI, states, getActiveIface(states));
|
mService.forceUpdateIfaces(NETWORKS_WIFI, states, getActiveIface(states), new VpnInfo[0]);
|
||||||
|
|
||||||
// verify service has empty history for wifi
|
// verify service has empty history for wifi
|
||||||
assertNetworkTotal(sTemplateWifi, 0L, 0L, 0L, 0L, 0);
|
assertNetworkTotal(sTemplateWifi, 0L, 0L, 0L, 0L, 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user