Search in sources :

Example 1 with StatsEvent

use of android.util.StatsEvent in project robolectric by robolectric.

the class ShadowStatsLogTest method testIntIntInt.

@Test
public void testIntIntInt() {
    final int expectedAtomId = 109;
    final int field1 = 1;
    final int field2 = 2;
    final int field3 = 3;
    final StatsEvent statsEvent = StatsEvent.newBuilder().setAtomId(expectedAtomId).writeInt(field1).writeInt(field2).writeInt(field3).usePooledBuffer().build();
    long minTimestamp = SystemClock.elapsedRealtimeNanos();
    StatsLog.write(statsEvent);
    long maxTimestamp = SystemClock.elapsedRealtimeNanos();
    assertEquals(1, ShadowStatsLog.getStatsLogs().size());
    assertEquals((int) expectedAtomId, (int) ShadowStatsLog.getStatsLogs().get(0).atomId());
    final ByteBuffer buffer = ByteBuffer.wrap(ShadowStatsLog.getStatsLogs().get(0).bytes()).order(ByteOrder.LITTLE_ENDIAN);
    assertWithMessage("Root element in buffer is not TYPE_OBJECT").that(buffer.get()).isEqualTo(StatsEvent.TYPE_OBJECT);
    assertWithMessage("Incorrect number of elements in root object").that(buffer.get()).isEqualTo(5);
    assertWithMessage("First element is not timestamp").that(buffer.get()).isEqualTo(StatsEvent.TYPE_LONG);
    assertWithMessage("Incorrect timestamp").that(buffer.getLong()).isIn(Range.closed(minTimestamp, maxTimestamp));
    assertWithMessage("Second element is not atom id").that(buffer.get()).isEqualTo(StatsEvent.TYPE_INT);
    assertWithMessage("Incorrect atom id").that(buffer.getInt()).isEqualTo(expectedAtomId);
    assertWithMessage("First field is not Int").that(buffer.get()).isEqualTo(StatsEvent.TYPE_INT);
    assertWithMessage("Incorrect field 1").that(buffer.getInt()).isEqualTo(field1);
    assertWithMessage("Third field is not Int").that(buffer.get()).isEqualTo(StatsEvent.TYPE_INT);
    assertWithMessage("Incorrect field 2").that(buffer.getInt()).isEqualTo(field2);
    assertWithMessage("Fourth field is not Int").that(buffer.get()).isEqualTo(StatsEvent.TYPE_INT);
    assertWithMessage("Incorrect field 3").that(buffer.getInt()).isEqualTo(field3);
    assertThat(statsEvent.getNumBytes()).isEqualTo(buffer.position());
    statsEvent.release();
}
Also used : StatsEvent(android.util.StatsEvent) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 2 with StatsEvent

use of android.util.StatsEvent in project android_frameworks_opt_telephony by LineageOS.

the class MetricsCollectorTest method onPullAtom_simSlotState_bothSimPresent.

@Test
@SmallTest
public void onPullAtom_simSlotState_bothSimPresent() {
    // these have been tested extensively in SimSlotStateTest, here we verify atom generation
    doReturn(true).when(mPhysicalSlot).isActive();
    doReturn(CardState.CARDSTATE_PRESENT).when(mPhysicalSlot).getCardState();
    doReturn(false).when(mPhysicalSlot).isEuicc();
    doReturn(true).when(mEsimSlot).isActive();
    doReturn(CardState.CARDSTATE_PRESENT).when(mEsimSlot).getCardState();
    doReturn(true).when(mEsimSlot).isEuicc();
    doReturn(mActiveCard).when(mEsimSlot).getUiccCard();
    doReturn(4).when(mActiveCard).getNumApplications();
    doReturn(new UiccSlot[] { mPhysicalSlot, mEsimSlot }).when(mUiccController).getUiccSlots();
    doReturn(mPhysicalSlot).when(mUiccController).getUiccSlot(eq(0));
    doReturn(mEsimSlot).when(mUiccController).getUiccSlot(eq(1));
    StatsEvent expectedAtom = StatsEvent.newBuilder().setAtomId(SIM_SLOT_STATE).writeInt(2).writeInt(2).writeInt(1).build();
    List<StatsEvent> actualAtoms = new ArrayList<>();
    int result = mMetricsCollector.onPullAtom(SIM_SLOT_STATE, actualAtoms);
    assertThat(actualAtoms).hasSize(1);
    assertThat(result).isEqualTo(StatsManager.PULL_SUCCESS);
// TODO(b/153196254): verify atom contents
}
Also used : ArrayList(java.util.ArrayList) StatsEvent(android.util.StatsEvent) 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 StatsEvent

use of android.util.StatsEvent in project android_frameworks_opt_telephony by LineageOS.

the class MetricsCollectorTest method onPullAtom_voiceCallRatUsage_bucketWithTooFewCalls.

@Test
@SmallTest
public void onPullAtom_voiceCallRatUsage_bucketWithTooFewCalls() throws Exception {
    RawVoiceCallRatUsage usage1 = new RawVoiceCallRatUsage();
    usage1.callCount = MIN_CALLS_PER_BUCKET;
    RawVoiceCallRatUsage usage2 = new RawVoiceCallRatUsage();
    usage2.callCount = MIN_CALLS_PER_BUCKET - 1L;
    doReturn(new RawVoiceCallRatUsage[] { usage1, usage1, usage1, usage2 }).when(mPersistAtomsStorage).getVoiceCallRatUsages(anyLong());
    List<StatsEvent> actualAtoms = new ArrayList<>();
    int result = mMetricsCollector.onPullAtom(VOICE_CALL_RAT_USAGE, actualAtoms);
    // usage 2 should be dropped
    assertThat(actualAtoms).hasSize(3);
    assertThat(result).isEqualTo(StatsManager.PULL_SUCCESS);
// TODO(b/153196254): verify atom contents
}
Also used : ArrayList(java.util.ArrayList) RawVoiceCallRatUsage(com.android.internal.telephony.nano.PersistAtomsProto.RawVoiceCallRatUsage) StatsEvent(android.util.StatsEvent) 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 StatsEvent

use of android.util.StatsEvent in project android_frameworks_opt_telephony by LineageOS.

the class MetricsCollectorTest method onPullAtom_voiceCallSession_multipleCalls.

@Test
@SmallTest
public void onPullAtom_voiceCallSession_multipleCalls() throws Exception {
    VoiceCallSession call = new VoiceCallSession();
    doReturn(new VoiceCallSession[] { call, call, call, call }).when(mPersistAtomsStorage).getVoiceCallSessions(anyLong());
    List<StatsEvent> actualAtoms = new ArrayList<>();
    int result = mMetricsCollector.onPullAtom(VOICE_CALL_SESSION, actualAtoms);
    assertThat(actualAtoms).hasSize(4);
    assertThat(result).isEqualTo(StatsManager.PULL_SUCCESS);
// TODO(b/153196254): verify atom contents
}
Also used : VoiceCallSession(com.android.internal.telephony.nano.PersistAtomsProto.VoiceCallSession) ArrayList(java.util.ArrayList) StatsEvent(android.util.StatsEvent) 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 StatsEvent

use of android.util.StatsEvent in project android_frameworks_opt_telephony by LineageOS.

the class MetricsCollectorTest method onPullAtom_supportedRadioAccessFamily_dualPhonesWithUnknownRaf.

@Test
@SmallTest
public void onPullAtom_supportedRadioAccessFamily_dualPhonesWithUnknownRaf() {
    doReturn(SUPPORTED_RAF_1).when(mPhone).getRadioAccessFamily();
    doReturn((int) TelephonyManager.NETWORK_TYPE_BITMASK_UNKNOWN).when(mSecondPhone).getRadioAccessFamily();
    mPhones = new Phone[] { mPhone, mSecondPhone };
    StatsEvent expectedAtom = StatsEvent.newBuilder().setAtomId(SUPPORTED_RADIO_ACCESS_FAMILY).writeLong(SUPPORTED_RAF_1).build();
    List<StatsEvent> actualAtoms = new ArrayList<>();
    int result = mMetricsCollector.onPullAtom(SUPPORTED_RADIO_ACCESS_FAMILY, actualAtoms);
    assertThat(actualAtoms).hasSize(1);
    assertThat(result).isEqualTo(StatsManager.PULL_SUCCESS);
// TODO(b/153196254): verify atom contents
}
Also used : ArrayList(java.util.ArrayList) StatsEvent(android.util.StatsEvent) SmallTest(android.test.suitebuilder.annotation.SmallTest) TelephonyTest(com.android.internal.telephony.TelephonyTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Aggregations

StatsEvent (android.util.StatsEvent)11 Test (org.junit.Test)9 SmallTest (android.test.suitebuilder.annotation.SmallTest)6 TelephonyTest (com.android.internal.telephony.TelephonyTest)6 ArrayList (java.util.ArrayList)6 ByteBuffer (java.nio.ByteBuffer)3 Phone (com.android.internal.telephony.Phone)1 RawVoiceCallRatUsage (com.android.internal.telephony.nano.PersistAtomsProto.RawVoiceCallRatUsage)1 VoiceCallSession (com.android.internal.telephony.nano.PersistAtomsProto.VoiceCallSession)1