Loading services/core/java/com/android/server/notification/NotificationManagerService.java +65 −36 Original line number Diff line number Diff line Loading @@ -124,6 +124,7 @@ import static com.android.server.utils.PriorityDump.PRIORITY_ARG_NORMAL; import android.Manifest; import android.Manifest.permission; import android.annotation.ElapsedRealtimeLong; import android.annotation.MainThread; import android.annotation.NonNull; import android.annotation.Nullable; Loading Loading @@ -851,7 +852,8 @@ public class NotificationManagerService extends SystemService { } if (summary.getSbn().getNotification().flags != oldFlags) { mHandler.post(new EnqueueNotificationRunnable(userId, summary, isAppForeground)); mHandler.post(new EnqueueNotificationRunnable(userId, summary, isAppForeground, SystemClock.elapsedRealtime())); } } Loading Loading @@ -1373,7 +1375,7 @@ public class NotificationManagerService extends SystemService { // Force isAppForeground true here, because for sysui's purposes we // want to adjust the flag behaviour. mHandler.post(new EnqueueNotificationRunnable(r.getUser().getIdentifier(), r, true /* isAppForeground*/)); r, true /* isAppForeground*/, SystemClock.elapsedRealtime())); } } } Loading Loading @@ -1404,7 +1406,7 @@ public class NotificationManagerService extends SystemService { r.getNotification().flags |= FLAG_ONLY_ALERT_ONCE; mHandler.post( new EnqueueNotificationRunnable(r.getUser().getIdentifier(), r, true /* isAppForeground */)); true /* isAppForeground */, SystemClock.elapsedRealtime())); } } } Loading Loading @@ -2554,7 +2556,8 @@ public class NotificationManagerService extends SystemService { if (r != null) { final boolean isAppForeground = mActivityManager.getPackageImportance(pkg) == IMPORTANCE_FOREGROUND; mHandler.post(new EnqueueNotificationRunnable(userId, r, isAppForeground)); mHandler.post(new EnqueueNotificationRunnable(userId, r, isAppForeground, SystemClock.elapsedRealtime())); } } Loading Loading @@ -5750,7 +5753,8 @@ public class NotificationManagerService extends SystemService { final NotificationRecord removed = findNotificationByKeyLocked(summaries.remove(pkg)); if (removed != null) { boolean wasPosted = removeFromNotificationListsLocked(removed); cancelNotificationLocked(removed, false, REASON_UNAUTOBUNDLED, wasPosted, null); cancelNotificationLocked(removed, false, REASON_UNAUTOBUNDLED, wasPosted, null, SystemClock.elapsedRealtime()); } } } Loading Loading @@ -6481,7 +6485,8 @@ public class NotificationManagerService extends SystemService { } finally { Binder.restoreCallingIdentity(token); } mHandler.post(new EnqueueNotificationRunnable(userId, r, isAppForeground)); mHandler.post(new EnqueueNotificationRunnable(userId, r, isAppForeground, SystemClock.elapsedRealtime())); } private void onConversationRemovedInternal(String pkg, int uid, Set<String> shortcuts) { Loading Loading @@ -6625,7 +6630,8 @@ public class NotificationManagerService extends SystemService { r.getNotification().flags |= FLAG_ONLY_ALERT_ONCE; mHandler.post( new NotificationManagerService.EnqueueNotificationRunnable( r.getUser().getIdentifier(), r, isAppForeground)); r.getUser().getIdentifier(), r, isAppForeground, SystemClock.elapsedRealtime())); } } } Loading Loading @@ -6929,7 +6935,8 @@ public class NotificationManagerService extends SystemService { NotificationRecordLogger.NotificationEvent.NOTIFICATION_SNOOZED, r); reportUserInteraction(r); boolean wasPosted = removeFromNotificationListsLocked(r); cancelNotificationLocked(r, false, REASON_SNOOZED, wasPosted, null); cancelNotificationLocked(r, false, REASON_SNOOZED, wasPosted, null, SystemClock.elapsedRealtime()); updateLightsLocked(); if (mSnoozeCriterionId != null) { mAssistants.notifyAssistantSnoozedLocked(r, mSnoozeCriterionId); Loading @@ -6956,12 +6963,14 @@ public class NotificationManagerService extends SystemService { private final int mRank; private final int mCount; private final ManagedServiceInfo mListener; private final long mCancellationElapsedTimeMs; CancelNotificationRunnable(final int callingUid, final int callingPid, final String pkg, final String tag, final int id, final int mustHaveFlags, final int mustNotHaveFlags, final boolean sendDelete, final int userId, final int reason, int rank, int count, final ManagedServiceInfo listener) { final ManagedServiceInfo listener, @ElapsedRealtimeLong long cancellationElapsedTimeMs) { this.mCallingUid = callingUid; this.mCallingPid = callingPid; this.mPkg = pkg; Loading @@ -6975,6 +6984,7 @@ public class NotificationManagerService extends SystemService { this.mRank = rank; this.mCount = count; this.mListener = listener; this.mCancellationElapsedTimeMs = cancellationElapsedTimeMs; } @Override Loading Loading @@ -7037,9 +7047,11 @@ public class NotificationManagerService extends SystemService { // Cancel the notification. boolean wasPosted = removeFromNotificationListsLocked(r); cancelNotificationLocked( r, mSendDelete, mReason, mRank, mCount, wasPosted, listenerName); r, mSendDelete, mReason, mRank, mCount, wasPosted, listenerName, mCancellationElapsedTimeMs); cancelGroupChildrenLocked(r, mCallingUid, mCallingPid, listenerName, mSendDelete, childrenFlagChecker, mReason); mSendDelete, childrenFlagChecker, mReason, mCancellationElapsedTimeMs); updateLightsLocked(); if (mShortcutHelper != null) { mShortcutHelper.maybeListenForShortcutChangesForBubbles(r, Loading Loading @@ -7101,11 +7113,14 @@ public class NotificationManagerService extends SystemService { private final NotificationRecord r; private final int userId; private final boolean isAppForeground; private final long enqueueElapsedTimeMs; EnqueueNotificationRunnable(int userId, NotificationRecord r, boolean foreground) { EnqueueNotificationRunnable(int userId, NotificationRecord r, boolean foreground, @ElapsedRealtimeLong long enqueueElapsedTimeMs) { this.userId = userId; this.r = r; this.isAppForeground = foreground; this.enqueueElapsedTimeMs = enqueueElapsedTimeMs; } @Override Loading Loading @@ -7178,10 +7193,11 @@ public class NotificationManagerService extends SystemService { // tell the assistant service about the notification if (mAssistants.isEnabled()) { mAssistants.onNotificationEnqueuedLocked(r); mHandler.postDelayed(new PostNotificationRunnable(r.getKey()), mHandler.postDelayed( new PostNotificationRunnable(r.getKey(), enqueueElapsedTimeMs), DELAY_FOR_ASSISTANT_TIME); } else { mHandler.post(new PostNotificationRunnable(r.getKey())); mHandler.post(new PostNotificationRunnable(r.getKey(), enqueueElapsedTimeMs)); } } } Loading @@ -7204,9 +7220,11 @@ public class NotificationManagerService extends SystemService { protected class PostNotificationRunnable implements Runnable { private final String key; private final long postElapsedTimeMs; PostNotificationRunnable(String key) { PostNotificationRunnable(String key, @ElapsedRealtimeLong long postElapsedTimeMs) { this.key = key; this.postElapsedTimeMs = postElapsedTimeMs; } @Override Loading Loading @@ -7262,7 +7280,7 @@ public class NotificationManagerService extends SystemService { mNotificationList.add(r); mUsageStats.registerPostedByApp(r); mUsageStatsManagerInternal.reportNotificationPosted(r.getSbn().getOpPkg(), r.getSbn().getUser(), SystemClock.elapsedRealtime()); r.getSbn().getUser(), postElapsedTimeMs); final boolean isInterruptive = isVisuallyInterruptive(null, r); r.setInterruptive(isInterruptive); r.setTextChanged(isInterruptive); Loading @@ -7271,7 +7289,7 @@ public class NotificationManagerService extends SystemService { mNotificationList.set(index, r); mUsageStats.registerUpdatedByApp(r, old); mUsageStatsManagerInternal.reportNotificationUpdated(r.getSbn().getOpPkg(), r.getSbn().getUser(), SystemClock.elapsedRealtime()); r.getSbn().getUser(), postElapsedTimeMs); // Make sure we don't lose the foreground service state. notification.flags |= old.getNotification().flags & FLAG_FOREGROUND_SERVICE; Loading Loading @@ -7576,7 +7594,7 @@ public class NotificationManagerService extends SystemService { // notification was a summary and its group key changed. if (oldIsSummary && (!isSummary || !oldGroup.equals(group))) { cancelGroupChildrenLocked(old, callingUid, callingPid, null, false /* sendDelete */, childrenFlagChecker, REASON_APP_CANCEL); childrenFlagChecker, REASON_APP_CANCEL, SystemClock.elapsedRealtime()); } } Loading Loading @@ -8662,14 +8680,17 @@ public class NotificationManagerService extends SystemService { @GuardedBy("mNotificationLock") private void cancelNotificationLocked(NotificationRecord r, boolean sendDelete, @NotificationListenerService.NotificationCancelReason int reason, boolean wasPosted, String listenerName) { cancelNotificationLocked(r, sendDelete, reason, -1, -1, wasPosted, listenerName); boolean wasPosted, String listenerName, @ElapsedRealtimeLong long cancellationElapsedTimeMs) { cancelNotificationLocked(r, sendDelete, reason, -1, -1, wasPosted, listenerName, cancellationElapsedTimeMs); } @GuardedBy("mNotificationLock") private void cancelNotificationLocked(NotificationRecord r, boolean sendDelete, @NotificationListenerService.NotificationCancelReason int reason, int rank, int count, boolean wasPosted, String listenerName) { int rank, int count, boolean wasPosted, String listenerName, @ElapsedRealtimeLong long cancellationElapsedTimeMs) { final String canceledKey = r.getKey(); // Get pending intent used to create alarm, use FLAG_NO_CREATE if PendingIntent Loading Loading @@ -8755,7 +8776,7 @@ public class NotificationManagerService extends SystemService { case REASON_APP_CANCEL_ALL: mUsageStats.registerRemovedByApp(r); mUsageStatsManagerInternal.reportNotificationRemoved(r.getSbn().getOpPkg(), r.getUser(), SystemClock.elapsedRealtime()); r.getUser(), cancellationElapsedTimeMs); break; } Loading Loading @@ -8932,7 +8953,7 @@ public class NotificationManagerService extends SystemService { * and none of the {@code mustNotHaveFlags}. */ void cancelNotification(final int callingUid, final int callingPid, final String pkg, final String tag, final int id, final String pkg, final String tag, int id, final int mustHaveFlags, final int mustNotHaveFlags, final boolean sendDelete, final int userId, final int reason, final ManagedServiceInfo listener) { cancelNotification(callingUid, callingPid, pkg, tag, id, mustHaveFlags, mustNotHaveFlags, Loading @@ -8954,7 +8975,7 @@ public class NotificationManagerService extends SystemService { // remove notification call ends up in not removing the notification. mHandler.scheduleCancelNotification(new CancelNotificationRunnable(callingUid, callingPid, pkg, tag, id, mustHaveFlags, mustNotHaveFlags, sendDelete, userId, reason, rank, count, listener)); count, listener, SystemClock.elapsedRealtime())); } /** Loading Loading @@ -8988,6 +9009,7 @@ public class NotificationManagerService extends SystemService { void cancelAllNotificationsInt(int callingUid, int callingPid, String pkg, String channelId, int mustHaveFlags, int mustNotHaveFlags, boolean doit, int userId, int reason, ManagedServiceInfo listener) { final long cancellationElapsedTimeMs = SystemClock.elapsedRealtime(); mHandler.post(new Runnable() { @Override public void run() { Loading Loading @@ -9015,11 +9037,12 @@ public class NotificationManagerService extends SystemService { cancelAllNotificationsByListLocked(mNotificationList, callingUid, callingPid, pkg, true /*nullPkgIndicatesUserSwitch*/, channelId, flagChecker, false /*includeCurrentProfiles*/, userId, false /*sendDelete*/, reason, listenerName, true /* wasPosted */); listenerName, true /* wasPosted */, cancellationElapsedTimeMs); cancelAllNotificationsByListLocked(mEnqueuedNotifications, callingUid, callingPid, pkg, true /*nullPkgIndicatesUserSwitch*/, channelId, flagChecker, false /*includeCurrentProfiles*/, userId, false /*sendDelete*/, reason, listenerName, false /* wasPosted */); false /*sendDelete*/, reason, listenerName, false /* wasPosted */, cancellationElapsedTimeMs); mSnoozeHelper.cancel(userId, pkg); } } Loading @@ -9035,7 +9058,8 @@ public class NotificationManagerService extends SystemService { private void cancelAllNotificationsByListLocked(ArrayList<NotificationRecord> notificationList, int callingUid, int callingPid, String pkg, boolean nullPkgIndicatesUserSwitch, String channelId, FlagChecker flagChecker, boolean includeCurrentProfiles, int userId, boolean sendDelete, int reason, String listenerName, boolean wasPosted) { boolean sendDelete, int reason, String listenerName, boolean wasPosted, @ElapsedRealtimeLong long cancellationElapsedTimeMs) { Set<String> childNotifications = null; for (int i = notificationList.size() - 1; i >= 0; --i) { NotificationRecord r = notificationList.get(i); Loading Loading @@ -9069,7 +9093,8 @@ public class NotificationManagerService extends SystemService { notificationList.remove(i); mNotificationsByKey.remove(r.getKey()); r.recordDismissalSentiment(NotificationStats.DISMISS_SENTIMENT_NEUTRAL); cancelNotificationLocked(r, sendDelete, reason, wasPosted, listenerName); cancelNotificationLocked(r, sendDelete, reason, wasPosted, listenerName, cancellationElapsedTimeMs); } if (childNotifications != null) { final int M = notificationList.size(); Loading @@ -9081,7 +9106,8 @@ public class NotificationManagerService extends SystemService { notificationList.remove(i); mNotificationsByKey.remove(r.getKey()); r.recordDismissalSentiment(NotificationStats.DISMISS_SENTIMENT_NEUTRAL); cancelNotificationLocked(r, sendDelete, reason, wasPosted, listenerName); cancelNotificationLocked(r, sendDelete, reason, wasPosted, listenerName, cancellationElapsedTimeMs); } } updateLightsLocked(); Loading Loading @@ -9127,6 +9153,7 @@ public class NotificationManagerService extends SystemService { @GuardedBy("mNotificationLock") void cancelAllLocked(int callingUid, int callingPid, int userId, int reason, ManagedServiceInfo listener, boolean includeCurrentProfiles) { final long cancellationElapsedTimeMs = SystemClock.elapsedRealtime(); mHandler.post(new Runnable() { @Override public void run() { Loading @@ -9151,11 +9178,11 @@ public class NotificationManagerService extends SystemService { cancelAllNotificationsByListLocked(mNotificationList, callingUid, callingPid, null, false /*nullPkgIndicatesUserSwitch*/, null, flagChecker, includeCurrentProfiles, userId, true /*sendDelete*/, reason, listenerName, true); listenerName, true, cancellationElapsedTimeMs); cancelAllNotificationsByListLocked(mEnqueuedNotifications, callingUid, callingPid, null, false /*nullPkgIndicatesUserSwitch*/, null, flagChecker, includeCurrentProfiles, userId, true /*sendDelete*/, reason, listenerName, false); reason, listenerName, false, cancellationElapsedTimeMs); mSnoozeHelper.cancel(userId, includeCurrentProfiles); } } Loading @@ -9165,7 +9192,8 @@ public class NotificationManagerService extends SystemService { // Warning: The caller is responsible for invoking updateLightsLocked(). @GuardedBy("mNotificationLock") private void cancelGroupChildrenLocked(NotificationRecord r, int callingUid, int callingPid, String listenerName, boolean sendDelete, FlagChecker flagChecker, int reason) { String listenerName, boolean sendDelete, FlagChecker flagChecker, int reason, @ElapsedRealtimeLong long cancellationElapsedTimeMs) { Notification n = r.getNotification(); if (!n.isGroupSummary()) { return; Loading @@ -9179,16 +9207,16 @@ public class NotificationManagerService extends SystemService { } cancelGroupChildrenByListLocked(mNotificationList, r, callingUid, callingPid, listenerName, sendDelete, true, flagChecker, reason); sendDelete, true, flagChecker, reason, cancellationElapsedTimeMs); cancelGroupChildrenByListLocked(mEnqueuedNotifications, r, callingUid, callingPid, listenerName, sendDelete, false, flagChecker, reason); listenerName, sendDelete, false, flagChecker, reason, cancellationElapsedTimeMs); } @GuardedBy("mNotificationLock") private void cancelGroupChildrenByListLocked(ArrayList<NotificationRecord> notificationList, NotificationRecord parentNotification, int callingUid, int callingPid, String listenerName, boolean sendDelete, boolean wasPosted, FlagChecker flagChecker, int reason) { int reason, @ElapsedRealtimeLong long cancellationElapsedTimeMs) { final String pkg = parentNotification.getSbn().getPackageName(); final int userId = parentNotification.getUserId(); final int childReason = REASON_GROUP_SUMMARY_CANCELED; Loading @@ -9204,7 +9232,8 @@ public class NotificationManagerService extends SystemService { childSbn.getTag(), userId, 0, 0, childReason, listenerName); notificationList.remove(i); mNotificationsByKey.remove(childR.getKey()); cancelNotificationLocked(childR, sendDelete, childReason, wasPosted, listenerName); cancelNotificationLocked(childR, sendDelete, childReason, wasPosted, listenerName, cancellationElapsedTimeMs); } } } Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +13 −10 Original line number Diff line number Diff line Loading @@ -1335,7 +1335,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mBinderService.applyEnqueuedAdjustmentFromAssistant(null, adjustment); NotificationManagerService.PostNotificationRunnable runnable = mService.new PostNotificationRunnable(r.getKey()); mService.new PostNotificationRunnable(r.getKey(), SystemClock.elapsedRealtime()); runnable.run(); waitForIdle(); Loading @@ -1356,7 +1356,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { when(mPreferencesHelper.getImportance(anyString(), anyInt())).thenReturn(IMPORTANCE_NONE); NotificationManagerService.PostNotificationRunnable runnable = mService.new PostNotificationRunnable(r.getKey()); mService.new PostNotificationRunnable(r.getKey(), SystemClock.elapsedRealtime()); runnable.run(); waitForIdle(); Loading Loading @@ -3918,7 +3918,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { NotificationRecord r = generateNotificationRecord(mTestNotificationChannel, 0, null, false); mService.addEnqueuedNotification(r); NotificationManagerService.PostNotificationRunnable runnable = mService.new PostNotificationRunnable(r.getKey()); mService.new PostNotificationRunnable(r.getKey(), SystemClock.elapsedRealtime()); runnable.run(); waitForIdle(); Loading @@ -3935,7 +3935,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { r = generateNotificationRecord(mTestNotificationChannel, 0, null, false); mService.addEnqueuedNotification(r); NotificationManagerService.PostNotificationRunnable runnable = mService.new PostNotificationRunnable(r.getKey()); mService.new PostNotificationRunnable(r.getKey(), SystemClock.elapsedRealtime()); runnable.run(); waitForIdle(); Loading @@ -3951,7 +3951,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.addEnqueuedNotification(r); NotificationManagerService.PostNotificationRunnable runnable = mService.new PostNotificationRunnable(r.getKey()); mService.new PostNotificationRunnable(r.getKey(), SystemClock.elapsedRealtime()); runnable.run(); waitForIdle(); Loading @@ -3964,12 +3964,12 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { r.setCriticality(CriticalNotificationExtractor.CRITICAL_LOW); mService.addEnqueuedNotification(r); NotificationManagerService.PostNotificationRunnable runnable = mService.new PostNotificationRunnable(r.getKey()); mService.new PostNotificationRunnable(r.getKey(), SystemClock.elapsedRealtime()); runnable.run(); r = generateNotificationRecord(mTestNotificationChannel, 1, null, false); r.setCriticality(CriticalNotificationExtractor.CRITICAL); runnable = mService.new PostNotificationRunnable(r.getKey()); runnable = mService.new PostNotificationRunnable(r.getKey(), SystemClock.elapsedRealtime()); mService.addEnqueuedNotification(r); runnable.run(); Loading Loading @@ -4412,7 +4412,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.addEnqueuedNotification(original); NotificationManagerService.PostNotificationRunnable runnable = mService.new PostNotificationRunnable(original.getKey()); mService.new PostNotificationRunnable(original.getKey(), SystemClock.elapsedRealtime()); runnable.run(); waitForIdle(); Loading @@ -4433,7 +4434,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.addEnqueuedNotification(update); NotificationManagerService.PostNotificationRunnable runnable = mService.new PostNotificationRunnable(update.getKey()); mService.new PostNotificationRunnable(update.getKey(), SystemClock.elapsedRealtime()); runnable.run(); waitForIdle(); Loading Loading @@ -6475,7 +6477,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertNull(update.getSbn().getNotification().getSmallIcon()); NotificationManagerService.PostNotificationRunnable runnable = mService.new PostNotificationRunnable(update.getKey()); mService.new PostNotificationRunnable(update.getKey(), SystemClock.elapsedRealtime()); runnable.run(); waitForIdle(); Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationPermissionMigrationTest.java +5 −4 Original line number Diff line number Diff line Loading @@ -91,6 +91,7 @@ import android.os.IBinder; import android.os.Looper; import android.os.Process; import android.os.RemoteException; import android.os.SystemClock; import android.os.UserHandle; import android.os.UserManager; import android.provider.Settings; Loading Loading @@ -656,7 +657,7 @@ public class NotificationPermissionMigrationTest extends UiServiceTestCase { when(mPermissionHelper.hasPermission(anyInt())).thenReturn(false); NotificationManagerService.PostNotificationRunnable runnable = mService.new PostNotificationRunnable(r.getKey()); mService.new PostNotificationRunnable(r.getKey(), SystemClock.elapsedRealtime()); runnable.run(); waitForIdle(); Loading Loading @@ -789,7 +790,7 @@ public class NotificationPermissionMigrationTest extends UiServiceTestCase { mService.addEnqueuedNotification(r); NotificationManagerService.PostNotificationRunnable runnable = mService.new PostNotificationRunnable(r.getKey()); mService.new PostNotificationRunnable(r.getKey(), SystemClock.elapsedRealtime()); runnable.run(); waitForIdle(); Loading @@ -805,7 +806,7 @@ public class NotificationPermissionMigrationTest extends UiServiceTestCase { r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); mService.addEnqueuedNotification(r); runnable = mService.new PostNotificationRunnable(r.getKey()); runnable = mService.new PostNotificationRunnable(r.getKey(), SystemClock.elapsedRealtime()); runnable.run(); waitForIdle(); Loading @@ -821,7 +822,7 @@ public class NotificationPermissionMigrationTest extends UiServiceTestCase { r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); mService.addEnqueuedNotification(r); runnable = mService.new PostNotificationRunnable(r.getKey()); runnable = mService.new PostNotificationRunnable(r.getKey(), SystemClock.elapsedRealtime()); runnable.run(); waitForIdle(); Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +65 −36 Original line number Diff line number Diff line Loading @@ -124,6 +124,7 @@ import static com.android.server.utils.PriorityDump.PRIORITY_ARG_NORMAL; import android.Manifest; import android.Manifest.permission; import android.annotation.ElapsedRealtimeLong; import android.annotation.MainThread; import android.annotation.NonNull; import android.annotation.Nullable; Loading Loading @@ -851,7 +852,8 @@ public class NotificationManagerService extends SystemService { } if (summary.getSbn().getNotification().flags != oldFlags) { mHandler.post(new EnqueueNotificationRunnable(userId, summary, isAppForeground)); mHandler.post(new EnqueueNotificationRunnable(userId, summary, isAppForeground, SystemClock.elapsedRealtime())); } } Loading Loading @@ -1373,7 +1375,7 @@ public class NotificationManagerService extends SystemService { // Force isAppForeground true here, because for sysui's purposes we // want to adjust the flag behaviour. mHandler.post(new EnqueueNotificationRunnable(r.getUser().getIdentifier(), r, true /* isAppForeground*/)); r, true /* isAppForeground*/, SystemClock.elapsedRealtime())); } } } Loading Loading @@ -1404,7 +1406,7 @@ public class NotificationManagerService extends SystemService { r.getNotification().flags |= FLAG_ONLY_ALERT_ONCE; mHandler.post( new EnqueueNotificationRunnable(r.getUser().getIdentifier(), r, true /* isAppForeground */)); true /* isAppForeground */, SystemClock.elapsedRealtime())); } } } Loading Loading @@ -2554,7 +2556,8 @@ public class NotificationManagerService extends SystemService { if (r != null) { final boolean isAppForeground = mActivityManager.getPackageImportance(pkg) == IMPORTANCE_FOREGROUND; mHandler.post(new EnqueueNotificationRunnable(userId, r, isAppForeground)); mHandler.post(new EnqueueNotificationRunnable(userId, r, isAppForeground, SystemClock.elapsedRealtime())); } } Loading Loading @@ -5750,7 +5753,8 @@ public class NotificationManagerService extends SystemService { final NotificationRecord removed = findNotificationByKeyLocked(summaries.remove(pkg)); if (removed != null) { boolean wasPosted = removeFromNotificationListsLocked(removed); cancelNotificationLocked(removed, false, REASON_UNAUTOBUNDLED, wasPosted, null); cancelNotificationLocked(removed, false, REASON_UNAUTOBUNDLED, wasPosted, null, SystemClock.elapsedRealtime()); } } } Loading Loading @@ -6481,7 +6485,8 @@ public class NotificationManagerService extends SystemService { } finally { Binder.restoreCallingIdentity(token); } mHandler.post(new EnqueueNotificationRunnable(userId, r, isAppForeground)); mHandler.post(new EnqueueNotificationRunnable(userId, r, isAppForeground, SystemClock.elapsedRealtime())); } private void onConversationRemovedInternal(String pkg, int uid, Set<String> shortcuts) { Loading Loading @@ -6625,7 +6630,8 @@ public class NotificationManagerService extends SystemService { r.getNotification().flags |= FLAG_ONLY_ALERT_ONCE; mHandler.post( new NotificationManagerService.EnqueueNotificationRunnable( r.getUser().getIdentifier(), r, isAppForeground)); r.getUser().getIdentifier(), r, isAppForeground, SystemClock.elapsedRealtime())); } } } Loading Loading @@ -6929,7 +6935,8 @@ public class NotificationManagerService extends SystemService { NotificationRecordLogger.NotificationEvent.NOTIFICATION_SNOOZED, r); reportUserInteraction(r); boolean wasPosted = removeFromNotificationListsLocked(r); cancelNotificationLocked(r, false, REASON_SNOOZED, wasPosted, null); cancelNotificationLocked(r, false, REASON_SNOOZED, wasPosted, null, SystemClock.elapsedRealtime()); updateLightsLocked(); if (mSnoozeCriterionId != null) { mAssistants.notifyAssistantSnoozedLocked(r, mSnoozeCriterionId); Loading @@ -6956,12 +6963,14 @@ public class NotificationManagerService extends SystemService { private final int mRank; private final int mCount; private final ManagedServiceInfo mListener; private final long mCancellationElapsedTimeMs; CancelNotificationRunnable(final int callingUid, final int callingPid, final String pkg, final String tag, final int id, final int mustHaveFlags, final int mustNotHaveFlags, final boolean sendDelete, final int userId, final int reason, int rank, int count, final ManagedServiceInfo listener) { final ManagedServiceInfo listener, @ElapsedRealtimeLong long cancellationElapsedTimeMs) { this.mCallingUid = callingUid; this.mCallingPid = callingPid; this.mPkg = pkg; Loading @@ -6975,6 +6984,7 @@ public class NotificationManagerService extends SystemService { this.mRank = rank; this.mCount = count; this.mListener = listener; this.mCancellationElapsedTimeMs = cancellationElapsedTimeMs; } @Override Loading Loading @@ -7037,9 +7047,11 @@ public class NotificationManagerService extends SystemService { // Cancel the notification. boolean wasPosted = removeFromNotificationListsLocked(r); cancelNotificationLocked( r, mSendDelete, mReason, mRank, mCount, wasPosted, listenerName); r, mSendDelete, mReason, mRank, mCount, wasPosted, listenerName, mCancellationElapsedTimeMs); cancelGroupChildrenLocked(r, mCallingUid, mCallingPid, listenerName, mSendDelete, childrenFlagChecker, mReason); mSendDelete, childrenFlagChecker, mReason, mCancellationElapsedTimeMs); updateLightsLocked(); if (mShortcutHelper != null) { mShortcutHelper.maybeListenForShortcutChangesForBubbles(r, Loading Loading @@ -7101,11 +7113,14 @@ public class NotificationManagerService extends SystemService { private final NotificationRecord r; private final int userId; private final boolean isAppForeground; private final long enqueueElapsedTimeMs; EnqueueNotificationRunnable(int userId, NotificationRecord r, boolean foreground) { EnqueueNotificationRunnable(int userId, NotificationRecord r, boolean foreground, @ElapsedRealtimeLong long enqueueElapsedTimeMs) { this.userId = userId; this.r = r; this.isAppForeground = foreground; this.enqueueElapsedTimeMs = enqueueElapsedTimeMs; } @Override Loading Loading @@ -7178,10 +7193,11 @@ public class NotificationManagerService extends SystemService { // tell the assistant service about the notification if (mAssistants.isEnabled()) { mAssistants.onNotificationEnqueuedLocked(r); mHandler.postDelayed(new PostNotificationRunnable(r.getKey()), mHandler.postDelayed( new PostNotificationRunnable(r.getKey(), enqueueElapsedTimeMs), DELAY_FOR_ASSISTANT_TIME); } else { mHandler.post(new PostNotificationRunnable(r.getKey())); mHandler.post(new PostNotificationRunnable(r.getKey(), enqueueElapsedTimeMs)); } } } Loading @@ -7204,9 +7220,11 @@ public class NotificationManagerService extends SystemService { protected class PostNotificationRunnable implements Runnable { private final String key; private final long postElapsedTimeMs; PostNotificationRunnable(String key) { PostNotificationRunnable(String key, @ElapsedRealtimeLong long postElapsedTimeMs) { this.key = key; this.postElapsedTimeMs = postElapsedTimeMs; } @Override Loading Loading @@ -7262,7 +7280,7 @@ public class NotificationManagerService extends SystemService { mNotificationList.add(r); mUsageStats.registerPostedByApp(r); mUsageStatsManagerInternal.reportNotificationPosted(r.getSbn().getOpPkg(), r.getSbn().getUser(), SystemClock.elapsedRealtime()); r.getSbn().getUser(), postElapsedTimeMs); final boolean isInterruptive = isVisuallyInterruptive(null, r); r.setInterruptive(isInterruptive); r.setTextChanged(isInterruptive); Loading @@ -7271,7 +7289,7 @@ public class NotificationManagerService extends SystemService { mNotificationList.set(index, r); mUsageStats.registerUpdatedByApp(r, old); mUsageStatsManagerInternal.reportNotificationUpdated(r.getSbn().getOpPkg(), r.getSbn().getUser(), SystemClock.elapsedRealtime()); r.getSbn().getUser(), postElapsedTimeMs); // Make sure we don't lose the foreground service state. notification.flags |= old.getNotification().flags & FLAG_FOREGROUND_SERVICE; Loading Loading @@ -7576,7 +7594,7 @@ public class NotificationManagerService extends SystemService { // notification was a summary and its group key changed. if (oldIsSummary && (!isSummary || !oldGroup.equals(group))) { cancelGroupChildrenLocked(old, callingUid, callingPid, null, false /* sendDelete */, childrenFlagChecker, REASON_APP_CANCEL); childrenFlagChecker, REASON_APP_CANCEL, SystemClock.elapsedRealtime()); } } Loading Loading @@ -8662,14 +8680,17 @@ public class NotificationManagerService extends SystemService { @GuardedBy("mNotificationLock") private void cancelNotificationLocked(NotificationRecord r, boolean sendDelete, @NotificationListenerService.NotificationCancelReason int reason, boolean wasPosted, String listenerName) { cancelNotificationLocked(r, sendDelete, reason, -1, -1, wasPosted, listenerName); boolean wasPosted, String listenerName, @ElapsedRealtimeLong long cancellationElapsedTimeMs) { cancelNotificationLocked(r, sendDelete, reason, -1, -1, wasPosted, listenerName, cancellationElapsedTimeMs); } @GuardedBy("mNotificationLock") private void cancelNotificationLocked(NotificationRecord r, boolean sendDelete, @NotificationListenerService.NotificationCancelReason int reason, int rank, int count, boolean wasPosted, String listenerName) { int rank, int count, boolean wasPosted, String listenerName, @ElapsedRealtimeLong long cancellationElapsedTimeMs) { final String canceledKey = r.getKey(); // Get pending intent used to create alarm, use FLAG_NO_CREATE if PendingIntent Loading Loading @@ -8755,7 +8776,7 @@ public class NotificationManagerService extends SystemService { case REASON_APP_CANCEL_ALL: mUsageStats.registerRemovedByApp(r); mUsageStatsManagerInternal.reportNotificationRemoved(r.getSbn().getOpPkg(), r.getUser(), SystemClock.elapsedRealtime()); r.getUser(), cancellationElapsedTimeMs); break; } Loading Loading @@ -8932,7 +8953,7 @@ public class NotificationManagerService extends SystemService { * and none of the {@code mustNotHaveFlags}. */ void cancelNotification(final int callingUid, final int callingPid, final String pkg, final String tag, final int id, final String pkg, final String tag, int id, final int mustHaveFlags, final int mustNotHaveFlags, final boolean sendDelete, final int userId, final int reason, final ManagedServiceInfo listener) { cancelNotification(callingUid, callingPid, pkg, tag, id, mustHaveFlags, mustNotHaveFlags, Loading @@ -8954,7 +8975,7 @@ public class NotificationManagerService extends SystemService { // remove notification call ends up in not removing the notification. mHandler.scheduleCancelNotification(new CancelNotificationRunnable(callingUid, callingPid, pkg, tag, id, mustHaveFlags, mustNotHaveFlags, sendDelete, userId, reason, rank, count, listener)); count, listener, SystemClock.elapsedRealtime())); } /** Loading Loading @@ -8988,6 +9009,7 @@ public class NotificationManagerService extends SystemService { void cancelAllNotificationsInt(int callingUid, int callingPid, String pkg, String channelId, int mustHaveFlags, int mustNotHaveFlags, boolean doit, int userId, int reason, ManagedServiceInfo listener) { final long cancellationElapsedTimeMs = SystemClock.elapsedRealtime(); mHandler.post(new Runnable() { @Override public void run() { Loading Loading @@ -9015,11 +9037,12 @@ public class NotificationManagerService extends SystemService { cancelAllNotificationsByListLocked(mNotificationList, callingUid, callingPid, pkg, true /*nullPkgIndicatesUserSwitch*/, channelId, flagChecker, false /*includeCurrentProfiles*/, userId, false /*sendDelete*/, reason, listenerName, true /* wasPosted */); listenerName, true /* wasPosted */, cancellationElapsedTimeMs); cancelAllNotificationsByListLocked(mEnqueuedNotifications, callingUid, callingPid, pkg, true /*nullPkgIndicatesUserSwitch*/, channelId, flagChecker, false /*includeCurrentProfiles*/, userId, false /*sendDelete*/, reason, listenerName, false /* wasPosted */); false /*sendDelete*/, reason, listenerName, false /* wasPosted */, cancellationElapsedTimeMs); mSnoozeHelper.cancel(userId, pkg); } } Loading @@ -9035,7 +9058,8 @@ public class NotificationManagerService extends SystemService { private void cancelAllNotificationsByListLocked(ArrayList<NotificationRecord> notificationList, int callingUid, int callingPid, String pkg, boolean nullPkgIndicatesUserSwitch, String channelId, FlagChecker flagChecker, boolean includeCurrentProfiles, int userId, boolean sendDelete, int reason, String listenerName, boolean wasPosted) { boolean sendDelete, int reason, String listenerName, boolean wasPosted, @ElapsedRealtimeLong long cancellationElapsedTimeMs) { Set<String> childNotifications = null; for (int i = notificationList.size() - 1; i >= 0; --i) { NotificationRecord r = notificationList.get(i); Loading Loading @@ -9069,7 +9093,8 @@ public class NotificationManagerService extends SystemService { notificationList.remove(i); mNotificationsByKey.remove(r.getKey()); r.recordDismissalSentiment(NotificationStats.DISMISS_SENTIMENT_NEUTRAL); cancelNotificationLocked(r, sendDelete, reason, wasPosted, listenerName); cancelNotificationLocked(r, sendDelete, reason, wasPosted, listenerName, cancellationElapsedTimeMs); } if (childNotifications != null) { final int M = notificationList.size(); Loading @@ -9081,7 +9106,8 @@ public class NotificationManagerService extends SystemService { notificationList.remove(i); mNotificationsByKey.remove(r.getKey()); r.recordDismissalSentiment(NotificationStats.DISMISS_SENTIMENT_NEUTRAL); cancelNotificationLocked(r, sendDelete, reason, wasPosted, listenerName); cancelNotificationLocked(r, sendDelete, reason, wasPosted, listenerName, cancellationElapsedTimeMs); } } updateLightsLocked(); Loading Loading @@ -9127,6 +9153,7 @@ public class NotificationManagerService extends SystemService { @GuardedBy("mNotificationLock") void cancelAllLocked(int callingUid, int callingPid, int userId, int reason, ManagedServiceInfo listener, boolean includeCurrentProfiles) { final long cancellationElapsedTimeMs = SystemClock.elapsedRealtime(); mHandler.post(new Runnable() { @Override public void run() { Loading @@ -9151,11 +9178,11 @@ public class NotificationManagerService extends SystemService { cancelAllNotificationsByListLocked(mNotificationList, callingUid, callingPid, null, false /*nullPkgIndicatesUserSwitch*/, null, flagChecker, includeCurrentProfiles, userId, true /*sendDelete*/, reason, listenerName, true); listenerName, true, cancellationElapsedTimeMs); cancelAllNotificationsByListLocked(mEnqueuedNotifications, callingUid, callingPid, null, false /*nullPkgIndicatesUserSwitch*/, null, flagChecker, includeCurrentProfiles, userId, true /*sendDelete*/, reason, listenerName, false); reason, listenerName, false, cancellationElapsedTimeMs); mSnoozeHelper.cancel(userId, includeCurrentProfiles); } } Loading @@ -9165,7 +9192,8 @@ public class NotificationManagerService extends SystemService { // Warning: The caller is responsible for invoking updateLightsLocked(). @GuardedBy("mNotificationLock") private void cancelGroupChildrenLocked(NotificationRecord r, int callingUid, int callingPid, String listenerName, boolean sendDelete, FlagChecker flagChecker, int reason) { String listenerName, boolean sendDelete, FlagChecker flagChecker, int reason, @ElapsedRealtimeLong long cancellationElapsedTimeMs) { Notification n = r.getNotification(); if (!n.isGroupSummary()) { return; Loading @@ -9179,16 +9207,16 @@ public class NotificationManagerService extends SystemService { } cancelGroupChildrenByListLocked(mNotificationList, r, callingUid, callingPid, listenerName, sendDelete, true, flagChecker, reason); sendDelete, true, flagChecker, reason, cancellationElapsedTimeMs); cancelGroupChildrenByListLocked(mEnqueuedNotifications, r, callingUid, callingPid, listenerName, sendDelete, false, flagChecker, reason); listenerName, sendDelete, false, flagChecker, reason, cancellationElapsedTimeMs); } @GuardedBy("mNotificationLock") private void cancelGroupChildrenByListLocked(ArrayList<NotificationRecord> notificationList, NotificationRecord parentNotification, int callingUid, int callingPid, String listenerName, boolean sendDelete, boolean wasPosted, FlagChecker flagChecker, int reason) { int reason, @ElapsedRealtimeLong long cancellationElapsedTimeMs) { final String pkg = parentNotification.getSbn().getPackageName(); final int userId = parentNotification.getUserId(); final int childReason = REASON_GROUP_SUMMARY_CANCELED; Loading @@ -9204,7 +9232,8 @@ public class NotificationManagerService extends SystemService { childSbn.getTag(), userId, 0, 0, childReason, listenerName); notificationList.remove(i); mNotificationsByKey.remove(childR.getKey()); cancelNotificationLocked(childR, sendDelete, childReason, wasPosted, listenerName); cancelNotificationLocked(childR, sendDelete, childReason, wasPosted, listenerName, cancellationElapsedTimeMs); } } } Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +13 −10 Original line number Diff line number Diff line Loading @@ -1335,7 +1335,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mBinderService.applyEnqueuedAdjustmentFromAssistant(null, adjustment); NotificationManagerService.PostNotificationRunnable runnable = mService.new PostNotificationRunnable(r.getKey()); mService.new PostNotificationRunnable(r.getKey(), SystemClock.elapsedRealtime()); runnable.run(); waitForIdle(); Loading @@ -1356,7 +1356,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { when(mPreferencesHelper.getImportance(anyString(), anyInt())).thenReturn(IMPORTANCE_NONE); NotificationManagerService.PostNotificationRunnable runnable = mService.new PostNotificationRunnable(r.getKey()); mService.new PostNotificationRunnable(r.getKey(), SystemClock.elapsedRealtime()); runnable.run(); waitForIdle(); Loading Loading @@ -3918,7 +3918,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { NotificationRecord r = generateNotificationRecord(mTestNotificationChannel, 0, null, false); mService.addEnqueuedNotification(r); NotificationManagerService.PostNotificationRunnable runnable = mService.new PostNotificationRunnable(r.getKey()); mService.new PostNotificationRunnable(r.getKey(), SystemClock.elapsedRealtime()); runnable.run(); waitForIdle(); Loading @@ -3935,7 +3935,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { r = generateNotificationRecord(mTestNotificationChannel, 0, null, false); mService.addEnqueuedNotification(r); NotificationManagerService.PostNotificationRunnable runnable = mService.new PostNotificationRunnable(r.getKey()); mService.new PostNotificationRunnable(r.getKey(), SystemClock.elapsedRealtime()); runnable.run(); waitForIdle(); Loading @@ -3951,7 +3951,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.addEnqueuedNotification(r); NotificationManagerService.PostNotificationRunnable runnable = mService.new PostNotificationRunnable(r.getKey()); mService.new PostNotificationRunnable(r.getKey(), SystemClock.elapsedRealtime()); runnable.run(); waitForIdle(); Loading @@ -3964,12 +3964,12 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { r.setCriticality(CriticalNotificationExtractor.CRITICAL_LOW); mService.addEnqueuedNotification(r); NotificationManagerService.PostNotificationRunnable runnable = mService.new PostNotificationRunnable(r.getKey()); mService.new PostNotificationRunnable(r.getKey(), SystemClock.elapsedRealtime()); runnable.run(); r = generateNotificationRecord(mTestNotificationChannel, 1, null, false); r.setCriticality(CriticalNotificationExtractor.CRITICAL); runnable = mService.new PostNotificationRunnable(r.getKey()); runnable = mService.new PostNotificationRunnable(r.getKey(), SystemClock.elapsedRealtime()); mService.addEnqueuedNotification(r); runnable.run(); Loading Loading @@ -4412,7 +4412,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.addEnqueuedNotification(original); NotificationManagerService.PostNotificationRunnable runnable = mService.new PostNotificationRunnable(original.getKey()); mService.new PostNotificationRunnable(original.getKey(), SystemClock.elapsedRealtime()); runnable.run(); waitForIdle(); Loading @@ -4433,7 +4434,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.addEnqueuedNotification(update); NotificationManagerService.PostNotificationRunnable runnable = mService.new PostNotificationRunnable(update.getKey()); mService.new PostNotificationRunnable(update.getKey(), SystemClock.elapsedRealtime()); runnable.run(); waitForIdle(); Loading Loading @@ -6475,7 +6477,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertNull(update.getSbn().getNotification().getSmallIcon()); NotificationManagerService.PostNotificationRunnable runnable = mService.new PostNotificationRunnable(update.getKey()); mService.new PostNotificationRunnable(update.getKey(), SystemClock.elapsedRealtime()); runnable.run(); waitForIdle(); Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationPermissionMigrationTest.java +5 −4 Original line number Diff line number Diff line Loading @@ -91,6 +91,7 @@ import android.os.IBinder; import android.os.Looper; import android.os.Process; import android.os.RemoteException; import android.os.SystemClock; import android.os.UserHandle; import android.os.UserManager; import android.provider.Settings; Loading Loading @@ -656,7 +657,7 @@ public class NotificationPermissionMigrationTest extends UiServiceTestCase { when(mPermissionHelper.hasPermission(anyInt())).thenReturn(false); NotificationManagerService.PostNotificationRunnable runnable = mService.new PostNotificationRunnable(r.getKey()); mService.new PostNotificationRunnable(r.getKey(), SystemClock.elapsedRealtime()); runnable.run(); waitForIdle(); Loading Loading @@ -789,7 +790,7 @@ public class NotificationPermissionMigrationTest extends UiServiceTestCase { mService.addEnqueuedNotification(r); NotificationManagerService.PostNotificationRunnable runnable = mService.new PostNotificationRunnable(r.getKey()); mService.new PostNotificationRunnable(r.getKey(), SystemClock.elapsedRealtime()); runnable.run(); waitForIdle(); Loading @@ -805,7 +806,7 @@ public class NotificationPermissionMigrationTest extends UiServiceTestCase { r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); mService.addEnqueuedNotification(r); runnable = mService.new PostNotificationRunnable(r.getKey()); runnable = mService.new PostNotificationRunnable(r.getKey(), SystemClock.elapsedRealtime()); runnable.run(); waitForIdle(); Loading @@ -821,7 +822,7 @@ public class NotificationPermissionMigrationTest extends UiServiceTestCase { r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); mService.addEnqueuedNotification(r); runnable = mService.new PostNotificationRunnable(r.getKey()); runnable = mService.new PostNotificationRunnable(r.getKey(), SystemClock.elapsedRealtime()); runnable.run(); waitForIdle(); Loading