Merge "Check user when snoozing" into sc-qpr1-dev am: b082cf64e1
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15676600 Change-Id: I27f2b4d2531ab2d564d6dc1a0f176104831d2009
This commit is contained in:
@@ -8756,10 +8756,22 @@ public class NotificationManagerService extends SystemService {
|
|||||||
|
|
||||||
void snoozeNotificationInt(String key, long duration, String snoozeCriterionId,
|
void snoozeNotificationInt(String key, long duration, String snoozeCriterionId,
|
||||||
ManagedServiceInfo listener) {
|
ManagedServiceInfo listener) {
|
||||||
String listenerName = listener == null ? null : listener.component.toShortString();
|
if (listener == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String listenerName = listener.component.toShortString();
|
||||||
if ((duration <= 0 && snoozeCriterionId == null) || key == null) {
|
if ((duration <= 0 && snoozeCriterionId == null) || key == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
synchronized (mNotificationLock) {
|
||||||
|
final NotificationRecord r = findInCurrentAndSnoozedNotificationByKeyLocked(key);
|
||||||
|
if (r == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!listener.enabledAndUserMatches(r.getSbn().getNormalizedUserId())){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
Slog.d(TAG, String.format("snooze event(%s, %d, %s, %s)", key, duration,
|
Slog.d(TAG, String.format("snooze event(%s, %d, %s, %s)", key, duration,
|
||||||
|
|||||||
@@ -516,7 +516,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
|
|||||||
|
|
||||||
when(mAssistants.isAdjustmentAllowed(anyString())).thenReturn(true);
|
when(mAssistants.isAdjustmentAllowed(anyString())).thenReturn(true);
|
||||||
|
|
||||||
mWorkerHandler = mService.new WorkerHandler(mTestableLooper.getLooper());
|
mWorkerHandler = spy(mService.new WorkerHandler(mTestableLooper.getLooper()));
|
||||||
mService.init(mWorkerHandler, mRankingHandler, mPackageManager, mPackageManagerClient,
|
mService.init(mWorkerHandler, mRankingHandler, mPackageManager, mPackageManagerClient,
|
||||||
mockLightsManager, mListeners, mAssistants, mConditionProviders, mCompanionMgr,
|
mockLightsManager, mListeners, mAssistants, mConditionProviders, mCompanionMgr,
|
||||||
mSnoozeHelper, mUsageStats, mPolicyFile, mActivityManager, mGroupHelper, mAm, mAtm,
|
mSnoozeHelper, mUsageStats, mPolicyFile, mActivityManager, mGroupHelper, mAm, mAtm,
|
||||||
@@ -2702,6 +2702,42 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
|
|||||||
assertFalse(noManService.hasCompanionDevice(mListener));
|
assertFalse(noManService.hasCompanionDevice(mListener));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCrossUserSnooze() {
|
||||||
|
NotificationRecord r = generateNotificationRecord(mTestNotificationChannel, 10);
|
||||||
|
mService.addNotification(r);
|
||||||
|
NotificationRecord r2 = generateNotificationRecord(mTestNotificationChannel, 0);
|
||||||
|
mService.addNotification(r2);
|
||||||
|
|
||||||
|
mListener = mock(ManagedServices.ManagedServiceInfo.class);
|
||||||
|
mListener.component = new ComponentName(PKG, PKG);
|
||||||
|
when(mListener.enabledAndUserMatches(anyInt())).thenReturn(false);
|
||||||
|
when(mListeners.checkServiceTokenLocked(any())).thenReturn(mListener);
|
||||||
|
|
||||||
|
mService.snoozeNotificationInt(r.getKey(), 1000, null, mListener);
|
||||||
|
|
||||||
|
verify(mWorkerHandler, never()).post(
|
||||||
|
any(NotificationManagerService.SnoozeNotificationRunnable.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSameUserSnooze() {
|
||||||
|
NotificationRecord r = generateNotificationRecord(mTestNotificationChannel, 10);
|
||||||
|
mService.addNotification(r);
|
||||||
|
NotificationRecord r2 = generateNotificationRecord(mTestNotificationChannel, 0);
|
||||||
|
mService.addNotification(r2);
|
||||||
|
|
||||||
|
mListener = mock(ManagedServices.ManagedServiceInfo.class);
|
||||||
|
mListener.component = new ComponentName(PKG, PKG);
|
||||||
|
when(mListener.enabledAndUserMatches(anyInt())).thenReturn(true);
|
||||||
|
when(mListeners.checkServiceTokenLocked(any())).thenReturn(mListener);
|
||||||
|
|
||||||
|
mService.snoozeNotificationInt(r2.getKey(), 1000, null, mListener);
|
||||||
|
|
||||||
|
verify(mWorkerHandler).post(
|
||||||
|
any(NotificationManagerService.SnoozeNotificationRunnable.class));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSnoozeRunnable_reSnoozeASingleSnoozedNotification() throws Exception {
|
public void testSnoozeRunnable_reSnoozeASingleSnoozedNotification() throws Exception {
|
||||||
final NotificationRecord notification = generateNotificationRecord(
|
final NotificationRecord notification = generateNotificationRecord(
|
||||||
|
|||||||
Reference in New Issue
Block a user