Search in sources :

Example 6 with StatsEvent

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

the class MetricsCollectorTest method onPullAtom_supportedRadioAccessFamily_dualPhones.

@Test
@SmallTest
public void onPullAtom_supportedRadioAccessFamily_dualPhones() {
    doReturn(SUPPORTED_RAF_1).when(mPhone).getRadioAccessFamily();
    doReturn(SUPPORTED_RAF_2).when(mSecondPhone).getRadioAccessFamily();
    mPhones = new Phone[] { mPhone, mSecondPhone };
    StatsEvent expectedAtom = StatsEvent.newBuilder().setAtomId(SUPPORTED_RADIO_ACCESS_FAMILY).writeLong(SUPPORTED_RAF_BOTH).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)

Example 7 with StatsEvent

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

the class ShadowStatsLogTest method testOnlyAtomId.

@Test
public void testOnlyAtomId() {
    final int expectedAtomId = 109;
    final StatsEvent statsEvent = StatsEvent.newBuilder().setAtomId(expectedAtomId).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(2);
    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);
    assertThat(statsEvent.getNumBytes()).isEqualTo(buffer.position());
    statsEvent.release();
}
Also used : StatsEvent(android.util.StatsEvent) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 8 with StatsEvent

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

the class ShadowStatsLogTest method testNoFields.

@Test
public void testNoFields() {
    final StatsEvent statsEvent = StatsEvent.newBuilder().usePooledBuffer().build();
    long minTimestamp = SystemClock.elapsedRealtimeNanos();
    StatsLog.write(statsEvent);
    long maxTimestamp = SystemClock.elapsedRealtimeNanos();
    final int expectedAtomId = 0;
    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(3);
    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("Third element is not errors type").that(buffer.get()).isEqualTo(StatsEvent.TYPE_ERRORS);
    final int errorMask = buffer.getInt();
    assertWithMessage("ERROR_NO_ATOM_ID should be the only error in the error mask").that(errorMask).isEqualTo(StatsEvent.ERROR_NO_ATOM_ID);
    assertThat(statsEvent.getNumBytes()).isEqualTo(buffer.position());
    statsEvent.release();
}
Also used : StatsEvent(android.util.StatsEvent) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 9 with StatsEvent

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

the class MetricsCollectorTest method onPullAtom_supportedRadioAccessFamily_singlePhone.

@Test
@SmallTest
public void onPullAtom_supportedRadioAccessFamily_singlePhone() {
    doReturn(SUPPORTED_RAF_1).when(mPhone).getRadioAccessFamily();
    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)

Example 10 with StatsEvent

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

the class MetricsCollector method pullSimSlotState.

private static int pullSimSlotState(List<StatsEvent> data) {
    SimSlotState state;
    try {
        state = SimSlotState.getCurrentState();
    } catch (RuntimeException e) {
        // UiccController has not been made yet
        return StatsManager.PULL_SKIP;
    }
    StatsEvent e = StatsEvent.newBuilder().setAtomId(SIM_SLOT_STATE).writeInt(state.numActiveSlots).writeInt(state.numActiveSims).writeInt(state.numActiveEsims).build();
    data.add(e);
    return StatsManager.PULL_SUCCESS;
}
Also used : StatsEvent(android.util.StatsEvent)

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