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

Commit 196da336 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Remove all_notifs_need_ttl flag

Test: TH
Flag: EXEMPT bug fix
Fixes: 409610810
Change-Id: Ieb9a296e581e7076df43ad49684e449ca3c05ff7
parent 7a270552
Loading
Loading
Loading
Loading
+9 −93
Original line number Diff line number Diff line
@@ -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;
@@ -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) {
@@ -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;
@@ -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);
@@ -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);
        }
@@ -8023,11 +7972,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:");
@@ -8862,11 +8809,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();
@@ -9681,11 +9626,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());
@@ -10328,27 +10269,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) {
@@ -10919,11 +10839,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);
+0 −1
Original line number Diff line number Diff line
@@ -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";
+0 −7
Original line number Diff line number Diff line
@@ -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"
+1 −42
Original line number Diff line number Diff line
@@ -142,7 +142,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;
@@ -896,10 +895,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<>();
@@ -1497,32 +1492,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();
@@ -7019,15 +6988,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
@@ -17461,7 +17422,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)
@@ -17473,7 +17433,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)