Selectively add stats based on iface active state.

Only combine /proc/net/dev and xt_qtaguid stats when iface is marked
as active.  When inactive, only return xt_qtaguid stats.  When iface
is unknown to xt_qtaguid, always pass through /proc/net/dev stats.

Bug: 5242730
Change-Id: I469fc6abe45309f794afebca814cbb39e4f13af5
This commit is contained in:
Jeff Sharkey
2011-09-01 01:07:31 -07:00
parent 971cd16561
commit 8e3b6c6eee

View File

@@ -106,6 +106,7 @@ public class NetworkManagementServiceTest extends AndroidTestCase {
public void testNetworkStatsSummaryDown() throws Exception { public void testNetworkStatsSummaryDown() throws Exception {
stageFile(R.raw.net_dev_typical, new File(mTestProc, "net/dev")); stageFile(R.raw.net_dev_typical, new File(mTestProc, "net/dev"));
stageLong(1L, new File(mTestProc, "net/xt_qtaguid/iface_stat/wlan0/active"));
stageLong(1024L, new File(mTestProc, "net/xt_qtaguid/iface_stat/wlan0/rx_bytes")); stageLong(1024L, new File(mTestProc, "net/xt_qtaguid/iface_stat/wlan0/rx_bytes"));
stageLong(128L, new File(mTestProc, "net/xt_qtaguid/iface_stat/wlan0/rx_packets")); stageLong(128L, new File(mTestProc, "net/xt_qtaguid/iface_stat/wlan0/rx_packets"));
stageLong(2048L, new File(mTestProc, "net/xt_qtaguid/iface_stat/wlan0/tx_bytes")); stageLong(2048L, new File(mTestProc, "net/xt_qtaguid/iface_stat/wlan0/tx_bytes"));
@@ -119,6 +120,7 @@ public class NetworkManagementServiceTest extends AndroidTestCase {
public void testNetworkStatsCombined() throws Exception { public void testNetworkStatsCombined() throws Exception {
stageFile(R.raw.net_dev_typical, new File(mTestProc, "net/dev")); stageFile(R.raw.net_dev_typical, new File(mTestProc, "net/dev"));
stageLong(1L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/active"));
stageLong(10L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/rx_bytes")); stageLong(10L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/rx_bytes"));
stageLong(20L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/rx_packets")); stageLong(20L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/rx_packets"));
stageLong(30L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/tx_bytes")); stageLong(30L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/tx_bytes"));
@@ -129,6 +131,18 @@ public class NetworkManagementServiceTest extends AndroidTestCase {
2205L + 20L, 489339L + 30L, 2237L + 40L); 2205L + 20L, 489339L + 30L, 2237L + 40L);
} }
public void testNetworkStatsCombinedInactive() throws Exception {
stageFile(R.raw.net_dev_typical, new File(mTestProc, "net/dev"));
stageLong(0L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/active"));
stageLong(10L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/rx_bytes"));
stageLong(20L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/rx_packets"));
stageLong(30L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/tx_bytes"));
stageLong(40L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/tx_packets"));
final NetworkStats stats = mService.getNetworkStatsSummary();
assertStatsEntry(stats, "rmnet0", UID_ALL, SET_DEFAULT, TAG_NONE, 10L, 20L, 30L, 40L);
}
public void testKernelTags() throws Exception { public void testKernelTags() throws Exception {
assertEquals("0", tagToKernel(0x0)); assertEquals("0", tagToKernel(0x0));
assertEquals("214748364800", tagToKernel(0x32)); assertEquals("214748364800", tagToKernel(0x32));