Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3a79b1d7 authored by Julia Reynolds's avatar Julia Reynolds Committed by Android (Google) Code Review
Browse files

Merge "Set a 3 day TTL on all notifications without a TTL" into main

parents 60c96d24 4dcfd601
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -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},
+8 −0
Original line number Diff line number Diff line
@@ -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;
@@ -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);
            }
        }
    }
    /**
+8 −0
Original line number Diff line number Diff line
@@ -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"
}
+26 −0
Original line number Diff line number Diff line
@@ -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;
@@ -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();