Skip to content

Commit 8ac35e3

Browse files
jsharkeyAndroid (Google) Code Review
authored andcommitted
Merge "Only write network stats when already loaded." into ics-mr1
2 parents aefc0ed + c506ff6 commit 8ac35e3

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

services/java/com/android/server/net/NetworkStatsService.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ public interface NetworkStatsSettings {
203203
/** Set of historical {@code xtables} stats for known UIDs. */
204204
private HashMap<UidStatsKey, NetworkStatsHistory> mUidStats = Maps.newHashMap();
205205

206+
/** Flag if {@link #mNetworkDevStats} have been loaded from disk. */
207+
private boolean mNetworkStatsLoaded = false;
206208
/** Flag if {@link #mUidStats} have been loaded from disk. */
207209
private boolean mUidStatsLoaded = false;
208210

@@ -272,6 +274,7 @@ public void systemReady() {
272274
// until actually needed.
273275
readNetworkDevStatsLocked();
274276
readNetworkXtStatsLocked();
277+
mNetworkStatsLoaded = true;
275278
}
276279

277280
// bootstrap initial stats to prevent double-counting later
@@ -322,14 +325,17 @@ private void shutdownLocked() {
322325

323326
mTeleManager.listen(mPhoneListener, LISTEN_NONE);
324327

325-
writeNetworkDevStatsLocked();
326-
writeNetworkXtStatsLocked();
328+
if (mNetworkStatsLoaded) {
329+
writeNetworkDevStatsLocked();
330+
writeNetworkXtStatsLocked();
331+
}
327332
if (mUidStatsLoaded) {
328333
writeUidStatsLocked();
329334
}
330335
mNetworkDevStats.clear();
331336
mNetworkXtStats.clear();
332337
mUidStats.clear();
338+
mNetworkStatsLoaded = false;
333339
mUidStatsLoaded = false;
334340
}
335341

services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -693,12 +693,13 @@ public void testOverWarningLimitNotification() throws Exception {
693693
expectSetInterfaceQuota(TEST_IFACE, Long.MAX_VALUE);
694694
expectMeteredIfacesChanged(TEST_IFACE);
695695

696-
expectClearNotifications();
696+
future = expectClearNotifications();
697697
tagFuture = expectEnqueueNotification();
698698

699699
replay();
700700
mService.snoozePolicy(sTemplateWifi);
701701
assertNotificationType(TYPE_LIMIT_SNOOZED, tagFuture.get());
702+
future.get();
702703
verifyAndReset();
703704
}
704705
}
@@ -734,9 +735,11 @@ private void expectForceUpdate() throws Exception {
734735
expectLastCall().atLeastOnce();
735736
}
736737

737-
private void expectClearNotifications() throws Exception {
738+
private Future<Void> expectClearNotifications() throws Exception {
739+
final FutureAnswer future = new FutureAnswer();
738740
mNotifManager.cancelNotificationWithTag(isA(String.class), isA(String.class), anyInt());
739-
expectLastCall().anyTimes();
741+
expectLastCall().andAnswer(future).anyTimes();
742+
return future;
740743
}
741744

742745
private Future<String> expectEnqueueNotification() throws Exception {

0 commit comments

Comments
 (0)