Fixes for enqueued adjustments
- Accept adjustments that arrie too late - send through the normal 'apply adjustment to posted notification' flow - Apply adjustments that are received onEnqueue Test: runtest systemui-notification Bug: 110347047 Change-Id: Ic4c9839cf2f63ef1689d72eb291f6bfae8f0674b
This commit is contained in:
@@ -3408,20 +3408,27 @@ public class NotificationManagerService extends SystemService {
|
||||
|
||||
@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);
|
||||
@@ -3430,7 +3437,7 @@ public class NotificationManagerService extends SystemService {
|
||||
|
||||
@Override
|
||||
public void applyAdjustmentFromAssistant(INotificationListener token,
|
||||
Adjustment adjustment) throws RemoteException {
|
||||
Adjustment adjustment) {
|
||||
final long identity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
synchronized (mNotificationLock) {
|
||||
@@ -3446,7 +3453,7 @@ public class NotificationManagerService extends SystemService {
|
||||
|
||||
@Override
|
||||
public void applyAdjustmentsFromAssistant(INotificationListener token,
|
||||
List<Adjustment> adjustments) throws RemoteException {
|
||||
List<Adjustment> adjustments) {
|
||||
|
||||
final long identity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
|
||||
@@ -2404,6 +2404,45 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
|
||||
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
|
||||
public void testRecents() throws Exception {
|
||||
Set<NotifyingApp> expected = new HashSet<>();
|
||||
|
||||
Reference in New Issue
Block a user