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

Commit c785c4fa authored by Steve Elliott's avatar Steve Elliott
Browse files

Remove dead code from NotifEntryManager

All removed code is unused; since all changes are relegated to
NotificationEntryManager.java, if this CL still builds, it is proof that
the code in question was not referenced anywhere (assuming no
reflection).

Bug: 200269355
Test: atest SystemUITests
Change-Id: If24a9a92c6af5c2edd4fe1b628bb720a6a12a311
parent 5c5931c7
Loading
Loading
Loading
Loading
+0 −7
Original line number Diff line number Diff line
@@ -87,7 +87,6 @@ import com.android.systemui.statusbar.events.PrivacyDotViewController;
import com.android.systemui.statusbar.events.SystemStatusAnimationScheduler;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.NotificationEntryManager.KeyguardEnvironment;
import com.android.systemui.statusbar.notification.NotificationFilter;
import com.android.systemui.statusbar.notification.collection.legacy.NotificationGroupManagerLegacy;
import com.android.systemui.statusbar.notification.collection.legacy.VisualStabilityManager;
import com.android.systemui.statusbar.notification.collection.render.GroupExpansionManager;
@@ -102,7 +101,6 @@ import com.android.systemui.statusbar.phone.KeyguardDismissUtil;
import com.android.systemui.statusbar.phone.LightBarController;
import com.android.systemui.statusbar.phone.LockscreenGestureLogger;
import com.android.systemui.statusbar.phone.ManagedProfileController;
import com.android.systemui.statusbar.phone.NotificationGroupAlertTransferHelper;
import com.android.systemui.statusbar.phone.ScreenOffAnimationController;
import com.android.systemui.statusbar.phone.StatusBarContentInsetsProvider;
import com.android.systemui.statusbar.phone.StatusBarIconController;
@@ -313,7 +311,6 @@ public class Dependency {
    @Inject Lazy<AccessibilityFloatingMenuController> mAccessibilityFloatingMenuController;
    @Inject Lazy<StatusBarStateController> mStatusBarStateController;
    @Inject Lazy<NotificationLockscreenUserManager> mNotificationLockscreenUserManager;
    @Inject Lazy<NotificationGroupAlertTransferHelper> mNotificationGroupAlertTransferHelper;
    @Inject Lazy<NotificationGroupManagerLegacy> mNotificationGroupManager;
    @Inject Lazy<VisualStabilityManager> mVisualStabilityManager;
    @Inject Lazy<NotificationGutsManager> mNotificationGutsManager;
@@ -322,7 +319,6 @@ public class Dependency {
    @Inject Lazy<SmartReplyConstants> mSmartReplyConstants;
    @Inject Lazy<NotificationListener> mNotificationListener;
    @Inject Lazy<NotificationLogger> mNotificationLogger;
    @Inject Lazy<NotificationFilter> mNotificationFilter;
    @Inject Lazy<KeyguardDismissUtil> mKeyguardDismissUtil;
    @Inject Lazy<SmartReplyController> mSmartReplyController;
    @Inject Lazy<RemoteInputQuickSettingsDisabler> mRemoteInputQuickSettingsDisabler;
@@ -529,8 +525,6 @@ public class Dependency {
                mNotificationLockscreenUserManager::get);
        mProviders.put(VisualStabilityManager.class, mVisualStabilityManager::get);
        mProviders.put(NotificationGroupManagerLegacy.class, mNotificationGroupManager::get);
        mProviders.put(NotificationGroupAlertTransferHelper.class,
                mNotificationGroupAlertTransferHelper::get);
        mProviders.put(NotificationMediaManager.class, mNotificationMediaManager::get);
        mProviders.put(NotificationGutsManager.class, mNotificationGutsManager::get);
        mProviders.put(NotificationRemoteInputManager.class,
@@ -538,7 +532,6 @@ public class Dependency {
        mProviders.put(SmartReplyConstants.class, mSmartReplyConstants::get);
        mProviders.put(NotificationListener.class, mNotificationListener::get);
        mProviders.put(NotificationLogger.class, mNotificationLogger::get);
        mProviders.put(NotificationFilter.class, mNotificationFilter::get);
        mProviders.put(KeyguardDismissUtil.class, mKeyguardDismissUtil::get);
        mProviders.put(SmartReplyController.class, mSmartReplyController::get);
        mProviders.put(RemoteInputQuickSettingsDisabler.class,
+1 −42
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ import java.util.stream.Stream;
 * remove notifications that appear on screen for a period of time and dismiss themselves at the
 * appropriate time.  These include heads up notifications and ambient pulses.
 */
public abstract class AlertingNotificationManager implements NotificationLifetimeExtender {
public abstract class AlertingNotificationManager {
    private static final String TAG = "AlertNotifManager";
    protected final Clock mClock = new Clock();
    protected final ArrayMap<String, AlertEntry> mAlertEntries = new ArrayMap<>();
@@ -47,14 +47,6 @@ public abstract class AlertingNotificationManager implements NotificationLifetim
        mHandler = handler;
    }

    /**
     * This is the list of entries that have already been removed from the
     * NotificationManagerService side, but we keep it to prevent the UI from looking weird and
     * will remove when possible. See {@link NotificationLifetimeExtender}
     */
    protected final ArraySet<NotificationEntry> mExtendedLifetimeAlertEntries = new ArraySet<>();

    protected NotificationSafeToRemoveCallback mNotificationLifetimeFinishedCallback;
    protected int mMinimumDisplayTime;
    protected int mAutoDismissNotificationDecay;
    private final Handler mHandler;
@@ -209,12 +201,6 @@ public abstract class AlertingNotificationManager implements NotificationLifetim
        onAlertEntryRemoved(alertEntry);
        entry.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
        alertEntry.reset();
        if (mExtendedLifetimeAlertEntries.contains(entry)) {
            if (mNotificationLifetimeFinishedCallback != null) {
                mNotificationLifetimeFinishedCallback.onSafeToRemove(key);
            }
            mExtendedLifetimeAlertEntries.remove(entry);
        }
    }

    /**
@@ -243,19 +229,6 @@ public abstract class AlertingNotificationManager implements NotificationLifetim
                || alertEntry.mEntry.isRowDismissed();
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////
    // NotificationLifetimeExtender Methods

    @Override
    public void setCallback(NotificationSafeToRemoveCallback callback) {
        mNotificationLifetimeFinishedCallback = callback;
    }

    @Override
    public boolean shouldExtendLifetime(NotificationEntry entry) {
        return !canRemoveImmediately(entry.getKey());
    }

    /**
     * @param key
     * @return true if the entry is pinned
@@ -280,20 +253,6 @@ public abstract class AlertingNotificationManager implements NotificationLifetim
        return 0;
    }

    @Override
    public void setShouldManageLifetime(NotificationEntry entry, boolean shouldExtend) {
        if (shouldExtend) {
            mExtendedLifetimeAlertEntries.add(entry);
            // We need to make sure that entries are stopping to alert eventually, let's remove
            // this as soon as possible.
            AlertEntry alertEntry = mAlertEntries.get(entry.getKey());
            alertEntry.removeAsSoonAsPossible();
        } else {
            mExtendedLifetimeAlertEntries.remove(entry);
        }
    }
    ///////////////////////////////////////////////////////////////////////////////////////////////

    protected class AlertEntry implements Comparable<AlertEntry> {
        @Nullable public NotificationEntry mEntry;
        public long mPostTime;
+0 −65
Original line number Diff line number Diff line
package com.android.systemui.statusbar;

import androidx.annotation.NonNull;

import com.android.systemui.statusbar.notification.collection.NotificationEntry;

/**
 * Interface for anything that may need to keep notifications managed even after
 * {@link NotificationListener} removes it.  The lifetime extender is in charge of performing the
 * callback when the notification is then safe to remove.
 */
public interface NotificationLifetimeExtender {

    /**
     * Set the handler to callback to when the notification is safe to remove.
     *
     * @param callback the handler to callback
     */
    void setCallback(@NonNull NotificationSafeToRemoveCallback callback);

    /**
     * Determines whether or not the extender needs the notification kept after removal.
     *
     * @param entry the entry containing the notification to check
     * @return true if the notification lifetime should be extended
     */
    boolean shouldExtendLifetime(@NonNull NotificationEntry entry);

    /**
     * It's possible that a notification was canceled before it ever became visible. This callback
     * gives lifetime extenders a chance to make sure it shows up. For example if a foreground
     * service is canceled too quickly but we still want to make sure a FGS notification shows.
     * @param pendingEntry the canceled (but pending) entry
     * @return true if the notification lifetime should be extended
     */
    default boolean shouldExtendLifetimeForPendingNotification(
            @NonNull NotificationEntry pendingEntry) {
        return false;
    }

    /**
     * Sets whether or not the lifetime should be managed by the extender.  In practice, if
     * shouldManage is true, this is where the extender starts managing the entry internally and is
     * now responsible for calling {@link NotificationSafeToRemoveCallback#onSafeToRemove(String)}
     * when the entry is safe to remove.  If shouldManage is false, the extender no longer needs to
     * worry about it (either because we will be removing it anyway or the entry is no longer
     * removed due to an update).
     *
     * @param entry the entry that needs an extended lifetime
     * @param shouldManage true if the extender should manage the entry now, false otherwise
     */
    void setShouldManageLifetime(@NonNull NotificationEntry entry, boolean shouldManage);

    /**
     * The callback for when the notification is now safe to remove (i.e. its lifetime has ended).
     */
    interface NotificationSafeToRemoveCallback {
        /**
         * Called when the lifetime extender determines it's safe to remove.
         *
         * @param key key of the entry that is now safe to remove
         */
        void onSafeToRemove(String key);
    }
}
+0 −247
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import android.app.RemoteInput;
import android.content.Context;
import android.content.Intent;
import android.content.pm.UserInfo;
import android.os.Handler;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
@@ -32,7 +31,6 @@ import android.os.SystemProperties;
import android.os.UserManager;
import android.service.notification.StatusBarNotification;
import android.text.TextUtils;
import android.util.ArraySet;
import android.util.IndentingPrintWriter;
import android.util.Log;
import android.util.Pair;
@@ -47,12 +45,10 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.statusbar.NotificationVisibility;
import com.android.systemui.Dumpable;
import com.android.systemui.R;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.dagger.CentralSurfacesDependenciesModule;
@@ -75,7 +71,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;

import dagger.Lazy;
@@ -100,8 +95,6 @@ public class NotificationRemoteInputManager implements Dumpable {
    private final NotificationLockscreenUserManager mLockscreenUserManager;
    private final SmartReplyController mSmartReplyController;
    private final NotificationVisibilityProvider mVisibilityProvider;
    private final NotificationEntryManager mEntryManager;
    private final Handler mMainHandler;
    private final ActionClickLogger mLogger;

    private final Lazy<Optional<CentralSurfaces>> mCentralSurfacesOptionalLazy;
@@ -110,7 +103,6 @@ public class NotificationRemoteInputManager implements Dumpable {
    protected final NotifPipelineFlags mNotifPipelineFlags;
    private final UserManager mUserManager;
    private final KeyguardManager mKeyguardManager;
    private final RemoteInputNotificationRebuilder mRebuilder;
    private final StatusBarStateController mStatusBarStateController;
    private final RemoteInputUriController mRemoteInputUriController;
    private final NotificationClickNotifier mClickNotifier;
@@ -265,10 +257,8 @@ public class NotificationRemoteInputManager implements Dumpable {
            SmartReplyController smartReplyController,
            NotificationVisibilityProvider visibilityProvider,
            NotificationEntryManager notificationEntryManager,
            RemoteInputNotificationRebuilder rebuilder,
            Lazy<Optional<CentralSurfaces>> centralSurfacesOptionalLazy,
            StatusBarStateController statusBarStateController,
            @Main Handler mainHandler,
            RemoteInputUriController remoteInputUriController,
            NotificationClickNotifier clickNotifier,
            ActionClickLogger logger,
@@ -278,14 +268,11 @@ public class NotificationRemoteInputManager implements Dumpable {
        mLockscreenUserManager = lockscreenUserManager;
        mSmartReplyController = smartReplyController;
        mVisibilityProvider = visibilityProvider;
        mEntryManager = notificationEntryManager;
        mCentralSurfacesOptionalLazy = centralSurfacesOptionalLazy;
        mMainHandler = mainHandler;
        mLogger = logger;
        mBarService = IStatusBarService.Stub.asInterface(
                ServiceManager.getService(Context.STATUS_BAR_SERVICE));
        mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
        mRebuilder = rebuilder;
        mKeyguardManager = context.getSystemService(KeyguardManager.class);
        mStatusBarStateController = statusBarStateController;
        mRemoteInputUriController = remoteInputUriController;
@@ -788,238 +775,4 @@ public class NotificationRemoteInputManager implements Dumpable {
        /** Called when the RemoteInputController is attached to the manager */
        void setRemoteInputController(@NonNull RemoteInputController remoteInputController);
    }

    @VisibleForTesting
    protected class LegacyRemoteInputLifetimeExtender implements RemoteInputListener, Dumpable {

        /**
         * How long to wait before auto-dismissing a notification that was kept for remote input,
         * and has now sent a remote input. We auto-dismiss, because the app may not see a reason to
         * cancel these given that they technically don't exist anymore. We wait a bit in case the
         * app issues an update.
         */
        private static final int REMOTE_INPUT_KEPT_ENTRY_AUTO_CANCEL_DELAY = 200;

        /**
         * Notifications that are already removed but are kept around because we want to show the
         * remote input history. See {@link RemoteInputHistoryExtender} and
         * {@link SmartReplyHistoryExtender}.
         */
        protected final ArraySet<String> mKeysKeptForRemoteInputHistory = new ArraySet<>();

        /**
         * Notifications that are already removed but are kept around because the remote input is
         * actively being used (i.e. user is typing in it).  See {@link RemoteInputActiveExtender}.
         */
        protected final ArraySet<NotificationEntry> mEntriesKeptForRemoteInputActive =
                new ArraySet<>();

        protected NotificationLifetimeExtender.NotificationSafeToRemoveCallback
                mNotificationLifetimeFinishedCallback;

        protected final ArrayList<NotificationLifetimeExtender> mLifetimeExtenders =
                new ArrayList<>();
        private RemoteInputController mRemoteInputController;

        LegacyRemoteInputLifetimeExtender() {
            addLifetimeExtenders();
        }

        /**
         * Adds all the notification lifetime extenders. Each extender represents a reason for the
         * NotificationRemoteInputManager to keep a notification lifetime extended.
         */
        protected void addLifetimeExtenders() {
            mLifetimeExtenders.add(new RemoteInputHistoryExtender());
            mLifetimeExtenders.add(new SmartReplyHistoryExtender());
            mLifetimeExtenders.add(new RemoteInputActiveExtender());
        }

        @Override
        public void setRemoteInputController(@NonNull RemoteInputController remoteInputController) {
            mRemoteInputController= remoteInputController;
        }

        @Override
        public void onRemoteInputSent(@NonNull NotificationEntry entry) {
            if (FORCE_REMOTE_INPUT_HISTORY
                    && isNotificationKeptForRemoteInputHistory(entry.getKey())) {
                mNotificationLifetimeFinishedCallback.onSafeToRemove(entry.getKey());
            } else if (mEntriesKeptForRemoteInputActive.contains(entry)) {
                // We're currently holding onto this notification, but from the apps point of
                // view it is already canceled, so we'll need to cancel it on the apps behalf
                // after sending - unless the app posts an update in the mean time, so wait a
                // bit.
                mMainHandler.postDelayed(() -> {
                    if (mEntriesKeptForRemoteInputActive.remove(entry)) {
                        mNotificationLifetimeFinishedCallback.onSafeToRemove(entry.getKey());
                    }
                }, REMOTE_INPUT_KEPT_ENTRY_AUTO_CANCEL_DELAY);
            }
        }

        @Override
        public void onPanelCollapsed() {
            for (int i = 0; i < mEntriesKeptForRemoteInputActive.size(); i++) {
                NotificationEntry entry = mEntriesKeptForRemoteInputActive.valueAt(i);
                if (mRemoteInputController != null) {
                    mRemoteInputController.removeRemoteInput(entry, null);
                }
                if (mNotificationLifetimeFinishedCallback != null) {
                    mNotificationLifetimeFinishedCallback.onSafeToRemove(entry.getKey());
                }
            }
            mEntriesKeptForRemoteInputActive.clear();
        }

        @Override
        public boolean isNotificationKeptForRemoteInputHistory(@NonNull String key) {
            return mKeysKeptForRemoteInputHistory.contains(key);
        }

        @Override
        public void releaseNotificationIfKeptForRemoteInputHistory(
                @NonNull NotificationEntry entry) {
            final String key = entry.getKey();
            if (isNotificationKeptForRemoteInputHistory(key)) {
                mMainHandler.postDelayed(() -> {
                    if (isNotificationKeptForRemoteInputHistory(key)) {
                        mNotificationLifetimeFinishedCallback.onSafeToRemove(key);
                    }
                }, REMOTE_INPUT_KEPT_ENTRY_AUTO_CANCEL_DELAY);
            }
        }

        @VisibleForTesting
        public Set<NotificationEntry> getEntriesKeptForRemoteInputActive() {
            return mEntriesKeptForRemoteInputActive;
        }

        @Override
        public void dump(@NonNull PrintWriter pw,
                @NonNull String[] args) {
            pw.println("LegacyRemoteInputLifetimeExtender:");
            pw.print("  mKeysKeptForRemoteInputHistory: ");
            pw.println(mKeysKeptForRemoteInputHistory);
            pw.print("  mEntriesKeptForRemoteInputActive: ");
            pw.println(mEntriesKeptForRemoteInputActive);
        }

        /**
         * NotificationRemoteInputManager has multiple reasons to keep notification lifetime
         * extended so we implement multiple NotificationLifetimeExtenders
         */
        protected abstract class RemoteInputExtender implements NotificationLifetimeExtender {
            @Override
            public void setCallback(NotificationSafeToRemoveCallback callback) {
                if (mNotificationLifetimeFinishedCallback == null) {
                    mNotificationLifetimeFinishedCallback = callback;
                }
            }
        }

        /**
         * Notification is kept alive as it was cancelled in response to a remote input interaction.
         * This allows us to show what you replied and allows you to continue typing into it.
         */
        protected class RemoteInputHistoryExtender extends RemoteInputExtender {
            @Override
            public boolean shouldExtendLifetime(@NonNull NotificationEntry entry) {
                return shouldKeepForRemoteInputHistory(entry);
            }

            @Override
            public void setShouldManageLifetime(NotificationEntry entry,
                    boolean shouldExtend) {
                if (shouldExtend) {
                    StatusBarNotification newSbn = mRebuilder.rebuildForRemoteInputReply(entry);
                    entry.onRemoteInputInserted();

                    if (newSbn == null) {
                        return;
                    }

                    mEntryManager.updateNotification(newSbn, null);

                    // Ensure the entry hasn't already been removed. This can happen if there is an
                    // inflation exception while updating the remote history
                    if (entry.isRemoved()) {
                        return;
                    }

                    if (Log.isLoggable(TAG, Log.DEBUG)) {
                        Log.d(TAG, "Keeping notification around after sending remote input "
                                + entry.getKey());
                    }

                    mKeysKeptForRemoteInputHistory.add(entry.getKey());
                } else {
                    mKeysKeptForRemoteInputHistory.remove(entry.getKey());
                }
            }
        }

        /**
         * Notification is kept alive for smart reply history.  Similar to REMOTE_INPUT_HISTORY but
         * with {@link SmartReplyController} specific logic
         */
        protected class SmartReplyHistoryExtender extends RemoteInputExtender {
            @Override
            public boolean shouldExtendLifetime(@NonNull NotificationEntry entry) {
                return shouldKeepForSmartReplyHistory(entry);
            }

            @Override
            public void setShouldManageLifetime(NotificationEntry entry,
                    boolean shouldExtend) {
                if (shouldExtend) {
                    StatusBarNotification newSbn = mRebuilder.rebuildForCanceledSmartReplies(entry);

                    if (newSbn == null) {
                        return;
                    }

                    mEntryManager.updateNotification(newSbn, null);

                    if (entry.isRemoved()) {
                        return;
                    }

                    if (Log.isLoggable(TAG, Log.DEBUG)) {
                        Log.d(TAG, "Keeping notification around after sending smart reply "
                                + entry.getKey());
                    }

                    mKeysKeptForRemoteInputHistory.add(entry.getKey());
                } else {
                    mKeysKeptForRemoteInputHistory.remove(entry.getKey());
                    mSmartReplyController.stopSending(entry);
                }
            }
        }

        /**
         * Notification is kept alive because the user is still using the remote input
         */
        protected class RemoteInputActiveExtender extends RemoteInputExtender {
            @Override
            public boolean shouldExtendLifetime(@NonNull NotificationEntry entry) {
                return isRemoteInputActive(entry);
            }

            @Override
            public void setShouldManageLifetime(NotificationEntry entry,
                    boolean shouldExtend) {
                if (shouldExtend) {
                    if (Log.isLoggable(TAG, Log.DEBUG)) {
                        Log.d(TAG, "Keeping notification around while remote input active "
                                + entry.getKey());
                    }
                    mEntriesKeptForRemoteInputActive.add(entry);
                } else {
                    mEntriesKeptForRemoteInputActive.remove(entry);
                }
            }
        }
    }
}
+0 −2
Original line number Diff line number Diff line
@@ -115,10 +115,8 @@ public interface CentralSurfacesDependenciesModule {
                smartReplyController,
                visibilityProvider,
                notificationEntryManager,
                rebuilder,
                centralSurfacesOptionalLazy,
                statusBarStateController,
                mainHandler,
                remoteInputUriController,
                clickNotifier,
                actionClickLogger,
Loading