Loading core/java/android/app/Notification.java +7 −0 Original line number Diff line number Diff line Loading @@ -3806,6 +3806,13 @@ public class Notification implements Parcelable return mTimeout; } /** * @hide */ public void setTimeoutAfter(long timeout) { mTimeout = timeout; } /** * Returns what icon should be shown for this notification if it is being displayed in a * Launcher that supports badging. Will be one of {@link #BADGE_ICON_NONE}, Loading services/core/java/com/android/server/notification/NotificationManagerService.java +8 −0 Original line number Diff line number Diff line Loading @@ -590,6 +590,8 @@ public class NotificationManagerService extends SystemService { private static final Duration POST_WAKE_LOCK_TIMEOUT = Duration.ofSeconds(30); static final long NOTIFICATION_TTL = Duration.ofDays(3).toMillis(); private IActivityManager mAm; private ActivityTaskManagerInternal mAtm; private ActivityManager mActivityManager; Loading Loading @@ -7581,6 +7583,12 @@ 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); } } } /** Loading services/core/java/com/android/server/notification/flags.aconfig +8 −0 Original line number Diff line number Diff line Loading @@ -86,3 +86,11 @@ flag { description: "This flag controls the polite notification attention behavior updates as per UXR feedback" 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" } services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +26 −0 Original line number Diff line number Diff line Loading @@ -112,6 +112,7 @@ 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.NotificationManagerService.BITMAP_DURATION; import static com.android.server.notification.NotificationManagerService.DEFAULT_MAX_NOTIFICATION_ENQUEUE_RATE; import static com.android.server.notification.NotificationManagerService.NOTIFICATION_TTL; import static com.android.server.notification.NotificationRecordLogger.NotificationReportedEvent.NOTIFICATION_ADJUSTED; import static com.android.server.notification.NotificationRecordLogger.NotificationReportedEvent.NOTIFICATION_POSTED; import static com.android.server.notification.NotificationRecordLogger.NotificationReportedEvent.NOTIFICATION_UPDATED; Loading Loading @@ -14898,6 +14899,31 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .isEqualTo(USAGE_NOTIFICATION); } @Test @EnableFlags(Flags.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) .build(); mService.fixNotification(n, mPkg, "tag", 0, mUserId, mUid, NOT_FOREGROUND_SERVICE, true); assertThat(n.getTimeoutAfter()).isEqualTo(NOTIFICATION_TTL); } @Test @EnableFlags(Flags.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) .setTimeoutAfter(20) .build(); mService.fixNotification(n, mPkg, "tag", 0, mUserId, mUid, NOT_FOREGROUND_SERVICE, true); assertThat(n.getTimeoutAfter()).isEqualTo(20); } private NotificationRecord createAndPostCallStyleNotification(String packageName, UserHandle userHandle, String testName) throws Exception { Person person = new Person.Builder().setName("caller").build(); Loading
core/java/android/app/Notification.java +7 −0 Original line number Diff line number Diff line Loading @@ -3806,6 +3806,13 @@ public class Notification implements Parcelable return mTimeout; } /** * @hide */ public void setTimeoutAfter(long timeout) { mTimeout = timeout; } /** * Returns what icon should be shown for this notification if it is being displayed in a * Launcher that supports badging. Will be one of {@link #BADGE_ICON_NONE}, Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +8 −0 Original line number Diff line number Diff line Loading @@ -590,6 +590,8 @@ public class NotificationManagerService extends SystemService { private static final Duration POST_WAKE_LOCK_TIMEOUT = Duration.ofSeconds(30); static final long NOTIFICATION_TTL = Duration.ofDays(3).toMillis(); private IActivityManager mAm; private ActivityTaskManagerInternal mAtm; private ActivityManager mActivityManager; Loading Loading @@ -7581,6 +7583,12 @@ 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); } } } /** Loading
services/core/java/com/android/server/notification/flags.aconfig +8 −0 Original line number Diff line number Diff line Loading @@ -86,3 +86,11 @@ flag { description: "This flag controls the polite notification attention behavior updates as per UXR feedback" 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" }
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +26 −0 Original line number Diff line number Diff line Loading @@ -112,6 +112,7 @@ 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.NotificationManagerService.BITMAP_DURATION; import static com.android.server.notification.NotificationManagerService.DEFAULT_MAX_NOTIFICATION_ENQUEUE_RATE; import static com.android.server.notification.NotificationManagerService.NOTIFICATION_TTL; import static com.android.server.notification.NotificationRecordLogger.NotificationReportedEvent.NOTIFICATION_ADJUSTED; import static com.android.server.notification.NotificationRecordLogger.NotificationReportedEvent.NOTIFICATION_POSTED; import static com.android.server.notification.NotificationRecordLogger.NotificationReportedEvent.NOTIFICATION_UPDATED; Loading Loading @@ -14898,6 +14899,31 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .isEqualTo(USAGE_NOTIFICATION); } @Test @EnableFlags(Flags.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) .build(); mService.fixNotification(n, mPkg, "tag", 0, mUserId, mUid, NOT_FOREGROUND_SERVICE, true); assertThat(n.getTimeoutAfter()).isEqualTo(NOTIFICATION_TTL); } @Test @EnableFlags(Flags.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) .setTimeoutAfter(20) .build(); mService.fixNotification(n, mPkg, "tag", 0, mUserId, mUid, NOT_FOREGROUND_SERVICE, true); assertThat(n.getTimeoutAfter()).isEqualTo(20); } private NotificationRecord createAndPostCallStyleNotification(String packageName, UserHandle userHandle, String testName) throws Exception { Person person = new Person.Builder().setName("caller").build();