Search in sources :

Example 6 with UsageEvents

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

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 7 with UsageEvents

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

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)

Example 8 with UsageEvents

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

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 9 with UsageEvents

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

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)

Example 10 with UsageEvents

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

the class RecentNotifyingAppsPreferenceControllerTest method display_showRecents_formatSummary.

@Test
public void display_showRecents_formatSummary() throws Exception {
    List<Event> events = new ArrayList<>();
    Event app = new Event();
    app.mEventType = Event.NOTIFICATION_INTERRUPTION;
    app.mPackage = "pkg.class";
    app.mTimeStamp = System.currentTimeMillis();
    events.add(app);
    UsageEvents usageEvents = getUsageEvents(new String[] { "pkg.class" }, events);
    when(mIUsageStatsManager.queryEventsForUser(anyLong(), anyLong(), anyInt(), anyString())).thenReturn(usageEvents);
    when(mAppState.getEntry(app.getPackageName(), UserHandle.myUserId())).thenReturn(mAppEntry);
    when(mPackageManager.resolveActivity(any(Intent.class), anyInt())).thenReturn(new ResolveInfo());
    mAppEntry.info = mApplicationInfo;
    mController.displayPreference(mScreen);
    verify(mCategory).addPreference(argThat(summaryMatches("Just now")));
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ArrayList(java.util.ArrayList) Event(android.app.usage.UsageEvents.Event) Intent(android.content.Intent) UsageEvents(android.app.usage.UsageEvents) Test(org.junit.Test)

Aggregations

UsageEvents (android.app.usage.UsageEvents)45 Event (android.app.usage.UsageEvents.Event)24 Test (org.junit.Test)23 ArrayList (java.util.ArrayList)19 NotificationsSentState (com.android.settings.applications.AppStateNotificationBridge.NotificationsSentState)14 AppEntry (com.android.settingslib.applications.ApplicationsState.AppEntry)8 RemoteException (android.os.RemoteException)7 Parcel (android.os.Parcel)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 ResolveInfo (android.content.pm.ResolveInfo)4 UsageStatsManager (android.app.usage.UsageStatsManager)3 Intent (android.content.Intent)3 ArrayMap (android.util.ArrayMap)3 MotionEvent (android.view.MotionEvent)3 Date (java.util.Date)3 SuppressLint (android.annotation.SuppressLint)2 TargetApi (android.annotation.TargetApi)2 NotifyingApp (android.service.notification.NotifyingApp)2 NonNull (androidx.annotation.NonNull)2 VisibleForTesting (androidx.annotation.VisibleForTesting)2