Loading src/java/com/android/internal/telephony/metrics/PersistAtomsStorage.java +17 −0 Original line number Diff line number Diff line Loading @@ -1589,6 +1589,7 @@ public class PersistAtomsStorage { /** Returns index of the item suitable for eviction when the array is full. */ private static <T> int findItemToEvict(T[] array) { if (array instanceof CellularServiceState[]) { // Evict the item that was used least recently CellularServiceState[] arr = (CellularServiceState[]) array; return IntStream.range(0, arr.length) .reduce((i, j) -> arr[i].lastUsedMillis < arr[j].lastUsedMillis ? i : j) Loading @@ -1596,6 +1597,7 @@ public class PersistAtomsStorage { } if (array instanceof CellularDataServiceSwitch[]) { // Evict the item that was used least recently CellularDataServiceSwitch[] arr = (CellularDataServiceSwitch[]) array; return IntStream.range(0, arr.length) .reduce((i, j) -> arr[i].lastUsedMillis < arr[j].lastUsedMillis ? i : j) Loading @@ -1603,6 +1605,7 @@ public class PersistAtomsStorage { } if (array instanceof ImsRegistrationStats[]) { // Evict the item that was used least recently ImsRegistrationStats[] arr = (ImsRegistrationStats[]) array; return IntStream.range(0, arr.length) .reduce((i, j) -> arr[i].lastUsedMillis < arr[j].lastUsedMillis ? i : j) Loading @@ -1610,12 +1613,26 @@ public class PersistAtomsStorage { } if (array instanceof ImsRegistrationTermination[]) { // Evict the item that was used least recently ImsRegistrationTermination[] arr = (ImsRegistrationTermination[]) array; return IntStream.range(0, arr.length) .reduce((i, j) -> arr[i].lastUsedMillis < arr[j].lastUsedMillis ? i : j) .getAsInt(); } if (array instanceof VoiceCallSession[]) { // For voice calls, try to keep emergency calls over regular calls. VoiceCallSession[] arr = (VoiceCallSession[]) array; int[] nonEmergencyCallIndexes = IntStream.range(0, arr.length) .filter(i -> !arr[i].isEmergency) .toArray(); if (nonEmergencyCallIndexes.length > 0) { return nonEmergencyCallIndexes[sRandom.nextInt(nonEmergencyCallIndexes.length)]; } // If all calls in the storage are emergency calls, proceed with default case // even if the new call is not an emergency call. } return sRandom.nextInt(array.length); } Loading tests/telephonytests/src/com/android/internal/telephony/metrics/PersistAtomsStorageTest.java +20 −2 Original line number Diff line number Diff line Loading @@ -310,7 +310,7 @@ public class PersistAtomsStorageTest extends TelephonyTest { mCall3Proto.isEmergency = false; mCall3Proto.isRoaming = false; // CS MO call while camped on LTE // CS MO emergency call while camped on LTE mCall4Proto = new VoiceCallSession(); mCall4Proto.bearerAtStart = VOICE_CALL_SESSION__BEARER_AT_END__CALL_BEARER_CS; mCall4Proto.bearerAtEnd = VOICE_CALL_SESSION__BEARER_AT_END__CALL_BEARER_CS; Loading @@ -335,7 +335,7 @@ public class PersistAtomsStorageTest extends TelephonyTest { mCall4Proto.srvccFailureCount = 0L; mCall4Proto.srvccCancellationCount = 0L; mCall4Proto.rttEnabled = false; mCall4Proto.isEmergency = false; mCall4Proto.isEmergency = true; mCall4Proto.isRoaming = true; mCarrier1LteUsageProto = new VoiceCallRatUsage(); Loading Loading @@ -1130,6 +1130,24 @@ public class PersistAtomsStorageTest extends TelephonyTest { assertHasCall(calls, mCall2Proto, /* expectedCount= */ 1); } @Test @SmallTest public void addVoiceCallSession_tooManyCalls_withEmergencyCalls() throws Exception { createEmptyTestFile(); // We initially have storage full of emergency calls except one. mPersistAtomsStorage = new TestablePersistAtomsStorage(mContext); addRepeatedCalls(mPersistAtomsStorage, mCall4Proto, 49); mPersistAtomsStorage.addVoiceCallSession(mCall1Proto); mPersistAtomsStorage.addVoiceCallSession(mCall4Proto); mPersistAtomsStorage.incTimeMillis(100L); // after adding one more emergency call, the previous non-emergency call should be evicted verifyCurrentStateSavedToFileOnce(); VoiceCallSession[] calls = mPersistAtomsStorage.getVoiceCallSessions(0L); assertHasCall(calls, mCall4Proto, /* expectedCount= */ 50); } @Test @SmallTest public void addVoiceCallRatUsage_emptyProto() throws Exception { Loading Loading
src/java/com/android/internal/telephony/metrics/PersistAtomsStorage.java +17 −0 Original line number Diff line number Diff line Loading @@ -1589,6 +1589,7 @@ public class PersistAtomsStorage { /** Returns index of the item suitable for eviction when the array is full. */ private static <T> int findItemToEvict(T[] array) { if (array instanceof CellularServiceState[]) { // Evict the item that was used least recently CellularServiceState[] arr = (CellularServiceState[]) array; return IntStream.range(0, arr.length) .reduce((i, j) -> arr[i].lastUsedMillis < arr[j].lastUsedMillis ? i : j) Loading @@ -1596,6 +1597,7 @@ public class PersistAtomsStorage { } if (array instanceof CellularDataServiceSwitch[]) { // Evict the item that was used least recently CellularDataServiceSwitch[] arr = (CellularDataServiceSwitch[]) array; return IntStream.range(0, arr.length) .reduce((i, j) -> arr[i].lastUsedMillis < arr[j].lastUsedMillis ? i : j) Loading @@ -1603,6 +1605,7 @@ public class PersistAtomsStorage { } if (array instanceof ImsRegistrationStats[]) { // Evict the item that was used least recently ImsRegistrationStats[] arr = (ImsRegistrationStats[]) array; return IntStream.range(0, arr.length) .reduce((i, j) -> arr[i].lastUsedMillis < arr[j].lastUsedMillis ? i : j) Loading @@ -1610,12 +1613,26 @@ public class PersistAtomsStorage { } if (array instanceof ImsRegistrationTermination[]) { // Evict the item that was used least recently ImsRegistrationTermination[] arr = (ImsRegistrationTermination[]) array; return IntStream.range(0, arr.length) .reduce((i, j) -> arr[i].lastUsedMillis < arr[j].lastUsedMillis ? i : j) .getAsInt(); } if (array instanceof VoiceCallSession[]) { // For voice calls, try to keep emergency calls over regular calls. VoiceCallSession[] arr = (VoiceCallSession[]) array; int[] nonEmergencyCallIndexes = IntStream.range(0, arr.length) .filter(i -> !arr[i].isEmergency) .toArray(); if (nonEmergencyCallIndexes.length > 0) { return nonEmergencyCallIndexes[sRandom.nextInt(nonEmergencyCallIndexes.length)]; } // If all calls in the storage are emergency calls, proceed with default case // even if the new call is not an emergency call. } return sRandom.nextInt(array.length); } Loading
tests/telephonytests/src/com/android/internal/telephony/metrics/PersistAtomsStorageTest.java +20 −2 Original line number Diff line number Diff line Loading @@ -310,7 +310,7 @@ public class PersistAtomsStorageTest extends TelephonyTest { mCall3Proto.isEmergency = false; mCall3Proto.isRoaming = false; // CS MO call while camped on LTE // CS MO emergency call while camped on LTE mCall4Proto = new VoiceCallSession(); mCall4Proto.bearerAtStart = VOICE_CALL_SESSION__BEARER_AT_END__CALL_BEARER_CS; mCall4Proto.bearerAtEnd = VOICE_CALL_SESSION__BEARER_AT_END__CALL_BEARER_CS; Loading @@ -335,7 +335,7 @@ public class PersistAtomsStorageTest extends TelephonyTest { mCall4Proto.srvccFailureCount = 0L; mCall4Proto.srvccCancellationCount = 0L; mCall4Proto.rttEnabled = false; mCall4Proto.isEmergency = false; mCall4Proto.isEmergency = true; mCall4Proto.isRoaming = true; mCarrier1LteUsageProto = new VoiceCallRatUsage(); Loading Loading @@ -1130,6 +1130,24 @@ public class PersistAtomsStorageTest extends TelephonyTest { assertHasCall(calls, mCall2Proto, /* expectedCount= */ 1); } @Test @SmallTest public void addVoiceCallSession_tooManyCalls_withEmergencyCalls() throws Exception { createEmptyTestFile(); // We initially have storage full of emergency calls except one. mPersistAtomsStorage = new TestablePersistAtomsStorage(mContext); addRepeatedCalls(mPersistAtomsStorage, mCall4Proto, 49); mPersistAtomsStorage.addVoiceCallSession(mCall1Proto); mPersistAtomsStorage.addVoiceCallSession(mCall4Proto); mPersistAtomsStorage.incTimeMillis(100L); // after adding one more emergency call, the previous non-emergency call should be evicted verifyCurrentStateSavedToFileOnce(); VoiceCallSession[] calls = mPersistAtomsStorage.getVoiceCallSessions(0L); assertHasCall(calls, mCall4Proto, /* expectedCount= */ 50); } @Test @SmallTest public void addVoiceCallRatUsage_emptyProto() throws Exception { Loading