Merge "Mock out usageStats in NotificationManagerServiceTests" into oc-dev

am: fd0b15c196

Change-Id: I56ff2491ee5fd1d72f215e41a4d6ee2ee535ab8a
This commit is contained in:
Geoffrey Pitsch
2017-06-02 14:50:54 +00:00
committed by android-build-merger
2 changed files with 13 additions and 13 deletions

View File

@@ -1051,7 +1051,8 @@ public class NotificationManagerService extends SystemService {
@VisibleForTesting
void init(Looper looper, IPackageManager packageManager, PackageManager packageManagerClient,
LightsManager lightsManager, NotificationListeners notificationListeners,
ICompanionDeviceManager companionManager, SnoozeHelper snoozeHelper) {
ICompanionDeviceManager companionManager, SnoozeHelper snoozeHelper,
NotificationUsageStats usageStats) {
Resources resources = getContext().getResources();
mMaxPackageEnqueueRate = Settings.Global.getFloat(getContext().getContentResolver(),
Settings.Global.MAX_NOTIFICATION_ENQUEUE_RATE,
@@ -1074,7 +1075,7 @@ public class NotificationManagerService extends SystemService {
} catch (Resources.NotFoundException e) {
extractorNames = new String[0];
}
mUsageStats = new NotificationUsageStats(getContext());
mUsageStats = usageStats;
mRankingHandler = new RankingHandlerWorker(mRankingThread.getLooper());
mRankingHelper = new RankingHelper(getContext(),
getContext().getPackageManager(),
@@ -1243,7 +1244,7 @@ public class NotificationManagerService extends SystemService {
init(Looper.myLooper(), AppGlobals.getPackageManager(), getContext().getPackageManager(),
getLocalService(LightsManager.class), new NotificationListeners(),
null, snoozeHelper);
null, snoozeHelper, new NotificationUsageStats(getContext()));
publishBinderService(Context.NOTIFICATION_SERVICE, mService);
publishLocalService(NotificationManagerInternal.class, mInternalService);
}

View File

@@ -91,6 +91,8 @@ public class NotificationManagerServiceTest extends NotificationTestCase {
private TestableLooper mTestableLooper;
@Mock
private RankingHelper mRankingHelper;
@Mock
private NotificationUsageStats mUsageStats;
private NotificationChannel mTestNotificationChannel = new NotificationChannel(
TEST_CHANNEL_ID, TEST_CHANNEL_ID, NotificationManager.IMPORTANCE_DEFAULT);
@Mock
@@ -147,7 +149,7 @@ public class NotificationManagerServiceTest extends NotificationTestCase {
when(mNotificationListeners.checkServiceTokenLocked(any())).thenReturn(mListener);
mNotificationManagerService.init(mTestableLooper.getLooper(), mPackageManager,
mPackageManagerClient, mockLightsManager, mNotificationListeners, mCompanionMgr,
mSnoozeHelper);
mSnoozeHelper, mUsageStats);
// Tests call directly into the Binder.
mBinderService = mNotificationManagerService.getBinderService();
@@ -261,40 +263,37 @@ public class NotificationManagerServiceTest extends NotificationTestCase {
@Test
public void testBlockedNotifications_suspended() throws Exception {
NotificationUsageStats usageStats = mock(NotificationUsageStats.class);
when(mPackageManager.isPackageSuspendedForUser(anyString(), anyInt())).thenReturn(true);
NotificationChannel channel = new NotificationChannel("id", "name",
NotificationManager.IMPORTANCE_HIGH);
NotificationRecord r = generateNotificationRecord(channel);
assertTrue(mNotificationManagerService.isBlocked(r, usageStats));
verify(usageStats, times(1)).registerSuspendedByAdmin(eq(r));
assertTrue(mNotificationManagerService.isBlocked(r, mUsageStats));
verify(mUsageStats, times(1)).registerSuspendedByAdmin(eq(r));
}
@Test
public void testBlockedNotifications_blockedChannel() throws Exception {
NotificationUsageStats usageStats = mock(NotificationUsageStats.class);
when(mPackageManager.isPackageSuspendedForUser(anyString(), anyInt())).thenReturn(false);
NotificationChannel channel = new NotificationChannel("id", "name",
NotificationManager.IMPORTANCE_HIGH);
channel.setImportance(NotificationManager.IMPORTANCE_NONE);
NotificationRecord r = generateNotificationRecord(channel);
assertTrue(mNotificationManagerService.isBlocked(r, usageStats));
verify(usageStats, times(1)).registerBlocked(eq(r));
assertTrue(mNotificationManagerService.isBlocked(r, mUsageStats));
verify(mUsageStats, times(1)).registerBlocked(eq(r));
}
@Test
public void testBlockedNotifications_blockedApp() throws Exception {
NotificationUsageStats usageStats = mock(NotificationUsageStats.class);
when(mPackageManager.isPackageSuspendedForUser(anyString(), anyInt())).thenReturn(false);
NotificationChannel channel = new NotificationChannel("id", "name",
NotificationManager.IMPORTANCE_HIGH);
NotificationRecord r = generateNotificationRecord(channel);
r.setUserImportance(NotificationManager.IMPORTANCE_NONE);
assertTrue(mNotificationManagerService.isBlocked(r, usageStats));
verify(usageStats, times(1)).registerBlocked(eq(r));
assertTrue(mNotificationManagerService.isBlocked(r, mUsageStats));
verify(mUsageStats, times(1)).registerBlocked(eq(r));
}
@Test