@Override
public void applyEnqueuedAdjustmentFromAssistant(INotificationListener token,
- Adjustment adjustment) throws RemoteException {
+ Adjustment adjustment) {
+ boolean foundEnqueued = false;
final long identity = Binder.clearCallingIdentity();
try {
synchronized (mNotificationLock) {
mAssistants.checkServiceTokenLocked(token);
int N = mEnqueuedNotifications.size();
for (int i = 0; i < N; i++) {
- final NotificationRecord n = mEnqueuedNotifications.get(i);
- if (Objects.equals(adjustment.getKey(), n.getKey())
- && Objects.equals(adjustment.getUser(), n.getUserId())) {
- applyAdjustment(n, adjustment);
+ final NotificationRecord r = mEnqueuedNotifications.get(i);
+ if (Objects.equals(adjustment.getKey(), r.getKey())
+ && Objects.equals(adjustment.getUser(), r.getUserId())) {
+ applyAdjustment(r, adjustment);
+ r.applyAdjustments();
+ foundEnqueued = true;
break;
}
}
+ if (!foundEnqueued) {
+ // adjustment arrived too late to apply to enqueued; apply to posted
+ applyAdjustmentFromAssistant(token, adjustment);
+ }
}
} finally {
Binder.restoreCallingIdentity(identity);
@Override
public void applyAdjustmentFromAssistant(INotificationListener token,
- Adjustment adjustment) throws RemoteException {
+ Adjustment adjustment) {
final long identity = Binder.clearCallingIdentity();
try {
synchronized (mNotificationLock) {
@Override
public void applyAdjustmentsFromAssistant(INotificationListener token,
- List<Adjustment> adjustments) throws RemoteException {
+ List<Adjustment> adjustments) {
final long identity = Binder.clearCallingIdentity();
try {
}
@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
public void testRecents() throws Exception {
Set<NotifyingApp> expected = new HashSet<>();