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

Commit 772e5325 authored by Gus Prevas's avatar Gus Prevas
Browse files

Makes NotificationRemoteInputManager a NotificationEntryListener.

This change makes NotificationRemoteInputManager register itself as a
NotificationEntryListener instead of having NotificationEntryManager
separately and explicitly notify it of a notification being removed.

Test: atest SystemUITests, manual
Change-Id: Ib212de504430fd3f543d4c2919e5f434ce2f0aea
parent 2d5a1e95
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -155,8 +155,12 @@ public class NotificationMediaManager implements Dumpable {
        mEntryManager = notificationEntryManager;
        notificationEntryManager.addNotificationEntryListener(new NotificationEntryListener() {
            @Override
            public void onEntryRemoved(String key, StatusBarNotification old,
                    boolean lifetimeExtended, boolean removedByUser) {
            public void onEntryRemoved(
                    Entry entry,
                    String key,
                    StatusBarNotification old,
                    boolean lifetimeExtended,
                    boolean removedByUser) {
                if (!lifetimeExtended) {
                    onNotificationRemoved(key);
                }
+44 −23
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@ package com.android.systemui.statusbar;

import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY;

import static com.android.systemui.Dependency.MAIN_HANDLER_NAME;

import android.annotation.NonNull;
import android.app.ActivityManager;
import android.app.ActivityOptions;
@@ -26,6 +28,7 @@ import android.app.PendingIntent;
import android.app.RemoteInput;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
@@ -46,9 +49,9 @@ import android.widget.TextView;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.statusbar.NotificationVisibility;
import com.android.systemui.Dependency;
import com.android.systemui.Dumpable;
import com.android.systemui.statusbar.notification.NotificationData;
import com.android.systemui.statusbar.notification.NotificationEntryListener;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.phone.ShadeController;
@@ -60,8 +63,11 @@ import java.util.ArrayList;
import java.util.Set;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

import dagger.Lazy;

/**
 * Class for handling remote input state over a set of notifications. This class handles things
 * like keeping notifications temporarily that were cancelled as a response to a remote input
@@ -100,15 +106,12 @@ public class NotificationRemoteInputManager implements Dumpable {
            new ArraySet<>();

    // Dependencies:
    protected final NotificationLockscreenUserManager mLockscreenUserManager =
            Dependency.get(NotificationLockscreenUserManager.class);
    protected final SmartReplyController mSmartReplyController =
            Dependency.get(SmartReplyController.class);
    private final NotificationEntryManager mEntryManager
            = Dependency.get(NotificationEntryManager.class);
    private final NotificationLockscreenUserManager mLockscreenUserManager;
    private final SmartReplyController mSmartReplyController;
    private final NotificationEntryManager mEntryManager;
    private final Handler mMainHandler;

    // Lazy
    private ShadeController mShadeController;
    private final Lazy<ShadeController> mShadeController;

    protected final Context mContext;
    private final UserManager mUserManager;
@@ -126,7 +129,7 @@ public class NotificationRemoteInputManager implements Dumpable {
        @Override
        public boolean onClickHandler(
                View view, PendingIntent pendingIntent, RemoteViews.RemoteResponse response) {
            getShadeController().wakeUpIfDozing(SystemClock.uptimeMillis(), view);
            mShadeController.get().wakeUpIfDozing(SystemClock.uptimeMillis(), view);

            if (handleRemoteInput(view, pendingIntent)) {
                return true;
@@ -226,21 +229,39 @@ public class NotificationRemoteInputManager implements Dumpable {
        }
    };

    private ShadeController getShadeController() {
        if (mShadeController == null) {
            mShadeController = Dependency.get(ShadeController.class);
        }
        return mShadeController;
    }

    @Inject
    public NotificationRemoteInputManager(Context context) {
    public NotificationRemoteInputManager(
            Context context,
            NotificationLockscreenUserManager lockscreenUserManager,
            SmartReplyController smartReplyController,
            NotificationEntryManager notificationEntryManager,
            Lazy<ShadeController> shadeController,
            @Named(MAIN_HANDLER_NAME) Handler mainHandler) {
        mContext = context;
        mLockscreenUserManager = lockscreenUserManager;
        mSmartReplyController = smartReplyController;
        mEntryManager = notificationEntryManager;
        mShadeController = shadeController;
        mMainHandler = mainHandler;
        mBarService = IStatusBarService.Stub.asInterface(
                ServiceManager.getService(Context.STATUS_BAR_SERVICE));
        mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
        addLifetimeExtenders();
        mKeyguardManager = context.getSystemService(KeyguardManager.class);

        notificationEntryManager.addNotificationEntryListener(new NotificationEntryListener() {
            @Override
            public void onEntryRemoved(
                    NotificationData.Entry entry,
                    String key,
                    StatusBarNotification old,
                    boolean lifetimeExtended,
                    boolean removedByUser) {
                if (removedByUser) {
                    onPerformRemoveNotification(entry, key);
                }
            }
        });
    }

    /** Initializes this component with the provided dependencies. */
@@ -258,7 +279,7 @@ public class NotificationRemoteInputManager implements Dumpable {
                    // 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.
                    Dependency.get(Dependency.MAIN_HANDLER).postDelayed(() -> {
                    mMainHandler.postDelayed(() -> {
                        if (mEntriesKeptForRemoteInputActive.remove(entry)) {
                            mNotificationLifetimeFinishedCallback.onSafeToRemove(entry.key);
                        }
@@ -392,10 +413,10 @@ public class NotificationRemoteInputManager implements Dumpable {
        return mRemoteInputController;
    }

    public void onPerformRemoveNotification(StatusBarNotification n,
            NotificationData.Entry entry) {
        if (mKeysKeptForRemoteInputHistory.contains(n.getKey())) {
            mKeysKeptForRemoteInputHistory.remove(n.getKey());
    @VisibleForTesting
    void onPerformRemoveNotification(NotificationData.Entry entry, final String key) {
        if (mKeysKeptForRemoteInputHistory.contains(key)) {
            mKeysKeptForRemoteInputHistory.remove(key);
        }
        if (mRemoteInputController.isRemoteInputActive(entry)) {
            mRemoteInputController.removeRemoteInput(entry, null);
+4 −1
Original line number Diff line number Diff line
@@ -81,7 +81,10 @@ public class NotificationAlertingManager {

            @Override
            public void onEntryRemoved(
                    String key, StatusBarNotification old, boolean lifetimeExtended,
                    NotificationData.Entry entry,
                    String key,
                    StatusBarNotification old,
                    boolean lifetimeExtended,
                    boolean removedByUser) {
                stopAlerting(key);
            }
+4 −1
Original line number Diff line number Diff line
@@ -59,12 +59,15 @@ public interface NotificationEntryListener {
    /**
     * Called when a notification has been removed (either because the user swiped it away or
     * because the developer retracted it).
     * @param entry notification data entry that was removed.  Null if no entry existed for the
     *              removed key at the time of removal.
     * @param key key of notification that was removed
     * @param old StatusBarNotification of the notification before it was removed
     * @param lifetimeExtended true if something is artificially extending how long the notification
     * @param removedByUser true if the notification was removed by a user action
     */
    default void onEntryRemoved(
            NotificationData.Entry entry,
            String key,
            StatusBarNotification old,
            boolean lifetimeExtended,
+1 −3
Original line number Diff line number Diff line
@@ -220,9 +220,7 @@ public class NotificationEntryManager implements
        final int count = mNotificationData.getActiveNotifications().size();
        final NotificationVisibility nv = NotificationVisibility.obtain(n.getKey(), rank, count,
                true);
        NotificationData.Entry entry = mNotificationData.get(n.getKey());

        getRemoteInputManager().onPerformRemoveNotification(n, entry);
        final String pkg = n.getPackageName();
        final String tag = n.getTag();
        final int id = n.getId();
@@ -396,7 +394,7 @@ public class NotificationEntryManager implements
        }

        for (NotificationEntryListener listener : mNotificationEntryListeners) {
            listener.onEntryRemoved(key, old, lifetimeExtended, removedByUser);
            listener.onEntryRemoved(entry, key, old, lifetimeExtended, removedByUser);
        }
    }

Loading