summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2011-07-12 15:19:31 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-07-12 15:19:31 -0700
commitf0c3b1b6b7fd2b851851c96d98d2f9a77415bf43 (patch)
tree9b41a0afbd1aac3c1cae6c1d5394aaa6b77052ae /services
parent099b3d2179b981ea70a8d9d30bb6750260297d55 (diff)
parentd37948f6ed1667d077e0e3a38808f42f981ddcc2 (diff)
downloadframeworks_base-f0c3b1b6b7fd2b851851c96d98d2f9a77415bf43.zip
frameworks_base-f0c3b1b6b7fd2b851851c96d98d2f9a77415bf43.tar.gz
frameworks_base-f0c3b1b6b7fd2b851851c96d98d2f9a77415bf43.tar.bz2
Merge "Hide NetworkStatsHistory internals."
Diffstat (limited to 'services')
-rw-r--r--services/java/com/android/server/ThrottleService.java5
-rw-r--r--services/java/com/android/server/net/NetworkPolicyManagerService.java6
-rw-r--r--services/java/com/android/server/net/NetworkStatsService.java83
-rw-r--r--services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java2
-rw-r--r--services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java84
-rw-r--r--services/tests/servicestests/src/com/android/server/ThrottleServiceTest.java2
6 files changed, 99 insertions, 83 deletions
diff --git a/services/java/com/android/server/ThrottleService.java b/services/java/com/android/server/ThrottleService.java
index 24d4dd3..b8890aa 100644
--- a/services/java/com/android/server/ThrottleService.java
+++ b/services/java/com/android/server/ThrottleService.java
@@ -515,8 +515,9 @@ public class ThrottleService extends IThrottleManager.Stub {
mIface, NetworkStats.UID_ALL, NetworkStats.TAG_NONE);
if (index != -1) {
- incRead = stats.rx[index] - mLastRead;
- incWrite = stats.tx[index] - mLastWrite;
+ final NetworkStats.Entry entry = stats.getValues(index, null);
+ incRead = entry.rxBytes - mLastRead;
+ incWrite = entry.txBytes - mLastWrite;
} else {
// missing iface, assume stats are 0
Slog.w(TAG, "unable to find stats for iface " + mIface);
diff --git a/services/java/com/android/server/net/NetworkPolicyManagerService.java b/services/java/com/android/server/net/NetworkPolicyManagerService.java
index d23d0f4..d30b66b 100644
--- a/services/java/com/android/server/net/NetworkPolicyManagerService.java
+++ b/services/java/com/android/server/net/NetworkPolicyManagerService.java
@@ -405,7 +405,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
try {
final NetworkStats stats = mNetworkStats.getSummaryForNetwork(
policy.template, start, end);
- total = stats.rx[0] + stats.tx[0];
+ final NetworkStats.Entry entry = stats.getValues(0, null);
+ total = entry.rxBytes + entry.txBytes;
} catch (RemoteException e) {
Slog.w(TAG, "problem reading summary for template " + policy.template);
continue;
@@ -605,7 +606,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
final long total;
try {
stats = mNetworkStats.getSummaryForNetwork(policy.template, start, end);
- total = stats.rx[0] + stats.tx[0];
+ final NetworkStats.Entry entry = stats.getValues(0, null);
+ total = entry.rxBytes + entry.txBytes;
} catch (RemoteException e) {
Slog.w(TAG, "problem reading summary for template " + policy.template);
continue;
diff --git a/services/java/com/android/server/net/NetworkStatsService.java b/services/java/com/android/server/net/NetworkStatsService.java
index b6834f6..872438c 100644
--- a/services/java/com/android/server/net/NetworkStatsService.java
+++ b/services/java/com/android/server/net/NetworkStatsService.java
@@ -313,22 +313,26 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
mContext.enforceCallingOrSelfPermission(READ_NETWORK_USAGE_HISTORY, TAG);
synchronized (mStatsLock) {
- long rx = 0;
- long tx = 0;
- long[] networkTotal = new long[2];
+ final NetworkStats stats = new NetworkStats(end - start, 1);
+ final NetworkStats.Entry entry = new NetworkStats.Entry();
+ long[] total = new long[2];
// combine total from all interfaces that match template
for (NetworkIdentitySet ident : mNetworkStats.keySet()) {
if (templateMatches(template, ident)) {
final NetworkStatsHistory history = mNetworkStats.get(ident);
- networkTotal = history.getTotalData(start, end, networkTotal);
- rx += networkTotal[0];
- tx += networkTotal[1];
+ total = history.getTotalData(start, end, total);
+
+ entry.iface = IFACE_ALL;
+ entry.uid = UID_ALL;
+ entry.tag = TAG_NONE;
+ entry.rxBytes = total[0];
+ entry.txBytes = total[1];
+
+ stats.combineValues(entry);
}
}
- final NetworkStats stats = new NetworkStats(end - start, 1);
- stats.addEntry(IFACE_ALL, UID_ALL, TAG_NONE, rx, tx);
return stats;
}
}
@@ -342,6 +346,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
ensureUidStatsLoadedLocked();
final NetworkStats stats = new NetworkStats(end - start, 24);
+ final NetworkStats.Entry entry = new NetworkStats.Entry();
long[] total = new long[2];
for (NetworkIdentitySet ident : mUidStats.keySet()) {
@@ -357,10 +362,15 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
if (tag == TAG_NONE || includeTags) {
final NetworkStatsHistory history = uidStats.valueAt(i);
total = history.getTotalData(start, end, total);
- final long rx = total[0];
- final long tx = total[1];
- if (rx > 0 || tx > 0) {
- stats.combineEntry(IFACE_ALL, uid, tag, rx, tx);
+
+ entry.iface = IFACE_ALL;
+ entry.uid = uid;
+ entry.tag = tag;
+ entry.rxBytes = total[0];
+ entry.txBytes = total[1];
+
+ if (entry.rxBytes > 0 || entry.txBytes > 0) {
+ stats.combineValues(entry);
}
}
}
@@ -512,10 +522,13 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
final NetworkStats persistDelta = computeStatsDelta(
mLastPersistNetworkSnapshot, networkSnapshot);
final long persistThreshold = mSettings.getPersistThreshold();
+
+ NetworkStats.Entry entry = null;
for (String iface : persistDelta.getUniqueIfaces()) {
final int index = persistDelta.findIndex(iface, UID_ALL, TAG_NONE);
- if (forcePersist || persistDelta.rx[index] > persistThreshold
- || persistDelta.tx[index] > persistThreshold) {
+ entry = persistDelta.getValues(index, entry);
+ if (forcePersist || entry.rxBytes > persistThreshold
+ || entry.txBytes > persistThreshold) {
writeNetworkStatsLocked();
if (mUidStatsLoaded) {
writeUidStatsLocked();
@@ -538,20 +551,19 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
final HashSet<String> unknownIface = Sets.newHashSet();
final NetworkStats delta = computeStatsDelta(mLastNetworkSnapshot, networkSnapshot);
- final long timeStart = currentTime - delta.elapsedRealtime;
- for (int i = 0; i < delta.size; i++) {
- final String iface = delta.iface[i];
- final NetworkIdentitySet ident = mActiveIfaces.get(iface);
+ final long timeStart = currentTime - delta.getElapsedRealtime();
+
+ NetworkStats.Entry entry = null;
+ for (int i = 0; i < delta.size(); i++) {
+ entry = delta.getValues(i, entry);
+ final NetworkIdentitySet ident = mActiveIfaces.get(entry.iface);
if (ident == null) {
- unknownIface.add(iface);
+ unknownIface.add(entry.iface);
continue;
}
- final long rx = delta.rx[i];
- final long tx = delta.tx[i];
-
final NetworkStatsHistory history = findOrCreateNetworkStatsLocked(ident);
- history.recordData(timeStart, currentTime, rx, tx);
+ history.recordData(timeStart, currentTime, entry.rxBytes, entry.txBytes);
}
// trim any history beyond max
@@ -574,22 +586,19 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
ensureUidStatsLoadedLocked();
final NetworkStats delta = computeStatsDelta(mLastUidSnapshot, uidSnapshot);
- final long timeStart = currentTime - delta.elapsedRealtime;
+ final long timeStart = currentTime - delta.getElapsedRealtime();
- for (int i = 0; i < delta.size; i++) {
- final String iface = delta.iface[i];
- final NetworkIdentitySet ident = mActiveIfaces.get(iface);
+ NetworkStats.Entry entry = null;
+ for (int i = 0; i < delta.size(); i++) {
+ entry = delta.getValues(i, entry);
+ final NetworkIdentitySet ident = mActiveIfaces.get(entry.iface);
if (ident == null) {
continue;
}
- final int uid = delta.uid[i];
- final int tag = delta.tag[i];
- final long rx = delta.rx[i];
- final long tx = delta.tx[i];
-
- final NetworkStatsHistory history = findOrCreateUidStatsLocked(ident, uid, tag);
- history.recordData(timeStart, currentTime, rx, tx);
+ final NetworkStatsHistory history = findOrCreateUidStatsLocked(
+ ident, entry.uid, entry.tag);
+ history.recordData(timeStart, currentTime, entry.rxBytes, entry.txBytes);
}
// trim any history beyond max
@@ -651,7 +660,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
NetworkStatsHistory updated = null;
if (existing == null) {
updated = new NetworkStatsHistory(bucketDuration, 10);
- } else if (existing.bucketDuration != bucketDuration) {
+ } else if (existing.getBucketDuration() != bucketDuration) {
updated = new NetworkStatsHistory(
bucketDuration, estimateResizeBuckets(existing, bucketDuration));
updated.recordEntireHistory(existing);
@@ -683,7 +692,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
NetworkStatsHistory updated = null;
if (existing == null) {
updated = new NetworkStatsHistory(bucketDuration, 10);
- } else if (existing.bucketDuration != bucketDuration) {
+ } else if (existing.getBucketDuration() != bucketDuration) {
updated = new NetworkStatsHistory(
bucketDuration, estimateResizeBuckets(existing, bucketDuration));
updated.recordEntireHistory(existing);
@@ -1003,7 +1012,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
}
private static int estimateResizeBuckets(NetworkStatsHistory existing, long newBucketDuration) {
- return (int) (existing.bucketCount * existing.bucketDuration / newBucketDuration);
+ return (int) (existing.size() * existing.getBucketDuration() / newBucketDuration);
}
// @VisibleForTesting
diff --git a/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java
index b4ac987..33fd355 100644
--- a/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java
@@ -447,7 +447,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
// pretend that 512 bytes total have happened
stats = new NetworkStats(elapsedRealtime, 1)
- .addEntry(TEST_IFACE, UID_ALL, TAG_NONE, 256L, 256L);
+ .addValues(TEST_IFACE, UID_ALL, TAG_NONE, 256L, 2L, 256L, 2L);
expect(mStatsService.getSummaryForNetwork(sTemplateWifi, TIME_FEB_15, TIME_MAR_10))
.andReturn(stats).atLeastOnce();
diff --git a/services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java b/services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java
index f2c28bb..36b3b82 100644
--- a/services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java
@@ -168,7 +168,7 @@ public class NetworkStatsServiceTest extends AndroidTestCase {
expectTime(TEST_START + elapsedRealtime);
expectDefaultSettings();
expectNetworkStatsSummary(new NetworkStats(elapsedRealtime, 1)
- .addEntry(TEST_IFACE, UID_ALL, TAG_NONE, 1024L, 2048L));
+ .addValues(TEST_IFACE, UID_ALL, TAG_NONE, 1024L, 1L, 2048L, 2L));
expectNetworkStatsDetail(buildEmptyStats(elapsedRealtime));
replay();
@@ -184,7 +184,7 @@ public class NetworkStatsServiceTest extends AndroidTestCase {
expectTime(TEST_START + elapsedRealtime);
expectDefaultSettings();
expectNetworkStatsSummary(new NetworkStats(elapsedRealtime, 1)
- .addEntry(TEST_IFACE, UID_ALL, TAG_NONE, 4096L, 8192L));
+ .addValues(TEST_IFACE, UID_ALL, TAG_NONE, 4096L, 4L, 8192L, 8L));
expectNetworkStatsDetail(buildEmptyStats(elapsedRealtime));
replay();
@@ -219,10 +219,10 @@ public class NetworkStatsServiceTest extends AndroidTestCase {
expectTime(TEST_START + elapsedRealtime);
expectDefaultSettings();
expectNetworkStatsSummary(new NetworkStats(elapsedRealtime, 1)
- .addEntry(TEST_IFACE, UID_ALL, TAG_NONE, 1024L, 2048L));
+ .addValues(TEST_IFACE, UID_ALL, TAG_NONE, 1024L, 8L, 2048L, 16L));
expectNetworkStatsDetail(new NetworkStats(elapsedRealtime, 2)
- .addEntry(TEST_IFACE, UID_RED, TAG_NONE, 512L, 256L)
- .addEntry(TEST_IFACE, UID_BLUE, TAG_NONE, 128L, 128L));
+ .addValues(TEST_IFACE, UID_RED, TAG_NONE, 512L, 4L, 256L, 2L)
+ .addValues(TEST_IFACE, UID_BLUE, TAG_NONE, 128L, 1L, 128L, 1L));
replay();
mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL));
@@ -284,7 +284,7 @@ public class NetworkStatsServiceTest extends AndroidTestCase {
expectTime(TEST_START + elapsedRealtime);
expectSettings(0L, HOUR_IN_MILLIS, WEEK_IN_MILLIS);
expectNetworkStatsSummary(new NetworkStats(elapsedRealtime, 1)
- .addEntry(TEST_IFACE, UID_ALL, TAG_NONE, 512L, 512L));
+ .addValues(TEST_IFACE, UID_ALL, TAG_NONE, 512L, 4L, 512L, 4L));
expectNetworkStatsDetail(buildEmptyStats(elapsedRealtime));
replay();
@@ -295,8 +295,8 @@ public class NetworkStatsServiceTest extends AndroidTestCase {
total = history.getTotalData(Long.MIN_VALUE, Long.MAX_VALUE, null);
assertEquals(512L, total[0]);
assertEquals(512L, total[1]);
- assertEquals(HOUR_IN_MILLIS, history.bucketDuration);
- assertEquals(2, history.bucketCount);
+ assertEquals(HOUR_IN_MILLIS, history.getBucketDuration());
+ assertEquals(2, history.size());
verifyAndReset();
// now change bucket duration setting and trigger another poll with
@@ -314,8 +314,8 @@ public class NetworkStatsServiceTest extends AndroidTestCase {
total = history.getTotalData(Long.MIN_VALUE, Long.MAX_VALUE, null);
assertEquals(512L, total[0]);
assertEquals(512L, total[1]);
- assertEquals(30 * MINUTE_IN_MILLIS, history.bucketDuration);
- assertEquals(4, history.bucketCount);
+ assertEquals(30 * MINUTE_IN_MILLIS, history.getBucketDuration());
+ assertEquals(4, history.size());
verifyAndReset();
}
@@ -338,11 +338,11 @@ public class NetworkStatsServiceTest extends AndroidTestCase {
expectTime(TEST_START + elapsedRealtime);
expectDefaultSettings();
expectNetworkStatsSummary(new NetworkStats(elapsedRealtime, 1)
- .addEntry(TEST_IFACE, UID_ALL, TAG_NONE, 2048L, 512L));
+ .addValues(TEST_IFACE, UID_ALL, TAG_NONE, 2048L, 16L, 512L, 4L));
expectNetworkStatsDetail(new NetworkStats(elapsedRealtime, 3)
- .addEntry(TEST_IFACE, UID_RED, TAG_NONE, 1536L, 512L)
- .addEntry(TEST_IFACE, UID_RED, 0xF00D, 512L, 512L)
- .addEntry(TEST_IFACE, UID_BLUE, TAG_NONE, 512L, 0L));
+ .addValues(TEST_IFACE, UID_RED, TAG_NONE, 1536L, 12L, 512L, 4L)
+ .addValues(TEST_IFACE, UID_RED, 0xF00D, 512L, 4L, 512L, 4L)
+ .addValues(TEST_IFACE, UID_BLUE, TAG_NONE, 512L, 4L, 0L, 0L));
replay();
mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL));
@@ -373,9 +373,9 @@ public class NetworkStatsServiceTest extends AndroidTestCase {
expectTime(TEST_START + elapsedRealtime);
expectDefaultSettings();
expectNetworkStatsSummary(new NetworkStats(elapsedRealtime, 1)
- .addEntry(TEST_IFACE, UID_ALL, TAG_NONE, 128L, 1024L));
+ .addValues(TEST_IFACE, UID_ALL, TAG_NONE, 128L, 1L, 1024L, 8L));
expectNetworkStatsDetail(new NetworkStats(elapsedRealtime, 1)
- .addEntry(TEST_IFACE, UID_BLUE, TAG_NONE, 128L, 1024L));
+ .addValues(TEST_IFACE, UID_BLUE, TAG_NONE, 128L, 1L, 1024L, 8L));
replay();
mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL));
@@ -412,11 +412,11 @@ public class NetworkStatsServiceTest extends AndroidTestCase {
expectTime(TEST_START + elapsedRealtime);
expectDefaultSettings();
expectNetworkStatsSummary(new NetworkStats(elapsedRealtime, 1)
- .addEntry(TEST_IFACE, UID_ALL, TAG_NONE, 4128L, 544L));
+ .addValues(TEST_IFACE, UID_ALL, TAG_NONE, 4128L, 258L, 544L, 34L));
expectNetworkStatsDetail(new NetworkStats(elapsedRealtime, 1)
- .addEntry(TEST_IFACE, UID_RED, TAG_NONE, 16L, 16L)
- .addEntry(TEST_IFACE, UID_BLUE, TAG_NONE, 4096L, 512L)
- .addEntry(TEST_IFACE, UID_GREEN, TAG_NONE, 16L, 16L));
+ .addValues(TEST_IFACE, UID_RED, TAG_NONE, 16L, 1L, 16L, 1L)
+ .addValues(TEST_IFACE, UID_BLUE, TAG_NONE, 4096L, 258L, 512L, 32L)
+ .addValues(TEST_IFACE, UID_GREEN, TAG_NONE, 16L, 1L, 16L, 1L));
replay();
mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL));
@@ -468,8 +468,8 @@ public class NetworkStatsServiceTest extends AndroidTestCase {
expectDefaultSettings();
expectNetworkStatsSummary(buildEmptyStats(elapsedRealtime));
expectNetworkStatsDetail(new NetworkStats(elapsedRealtime, 1)
- .addEntry(TEST_IFACE, UID_RED, TAG_NONE, 1024L, 1024L)
- .addEntry(TEST_IFACE, UID_RED, 0xF00D, 512L, 512L));
+ .addValues(TEST_IFACE, UID_RED, TAG_NONE, 1024L, 8L, 1024L, 8L)
+ .addValues(TEST_IFACE, UID_RED, 0xF00D, 512L, 4L, 512L, 4L));
replay();
mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL));
@@ -497,7 +497,7 @@ public class NetworkStatsServiceTest extends AndroidTestCase {
expectDefaultSettings();
expectNetworkStatsSummary(buildEmptyStats(elapsedRealtime));
expectNetworkStatsDetail(new NetworkStats(elapsedRealtime, 1)
- .addEntry(TEST_IFACE, UID_RED, TAG_NONE, 512L, 256L));
+ .addValues(TEST_IFACE, UID_RED, TAG_NONE, 512L, 4L, 256L, 2L));
replay();
mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL));
@@ -548,9 +548,9 @@ public class NetworkStatsServiceTest extends AndroidTestCase {
expectDefaultSettings();
expectNetworkStatsSummary(buildEmptyStats(elapsedRealtime));
expectNetworkStatsDetail(new NetworkStats(elapsedRealtime, 1)
- .addEntry(TEST_IFACE, UID_RED, TAG_NONE, 50L, 50L)
- .addEntry(TEST_IFACE, UID_RED, 0xF00D, 10L, 10L)
- .addEntry(TEST_IFACE, UID_BLUE, TAG_NONE, 1024L, 512L));
+ .addValues(TEST_IFACE, UID_RED, TAG_NONE, 50L, 5L, 50L, 5L)
+ .addValues(TEST_IFACE, UID_RED, 0xF00D, 10L, 1L, 10L, 1L)
+ .addValues(TEST_IFACE, UID_BLUE, TAG_NONE, 1024L, 8L, 512L, 4L));
replay();
mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL));
@@ -566,7 +566,7 @@ public class NetworkStatsServiceTest extends AndroidTestCase {
expectDefaultSettings();
expectNetworkStatsSummary(buildEmptyStats(elapsedRealtime));
expectNetworkStatsDetail(new NetworkStats(elapsedRealtime, 1)
- .addEntry(TEST_IFACE, UID_BLUE, TAG_NONE, 2048L, 1024L));
+ .addValues(TEST_IFACE, UID_BLUE, TAG_NONE, 2048L, 16L, 1024L, 8L));
replay();
mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL));
@@ -574,17 +574,17 @@ public class NetworkStatsServiceTest extends AndroidTestCase {
// first verify entire history present
NetworkStats stats = mService.getSummaryForAllUid(
sTemplateWifi, Long.MIN_VALUE, Long.MAX_VALUE, true);
- assertEquals(3, stats.size);
- assertStatsEntry(stats, 0, IFACE_ALL, UID_RED, TAG_NONE, 50L, 50L);
- assertStatsEntry(stats, 1, IFACE_ALL, UID_RED, 0xF00D, 10L, 10L);
- assertStatsEntry(stats, 2, IFACE_ALL, UID_BLUE, TAG_NONE, 2048L, 1024L);
+ assertEquals(3, stats.size());
+ assertEntry(stats, 0, IFACE_ALL, UID_RED, TAG_NONE, 50L, 5L, 50L, 5L);
+ assertEntry(stats, 1, IFACE_ALL, UID_RED, 0xF00D, 10L, 1L, 10L, 1L);
+ assertEntry(stats, 2, IFACE_ALL, UID_BLUE, TAG_NONE, 2048L, 16L, 1024L, 8L);
// now verify that recent history only contains one uid
final long currentTime = TEST_START + elapsedRealtime;
stats = mService.getSummaryForAllUid(
sTemplateWifi, currentTime - HOUR_IN_MILLIS, currentTime, true);
- assertEquals(1, stats.size);
- assertStatsEntry(stats, 0, IFACE_ALL, UID_BLUE, TAG_NONE, 1024L, 512L);
+ assertEquals(1, stats.size());
+ assertEntry(stats, 0, IFACE_ALL, UID_BLUE, TAG_NONE, 1024L, 8L, 512L, 4L);
verifyAndReset();
}
@@ -660,13 +660,17 @@ public class NetworkStatsServiceTest extends AndroidTestCase {
}
}
- private static void assertStatsEntry(
- NetworkStats stats, int i, String iface, int uid, int tag, long rx, long tx) {
- assertEquals(iface, stats.iface[i]);
- assertEquals(uid, stats.uid[i]);
- assertEquals(tag, stats.tag[i]);
- assertEquals(rx, stats.rx[i]);
- assertEquals(tx, stats.tx[i]);
+ private static void assertEntry(NetworkStats stats, int i, String iface, int uid, int tag,
+ long rxBytes, long rxPackets, long txBytes, long txPackets) {
+ final NetworkStats.Entry entry = stats.getValues(i, null);
+ assertEquals(iface, entry.iface);
+ assertEquals(uid, entry.uid);
+ assertEquals(tag, entry.tag);
+ assertEquals(rxBytes, entry.rxBytes);
+ // TODO: enable testing packet counts once stored in history
+// assertEquals(rxPackets, entry.rxPackets);
+ assertEquals(txBytes, entry.txBytes);
+// assertEquals(txPackets, entry.txPackets);
}
private static NetworkState buildWifiState() {
diff --git a/services/tests/servicestests/src/com/android/server/ThrottleServiceTest.java b/services/tests/servicestests/src/com/android/server/ThrottleServiceTest.java
index 2f275c3..50c18f0 100644
--- a/services/tests/servicestests/src/com/android/server/ThrottleServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/ThrottleServiceTest.java
@@ -289,7 +289,7 @@ public class ThrottleServiceTest extends AndroidTestCase {
public void expectGetInterfaceCounter(long rx, long tx) throws Exception {
// TODO: provide elapsedRealtime mock to match TimeAuthority
final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 1);
- stats.addEntry(TEST_IFACE, NetworkStats.UID_ALL, NetworkStats.TAG_NONE, rx, tx);
+ stats.addValues(TEST_IFACE, NetworkStats.UID_ALL, NetworkStats.TAG_NONE, rx, 0L, tx, 0L);
expect(mMockNMService.getNetworkStatsSummary()).andReturn(stats).atLeastOnce();
}