use of android.app.usage.UsageEvents.Event in project android_frameworks_base by crdroidandroid.
the class UserUsageStatsService method printIntervalStats.
void printIntervalStats(IndentingPrintWriter pw, IntervalStats stats, boolean prettyDates) {
if (prettyDates) {
pw.printPair("timeRange", "\"" + DateUtils.formatDateRange(mContext, stats.beginTime, stats.endTime, sDateFormatFlags) + "\"");
} else {
pw.printPair("beginTime", stats.beginTime);
pw.printPair("endTime", stats.endTime);
}
pw.println();
pw.increaseIndent();
pw.println("packages");
pw.increaseIndent();
final ArrayMap<String, UsageStats> pkgStats = stats.packageStats;
final int pkgCount = pkgStats.size();
for (int i = 0; i < pkgCount; i++) {
final UsageStats usageStats = pkgStats.valueAt(i);
pw.printPair("package", usageStats.mPackageName);
pw.printPair("totalTime", formatElapsedTime(usageStats.mTotalTimeInForeground, prettyDates));
pw.printPair("lastTime", formatDateTime(usageStats.mLastTimeUsed, prettyDates));
pw.println();
}
pw.decreaseIndent();
pw.println("configurations");
pw.increaseIndent();
final ArrayMap<Configuration, ConfigurationStats> configStats = stats.configurations;
final int configCount = configStats.size();
for (int i = 0; i < configCount; i++) {
final ConfigurationStats config = configStats.valueAt(i);
pw.printPair("config", Configuration.resourceQualifierString(config.mConfiguration));
pw.printPair("totalTime", formatElapsedTime(config.mTotalTimeActive, prettyDates));
pw.printPair("lastTime", formatDateTime(config.mLastTimeActive, prettyDates));
pw.printPair("count", config.mActivationCount);
pw.println();
}
pw.decreaseIndent();
pw.println("events");
pw.increaseIndent();
final TimeSparseArray<UsageEvents.Event> events = stats.events;
final int eventCount = events != null ? events.size() : 0;
for (int i = 0; i < eventCount; i++) {
final UsageEvents.Event event = events.valueAt(i);
pw.printPair("time", formatDateTime(event.mTimeStamp, prettyDates));
pw.printPair("type", eventToString(event.mEventType));
pw.printPair("package", event.mPackage);
if (event.mClass != null) {
pw.printPair("class", event.mClass);
}
if (event.mConfiguration != null) {
pw.printPair("config", Configuration.resourceQualifierString(event.mConfiguration));
}
if (event.mShortcutId != null) {
pw.printPair("shortcutId", event.mShortcutId);
}
pw.println();
}
pw.decreaseIndent();
pw.decreaseIndent();
}
use of android.app.usage.UsageEvents.Event in project robolectric by robolectric.
the class ShadowUsageStatsManagerTest method eventBuilder.
@Test
@Config(minSdk = Build.VERSION_CODES.Q)
public void eventBuilder() {
Event event = ShadowUsageStatsManager.EventBuilder.buildEvent().setEventType(Event.ACTIVITY_RESUMED).setTimeStamp(123456).setPackage("com.sample.pkg").setClass("SampleClass").setInstanceId(999).setTaskRootPackage("org.example.root").setTaskRootClass("RootKlass").setAppStandbyBucket(50).build();
assertThat(event.getEventType()).isEqualTo(Event.ACTIVITY_RESUMED);
assertThat(event.getTimeStamp()).isEqualTo(123456);
assertThat(event.getPackageName()).isEqualTo("com.sample.pkg");
assertThat(event.getClassName()).isEqualTo("SampleClass");
assertThat(event.getInstanceId()).isEqualTo(999);
assertThat(event.getTaskRootPackageName()).isEqualTo("org.example.root");
assertThat(event.getTaskRootClassName()).isEqualTo("RootKlass");
assertThat(event.getAppStandbyBucket()).isEqualTo(50);
}
use of android.app.usage.UsageEvents.Event in project robolectric by robolectric.
the class ShadowUsageStatsManagerTest method testQueryEvents_emptyEvents.
@Test
public void testQueryEvents_emptyEvents() throws Exception {
UsageEvents events = usageStatsManager.queryEvents(1000L, 2000L);
Event event = new Event();
assertThat(events.hasNextEvent()).isFalse();
assertThat(events.getNextEvent(event)).isFalse();
}
use of android.app.usage.UsageEvents.Event in project robolectric by robolectric.
the class ShadowUsageStatsManagerTest method testQueryEvents_appendEventData_shouldCombineWithPreviousData.
@Test
public void testQueryEvents_appendEventData_shouldCombineWithPreviousData() throws Exception {
shadowOf(usageStatsManager).addEvent(TEST_PACKAGE_NAME1, 500L, Event.MOVE_TO_FOREGROUND);
shadowOf(usageStatsManager).addEvent(TEST_PACKAGE_NAME1, 1000L, Event.MOVE_TO_BACKGROUND);
shadowOf(usageStatsManager).addEvent(ShadowUsageStatsManager.EventBuilder.buildEvent().setTimeStamp(1500L).setPackage(TEST_PACKAGE_NAME2).setClass(TEST_ACTIVITY_NAME).setEventType(Event.MOVE_TO_FOREGROUND).build());
shadowOf(usageStatsManager).addEvent(TEST_PACKAGE_NAME2, 2000L, Event.MOVE_TO_BACKGROUND);
shadowOf(usageStatsManager).addEvent(ShadowUsageStatsManager.EventBuilder.buildEvent().setTimeStamp(2500L).setPackage(TEST_PACKAGE_NAME1).setEventType(Event.MOVE_TO_FOREGROUND).setClass(TEST_ACTIVITY_NAME).build());
UsageEvents events = usageStatsManager.queryEvents(1000L, 2000L);
Event event = new Event();
assertThat(events.hasNextEvent()).isTrue();
assertThat(events.getNextEvent(event)).isTrue();
assertThat(event.getPackageName()).isEqualTo(TEST_PACKAGE_NAME1);
assertThat(event.getTimeStamp()).isEqualTo(1000L);
assertThat(event.getEventType()).isEqualTo(Event.MOVE_TO_BACKGROUND);
assertThat(events.hasNextEvent()).isTrue();
assertThat(events.getNextEvent(event)).isTrue();
assertThat(event.getPackageName()).isEqualTo(TEST_PACKAGE_NAME2);
assertThat(event.getTimeStamp()).isEqualTo(1500L);
assertThat(event.getEventType()).isEqualTo(Event.MOVE_TO_FOREGROUND);
assertThat(event.getClassName()).isEqualTo(TEST_ACTIVITY_NAME);
assertThat(events.hasNextEvent()).isFalse();
assertThat(events.getNextEvent(event)).isFalse();
}
use of android.app.usage.UsageEvents.Event in project robolectric by robolectric.
the class ShadowUsageStatsManager method queryEventsForSelf.
@Implementation(minSdk = Build.VERSION_CODES.P)
protected UsageEvents queryEventsForSelf(long beginTime, long endTime) {
String packageName = RuntimeEnvironment.getApplication().getOpPackageName();
ImmutableList.Builder<Event> listBuilder = new ImmutableList.Builder<>();
for (Event event : Iterables.concat(eventsByTimeStamp.subMap(beginTime, endTime).values())) {
if (packageName.equals(event.getPackageName())) {
listBuilder.add(event);
}
}
return createUsageEvents(listBuilder.build());
}
Aggregations