Search in sources :

Example 1 with Event

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();
}
Also used : ConfigurationStats(android.app.usage.ConfigurationStats) Configuration(android.content.res.Configuration) Event(android.app.usage.UsageEvents.Event) Event(android.app.usage.UsageEvents.Event) UsageStats(android.app.usage.UsageStats) UsageEvents(android.app.usage.UsageEvents)

Example 2 with Event

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);
}
Also used : Event(android.app.usage.UsageEvents.Event) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 3 with Event

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();
}
Also used : Event(android.app.usage.UsageEvents.Event) UsageEvents(android.app.usage.UsageEvents) Test(org.junit.Test)

Example 4 with Event

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();
}
Also used : Event(android.app.usage.UsageEvents.Event) UsageEvents(android.app.usage.UsageEvents) Test(org.junit.Test)

Example 5 with Event

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());
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Event(android.app.usage.UsageEvents.Event) Implementation(org.robolectric.annotation.Implementation)

Aggregations

Event (android.app.usage.UsageEvents.Event)24 UsageEvents (android.app.usage.UsageEvents)21 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)11 NotificationsSentState (com.android.settings.applications.AppStateNotificationBridge.NotificationsSentState)7 ConfigurationStats (android.app.usage.ConfigurationStats)4 UsageStats (android.app.usage.UsageStats)4 Configuration (android.content.res.Configuration)4 AppEntry (com.android.settingslib.applications.ApplicationsState.AppEntry)4 ResolveInfo (android.content.pm.ResolveInfo)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 Intent (android.content.Intent)2 Preference (androidx.preference.Preference)2 Config (org.robolectric.annotation.Config)2 ApplicationInfo (android.content.pm.ApplicationInfo)1 Parcel (android.os.Parcel)1 NotifyingApp (android.service.notification.NotifyingApp)1 ArraySet (android.util.ArraySet)1 ApplicationsState (com.android.settingslib.applications.ApplicationsState)1 ImmutableList (com.google.common.collect.ImmutableList)1