Loading core/java/android/net/NetworkStats.java +11 −0 Original line number Diff line number Diff line Loading @@ -165,6 +165,17 @@ public class NetworkStats implements Parcelable { dest.writeLongArray(operations); } @Override public NetworkStats clone() { final NetworkStats clone = new NetworkStats(elapsedRealtime, size); NetworkStats.Entry entry = null; for (int i = 0; i < size; i++) { entry = getValues(i, entry); clone.addValues(entry); } return clone; } // @VisibleForTesting public NetworkStats addIfaceValues( String iface, long rxBytes, long rxPackets, long txBytes, long txPackets) { Loading core/tests/coretests/src/android/net/NetworkStatsTest.java +16 −0 Original line number Diff line number Diff line Loading @@ -294,6 +294,22 @@ public class NetworkStatsTest extends TestCase { assertValues(after, 1, TEST_IFACE, 101, SET_DEFAULT, 0xF00D, 128L, 8L, 0L, 0L, 0L); } public void testClone() throws Exception { final NetworkStats original = 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); // make clone and mutate original final NetworkStats clone = original.clone(); original.addValues(TEST_IFACE, 101, SET_DEFAULT, TAG_NONE, 128L, 8L, 0L, 0L, 0L); assertEquals(3, original.size()); assertEquals(2, clone.size()); assertEquals(128L + 512L + 128L, original.getTotalBytes()); assertEquals(128L + 512L, clone.getTotalBytes()); } 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); Loading services/java/com/android/server/net/NetworkStatsService.java +1 −2 Original line number Diff line number Diff line Loading @@ -971,8 +971,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { } mLastPollUidSnapshot = uidSnapshot; mLastPollOperationsSnapshot = mOperations; mOperations = new NetworkStats(0L, 10); mLastPollOperationsSnapshot = mOperations.clone(); } /** Loading Loading
core/java/android/net/NetworkStats.java +11 −0 Original line number Diff line number Diff line Loading @@ -165,6 +165,17 @@ public class NetworkStats implements Parcelable { dest.writeLongArray(operations); } @Override public NetworkStats clone() { final NetworkStats clone = new NetworkStats(elapsedRealtime, size); NetworkStats.Entry entry = null; for (int i = 0; i < size; i++) { entry = getValues(i, entry); clone.addValues(entry); } return clone; } // @VisibleForTesting public NetworkStats addIfaceValues( String iface, long rxBytes, long rxPackets, long txBytes, long txPackets) { Loading
core/tests/coretests/src/android/net/NetworkStatsTest.java +16 −0 Original line number Diff line number Diff line Loading @@ -294,6 +294,22 @@ public class NetworkStatsTest extends TestCase { assertValues(after, 1, TEST_IFACE, 101, SET_DEFAULT, 0xF00D, 128L, 8L, 0L, 0L, 0L); } public void testClone() throws Exception { final NetworkStats original = 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); // make clone and mutate original final NetworkStats clone = original.clone(); original.addValues(TEST_IFACE, 101, SET_DEFAULT, TAG_NONE, 128L, 8L, 0L, 0L, 0L); assertEquals(3, original.size()); assertEquals(2, clone.size()); assertEquals(128L + 512L + 128L, original.getTotalBytes()); assertEquals(128L + 512L, clone.getTotalBytes()); } 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); Loading
services/java/com/android/server/net/NetworkStatsService.java +1 −2 Original line number Diff line number Diff line Loading @@ -971,8 +971,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { } mLastPollUidSnapshot = uidSnapshot; mLastPollOperationsSnapshot = mOperations; mOperations = new NetworkStats(0L, 10); mLastPollOperationsSnapshot = mOperations.clone(); } /** Loading