Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8ac35e30 authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Android (Google) Code Review
Browse files

Merge "Only write network stats when already loaded." into ics-mr1

parents aefc0ed9 c506ff61
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -203,6 +203,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
    /** Set of historical {@code xtables} stats for known UIDs. */
    private HashMap<UidStatsKey, NetworkStatsHistory> mUidStats = Maps.newHashMap();

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

@@ -272,6 +274,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
            // until actually needed.
            readNetworkDevStatsLocked();
            readNetworkXtStatsLocked();
            mNetworkStatsLoaded = true;
        }

        // bootstrap initial stats to prevent double-counting later
@@ -322,14 +325,17 @@ public class NetworkStatsService extends INetworkStatsService.Stub {

        mTeleManager.listen(mPhoneListener, LISTEN_NONE);

        if (mNetworkStatsLoaded) {
            writeNetworkDevStatsLocked();
            writeNetworkXtStatsLocked();
        }
        if (mUidStatsLoaded) {
            writeUidStatsLocked();
        }
        mNetworkDevStats.clear();
        mNetworkXtStats.clear();
        mUidStats.clear();
        mNetworkStatsLoaded = false;
        mUidStatsLoaded = false;
    }

+6 −3
Original line number Diff line number Diff line
@@ -693,12 +693,13 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
            expectSetInterfaceQuota(TEST_IFACE, Long.MAX_VALUE);
            expectMeteredIfacesChanged(TEST_IFACE);

            expectClearNotifications();
            future = expectClearNotifications();
            tagFuture = expectEnqueueNotification();

            replay();
            mService.snoozePolicy(sTemplateWifi);
            assertNotificationType(TYPE_LIMIT_SNOOZED, tagFuture.get());
            future.get();
            verifyAndReset();
        }
    }
@@ -734,9 +735,11 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
        expectLastCall().atLeastOnce();
    }

    private void expectClearNotifications() throws Exception {
    private Future<Void> expectClearNotifications() throws Exception {
        final FutureAnswer future = new FutureAnswer();
        mNotifManager.cancelNotificationWithTag(isA(String.class), isA(String.class), anyInt());
        expectLastCall().anyTimes();
        expectLastCall().andAnswer(future).anyTimes();
        return future;
    }

    private Future<String> expectEnqueueNotification() throws Exception {