use of com.android.settings.applications.AppStateNotificationBridge.NotificationsSentState 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();
}
use of com.android.settings.applications.AppStateNotificationBridge.NotificationsSentState in project android_packages_apps_Settings by omnirom.
the class AppStateNotificationBridgeTest method testFilterBlocked.
@Test
public void testFilterBlocked() {
NotificationsSentState allowState = new NotificationsSentState();
allowState.blocked = true;
AppEntry allow = mock(AppEntry.class);
allow.extraInfo = allowState;
assertTrue(FILTER_APP_NOTIFICATION_BLOCKED.filterApp(allow));
NotificationsSentState denyState = new NotificationsSentState();
denyState.blocked = false;
AppEntry deny = mock(AppEntry.class);
deny.extraInfo = denyState;
assertFalse(FILTER_APP_NOTIFICATION_BLOCKED.filterApp(deny));
}
use of com.android.settings.applications.AppStateNotificationBridge.NotificationsSentState 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);
}
use of com.android.settings.applications.AppStateNotificationBridge.NotificationsSentState in project android_packages_apps_Settings by omnirom.
the class AppStateNotificationBridgeTest method testSwitchOnChangeListener.
@Test
public void testSwitchOnChangeListener() {
Switch toggle = mock(Switch.class);
when(toggle.isChecked()).thenReturn(true);
when(toggle.isEnabled()).thenReturn(true);
AppEntry entry = mock(AppEntry.class);
entry.info = new ApplicationInfo();
entry.info.packageName = "pkg";
entry.info.uid = 1356;
entry.extraInfo = new NotificationsSentState();
CompoundButton.OnCheckedChangeListener listener = mBridge.getSwitchOnCheckedListener(entry);
listener.onCheckedChanged(toggle, true);
verify(mBackend).setNotificationsEnabledForPackage(entry.info.packageName, entry.info.uid, true);
assertThat(((NotificationsSentState) entry.extraInfo).blocked).isFalse();
}
use of com.android.settings.applications.AppStateNotificationBridge.NotificationsSentState in project android_packages_apps_Settings by omnirom.
the class AppStateNotificationBridgeTest method testRecencyComparator.
@Test
public void testRecencyComparator() {
List<AppEntry> entries = new ArrayList<>();
NotificationsSentState earlier = new NotificationsSentState();
earlier.lastSent = 1;
AppEntry earlyEntry = mock(AppEntry.class);
earlyEntry.extraInfo = earlier;
entries.add(earlyEntry);
NotificationsSentState later = new NotificationsSentState();
later.lastSent = 8;
AppEntry lateEntry = mock(AppEntry.class);
lateEntry.extraInfo = later;
entries.add(lateEntry);
entries.sort(RECENT_NOTIFICATION_COMPARATOR);
assertThat(entries).containsExactly(lateEntry, earlyEntry);
}
Aggregations