Search in sources :

Example 21 with NotificationsSentState

use of com.android.settings.applications.AppStateNotificationBridge.NotificationsSentState 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 22 with NotificationsSentState

use of com.android.settings.applications.AppStateNotificationBridge.NotificationsSentState 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 23 with NotificationsSentState

use of com.android.settings.applications.AppStateNotificationBridge.NotificationsSentState in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AppStateNotificationBridgeTest method testFilterRecency.

@Test
public void testFilterRecency() {
    NotificationsSentState allowState = new NotificationsSentState();
    allowState.lastSent = 1;
    AppEntry allow = mock(AppEntry.class);
    allow.extraInfo = allowState;
    assertTrue(FILTER_APP_NOTIFICATION_RECENCY.filterApp(allow));
    NotificationsSentState denyState = new NotificationsSentState();
    denyState.lastSent = 0;
    AppEntry deny = mock(AppEntry.class);
    deny.extraInfo = denyState;
    assertFalse(FILTER_APP_NOTIFICATION_RECENCY.filterApp(deny));
}
Also used : NotificationsSentState(com.android.settings.applications.AppStateNotificationBridge.NotificationsSentState) AppEntry(com.android.settingslib.applications.ApplicationsState.AppEntry) Test(org.junit.Test)

Example 24 with NotificationsSentState

use of com.android.settings.applications.AppStateNotificationBridge.NotificationsSentState in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AppStateNotificationBridgeTest method testSwitchOnClickListener.

@Test
public void testSwitchOnClickListener() {
    ViewGroup parent = mock(ViewGroup.class);
    Switch toggle = mock(Switch.class);
    when(toggle.isChecked()).thenReturn(true);
    when(toggle.isEnabled()).thenReturn(true);
    when(parent.findViewById(anyInt())).thenReturn(toggle);
    AppEntry entry = mock(AppEntry.class);
    entry.info = new ApplicationInfo();
    entry.info.packageName = "pkg";
    entry.info.uid = 1356;
    entry.extraInfo = new NotificationsSentState();
    ViewGroup.OnClickListener listener = mBridge.getSwitchOnClickListener(entry);
    listener.onClick(parent);
    verify(toggle).toggle();
    verify(mBackend).setNotificationsEnabledForPackage(entry.info.packageName, entry.info.uid, true);
    assertThat(((NotificationsSentState) entry.extraInfo).blocked).isFalse();
}
Also used : Switch(android.widget.Switch) AppEntry(com.android.settingslib.applications.ApplicationsState.AppEntry) NotificationsSentState(com.android.settings.applications.AppStateNotificationBridge.NotificationsSentState) ViewGroup(android.view.ViewGroup) ApplicationInfo(android.content.pm.ApplicationInfo) Test(org.junit.Test)

Example 25 with NotificationsSentState

use of com.android.settings.applications.AppStateNotificationBridge.NotificationsSentState in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AppStateNotificationBridgeTest method testFrequencyComparator.

@Test
public void testFrequencyComparator() {
    List<AppEntry> entries = new ArrayList<>();
    NotificationsSentState notFrequentWeekly = new NotificationsSentState();
    notFrequentWeekly.sentCount = 2;
    AppEntry notFrequentWeeklyEntry = mock(AppEntry.class);
    notFrequentWeeklyEntry.extraInfo = notFrequentWeekly;
    entries.add(notFrequentWeeklyEntry);
    NotificationsSentState notFrequentDaily = new NotificationsSentState();
    notFrequentDaily.sentCount = 7;
    AppEntry notFrequentDailyEntry = mock(AppEntry.class);
    notFrequentDailyEntry.extraInfo = notFrequentDaily;
    entries.add(notFrequentDailyEntry);
    NotificationsSentState veryFrequentWeekly = new NotificationsSentState();
    veryFrequentWeekly.sentCount = 6;
    AppEntry veryFrequentWeeklyEntry = mock(AppEntry.class);
    veryFrequentWeeklyEntry.extraInfo = veryFrequentWeekly;
    entries.add(veryFrequentWeeklyEntry);
    NotificationsSentState veryFrequentDaily = new NotificationsSentState();
    veryFrequentDaily.sentCount = 19;
    AppEntry veryFrequentDailyEntry = mock(AppEntry.class);
    veryFrequentDailyEntry.extraInfo = veryFrequentDaily;
    entries.add(veryFrequentDailyEntry);
    entries.sort(FREQUENCY_NOTIFICATION_COMPARATOR);
    assertThat(entries).containsExactly(veryFrequentDailyEntry, notFrequentDailyEntry, veryFrequentWeeklyEntry, notFrequentWeeklyEntry);
}
Also used : AppEntry(com.android.settingslib.applications.ApplicationsState.AppEntry) NotificationsSentState(com.android.settings.applications.AppStateNotificationBridge.NotificationsSentState) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

NotificationsSentState (com.android.settings.applications.AppStateNotificationBridge.NotificationsSentState)32 Test (org.junit.Test)32 AppEntry (com.android.settingslib.applications.ApplicationsState.AppEntry)20 ArrayList (java.util.ArrayList)18 UsageEvents (android.app.usage.UsageEvents)14 Event (android.app.usage.UsageEvents.Event)14 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 ApplicationInfo (android.content.pm.ApplicationInfo)2 Switch (android.widget.Switch)2 ViewGroup (android.view.ViewGroup)1 CompoundButton (android.widget.CompoundButton)1