Search in sources :

Example 1 with RawVoiceCallRatUsage

use of com.android.internal.telephony.nano.PersistAtomsProto.RawVoiceCallRatUsage in project android_frameworks_opt_telephony by LineageOS.

the class PersistAtomsStorageTest method addVoiceCallSession_emptyProto.

@Test
@SmallTest
public void addVoiceCallSession_emptyProto() throws Exception {
    createEmptyTestFile();
    mPersistAtomsStorage = new TestablePersistAtomsStorage(mContext);
    mPersistAtomsStorage.addVoiceCallSession(mCall1Proto);
    mPersistAtomsStorage.incTimeMillis(100L);
    // call should be added successfully, there should be no RAT usage, changes should be saved
    RawVoiceCallRatUsage[] voiceCallRatUsage = mPersistAtomsStorage.getVoiceCallRatUsages(0L);
    VoiceCallSession[] voiceCallSession = mPersistAtomsStorage.getVoiceCallSessions(0L);
    assertNotNull(voiceCallRatUsage);
    assertEquals(0, voiceCallRatUsage.length);
    assertProtoArrayEquals(new VoiceCallSession[] { mCall1Proto }, voiceCallSession);
    InOrder inOrder = inOrder(mTestFileOutputStream);
    inOrder.verify(mTestFileOutputStream, times(1)).write(eq(PersistAtoms.toByteArray(mPersistAtomsStorage.getAtomsProto())));
    inOrder.verify(mTestFileOutputStream, times(1)).close();
    inOrder.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) VoiceCallSession(com.android.internal.telephony.nano.PersistAtomsProto.VoiceCallSession) RawVoiceCallRatUsage(com.android.internal.telephony.nano.PersistAtomsProto.RawVoiceCallRatUsage) SmallTest(android.test.suitebuilder.annotation.SmallTest) TelephonyTest(com.android.internal.telephony.TelephonyTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 2 with RawVoiceCallRatUsage

use of com.android.internal.telephony.nano.PersistAtomsProto.RawVoiceCallRatUsage in project android_frameworks_opt_telephony by LineageOS.

the class PersistAtomsStorageTest method getVoiceCallRatUsages_withSavedAtoms.

@Test
@SmallTest
public void getVoiceCallRatUsages_withSavedAtoms() throws Exception {
    createTestFile(START_TIME_MILLIS);
    mPersistAtomsStorage = new TestablePersistAtomsStorage(mContext);
    mPersistAtomsStorage.incTimeMillis(100L);
    RawVoiceCallRatUsage[] voiceCallRatUsage1 = mPersistAtomsStorage.getVoiceCallRatUsages(50L);
    mPersistAtomsStorage.incTimeMillis(100L);
    RawVoiceCallRatUsage[] voiceCallRatUsage2 = mPersistAtomsStorage.getVoiceCallRatUsages(50L);
    long voiceCallSessionPullTimestampMillis = mPersistAtomsStorage.getAtomsProto().voiceCallSessionPullTimestampMillis;
    VoiceCallSession[] voiceCallSession = mPersistAtomsStorage.getVoiceCallSessions(50L);
    // first set of results should equal to file contents, second should be empty, corresponding
    // pull timestamp should be updated and saved, other fields should be unaffected
    assertProtoArrayEquals(mVoiceCallRatUsages, voiceCallRatUsage1);
    assertProtoArrayEquals(new RawVoiceCallRatUsage[0], voiceCallRatUsage2);
    assertEquals(START_TIME_MILLIS + 200L, mPersistAtomsStorage.getAtomsProto().rawVoiceCallRatUsagePullTimestampMillis);
    assertProtoArrayEquals(mVoiceCallSessions, voiceCallSession);
    assertEquals(START_TIME_MILLIS, voiceCallSessionPullTimestampMillis);
    InOrder inOrder = inOrder(mTestFileOutputStream);
    assertEquals(START_TIME_MILLIS + 100L, getAtomsWritten(inOrder).rawVoiceCallRatUsagePullTimestampMillis);
    assertEquals(START_TIME_MILLIS + 200L, getAtomsWritten(inOrder).rawVoiceCallRatUsagePullTimestampMillis);
    assertEquals(START_TIME_MILLIS + 200L, getAtomsWritten(inOrder).voiceCallSessionPullTimestampMillis);
    inOrder.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) VoiceCallSession(com.android.internal.telephony.nano.PersistAtomsProto.VoiceCallSession) RawVoiceCallRatUsage(com.android.internal.telephony.nano.PersistAtomsProto.RawVoiceCallRatUsage) SmallTest(android.test.suitebuilder.annotation.SmallTest) TelephonyTest(com.android.internal.telephony.TelephonyTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 3 with RawVoiceCallRatUsage

use of com.android.internal.telephony.nano.PersistAtomsProto.RawVoiceCallRatUsage in project android_frameworks_opt_telephony by LineageOS.

the class PersistAtomsStorageTest method addVoiceCallSession_withExistingCalls.

@Test
@SmallTest
public void addVoiceCallSession_withExistingCalls() throws Exception {
    createTestFile(100L);
    mPersistAtomsStorage = new TestablePersistAtomsStorage(mContext);
    mPersistAtomsStorage.addVoiceCallSession(mCall1Proto);
    mPersistAtomsStorage.incTimeMillis(100L);
    // call should be added successfully, RAT usages should not change, changes should be saved
    RawVoiceCallRatUsage[] voiceCallRatUsage = mPersistAtomsStorage.getVoiceCallRatUsages(0L);
    VoiceCallSession[] voiceCallSession = mPersistAtomsStorage.getVoiceCallSessions(0L);
    assertNotNull(voiceCallRatUsage);
    assertEquals(mVoiceCallRatUsages.length, voiceCallRatUsage.length);
    assertNotNull(voiceCallSession);
    // call lists are randomized, but sorted version should be identical
    VoiceCallSession[] expectedVoiceCallSessions = new VoiceCallSession[] { mCall1Proto, mCall1Proto, mCall2Proto, mCall3Proto, mCall4Proto };
    Arrays.sort(expectedVoiceCallSessions, sProtoComparator);
    Arrays.sort(voiceCallSession, sProtoComparator);
    assertProtoArrayEquals(expectedVoiceCallSessions, voiceCallSession);
    InOrder inOrder = inOrder(mTestFileOutputStream);
    inOrder.verify(mTestFileOutputStream, times(1)).write(eq(PersistAtoms.toByteArray(mPersistAtomsStorage.getAtomsProto())));
    inOrder.verify(mTestFileOutputStream, times(1)).close();
    inOrder.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) VoiceCallSession(com.android.internal.telephony.nano.PersistAtomsProto.VoiceCallSession) RawVoiceCallRatUsage(com.android.internal.telephony.nano.PersistAtomsProto.RawVoiceCallRatUsage) SmallTest(android.test.suitebuilder.annotation.SmallTest) TelephonyTest(com.android.internal.telephony.TelephonyTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 4 with RawVoiceCallRatUsage

use of com.android.internal.telephony.nano.PersistAtomsProto.RawVoiceCallRatUsage in project android_frameworks_opt_telephony by LineageOS.

the class PersistAtomsStorageTest method loadAtoms_malformedFile.

@Test
@SmallTest
public void loadAtoms_malformedFile() throws Exception {
    FileOutputStream stream = new FileOutputStream(mTestFile);
    stream.write("This is not a proto file.".getBytes(StandardCharsets.UTF_8));
    stream.close();
    mPersistAtomsStorage = new TestablePersistAtomsStorage(mContext);
    mPersistAtomsStorage.incTimeMillis(100L);
    // no exception should be thrown, storage should be empty, pull time should be start time
    assertEquals(START_TIME_MILLIS, mPersistAtomsStorage.getAtomsProto().rawVoiceCallRatUsagePullTimestampMillis);
    assertEquals(START_TIME_MILLIS, mPersistAtomsStorage.getAtomsProto().voiceCallSessionPullTimestampMillis);
    RawVoiceCallRatUsage[] voiceCallRatUsage = mPersistAtomsStorage.getVoiceCallRatUsages(0L);
    VoiceCallSession[] voiceCallSession = mPersistAtomsStorage.getVoiceCallSessions(0L);
    assertNotNull(voiceCallRatUsage);
    assertEquals(0, voiceCallRatUsage.length);
    assertNotNull(voiceCallSession);
    assertEquals(0, voiceCallSession.length);
}
Also used : VoiceCallSession(com.android.internal.telephony.nano.PersistAtomsProto.VoiceCallSession) FileOutputStream(java.io.FileOutputStream) RawVoiceCallRatUsage(com.android.internal.telephony.nano.PersistAtomsProto.RawVoiceCallRatUsage) SmallTest(android.test.suitebuilder.annotation.SmallTest) TelephonyTest(com.android.internal.telephony.TelephonyTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 5 with RawVoiceCallRatUsage

use of com.android.internal.telephony.nano.PersistAtomsProto.RawVoiceCallRatUsage in project android_frameworks_opt_telephony by LineageOS.

the class VoiceCallSessionStatsTest method singleImsCall_mtAccepted.

@Test
@SmallTest
public void singleImsCall_mtAccepted() {
    doReturn(TelephonyManager.NETWORK_TYPE_LTE).when(mServiceState).getVoiceNetworkType();
    doReturn(true).when(mImsConnection0).isIncoming();
    doReturn(2000L).when(mImsConnection0).getCreateTime();
    doReturn(mImsCall0).when(mImsConnection0).getCall();
    doReturn(new ArrayList(List.of(mImsConnection0))).when(mImsCall0).getConnections();
    VoiceCallSession expectedCall = makeSlot0CallProto(VOICE_CALL_SESSION__BEARER_AT_END__CALL_BEARER_IMS, VOICE_CALL_SESSION__DIRECTION__CALL_DIRECTION_MT, TelephonyManager.NETWORK_TYPE_LTE, ImsReasonInfo.CODE_USER_TERMINATED);
    expectedCall.setupDuration = VOICE_CALL_SESSION__SETUP_DURATION__CALL_SETUP_DURATION_ULTRA_FAST;
    expectedCall.setupFailed = false;
    expectedCall.codecBitmask = 1L << AudioCodec.AUDIO_CODEC_AMR;
    RawVoiceCallRatUsage expectedRatUsage = makeRatUsageProto(CARRIER_ID_SLOT_0, TelephonyManager.NETWORK_TYPE_LTE, 2000L, 12000L, 1L);
    final AtomicReference<RawVoiceCallRatUsage[]> ratUsage = setupRatUsageCapture();
    mVoiceCallSessionStats0.setTimeMillis(2000L);
    doReturn(Call.State.INCOMING).when(mImsCall0).getState();
    doReturn(Call.State.INCOMING).when(mImsConnection0).getState();
    mVoiceCallSessionStats0.onImsCallReceived(mImsConnection0);
    mVoiceCallSessionStats0.setTimeMillis(2100L);
    mVoiceCallSessionStats0.onAudioCodecChanged(mImsConnection0, ImsStreamMediaProfile.AUDIO_QUALITY_AMR);
    mVoiceCallSessionStats0.setTimeMillis(2200L);
    mVoiceCallSessionStats0.onImsAcceptCall(List.of(mImsConnection0));
    mVoiceCallSessionStats0.setTimeMillis(2280L);
    doReturn(Call.State.ACTIVE).when(mImsCall0).getState();
    doReturn(Call.State.ACTIVE).when(mImsConnection0).getState();
    mVoiceCallSessionStats0.onCallStateChanged(mImsCall0);
    mVoiceCallSessionStats0.setTimeMillis(12000L);
    mVoiceCallSessionStats0.onImsCallTerminated(mImsConnection0, new ImsReasonInfo(ImsReasonInfo.CODE_USER_TERMINATED, 0));
    ArgumentCaptor<VoiceCallSession> callCaptor = ArgumentCaptor.forClass(VoiceCallSession.class);
    verify(mPersistAtomsStorage, times(1)).addVoiceCallSession(callCaptor.capture());
    verify(mPersistAtomsStorage, times(1)).addVoiceCallRatUsage(any());
    verifyNoMoreInteractions(mPersistAtomsStorage);
    assertProtoEquals(expectedCall, callCaptor.getValue());
    assertThat(ratUsage.get()).hasLength(1);
    assertProtoEquals(expectedRatUsage, ratUsage.get()[0]);
}
Also used : VoiceCallSession(com.android.internal.telephony.nano.PersistAtomsProto.VoiceCallSession) ArrayList(java.util.ArrayList) RawVoiceCallRatUsage(com.android.internal.telephony.nano.PersistAtomsProto.RawVoiceCallRatUsage) ImsReasonInfo(android.telephony.ims.ImsReasonInfo) TelephonyTest(com.android.internal.telephony.TelephonyTest) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Aggregations

RawVoiceCallRatUsage (com.android.internal.telephony.nano.PersistAtomsProto.RawVoiceCallRatUsage)32 SmallTest (android.test.suitebuilder.annotation.SmallTest)28 TelephonyTest (com.android.internal.telephony.TelephonyTest)28 VoiceCallSession (com.android.internal.telephony.nano.PersistAtomsProto.VoiceCallSession)28 Test (org.junit.Test)28 ArrayList (java.util.ArrayList)16 ImsReasonInfo (android.telephony.ims.ImsReasonInfo)13 InOrder (org.mockito.InOrder)6 StatsEvent (android.util.StatsEvent)1 FileOutputStream (java.io.FileOutputStream)1