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

Commit ef61d155 authored by Kiwon Park's avatar Kiwon Park Committed by Android (Google) Code Review
Browse files

Merge "Add --clearatoms command to clear PersistAtomsStorage cache" into tm-qpr-dev

parents 1da1f284 df29842a
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.internal.telephony;

import android.os.Build;

import com.android.internal.telephony.metrics.TelephonyMetrics;
import com.android.telephony.Rlog;

@@ -53,6 +55,12 @@ public class DebugService {
                    log("Saving atoms..");
                    PhoneFactory.getMetricsCollector().getAtomsStorage().flushAtoms();
                    return;
                case "--clearatoms":
                    if (Build.IS_DEBUGGABLE) {
                        log("Clearing atoms..");
                        PhoneFactory.getMetricsCollector().getAtomsStorage().clearAtoms();
                    }
                    return;
            }
        }
        log("Dump telephony.");
+13 −10
Original line number Diff line number Diff line
@@ -158,7 +158,7 @@ public class PersistAtomsStorage {
    private final int mMaxNumGbaEventStats;

    /** Stores persist atoms and persist states of the puller. */
    @VisibleForTesting protected final PersistAtoms mAtoms;
    @VisibleForTesting protected PersistAtoms mAtoms;

    /** Aggregates RAT duration and call count. */
    private final VoiceCallRatTracker mVoiceCallRatTracker;
@@ -1098,12 +1098,15 @@ public class PersistAtomsStorage {
        return bitmask;
    }

    /** Saves a pending {@link PersistAtoms} to a file in private storage immediately. */
    public void flushAtoms() {
        if (mHandler.hasCallbacks(mSaveRunnable)) {
            mHandler.removeCallbacks(mSaveRunnable);
            saveAtomsToFileNow();
    /** Saves {@link PersistAtoms} to a file in private storage immediately. */
    public synchronized void flushAtoms() {
        saveAtomsToFile(0);
    }

    /** Clears atoms for testing purpose. */
    public synchronized void clearAtoms() {
        mAtoms = makeNewPersistAtoms();
        saveAtomsToFile(0);
    }

    /** Loads {@link PersistAtoms} from a file in private storage. */
@@ -1289,14 +1292,14 @@ public class PersistAtomsStorage {
    }

    /**
     * Posts message to save a copy of {@link PersistAtoms} to a file after a delay.
     * Posts message to save a copy of {@link PersistAtoms} to a file after a delay or immediately.
     *
     * <p>The delay is introduced to avoid too frequent operations to disk, which would negatively
     * impact the power consumption.
     */
    private void saveAtomsToFile(int delayMillis) {
        if (delayMillis > 0 && !mSaveImmediately) {
    private synchronized void saveAtomsToFile(int delayMillis) {
        mHandler.removeCallbacks(mSaveRunnable);
        if (delayMillis > 0 && !mSaveImmediately) {
            if (mHandler.postDelayed(mSaveRunnable, delayMillis)) {
                return;
            }
+22 −0
Original line number Diff line number Diff line
@@ -3273,6 +3273,28 @@ public class PersistAtomsStorageTest extends TelephonyTest {
        inOrder.verify(mTestFileOutputStream, times(1)).close();
        inOrder.verifyNoMoreInteractions();
    }

    @Test
    @SmallTest
    public void clearAtoms() throws Exception {
        createTestFile(START_TIME_MILLIS);
        mPersistAtomsStorage = new TestablePersistAtomsStorage(mContext);
        mPersistAtomsStorage.addCompleteSipTransportSession(copyOf(mSipTransportSession1));
        mPersistAtomsStorage.incTimeMillis(100L);
        verifyCurrentStateSavedToFileOnce();

        mPersistAtomsStorage.addUceEventStats(mUceEventStats1);
        mPersistAtomsStorage.incTimeMillis(100L);
        verifyCurrentStateSavedToFileOnce();

        mPersistAtomsStorage.clearAtoms();
        verifyCurrentStateSavedToFileOnce();
        UceEventStats[] uceEventStats = mPersistAtomsStorage.getUceEventStats(0L);
        assertEquals(null, uceEventStats);
        SipTransportSession[] sipTransportSession = mPersistAtomsStorage.getSipTransportSession(0L);
        assertEquals(null, sipTransportSession);
    }

    /* Utilities */

    private void createEmptyTestFile() throws Exception {