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();
}
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
}
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
}
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
}
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
}
Aggregations