Search in sources :

Example 26 with Event

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

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

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

the class AppStateNotificationBridgeTest method testUpdateExtraInfo_multipleEventsAgg.

@Test
public void testUpdateExtraInfo_multipleEventsAgg() throws RemoteException {
    List<Event> events = new ArrayList<>();
    for (int i = 0; i < 13; 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.queryEventsForPackageForUser(anyLong(), anyLong(), anyInt(), anyString(), anyString())).thenReturn(usageEvents);
    AppEntry entry = getMockAppEntry(PKG1);
    mBridge.updateExtraInfo(entry, "", 0);
    assertThat(((NotificationsSentState) entry.extraInfo).sentCount).isEqualTo(13);
    assertThat(((NotificationsSentState) entry.extraInfo).lastSent).isEqualTo(12);
    assertThat(((NotificationsSentState) entry.extraInfo).avgSentDaily).isEqualTo(2);
    assertThat(((NotificationsSentState) entry.extraInfo).avgSentWeekly).isEqualTo(0);
    assertThat(((NotificationsSentState) entry.extraInfo).blocked).isTrue();
    assertThat(((NotificationsSentState) entry.extraInfo).systemApp).isTrue();
    assertThat(((NotificationsSentState) entry.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)

Example 28 with Event

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

the class RecentNotifyingAppsPreferenceControllerTest method display_showRecents.

@Test
public void display_showRecents() throws Exception {
    List<Event> events = new ArrayList<>();
    Event app = new Event();
    app.mEventType = Event.NOTIFICATION_INTERRUPTION;
    app.mPackage = "a";
    app.mTimeStamp = System.currentTimeMillis();
    events.add(app);
    Event app1 = new Event();
    app1.mEventType = Event.NOTIFICATION_INTERRUPTION;
    app1.mPackage = "com.android.settings";
    app1.mTimeStamp = System.currentTimeMillis();
    events.add(app1);
    Event app2 = new Event();
    app2.mEventType = Event.NOTIFICATION_INTERRUPTION;
    app2.mPackage = "pkg.class2";
    app2.mTimeStamp = System.currentTimeMillis() - 1000;
    events.add(app2);
    // app1, app2 are valid apps. app3 is invalid.
    when(mAppState.getEntry(app.getPackageName(), UserHandle.myUserId())).thenReturn(mAppEntry);
    when(mAppState.getEntry(app1.getPackageName(), UserHandle.myUserId())).thenReturn(mAppEntry);
    when(mAppState.getEntry(app2.getPackageName(), UserHandle.myUserId())).thenReturn(null);
    when(mPackageManager.resolveActivity(any(Intent.class), anyInt())).thenReturn(new ResolveInfo());
    UsageEvents usageEvents = getUsageEvents(new String[] { app.getPackageName(), app1.getPackageName(), app2.getPackageName() }, events);
    when(mIUsageStatsManager.queryEventsForUser(anyLong(), anyLong(), anyInt(), anyString())).thenReturn(usageEvents);
    mAppEntry.info = mApplicationInfo;
    mController.displayPreference(mScreen);
    verify(mCategory).setTitle(R.string.recent_notifications);
    // Only add app1 & app2. app3 skipped because it's invalid app.
    verify(mCategory, times(2)).addPreference(any(Preference.class));
    verify(mSeeAllPref).setSummary(null);
    verify(mSeeAllPref).setIcon(R.drawable.ic_chevron_right_24dp);
    verify(mDivider).setVisible(true);
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) Preference(androidx.preference.Preference) ArrayList(java.util.ArrayList) Event(android.app.usage.UsageEvents.Event) Intent(android.content.Intent) UsageEvents(android.app.usage.UsageEvents) Test(org.junit.Test)

Example 29 with Event

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

the class AppStateNotificationBridgeTest method testUpdateExtraInfo_multipleEventsAgg.

@Test
public void testUpdateExtraInfo_multipleEventsAgg() throws RemoteException {
    List<Event> events = new ArrayList<>();
    for (int i = 0; i < 13; 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.queryEventsForPackageForUser(anyLong(), anyLong(), anyInt(), anyString(), anyString())).thenReturn(usageEvents);
    AppEntry entry = getMockAppEntry(PKG1);
    mBridge.updateExtraInfo(entry, "", 0);
    assertThat(((NotificationsSentState) entry.extraInfo).sentCount).isEqualTo(13);
    assertThat(((NotificationsSentState) entry.extraInfo).lastSent).isEqualTo(12);
    assertThat(((NotificationsSentState) entry.extraInfo).avgSentDaily).isEqualTo(2);
    assertThat(((NotificationsSentState) entry.extraInfo).avgSentWeekly).isEqualTo(0);
    assertThat(((NotificationsSentState) entry.extraInfo).blocked).isTrue();
    assertThat(((NotificationsSentState) entry.extraInfo).systemApp).isTrue();
    assertThat(((NotificationsSentState) entry.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)

Example 30 with Event

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

the class AppStateNotificationBridgeTest method testLoadAllExtraInfo_multipleUsers.

@Test
public void testLoadAllExtraInfo_multipleUsers() throws RemoteException {
    // has work profile
    when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] { 1 });
    mBridge = new AppStateNotificationBridge(mContext, mState, mock(AppStateBaseBridge.Callback.class), mUsageStats, mUserManager, mBackend);
    List<Event> eventsProfileOwner = new ArrayList<>();
    for (int i = 0; i < 8; i++) {
        Event good = new Event();
        good.mEventType = Event.NOTIFICATION_INTERRUPTION;
        good.mPackage = PKG1;
        good.mTimeStamp = i;
        eventsProfileOwner.add(good);
    }
    List<Event> eventsProfile = new ArrayList<>();
    for (int i = 0; i < 4; i++) {
        Event good = new Event();
        good.mEventType = Event.NOTIFICATION_INTERRUPTION;
        good.mPackage = PKG1;
        good.mTimeStamp = i;
        eventsProfile.add(good);
    }
    UsageEvents usageEventsOwner = getUsageEvents(eventsProfileOwner);
    when(mUsageStats.queryEventsForUser(anyLong(), anyLong(), eq(0), anyString())).thenReturn(usageEventsOwner);
    UsageEvents usageEventsProfile = getUsageEvents(eventsProfile);
    when(mUsageStats.queryEventsForUser(anyLong(), anyLong(), eq(1), anyString())).thenReturn(usageEventsProfile);
    ArrayList<AppEntry> apps = new ArrayList<>();
    AppEntry owner = getMockAppEntry(PKG1);
    owner.info.uid = 1;
    apps.add(owner);
    AppEntry profile = getMockAppEntry(PKG1);
    profile.info.uid = UserHandle.PER_USER_RANGE + 1;
    apps.add(profile);
    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(4);
    assertThat(((NotificationsSentState) apps.get(1).extraInfo).lastSent).isEqualTo(3);
    assertThat(((NotificationsSentState) apps.get(1).extraInfo).avgSentWeekly).isEqualTo(4);
    assertThat(((NotificationsSentState) apps.get(1).extraInfo).avgSentDaily).isEqualTo(1);
}
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