Loading services/core/java/com/android/server/notification/NotificationManagerService.java +14 −7 Original line number Original line Diff line number Diff line Loading @@ -3408,20 +3408,27 @@ public class NotificationManagerService extends SystemService { @Override @Override public void applyEnqueuedAdjustmentFromAssistant(INotificationListener token, public void applyEnqueuedAdjustmentFromAssistant(INotificationListener token, Adjustment adjustment) throws RemoteException { Adjustment adjustment) { boolean foundEnqueued = false; final long identity = Binder.clearCallingIdentity(); final long identity = Binder.clearCallingIdentity(); try { try { synchronized (mNotificationLock) { synchronized (mNotificationLock) { mAssistants.checkServiceTokenLocked(token); mAssistants.checkServiceTokenLocked(token); int N = mEnqueuedNotifications.size(); int N = mEnqueuedNotifications.size(); for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { final NotificationRecord n = mEnqueuedNotifications.get(i); final NotificationRecord r = mEnqueuedNotifications.get(i); if (Objects.equals(adjustment.getKey(), n.getKey()) if (Objects.equals(adjustment.getKey(), r.getKey()) && Objects.equals(adjustment.getUser(), n.getUserId())) { && Objects.equals(adjustment.getUser(), r.getUserId())) { applyAdjustment(n, adjustment); applyAdjustment(r, adjustment); r.applyAdjustments(); foundEnqueued = true; break; break; } } } } if (!foundEnqueued) { // adjustment arrived too late to apply to enqueued; apply to posted applyAdjustmentFromAssistant(token, adjustment); } } } } finally { } finally { Binder.restoreCallingIdentity(identity); Binder.restoreCallingIdentity(identity); Loading @@ -3430,7 +3437,7 @@ public class NotificationManagerService extends SystemService { @Override @Override public void applyAdjustmentFromAssistant(INotificationListener token, public void applyAdjustmentFromAssistant(INotificationListener token, Adjustment adjustment) throws RemoteException { Adjustment adjustment) { final long identity = Binder.clearCallingIdentity(); final long identity = Binder.clearCallingIdentity(); try { try { synchronized (mNotificationLock) { synchronized (mNotificationLock) { Loading @@ -3446,7 +3453,7 @@ public class NotificationManagerService extends SystemService { @Override @Override public void applyAdjustmentsFromAssistant(INotificationListener token, public void applyAdjustmentsFromAssistant(INotificationListener token, List<Adjustment> adjustments) throws RemoteException { List<Adjustment> adjustments) { final long identity = Binder.clearCallingIdentity(); final long identity = Binder.clearCallingIdentity(); try { try { Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +39 −0 Original line number Original line Diff line number Diff line Loading @@ -2404,6 +2404,45 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { verify(handler, timeout(300).times(1)).scheduleSendRankingUpdate(); verify(handler, timeout(300).times(1)).scheduleSendRankingUpdate(); } } @Test public void testTooLateAdjustmentTriggersUpdate() throws Exception { final NotificationRecord r = generateNotificationRecord(mTestNotificationChannel); mService.addNotification(r); NotificationManagerService.WorkerHandler handler = mock( NotificationManagerService.WorkerHandler.class); mService.setHandler(handler); Bundle signals = new Bundle(); signals.putInt(Adjustment.KEY_USER_SENTIMENT, NotificationListenerService.Ranking.USER_SENTIMENT_NEGATIVE); Adjustment adjustment = new Adjustment( r.sbn.getPackageName(), r.getKey(), signals, "", r.getUser().getIdentifier()); mBinderService.applyEnqueuedAdjustmentFromAssistant(null, adjustment); waitForIdle(); verify(handler, timeout(300).times(1)).scheduleSendRankingUpdate(); } @Test public void testEnqueuedAdjustmentAppliesAdjustments() throws Exception { final NotificationRecord r = generateNotificationRecord(mTestNotificationChannel); mService.addEnqueuedNotification(r); NotificationManagerService.WorkerHandler handler = mock( NotificationManagerService.WorkerHandler.class); mService.setHandler(handler); Bundle signals = new Bundle(); signals.putInt(Adjustment.KEY_USER_SENTIMENT, NotificationListenerService.Ranking.USER_SENTIMENT_NEGATIVE); Adjustment adjustment = new Adjustment( r.sbn.getPackageName(), r.getKey(), signals, "", r.getUser().getIdentifier()); mBinderService.applyEnqueuedAdjustmentFromAssistant(null, adjustment); assertEquals(NotificationListenerService.Ranking.USER_SENTIMENT_NEGATIVE, r.getUserSentiment()); } @Test @Test public void testRecents() throws Exception { public void testRecents() throws Exception { Set<NotifyingApp> expected = new HashSet<>(); Set<NotifyingApp> expected = new HashSet<>(); Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +14 −7 Original line number Original line Diff line number Diff line Loading @@ -3408,20 +3408,27 @@ public class NotificationManagerService extends SystemService { @Override @Override public void applyEnqueuedAdjustmentFromAssistant(INotificationListener token, public void applyEnqueuedAdjustmentFromAssistant(INotificationListener token, Adjustment adjustment) throws RemoteException { Adjustment adjustment) { boolean foundEnqueued = false; final long identity = Binder.clearCallingIdentity(); final long identity = Binder.clearCallingIdentity(); try { try { synchronized (mNotificationLock) { synchronized (mNotificationLock) { mAssistants.checkServiceTokenLocked(token); mAssistants.checkServiceTokenLocked(token); int N = mEnqueuedNotifications.size(); int N = mEnqueuedNotifications.size(); for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { final NotificationRecord n = mEnqueuedNotifications.get(i); final NotificationRecord r = mEnqueuedNotifications.get(i); if (Objects.equals(adjustment.getKey(), n.getKey()) if (Objects.equals(adjustment.getKey(), r.getKey()) && Objects.equals(adjustment.getUser(), n.getUserId())) { && Objects.equals(adjustment.getUser(), r.getUserId())) { applyAdjustment(n, adjustment); applyAdjustment(r, adjustment); r.applyAdjustments(); foundEnqueued = true; break; break; } } } } if (!foundEnqueued) { // adjustment arrived too late to apply to enqueued; apply to posted applyAdjustmentFromAssistant(token, adjustment); } } } } finally { } finally { Binder.restoreCallingIdentity(identity); Binder.restoreCallingIdentity(identity); Loading @@ -3430,7 +3437,7 @@ public class NotificationManagerService extends SystemService { @Override @Override public void applyAdjustmentFromAssistant(INotificationListener token, public void applyAdjustmentFromAssistant(INotificationListener token, Adjustment adjustment) throws RemoteException { Adjustment adjustment) { final long identity = Binder.clearCallingIdentity(); final long identity = Binder.clearCallingIdentity(); try { try { synchronized (mNotificationLock) { synchronized (mNotificationLock) { Loading @@ -3446,7 +3453,7 @@ public class NotificationManagerService extends SystemService { @Override @Override public void applyAdjustmentsFromAssistant(INotificationListener token, public void applyAdjustmentsFromAssistant(INotificationListener token, List<Adjustment> adjustments) throws RemoteException { List<Adjustment> adjustments) { final long identity = Binder.clearCallingIdentity(); final long identity = Binder.clearCallingIdentity(); try { try { Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +39 −0 Original line number Original line Diff line number Diff line Loading @@ -2404,6 +2404,45 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { verify(handler, timeout(300).times(1)).scheduleSendRankingUpdate(); verify(handler, timeout(300).times(1)).scheduleSendRankingUpdate(); } } @Test public void testTooLateAdjustmentTriggersUpdate() throws Exception { final NotificationRecord r = generateNotificationRecord(mTestNotificationChannel); mService.addNotification(r); NotificationManagerService.WorkerHandler handler = mock( NotificationManagerService.WorkerHandler.class); mService.setHandler(handler); Bundle signals = new Bundle(); signals.putInt(Adjustment.KEY_USER_SENTIMENT, NotificationListenerService.Ranking.USER_SENTIMENT_NEGATIVE); Adjustment adjustment = new Adjustment( r.sbn.getPackageName(), r.getKey(), signals, "", r.getUser().getIdentifier()); mBinderService.applyEnqueuedAdjustmentFromAssistant(null, adjustment); waitForIdle(); verify(handler, timeout(300).times(1)).scheduleSendRankingUpdate(); } @Test public void testEnqueuedAdjustmentAppliesAdjustments() throws Exception { final NotificationRecord r = generateNotificationRecord(mTestNotificationChannel); mService.addEnqueuedNotification(r); NotificationManagerService.WorkerHandler handler = mock( NotificationManagerService.WorkerHandler.class); mService.setHandler(handler); Bundle signals = new Bundle(); signals.putInt(Adjustment.KEY_USER_SENTIMENT, NotificationListenerService.Ranking.USER_SENTIMENT_NEGATIVE); Adjustment adjustment = new Adjustment( r.sbn.getPackageName(), r.getKey(), signals, "", r.getUser().getIdentifier()); mBinderService.applyEnqueuedAdjustmentFromAssistant(null, adjustment); assertEquals(NotificationListenerService.Ranking.USER_SENTIMENT_NEGATIVE, r.getUserSentiment()); } @Test @Test public void testRecents() throws Exception { public void testRecents() throws Exception { Set<NotifyingApp> expected = new HashSet<>(); Set<NotifyingApp> expected = new HashSet<>(); Loading