Search in sources :

Example 11 with NotificationsSentState

use of com.android.settings.applications.AppStateNotificationBridge.NotificationsSentState in project android_packages_apps_Settings by omnirom.

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)

Example 12 with NotificationsSentState

use of com.android.settings.applications.AppStateNotificationBridge.NotificationsSentState in project android_packages_apps_Settings by omnirom.

the class AppStateNotificationBridgeTest method testSummary_alpha.

@Test
public void testSummary_alpha() {
    NotificationsSentState sentRarely = new NotificationsSentState();
    sentRarely.avgSentWeekly = 1;
    assertThat(AppStateNotificationBridge.getSummary(mContext, sentRarely, R.id.sort_order_alpha).toString()).isEqualTo("");
}
Also used : NotificationsSentState(com.android.settings.applications.AppStateNotificationBridge.NotificationsSentState) Test(org.junit.Test)

Example 13 with NotificationsSentState

use of com.android.settings.applications.AppStateNotificationBridge.NotificationsSentState in project android_packages_apps_Settings by omnirom.

the class AppStateNotificationBridgeTest method testSummary_frequency.

@Test
public void testSummary_frequency() {
    NotificationsSentState sentRarely = new NotificationsSentState();
    sentRarely.avgSentWeekly = 1;
    NotificationsSentState sentOften = new NotificationsSentState();
    sentOften.avgSentDaily = 8;
    assertThat(AppStateNotificationBridge.getSummary(mContext, sentRarely, R.id.sort_order_frequent_notification).toString()).contains("1");
    assertThat(AppStateNotificationBridge.getSummary(mContext, sentRarely, R.id.sort_order_frequent_notification).toString()).contains("notification ");
    assertThat(AppStateNotificationBridge.getSummary(mContext, sentRarely, R.id.sort_order_frequent_notification).toString()).contains("week");
    assertThat(AppStateNotificationBridge.getSummary(mContext, sentOften, R.id.sort_order_frequent_notification).toString()).contains("8");
    assertThat(AppStateNotificationBridge.getSummary(mContext, sentOften, R.id.sort_order_frequent_notification).toString()).contains("notifications");
    assertThat(AppStateNotificationBridge.getSummary(mContext, sentOften, R.id.sort_order_frequent_notification).toString()).contains("day");
}
Also used : NotificationsSentState(com.android.settings.applications.AppStateNotificationBridge.NotificationsSentState) Test(org.junit.Test)

Example 14 with NotificationsSentState

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

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

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