Loading src/java/com/android/internal/telephony/DebugService.java +8 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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."); Loading src/java/com/android/internal/telephony/metrics/PersistAtomsStorage.java +13 −10 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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. */ Loading Loading @@ -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; } Loading tests/telephonytests/src/com/android/internal/telephony/metrics/PersistAtomsStorageTest.java +22 −0 Original line number Diff line number Diff line Loading @@ -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 { Loading Loading
src/java/com/android/internal/telephony/DebugService.java +8 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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."); Loading
src/java/com/android/internal/telephony/metrics/PersistAtomsStorage.java +13 −10 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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. */ Loading Loading @@ -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; } Loading
tests/telephonytests/src/com/android/internal/telephony/metrics/PersistAtomsStorageTest.java +22 −0 Original line number Diff line number Diff line Loading @@ -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 { Loading