Loading services/core/java/com/android/server/notification/NotificationManagerService.java +9 −93 Original line number Diff line number Diff line Loading @@ -2043,7 +2043,6 @@ public class NotificationManagerService extends SystemService { } @Override @FlaggedApi(Flags.FLAG_ALL_NOTIFS_NEED_TTL) public void timeoutNotification(String key) { boolean foundNotification = false; int uid = 0; Loading Loading @@ -2163,41 +2162,6 @@ public class NotificationManagerService extends SystemService { } }; private final BroadcastReceiver mNotificationTimeoutReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action == null) { return; } if (ACTION_NOTIFICATION_TIMEOUT.equals(action)) { final NotificationRecord record; // TODO: b/323013410 - Record should be cloned instead of used directly. synchronized (mNotificationLock) { record = findNotificationByKeyLocked(intent.getStringExtra(EXTRA_KEY)); } if (record != null) { if (lifetimeExtensionRefactor()) { cancelNotification(record.getSbn().getUid(), record.getSbn().getInitialPid(), record.getSbn().getPackageName(), record.getSbn().getTag(), record.getSbn().getId(), 0, FLAG_FOREGROUND_SERVICE | FLAG_USER_INITIATED_JOB | FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY, true, record.getUserId(), REASON_TIMEOUT, null); } else { cancelNotification(record.getSbn().getUid(), record.getSbn().getInitialPid(), record.getSbn().getPackageName(), record.getSbn().getTag(), record.getSbn().getId(), 0, FLAG_FOREGROUND_SERVICE | FLAG_USER_INITIATED_JOB, true, record.getUserId(), REASON_TIMEOUT, null); } } } } }; private final BroadcastReceiver mPackageIntentReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Loading Loading @@ -2835,9 +2799,7 @@ public class NotificationManagerService extends SystemService { mSnoozeHelper = snoozeHelper; mGroupHelper = groupHelper; mHistoryManager = historyManager; if (Flags.allNotifsNeedTtl()) { mTtlHelper = new TimeToLiveHelper(mNotificationManagerPrivate, getContext()); } // This is a ManagedServices object that keeps track of the listeners. mListeners = notificationListeners; Loading Loading @@ -2926,13 +2888,6 @@ public class NotificationManagerService extends SystemService { getContext().registerReceiverAsUser(mPackageIntentReceiver, UserHandle.ALL, sdFilter, null, null); if (!Flags.allNotifsNeedTtl()) { IntentFilter timeoutFilter = new IntentFilter(ACTION_NOTIFICATION_TIMEOUT); timeoutFilter.addDataScheme(SCHEME_TIMEOUT); getContext().registerReceiver(mNotificationTimeoutReceiver, timeoutFilter, Context.RECEIVER_EXPORTED_UNAUDITED); } IntentFilter settingsRestoredFilter = new IntentFilter(Intent.ACTION_SETTING_RESTORED); getContext().registerReceiver(mRestoreReceiver, settingsRestoredFilter); Loading Loading @@ -2966,15 +2921,9 @@ public class NotificationManagerService extends SystemService { if (mPackageIntentReceiver != null) { getContext().unregisterReceiver(mPackageIntentReceiver); } if (Flags.allNotifsNeedTtl()) { if (mTtlHelper != null) { mTtlHelper.destroy(); } } else { if (mNotificationTimeoutReceiver != null) { getContext().unregisterReceiver(mNotificationTimeoutReceiver); } } if (mRestoreReceiver != null) { getContext().unregisterReceiver(mRestoreReceiver); } Loading Loading @@ -8021,11 +7970,9 @@ public class NotificationManagerService extends SystemService { pw.println("\n Usage Stats:"); mUsageStats.dump(pw, " ", filter); if (Flags.allNotifsNeedTtl()) { pw.println("\n TimeToLive alarms:"); mTtlHelper.dump(pw, " "); } } if (notificationForceGrouping()) { pw.println("\n GroupHelper:"); Loading Loading @@ -8860,11 +8807,9 @@ public class NotificationManagerService extends SystemService { // Remote views? Are they too big? checkRemoteViews(pkg, tag, id, notification); if (Flags.allNotifsNeedTtl()) { if (notification.getTimeoutAfter() == 0) { notification.setTimeoutAfter(NOTIFICATION_TTL); } } if (notificationForceGrouping()) { notification.fixSilentGroup(); Loading Loading @@ -9679,11 +9624,7 @@ public class NotificationManagerService extends SystemService { } mEnqueuedNotifications.add(r); if (Flags.allNotifsNeedTtl()) { mTtlHelper.scheduleTimeoutLocked(r, SystemClock.elapsedRealtime()); } else { scheduleTimeoutLocked(r); } final StatusBarNotification n = r.getSbn(); if (DBG) Slog.d(TAG, "EnqueueNotificationRunnable.run for: " + n.getKey()); Loading Loading @@ -10292,27 +10233,6 @@ public class NotificationManagerService extends SystemService { flags); } @VisibleForTesting @GuardedBy("mNotificationLock") void scheduleTimeoutLocked(NotificationRecord record) { if (record.getNotification().getTimeoutAfter() > 0) { final PendingIntent pi = getNotificationTimeoutPendingIntent( record, PendingIntent.FLAG_UPDATE_CURRENT); mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + record.getNotification().getTimeoutAfter(), pi); } } @VisibleForTesting @GuardedBy("mNotificationLock") void cancelScheduledTimeoutLocked(NotificationRecord record) { final PendingIntent pi = getNotificationTimeoutPendingIntent( record, PendingIntent.FLAG_CANCEL_CURRENT); if (pi != null) { mAlarmManager.cancel(pi); } } @GuardedBy("mToastQueue") void showNextToastLocked(boolean lastToastWasTextRecord) { if (mIsCurrentToastShown) { Loading Loading @@ -10883,11 +10803,7 @@ public class NotificationManagerService extends SystemService { int rank, int count, boolean wasPosted, String listenerName, @ElapsedRealtimeLong long cancellationElapsedTimeMs) { final String canceledKey = r.getKey(); if (Flags.allNotifsNeedTtl()) { mTtlHelper.cancelScheduledTimeoutLocked(r); } else { cancelScheduledTimeoutLocked(r); } // Record caller. recordCallerLocked(r); Loading services/core/java/com/android/server/notification/TimeToLiveHelper.java +0 −1 Original line number Diff line number Diff line Loading @@ -41,7 +41,6 @@ import java.util.TreeSet; /** * Handles canceling notifications when their time to live expires */ @FlaggedApi(Flags.FLAG_ALL_NOTIFS_NEED_TTL) public class TimeToLiveHelper { private static final String TAG = TimeToLiveHelper.class.getSimpleName(); private static final String ACTION = "com.android.server.notification.TimeToLiveHelper"; Loading services/core/java/com/android/server/notification/flags.aconfig +0 −7 Original line number Diff line number Diff line Loading @@ -81,13 +81,6 @@ flag { bug: "270456865" } flag { name: "all_notifs_need_ttl" namespace: "systemui" description: "This flag sets a TTL on all notifications that don't already have an app provided one" bug: "331967355" } flag { name: "persist_incomplete_restore_data" namespace: "systemui" Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +1 −42 Original line number Diff line number Diff line Loading @@ -141,7 +141,6 @@ import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STR import static com.android.server.am.PendingIntentRecord.FLAG_ACTIVITY_SENDER; import static com.android.server.am.PendingIntentRecord.FLAG_BROADCAST_SENDER; import static com.android.server.am.PendingIntentRecord.FLAG_SERVICE_SENDER; import static com.android.server.notification.Flags.FLAG_ALL_NOTIFS_NEED_TTL; import static com.android.server.notification.Flags.FLAG_LOG_CACHED_POSTS; import static com.android.server.notification.Flags.FLAG_MANAGED_SERVICES_CONCURRENT_MULTIUSER; import static com.android.server.notification.Flags.FLAG_REJECT_OLD_NOTIFICATIONS; Loading Loading @@ -895,10 +894,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { } assertNotNull("package intent receiver should exist", mPackageIntentReceiver); assertNotNull("User receiver should exist", mUserIntentReceiver); if (!Flags.allNotifsNeedTtl()) { assertNotNull("Notification timeout receiver should exist", mNotificationTimeoutReceiver); } // Pretend the shortcut exists List<ShortcutInfo> shortcutInfos = new ArrayList<>(); Loading Loading @@ -1496,32 +1491,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { eq(TOAST_DURATION), any(), eq(displayId)); } @Test @DisableFlags(FLAG_ALL_NOTIFS_NEED_TTL) public void testLimitTimeOutBroadcast() { NotificationChannel channel = new NotificationChannel("id", "name", NotificationManager.IMPORTANCE_HIGH); Notification.Builder nb = new Notification.Builder(mContext, channel.getId()) .setContentTitle("foo") .setSmallIcon(android.R.drawable.sym_def_app_icon) .setTimeoutAfter(1); StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 8, "tag", mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, channel); mService.scheduleTimeoutLocked(r); ArgumentCaptor<PendingIntent> captor = ArgumentCaptor.forClass(PendingIntent.class); verify(mAlarmManager).setExactAndAllowWhileIdle(anyInt(), anyLong(), captor.capture()); assertEquals(PackageManagerService.PLATFORM_PACKAGE_NAME, captor.getValue().getIntent().getPackage()); mService.cancelScheduledTimeoutLocked(r); verify(mAlarmManager).cancel(captor.capture()); assertEquals(PackageManagerService.PLATFORM_PACKAGE_NAME, captor.getValue().getIntent().getPackage()); } @Test public void testDefaultAssistant_overrideDefault() { final int userId = mContext.getUserId(); Loading Loading @@ -7011,15 +6980,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { } private void simulateNotificationTimeout(String notificationKey) { if (Flags.allNotifsNeedTtl()) { mService.mNotificationManagerPrivate.timeoutNotification(notificationKey); } else { final Bundle extras = new Bundle(); extras.putString(EXTRA_KEY, notificationKey); final Intent intent = new Intent(ACTION_NOTIFICATION_TIMEOUT); intent.putExtras(extras); mNotificationTimeoutReceiver.onReceive(getContext(), intent); } } @Test Loading Loading @@ -17452,7 +17413,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { } @Test @EnableFlags(FLAG_ALL_NOTIFS_NEED_TTL) public void testFixNotification_missingTtl() throws Exception { Notification n = new Notification.Builder(mContext, mTestNotificationChannel.getId()) .setSmallIcon(android.R.drawable.sym_def_app_icon) Loading @@ -17464,7 +17424,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { } @Test @EnableFlags(FLAG_ALL_NOTIFS_NEED_TTL) public void testFixNotification_doesNotOverwriteTtl() throws Exception { Notification n = new Notification.Builder(mContext, mTestNotificationChannel.getId()) .setSmallIcon(android.R.drawable.sym_def_app_icon) Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +9 −93 Original line number Diff line number Diff line Loading @@ -2043,7 +2043,6 @@ public class NotificationManagerService extends SystemService { } @Override @FlaggedApi(Flags.FLAG_ALL_NOTIFS_NEED_TTL) public void timeoutNotification(String key) { boolean foundNotification = false; int uid = 0; Loading Loading @@ -2163,41 +2162,6 @@ public class NotificationManagerService extends SystemService { } }; private final BroadcastReceiver mNotificationTimeoutReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action == null) { return; } if (ACTION_NOTIFICATION_TIMEOUT.equals(action)) { final NotificationRecord record; // TODO: b/323013410 - Record should be cloned instead of used directly. synchronized (mNotificationLock) { record = findNotificationByKeyLocked(intent.getStringExtra(EXTRA_KEY)); } if (record != null) { if (lifetimeExtensionRefactor()) { cancelNotification(record.getSbn().getUid(), record.getSbn().getInitialPid(), record.getSbn().getPackageName(), record.getSbn().getTag(), record.getSbn().getId(), 0, FLAG_FOREGROUND_SERVICE | FLAG_USER_INITIATED_JOB | FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY, true, record.getUserId(), REASON_TIMEOUT, null); } else { cancelNotification(record.getSbn().getUid(), record.getSbn().getInitialPid(), record.getSbn().getPackageName(), record.getSbn().getTag(), record.getSbn().getId(), 0, FLAG_FOREGROUND_SERVICE | FLAG_USER_INITIATED_JOB, true, record.getUserId(), REASON_TIMEOUT, null); } } } } }; private final BroadcastReceiver mPackageIntentReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Loading Loading @@ -2835,9 +2799,7 @@ public class NotificationManagerService extends SystemService { mSnoozeHelper = snoozeHelper; mGroupHelper = groupHelper; mHistoryManager = historyManager; if (Flags.allNotifsNeedTtl()) { mTtlHelper = new TimeToLiveHelper(mNotificationManagerPrivate, getContext()); } // This is a ManagedServices object that keeps track of the listeners. mListeners = notificationListeners; Loading Loading @@ -2926,13 +2888,6 @@ public class NotificationManagerService extends SystemService { getContext().registerReceiverAsUser(mPackageIntentReceiver, UserHandle.ALL, sdFilter, null, null); if (!Flags.allNotifsNeedTtl()) { IntentFilter timeoutFilter = new IntentFilter(ACTION_NOTIFICATION_TIMEOUT); timeoutFilter.addDataScheme(SCHEME_TIMEOUT); getContext().registerReceiver(mNotificationTimeoutReceiver, timeoutFilter, Context.RECEIVER_EXPORTED_UNAUDITED); } IntentFilter settingsRestoredFilter = new IntentFilter(Intent.ACTION_SETTING_RESTORED); getContext().registerReceiver(mRestoreReceiver, settingsRestoredFilter); Loading Loading @@ -2966,15 +2921,9 @@ public class NotificationManagerService extends SystemService { if (mPackageIntentReceiver != null) { getContext().unregisterReceiver(mPackageIntentReceiver); } if (Flags.allNotifsNeedTtl()) { if (mTtlHelper != null) { mTtlHelper.destroy(); } } else { if (mNotificationTimeoutReceiver != null) { getContext().unregisterReceiver(mNotificationTimeoutReceiver); } } if (mRestoreReceiver != null) { getContext().unregisterReceiver(mRestoreReceiver); } Loading Loading @@ -8021,11 +7970,9 @@ public class NotificationManagerService extends SystemService { pw.println("\n Usage Stats:"); mUsageStats.dump(pw, " ", filter); if (Flags.allNotifsNeedTtl()) { pw.println("\n TimeToLive alarms:"); mTtlHelper.dump(pw, " "); } } if (notificationForceGrouping()) { pw.println("\n GroupHelper:"); Loading Loading @@ -8860,11 +8807,9 @@ public class NotificationManagerService extends SystemService { // Remote views? Are they too big? checkRemoteViews(pkg, tag, id, notification); if (Flags.allNotifsNeedTtl()) { if (notification.getTimeoutAfter() == 0) { notification.setTimeoutAfter(NOTIFICATION_TTL); } } if (notificationForceGrouping()) { notification.fixSilentGroup(); Loading Loading @@ -9679,11 +9624,7 @@ public class NotificationManagerService extends SystemService { } mEnqueuedNotifications.add(r); if (Flags.allNotifsNeedTtl()) { mTtlHelper.scheduleTimeoutLocked(r, SystemClock.elapsedRealtime()); } else { scheduleTimeoutLocked(r); } final StatusBarNotification n = r.getSbn(); if (DBG) Slog.d(TAG, "EnqueueNotificationRunnable.run for: " + n.getKey()); Loading Loading @@ -10292,27 +10233,6 @@ public class NotificationManagerService extends SystemService { flags); } @VisibleForTesting @GuardedBy("mNotificationLock") void scheduleTimeoutLocked(NotificationRecord record) { if (record.getNotification().getTimeoutAfter() > 0) { final PendingIntent pi = getNotificationTimeoutPendingIntent( record, PendingIntent.FLAG_UPDATE_CURRENT); mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + record.getNotification().getTimeoutAfter(), pi); } } @VisibleForTesting @GuardedBy("mNotificationLock") void cancelScheduledTimeoutLocked(NotificationRecord record) { final PendingIntent pi = getNotificationTimeoutPendingIntent( record, PendingIntent.FLAG_CANCEL_CURRENT); if (pi != null) { mAlarmManager.cancel(pi); } } @GuardedBy("mToastQueue") void showNextToastLocked(boolean lastToastWasTextRecord) { if (mIsCurrentToastShown) { Loading Loading @@ -10883,11 +10803,7 @@ public class NotificationManagerService extends SystemService { int rank, int count, boolean wasPosted, String listenerName, @ElapsedRealtimeLong long cancellationElapsedTimeMs) { final String canceledKey = r.getKey(); if (Flags.allNotifsNeedTtl()) { mTtlHelper.cancelScheduledTimeoutLocked(r); } else { cancelScheduledTimeoutLocked(r); } // Record caller. recordCallerLocked(r); Loading
services/core/java/com/android/server/notification/TimeToLiveHelper.java +0 −1 Original line number Diff line number Diff line Loading @@ -41,7 +41,6 @@ import java.util.TreeSet; /** * Handles canceling notifications when their time to live expires */ @FlaggedApi(Flags.FLAG_ALL_NOTIFS_NEED_TTL) public class TimeToLiveHelper { private static final String TAG = TimeToLiveHelper.class.getSimpleName(); private static final String ACTION = "com.android.server.notification.TimeToLiveHelper"; Loading
services/core/java/com/android/server/notification/flags.aconfig +0 −7 Original line number Diff line number Diff line Loading @@ -81,13 +81,6 @@ flag { bug: "270456865" } flag { name: "all_notifs_need_ttl" namespace: "systemui" description: "This flag sets a TTL on all notifications that don't already have an app provided one" bug: "331967355" } flag { name: "persist_incomplete_restore_data" namespace: "systemui" Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +1 −42 Original line number Diff line number Diff line Loading @@ -141,7 +141,6 @@ import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STR import static com.android.server.am.PendingIntentRecord.FLAG_ACTIVITY_SENDER; import static com.android.server.am.PendingIntentRecord.FLAG_BROADCAST_SENDER; import static com.android.server.am.PendingIntentRecord.FLAG_SERVICE_SENDER; import static com.android.server.notification.Flags.FLAG_ALL_NOTIFS_NEED_TTL; import static com.android.server.notification.Flags.FLAG_LOG_CACHED_POSTS; import static com.android.server.notification.Flags.FLAG_MANAGED_SERVICES_CONCURRENT_MULTIUSER; import static com.android.server.notification.Flags.FLAG_REJECT_OLD_NOTIFICATIONS; Loading Loading @@ -895,10 +894,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { } assertNotNull("package intent receiver should exist", mPackageIntentReceiver); assertNotNull("User receiver should exist", mUserIntentReceiver); if (!Flags.allNotifsNeedTtl()) { assertNotNull("Notification timeout receiver should exist", mNotificationTimeoutReceiver); } // Pretend the shortcut exists List<ShortcutInfo> shortcutInfos = new ArrayList<>(); Loading Loading @@ -1496,32 +1491,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { eq(TOAST_DURATION), any(), eq(displayId)); } @Test @DisableFlags(FLAG_ALL_NOTIFS_NEED_TTL) public void testLimitTimeOutBroadcast() { NotificationChannel channel = new NotificationChannel("id", "name", NotificationManager.IMPORTANCE_HIGH); Notification.Builder nb = new Notification.Builder(mContext, channel.getId()) .setContentTitle("foo") .setSmallIcon(android.R.drawable.sym_def_app_icon) .setTimeoutAfter(1); StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 8, "tag", mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, channel); mService.scheduleTimeoutLocked(r); ArgumentCaptor<PendingIntent> captor = ArgumentCaptor.forClass(PendingIntent.class); verify(mAlarmManager).setExactAndAllowWhileIdle(anyInt(), anyLong(), captor.capture()); assertEquals(PackageManagerService.PLATFORM_PACKAGE_NAME, captor.getValue().getIntent().getPackage()); mService.cancelScheduledTimeoutLocked(r); verify(mAlarmManager).cancel(captor.capture()); assertEquals(PackageManagerService.PLATFORM_PACKAGE_NAME, captor.getValue().getIntent().getPackage()); } @Test public void testDefaultAssistant_overrideDefault() { final int userId = mContext.getUserId(); Loading Loading @@ -7011,15 +6980,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { } private void simulateNotificationTimeout(String notificationKey) { if (Flags.allNotifsNeedTtl()) { mService.mNotificationManagerPrivate.timeoutNotification(notificationKey); } else { final Bundle extras = new Bundle(); extras.putString(EXTRA_KEY, notificationKey); final Intent intent = new Intent(ACTION_NOTIFICATION_TIMEOUT); intent.putExtras(extras); mNotificationTimeoutReceiver.onReceive(getContext(), intent); } } @Test Loading Loading @@ -17452,7 +17413,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { } @Test @EnableFlags(FLAG_ALL_NOTIFS_NEED_TTL) public void testFixNotification_missingTtl() throws Exception { Notification n = new Notification.Builder(mContext, mTestNotificationChannel.getId()) .setSmallIcon(android.R.drawable.sym_def_app_icon) Loading @@ -17464,7 +17424,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { } @Test @EnableFlags(FLAG_ALL_NOTIFS_NEED_TTL) public void testFixNotification_doesNotOverwriteTtl() throws Exception { Notification n = new Notification.Builder(mContext, mTestNotificationChannel.getId()) .setSmallIcon(android.R.drawable.sym_def_app_icon)