Search in sources :

Example 11 with Event

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

the class RecentNotifyingAppsPreferenceControllerTest method reloadData.

@Test
public void reloadData() throws Exception {
    when(mUserManager.getProfileIdsWithDisabled(0)).thenReturn(new int[] { 0, 10 });
    mController = new RecentNotifyingAppsPreferenceController(mContext, mBackend, mIUsageStatsManager, mUserManager, mAppState, mHost);
    List<Event> events = new ArrayList<>();
    Event app = new Event();
    app.mEventType = Event.NOTIFICATION_INTERRUPTION;
    app.mPackage = "b";
    app.mTimeStamp = 1;
    events.add(app);
    Event app1 = new Event();
    app1.mEventType = Event.MAX_EVENT_TYPE;
    app1.mPackage = "com.foo.bar";
    app1.mTimeStamp = 10;
    events.add(app1);
    UsageEvents usageEvents = getUsageEvents(new String[] { "b", "com.foo.bar" }, events);
    when(mIUsageStatsManager.queryEventsForUser(anyLong(), anyLong(), eq(0), anyString())).thenReturn(usageEvents);
    List<Event> events10 = new ArrayList<>();
    Event app10 = new Event();
    app10.mEventType = Event.NOTIFICATION_INTERRUPTION;
    app10.mPackage = "a";
    app10.mTimeStamp = 2;
    events10.add(app10);
    Event app10a = new Event();
    app10a.mEventType = Event.NOTIFICATION_INTERRUPTION;
    app10a.mPackage = "a";
    app10a.mTimeStamp = 20;
    events10.add(app10a);
    UsageEvents usageEvents10 = getUsageEvents(new String[] { "a" }, events10);
    when(mIUsageStatsManager.queryEventsForUser(anyLong(), anyLong(), eq(10), anyString())).thenReturn(usageEvents10);
    mController.reloadData();
    assertThat(mController.mApps.size()).isEqualTo(2);
    boolean foundPkg0 = false;
    boolean foundPkg10 = false;
    for (NotifyingApp notifyingApp : mController.mApps) {
        if (notifyingApp.getLastNotified() == 20 && notifyingApp.getPackage().equals("a") && notifyingApp.getUserId() == 10) {
            foundPkg10 = true;
        }
        if (notifyingApp.getLastNotified() == 1 && notifyingApp.getPackage().equals("b") && notifyingApp.getUserId() == 0) {
            foundPkg0 = true;
        }
    }
    assertThat(foundPkg0).isTrue();
    assertThat(foundPkg10).isTrue();
}
Also used : ArrayList(java.util.ArrayList) Event(android.app.usage.UsageEvents.Event) UsageEvents(android.app.usage.UsageEvents) NotifyingApp(android.service.notification.NotifyingApp) Test(org.junit.Test)

Example 12 with Event

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

the class RecentNotifyingAppsPreferenceControllerTest method display_showRecentsWithInstantApp.

@Test
public void display_showRecentsWithInstantApp() throws Exception {
    List<Event> events = new ArrayList<>();
    Event app = new Event();
    app.mEventType = Event.NOTIFICATION_INTERRUPTION;
    app.mPackage = "com.foo.bar";
    app.mTimeStamp = System.currentTimeMillis();
    events.add(app);
    Event app1 = new Event();
    app1.mEventType = Event.NOTIFICATION_INTERRUPTION;
    app1.mPackage = "com.foo.barinstant";
    app1.mTimeStamp = System.currentTimeMillis() + 200;
    events.add(app1);
    UsageEvents usageEvents = getUsageEvents(new String[] { "com.foo.bar", "com.foo.barinstant" }, events);
    when(mIUsageStatsManager.queryEventsForUser(anyLong(), anyLong(), anyInt(), anyString())).thenReturn(usageEvents);
    ApplicationsState.AppEntry app1Entry = mock(ApplicationsState.AppEntry.class);
    ApplicationsState.AppEntry app2Entry = mock(ApplicationsState.AppEntry.class);
    app1Entry.info = mApplicationInfo;
    app2Entry.info = mApplicationInfo;
    when(mAppState.getEntry(app.getPackageName(), UserHandle.myUserId())).thenReturn(app1Entry);
    when(mAppState.getEntry(app1.getPackageName(), UserHandle.myUserId())).thenReturn(app2Entry);
    // Only the regular app app1 should have its intent resolve.
    when(mPackageManager.resolveActivity(argThat(intentMatcher(app.getPackageName())), anyInt())).thenReturn(new ResolveInfo());
    // Make sure app2 is considered an instant app.
    ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider", (InstantAppDataProvider) (ApplicationInfo info) -> {
        if (info == app2Entry.info) {
            return true;
        } else {
            return false;
        }
    });
    mController.displayPreference(mScreen);
    ArgumentCaptor<Preference> prefCaptor = ArgumentCaptor.forClass(Preference.class);
    verify(mCategory, times(2)).addPreference(prefCaptor.capture());
    List<Preference> prefs = prefCaptor.getAllValues();
    assertThat(prefs.get(1).getKey()).isEqualTo(RecentNotifyingAppsPreferenceController.getKey(UserHandle.myUserId(), app.getPackageName()));
    assertThat(prefs.get(0).getKey()).isEqualTo(RecentNotifyingAppsPreferenceController.getKey(UserHandle.myUserId(), app1.getPackageName()));
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) Preference(androidx.preference.Preference) ApplicationsState(com.android.settingslib.applications.ApplicationsState) ArrayList(java.util.ArrayList) ApplicationInfo(android.content.pm.ApplicationInfo) Event(android.app.usage.UsageEvents.Event) UsageEvents(android.app.usage.UsageEvents) Test(org.junit.Test)

Example 13 with Event

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

the class AppStateNotificationBridgeTest method testGetAggregatedUsageEvents_multipleEventsAgg.

@Test
public void testGetAggregatedUsageEvents_multipleEventsAgg() throws Exception {
    List<Event> events = new ArrayList<>();
    Event good = new Event();
    good.mEventType = Event.NOTIFICATION_INTERRUPTION;
    good.mPackage = PKG1;
    good.mTimeStamp = 6;
    events.add(good);
    Event good1 = new Event();
    good1.mEventType = Event.NOTIFICATION_INTERRUPTION;
    good1.mPackage = PKG1;
    good1.mTimeStamp = 1;
    events.add(good1);
    UsageEvents usageEvents = getUsageEvents(events);
    when(mUsageStats.queryEventsForUser(anyLong(), anyLong(), anyInt(), anyString())).thenReturn(usageEvents);
    Map<String, NotificationsSentState> map = mBridge.getAggregatedUsageEvents();
    assertThat(map.get(AppStateNotificationBridge.getKey(0, PKG1)).sentCount).isEqualTo(2);
    assertThat(map.get(AppStateNotificationBridge.getKey(0, PKG1)).lastSent).isEqualTo(6);
}
Also used : NotificationsSentState(com.android.settings.applications.AppStateNotificationBridge.NotificationsSentState) ArrayList(java.util.ArrayList) Event(android.app.usage.UsageEvents.Event) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UsageEvents(android.app.usage.UsageEvents) Test(org.junit.Test)

Example 14 with Event

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

the class AppStateNotificationBridgeTest method testGetAggregatedUsageEvents_multiplePkgs.

@Test
public void testGetAggregatedUsageEvents_multiplePkgs() throws Exception {
    List<Event> events = new ArrayList<>();
    Event good = new Event();
    good.mEventType = Event.NOTIFICATION_INTERRUPTION;
    good.mPackage = PKG1;
    good.mTimeStamp = 6;
    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);
    Map<String, NotificationsSentState> map = mBridge.getAggregatedUsageEvents();
    assertThat(map.get(AppStateNotificationBridge.getKey(0, PKG1)).sentCount).isEqualTo(1);
    assertThat(map.get(AppStateNotificationBridge.getKey(0, PKG2)).sentCount).isEqualTo(1);
    assertThat(map.get(AppStateNotificationBridge.getKey(0, PKG1)).lastSent).isEqualTo(6);
    assertThat(map.get(AppStateNotificationBridge.getKey(0, PKG2)).lastSent).isEqualTo(1);
}
Also used : NotificationsSentState(com.android.settings.applications.AppStateNotificationBridge.NotificationsSentState) ArrayList(java.util.ArrayList) Event(android.app.usage.UsageEvents.Event) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UsageEvents(android.app.usage.UsageEvents) Test(org.junit.Test)

Example 15 with Event

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

the class AppStateNotificationBridgeTest method testLoadAllExtraInfo_multipleEventsAgg.

@Test
public void testLoadAllExtraInfo_multipleEventsAgg() throws RemoteException {
    List<Event> events = new ArrayList<>();
    for (int i = 0; i < 7; i++) {
        Event good = new Event();
        good.mEventType = Event.NOTIFICATION_INTERRUPTION;
        good.mPackage = PKG1;
        good.mTimeStamp = i;
        events.add(good);
    }
    UsageEvents usageEvents = getUsageEvents(events);
    when(mUsageStats.queryEventsForUser(anyLong(), anyLong(), anyInt(), anyString())).thenReturn(usageEvents);
    ArrayList<AppEntry> apps = new ArrayList<>();
    apps.add(getMockAppEntry(PKG1));
    when(mSession.getAllApps()).thenReturn(apps);
    mBridge.loadAllExtraInfo();
    assertThat(((NotificationsSentState) apps.get(0).extraInfo).sentCount).isEqualTo(7);
    assertThat(((NotificationsSentState) apps.get(0).extraInfo).lastSent).isEqualTo(6);
    assertThat(((NotificationsSentState) apps.get(0).extraInfo).avgSentDaily).isEqualTo(1);
    assertThat(((NotificationsSentState) apps.get(0).extraInfo).avgSentWeekly).isEqualTo(0);
    assertThat(((NotificationsSentState) apps.get(0).extraInfo).blocked).isTrue();
    assertThat(((NotificationsSentState) apps.get(0).extraInfo).systemApp).isTrue();
    assertThat(((NotificationsSentState) apps.get(0).extraInfo).blockable).isTrue();
}
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)

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