Merge "Fixes for enqueued adjustments"

This commit is contained in:
TreeHugger Robot
2018-06-18 17:31:32 +00:00
committed by Android (Google) Code Review
2 changed files with 53 additions and 7 deletions

View File

@@ -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 {

View File

@@ -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<>();