Search in sources :

Example 16 with Event

use of android.app.usage.UsageEvents.Event in project android_packages_apps_Settings by omnirom.

the class AppStateNotificationBridgeTest method testLoadAllExtraInfo_multiplePkgs.

@Test
public void testLoadAllExtraInfo_multiplePkgs() throws RemoteException {
    List<Event> events = new ArrayList<>();
    for (int i = 0; i < 8; i++) {
        Event good = new Event();
        good.mEventType = Event.NOTIFICATION_INTERRUPTION;
        good.mPackage = PKG1;
        good.mTimeStamp = i;
        events.add(good);
    }
    Event good1 = new Event();
    good1.mEventType = Event.NOTIFICATION_INTERRUPTION;
    good1.mPackage = PKG2;
    good1.mTimeStamp = 1;
    events.add(good1);
    UsageEvents usageEvents = getUsageEvents(events);
    when(mUsageStats.queryEventsForUser(anyLong(), anyLong(), anyInt(), anyString())).thenReturn(usageEvents);
    ArrayList<AppEntry> apps = new ArrayList<>();
    apps.add(getMockAppEntry(PKG1));
    apps.add(getMockAppEntry(PKG2));
    when(mSession.getAllApps()).thenReturn(apps);
    mBridge.loadAllExtraInfo();
    assertThat(((NotificationsSentState) apps.get(0).extraInfo).sentCount).isEqualTo(8);
    assertThat(((NotificationsSentState) apps.get(0).extraInfo).lastSent).isEqualTo(7);
    assertThat(((NotificationsSentState) apps.get(0).extraInfo).avgSentWeekly).isEqualTo(0);
    assertThat(((NotificationsSentState) apps.get(0).extraInfo).avgSentDaily).isEqualTo(1);
    assertThat(((NotificationsSentState) apps.get(1).extraInfo).sentCount).isEqualTo(1);
    assertThat(((NotificationsSentState) apps.get(1).extraInfo).lastSent).isEqualTo(1);
    assertThat(((NotificationsSentState) apps.get(1).extraInfo).avgSentWeekly).isEqualTo(1);
    assertThat(((NotificationsSentState) apps.get(1).extraInfo).avgSentDaily).isEqualTo(0);
}
Also used : AppEntry(com.android.settingslib.applications.ApplicationsState.AppEntry) NotificationsSentState(com.android.settings.applications.AppStateNotificationBridge.NotificationsSentState) ArrayList(java.util.ArrayList) Event(android.app.usage.UsageEvents.Event) UsageEvents(android.app.usage.UsageEvents) Test(org.junit.Test)

Example 17 with Event

use of android.app.usage.UsageEvents.Event in project platform_frameworks_base by android.

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 18 with Event

use of android.app.usage.UsageEvents.Event in project android_frameworks_base by DirtyUnicorns.

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 19 with Event

use of android.app.usage.UsageEvents.Event in project android_frameworks_base by ResurrectionRemix.

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 20 with Event

use of android.app.usage.UsageEvents.Event in project robolectric by robolectric.

the class ShadowUsageStatsManagerTest method testQueryEventsForSelf_shouldReturnsEventsForCurrentPackageOnly.

@Test
@Config(minSdk = Build.VERSION_CODES.P)
public void testQueryEventsForSelf_shouldReturnsEventsForCurrentPackageOnly() {
    String packageName = context.getOpPackageName();
    shadowOf(usageStatsManager).addEvent(ShadowUsageStatsManager.EventBuilder.buildEvent().setTimeStamp(1500L).setPackage(TEST_PACKAGE_NAME2).setClass(TEST_ACTIVITY_NAME).setEventType(Event.ACTIVITY_PAUSED).build());
    shadowOf(usageStatsManager).addEvent(ShadowUsageStatsManager.EventBuilder.buildEvent().setTimeStamp(2200L).setPackage(packageName).setEventType(Event.ACTIVITY_RESUMED).setClass(TEST_ACTIVITY_NAME).build());
    shadowOf(usageStatsManager).addEvent(ShadowUsageStatsManager.EventBuilder.buildEvent().setTimeStamp(2500L).setPackage(TEST_PACKAGE_NAME1).setEventType(Event.ACTIVITY_RESUMED).setClass(TEST_ACTIVITY_NAME).build());
    shadowOf(usageStatsManager).addEvent(ShadowUsageStatsManager.EventBuilder.buildEvent().setTimeStamp(2800L).setPackage(packageName).setEventType(Event.ACTIVITY_STOPPED).setClass(TEST_ACTIVITY_NAME).build());
    UsageEvents events = usageStatsManager.queryEventsForSelf(0L, 3000L);
    Event event = new Event();
    assertThat(events.hasNextEvent()).isTrue();
    assertThat(events.getNextEvent(event)).isTrue();
    assertThat(event.getPackageName()).isEqualTo(packageName);
    assertThat(event.getTimeStamp()).isEqualTo(2200L);
    assertThat(event.getEventType()).isEqualTo(Event.ACTIVITY_RESUMED);
    assertThat(events.hasNextEvent()).isTrue();
    assertThat(events.getNextEvent(event)).isTrue();
    assertThat(event.getPackageName()).isEqualTo(packageName);
    assertThat(event.getTimeStamp()).isEqualTo(2800L);
    assertThat(event.getEventType()).isEqualTo(Event.ACTIVITY_STOPPED);
    assertThat(events.hasNextEvent()).isFalse();
}
Also used : Event(android.app.usage.UsageEvents.Event) UsageEvents(android.app.usage.UsageEvents) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Aggregations

Event (android.app.usage.UsageEvents.Event)31 UsageEvents (android.app.usage.UsageEvents)28 Test (org.junit.Test)24 ArrayList (java.util.ArrayList)18 NotificationsSentState (com.android.settings.applications.AppStateNotificationBridge.NotificationsSentState)14 AppEntry (com.android.settingslib.applications.ApplicationsState.AppEntry)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 ConfigurationStats (android.app.usage.ConfigurationStats)4 UsageStats (android.app.usage.UsageStats)4 Configuration (android.content.res.Configuration)4 ResolveInfo (android.content.pm.ResolveInfo)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