From 7b51ae7abc2bf66822536df1bc51c596d5b2cd83 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Wed, 17 Sep 2014 09:26:28 -0700 Subject: [PATCH] NetworkStats always needs arrays. Internal logic relies on Arrays.copyOf(), so always give ourselves valid arrays, using shared empty objects to save overhead. Bug: 17502649 Change-Id: I5dbb00545bdfe45bbd48144ab505ea08cc92cbcd --- .../coretests/src/android/net/NetworkStatsTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/tests/coretests/src/android/net/NetworkStatsTest.java b/core/tests/coretests/src/android/net/NetworkStatsTest.java index 633196433d..9ee4e2073d 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);