summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2014-09-17 19:41:45 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-09-17 19:41:45 +0000
commit5d2527a8b03c9c7501d42b512110a27ef32872e5 (patch)
tree4be5495a28973df10abc0952d1749ae56767c339
parentcf6ad4958dee935c73fcc46ae5927fdbbea52a39 (diff)
parent9d18913d34ea2a3abfa2b9817ee0aacf113752a9 (diff)
downloadframeworks_base-5d2527a8b03c9c7501d42b512110a27ef32872e5.zip
frameworks_base-5d2527a8b03c9c7501d42b512110a27ef32872e5.tar.gz
frameworks_base-5d2527a8b03c9c7501d42b512110a27ef32872e5.tar.bz2
am eec860ae: am a7b20bba: am bfd9a30f: Merge "NetworkStats always needs arrays." into lmp-dev
* commit 'eec860aee483f05661cbadcd40b99a08d9c801d3': NetworkStats always needs arrays.
-rw-r--r--core/java/android/net/NetworkStats.java11
-rw-r--r--core/tests/coretests/src/android/net/NetworkStatsTest.java10
2 files changed, 21 insertions, 0 deletions
diff --git a/core/java/android/net/NetworkStats.java b/core/java/android/net/NetworkStats.java
index 54d43d3..ea5dfd1 100644
--- a/core/java/android/net/NetworkStats.java
+++ b/core/java/android/net/NetworkStats.java
@@ -24,6 +24,8 @@ import android.util.SparseBooleanArray;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ArrayUtils;
+import libcore.util.EmptyArray;
+
import java.io.CharArrayWriter;
import java.io.PrintWriter;
import java.util.Arrays;
@@ -169,6 +171,15 @@ public class NetworkStats implements Parcelable {
} else {
// Special case for use by NetworkStatsFactory to start out *really* empty.
this.capacity = 0;
+ this.iface = EmptyArray.STRING;
+ this.uid = EmptyArray.INT;
+ this.set = EmptyArray.INT;
+ this.tag = EmptyArray.INT;
+ this.rxBytes = EmptyArray.LONG;
+ this.rxPackets = EmptyArray.LONG;
+ this.txBytes = EmptyArray.LONG;
+ this.txPackets = EmptyArray.LONG;
+ this.operations = EmptyArray.LONG;
}
}
diff --git a/core/tests/coretests/src/android/net/NetworkStatsTest.java b/core/tests/coretests/src/android/net/NetworkStatsTest.java
index 6331964..9ee4e20 100644
--- a/core/tests/coretests/src/android/net/NetworkStatsTest.java
+++ b/core/tests/coretests/src/android/net/NetworkStatsTest.java
@@ -310,6 +310,16 @@ public class NetworkStatsTest extends TestCase {
assertEquals(128L + 512L, clone.getTotalBytes());
}
+ public void testAddWhenEmpty() throws Exception {
+ final NetworkStats red = new NetworkStats(TEST_START, -1);
+ final NetworkStats blue = new NetworkStats(TEST_START, 5)
+ .addValues(TEST_IFACE, 100, SET_DEFAULT, TAG_NONE, 128L, 8L, 0L, 2L, 20L)
+ .addValues(TEST_IFACE2, 100, SET_DEFAULT, TAG_NONE, 512L, 32L, 0L, 0L, 0L);
+
+ // We're mostly checking that we don't crash
+ red.combineAllValues(blue);
+ }
+
private static void assertValues(NetworkStats stats, int index, String iface, int uid, int set,
int tag, long rxBytes, long rxPackets, long txBytes, long txPackets, long operations) {
final NetworkStats.Entry entry = stats.getValues(index, null);