Merge "Mock out usageStats in NotificationManagerServiceTests" into oc-dev
am: fd0b15c196
Change-Id: I56ff2491ee5fd1d72f215e41a4d6ee2ee535ab8a
This commit is contained in:
@@ -1051,7 +1051,8 @@ public class NotificationManagerService extends SystemService {
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void init(Looper looper, IPackageManager packageManager, PackageManager packageManagerClient,
|
void init(Looper looper, IPackageManager packageManager, PackageManager packageManagerClient,
|
||||||
LightsManager lightsManager, NotificationListeners notificationListeners,
|
LightsManager lightsManager, NotificationListeners notificationListeners,
|
||||||
ICompanionDeviceManager companionManager, SnoozeHelper snoozeHelper) {
|
ICompanionDeviceManager companionManager, SnoozeHelper snoozeHelper,
|
||||||
|
NotificationUsageStats usageStats) {
|
||||||
Resources resources = getContext().getResources();
|
Resources resources = getContext().getResources();
|
||||||
mMaxPackageEnqueueRate = Settings.Global.getFloat(getContext().getContentResolver(),
|
mMaxPackageEnqueueRate = Settings.Global.getFloat(getContext().getContentResolver(),
|
||||||
Settings.Global.MAX_NOTIFICATION_ENQUEUE_RATE,
|
Settings.Global.MAX_NOTIFICATION_ENQUEUE_RATE,
|
||||||
@@ -1074,7 +1075,7 @@ public class NotificationManagerService extends SystemService {
|
|||||||
} catch (Resources.NotFoundException e) {
|
} catch (Resources.NotFoundException e) {
|
||||||
extractorNames = new String[0];
|
extractorNames = new String[0];
|
||||||
}
|
}
|
||||||
mUsageStats = new NotificationUsageStats(getContext());
|
mUsageStats = usageStats;
|
||||||
mRankingHandler = new RankingHandlerWorker(mRankingThread.getLooper());
|
mRankingHandler = new RankingHandlerWorker(mRankingThread.getLooper());
|
||||||
mRankingHelper = new RankingHelper(getContext(),
|
mRankingHelper = new RankingHelper(getContext(),
|
||||||
getContext().getPackageManager(),
|
getContext().getPackageManager(),
|
||||||
@@ -1243,7 +1244,7 @@ public class NotificationManagerService extends SystemService {
|
|||||||
|
|
||||||
init(Looper.myLooper(), AppGlobals.getPackageManager(), getContext().getPackageManager(),
|
init(Looper.myLooper(), AppGlobals.getPackageManager(), getContext().getPackageManager(),
|
||||||
getLocalService(LightsManager.class), new NotificationListeners(),
|
getLocalService(LightsManager.class), new NotificationListeners(),
|
||||||
null, snoozeHelper);
|
null, snoozeHelper, new NotificationUsageStats(getContext()));
|
||||||
publishBinderService(Context.NOTIFICATION_SERVICE, mService);
|
publishBinderService(Context.NOTIFICATION_SERVICE, mService);
|
||||||
publishLocalService(NotificationManagerInternal.class, mInternalService);
|
publishLocalService(NotificationManagerInternal.class, mInternalService);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,6 +91,8 @@ public class NotificationManagerServiceTest extends NotificationTestCase {
|
|||||||
private TestableLooper mTestableLooper;
|
private TestableLooper mTestableLooper;
|
||||||
@Mock
|
@Mock
|
||||||
private RankingHelper mRankingHelper;
|
private RankingHelper mRankingHelper;
|
||||||
|
@Mock
|
||||||
|
private NotificationUsageStats mUsageStats;
|
||||||
private NotificationChannel mTestNotificationChannel = new NotificationChannel(
|
private NotificationChannel mTestNotificationChannel = new NotificationChannel(
|
||||||
TEST_CHANNEL_ID, TEST_CHANNEL_ID, NotificationManager.IMPORTANCE_DEFAULT);
|
TEST_CHANNEL_ID, TEST_CHANNEL_ID, NotificationManager.IMPORTANCE_DEFAULT);
|
||||||
@Mock
|
@Mock
|
||||||
@@ -147,7 +149,7 @@ public class NotificationManagerServiceTest extends NotificationTestCase {
|
|||||||
when(mNotificationListeners.checkServiceTokenLocked(any())).thenReturn(mListener);
|
when(mNotificationListeners.checkServiceTokenLocked(any())).thenReturn(mListener);
|
||||||
mNotificationManagerService.init(mTestableLooper.getLooper(), mPackageManager,
|
mNotificationManagerService.init(mTestableLooper.getLooper(), mPackageManager,
|
||||||
mPackageManagerClient, mockLightsManager, mNotificationListeners, mCompanionMgr,
|
mPackageManagerClient, mockLightsManager, mNotificationListeners, mCompanionMgr,
|
||||||
mSnoozeHelper);
|
mSnoozeHelper, mUsageStats);
|
||||||
|
|
||||||
// Tests call directly into the Binder.
|
// Tests call directly into the Binder.
|
||||||
mBinderService = mNotificationManagerService.getBinderService();
|
mBinderService = mNotificationManagerService.getBinderService();
|
||||||
@@ -261,40 +263,37 @@ public class NotificationManagerServiceTest extends NotificationTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBlockedNotifications_suspended() throws Exception {
|
public void testBlockedNotifications_suspended() throws Exception {
|
||||||
NotificationUsageStats usageStats = mock(NotificationUsageStats.class);
|
|
||||||
when(mPackageManager.isPackageSuspendedForUser(anyString(), anyInt())).thenReturn(true);
|
when(mPackageManager.isPackageSuspendedForUser(anyString(), anyInt())).thenReturn(true);
|
||||||
|
|
||||||
NotificationChannel channel = new NotificationChannel("id", "name",
|
NotificationChannel channel = new NotificationChannel("id", "name",
|
||||||
NotificationManager.IMPORTANCE_HIGH);
|
NotificationManager.IMPORTANCE_HIGH);
|
||||||
NotificationRecord r = generateNotificationRecord(channel);
|
NotificationRecord r = generateNotificationRecord(channel);
|
||||||
assertTrue(mNotificationManagerService.isBlocked(r, usageStats));
|
assertTrue(mNotificationManagerService.isBlocked(r, mUsageStats));
|
||||||
verify(usageStats, times(1)).registerSuspendedByAdmin(eq(r));
|
verify(mUsageStats, times(1)).registerSuspendedByAdmin(eq(r));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBlockedNotifications_blockedChannel() throws Exception {
|
public void testBlockedNotifications_blockedChannel() throws Exception {
|
||||||
NotificationUsageStats usageStats = mock(NotificationUsageStats.class);
|
|
||||||
when(mPackageManager.isPackageSuspendedForUser(anyString(), anyInt())).thenReturn(false);
|
when(mPackageManager.isPackageSuspendedForUser(anyString(), anyInt())).thenReturn(false);
|
||||||
|
|
||||||
NotificationChannel channel = new NotificationChannel("id", "name",
|
NotificationChannel channel = new NotificationChannel("id", "name",
|
||||||
NotificationManager.IMPORTANCE_HIGH);
|
NotificationManager.IMPORTANCE_HIGH);
|
||||||
channel.setImportance(NotificationManager.IMPORTANCE_NONE);
|
channel.setImportance(NotificationManager.IMPORTANCE_NONE);
|
||||||
NotificationRecord r = generateNotificationRecord(channel);
|
NotificationRecord r = generateNotificationRecord(channel);
|
||||||
assertTrue(mNotificationManagerService.isBlocked(r, usageStats));
|
assertTrue(mNotificationManagerService.isBlocked(r, mUsageStats));
|
||||||
verify(usageStats, times(1)).registerBlocked(eq(r));
|
verify(mUsageStats, times(1)).registerBlocked(eq(r));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBlockedNotifications_blockedApp() throws Exception {
|
public void testBlockedNotifications_blockedApp() throws Exception {
|
||||||
NotificationUsageStats usageStats = mock(NotificationUsageStats.class);
|
|
||||||
when(mPackageManager.isPackageSuspendedForUser(anyString(), anyInt())).thenReturn(false);
|
when(mPackageManager.isPackageSuspendedForUser(anyString(), anyInt())).thenReturn(false);
|
||||||
|
|
||||||
NotificationChannel channel = new NotificationChannel("id", "name",
|
NotificationChannel channel = new NotificationChannel("id", "name",
|
||||||
NotificationManager.IMPORTANCE_HIGH);
|
NotificationManager.IMPORTANCE_HIGH);
|
||||||
NotificationRecord r = generateNotificationRecord(channel);
|
NotificationRecord r = generateNotificationRecord(channel);
|
||||||
r.setUserImportance(NotificationManager.IMPORTANCE_NONE);
|
r.setUserImportance(NotificationManager.IMPORTANCE_NONE);
|
||||||
assertTrue(mNotificationManagerService.isBlocked(r, usageStats));
|
assertTrue(mNotificationManagerService.isBlocked(r, mUsageStats));
|
||||||
verify(usageStats, times(1)).registerBlocked(eq(r));
|
verify(mUsageStats, times(1)).registerBlocked(eq(r));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user