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

Commit 5a035c0c authored by Steve Elliott's avatar Steve Elliott Committed by Android (Google) Code Review
Browse files

Merge "Move mRemoteInputManager + logic to Controller" into sc-v2-dev

parents 08e5913a adc83603
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -290,7 +290,7 @@ public class NavigationBar implements View.OnAttachStateChangeListener,

        @Override
        public boolean shouldHideOnTouch() {
            return !mNotificationRemoteInputManager.getController().isRemoteInputActive();
            return !mNotificationRemoteInputManager.isRemoteInputActive();
        }

        @Override
+50 −12
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
@@ -136,6 +137,8 @@ public class NotificationRemoteInputManager implements Dumpable {
    protected Callback mCallback;
    protected final ArrayList<NotificationLifetimeExtender> mLifetimeExtenders = new ArrayList<>();

    private final List<RemoteInputController.Callback> mControllerCallbacks = new ArrayList<>();

    private final InteractionHandler mInteractionHandler = new InteractionHandler() {

        @Override
@@ -332,6 +335,11 @@ public class NotificationRemoteInputManager implements Dumpable {
    public void setUpWithCallback(Callback callback, RemoteInputController.Delegate delegate) {
        mCallback = callback;
        mRemoteInputController = new RemoteInputController(delegate, mRemoteInputUriController);
        // Register all stored callbacks from before the Controller was initialized.
        for (RemoteInputController.Callback cb : mControllerCallbacks) {
            mRemoteInputController.addCallback(cb);
        }
        mControllerCallbacks.clear();
        mRemoteInputController.addCallback(new RemoteInputController.Callback() {
            @Override
            public void onRemoteInputSent(NotificationEntry entry) {
@@ -377,6 +385,22 @@ public class NotificationRemoteInputManager implements Dumpable {
        });
    }

    public void addControllerCallback(RemoteInputController.Callback callback) {
        if (mRemoteInputController != null) {
            mRemoteInputController.addCallback(callback);
        } else {
            mControllerCallbacks.add(callback);
        }
    }

    public void removeControllerCallback(RemoteInputController.Callback callback) {
        if (mRemoteInputController != null) {
            mRemoteInputController.removeCallback(callback);
        } else {
            mControllerCallbacks.remove(callback);
        }
    }

    /**
     * Activates a given {@link RemoteInput}
     *
@@ -563,17 +587,12 @@ public class NotificationRemoteInputManager implements Dumpable {
        return mLifetimeExtenders;
    }

    @Nullable
    public RemoteInputController getController() {
        return mRemoteInputController;
    }

    @VisibleForTesting
    void onPerformRemoveNotification(NotificationEntry entry, final String key) {
        if (mKeysKeptForRemoteInputHistory.contains(key)) {
            mKeysKeptForRemoteInputHistory.remove(key);
        }
        if (mRemoteInputController.isRemoteInputActive(entry)) {
        if (isRemoteInputActive(entry)) {
            entry.mRemoteEditImeVisible = false;
            mRemoteInputController.removeRemoteInput(entry, null);
        }
@@ -582,7 +601,9 @@ public class NotificationRemoteInputManager implements Dumpable {
    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());
            }
@@ -598,8 +619,7 @@ public class NotificationRemoteInputManager implements Dumpable {
        if (!FORCE_REMOTE_INPUT_HISTORY) {
            return false;
        }
        return (mRemoteInputController.isSpinning(entry.getKey())
                || entry.hasJustSentRemoteInput());
        return isSpinning(entry.getKey()) || entry.hasJustSentRemoteInput();
    }

    /**
@@ -632,8 +652,8 @@ public class NotificationRemoteInputManager implements Dumpable {
    public void checkRemoteInputOutside(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_OUTSIDE // touch outside the source bar
                && event.getX() == 0 && event.getY() == 0  // a touch outside both bars
                && mRemoteInputController.isRemoteInputActive()) {
            mRemoteInputController.closeRemoteInputs();
                && isRemoteInputActive()) {
            closeRemoteInputs();
        }
    }

@@ -715,6 +735,24 @@ public class NotificationRemoteInputManager implements Dumpable {
        return mEntriesKeptForRemoteInputActive;
    }

    public boolean isRemoteInputActive() {
        return mRemoteInputController != null && mRemoteInputController.isRemoteInputActive();
    }

    public boolean isRemoteInputActive(NotificationEntry entry) {
        return mRemoteInputController != null && mRemoteInputController.isRemoteInputActive(entry);
    }

    public boolean isSpinning(String entryKey) {
        return mRemoteInputController != null && mRemoteInputController.isSpinning(entryKey);
    }

    public void closeRemoteInputs() {
        if (mRemoteInputController != null) {
            mRemoteInputController.closeRemoteInputs();
        }
    }

    /**
     * NotificationRemoteInputManager has multiple reasons to keep notification lifetime extended
     * so we implement multiple NotificationLifetimeExtenders
@@ -822,7 +860,7 @@ public class NotificationRemoteInputManager implements Dumpable {
    protected class RemoteInputActiveExtender extends RemoteInputExtender {
        @Override
        public boolean shouldExtendLifetime(@NonNull NotificationEntry entry) {
            return mRemoteInputController.isRemoteInputActive(entry);
            return isRemoteInputActive(entry);
        }

        @Override
+4 −1
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import android.service.notification.StatusBarNotification;
import android.util.ArrayMap;
import android.util.Pair;

import com.android.internal.util.Preconditions;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.policy.RemoteInputUriController;
import com.android.systemui.statusbar.policy.RemoteInputView;
@@ -245,6 +244,10 @@ public class RemoteInputController {
        mCallbacks.add(callback);
    }

    public void removeCallback(Callback callback) {
        mCallbacks.remove(callback);
    }

    public void remoteInputSent(NotificationEntry entry) {
        int N = mCallbacks.size();
        for (int i = 0; i < N; i++) {
+1 −1
Original line number Diff line number Diff line
@@ -149,7 +149,7 @@ public class HeadsUpCoordinator implements Coordinator {
            final String entryKey = entry.getKey();
            if (mHeadsUpManager.isAlerting(entryKey)) {
                boolean removeImmediatelyForRemoteInput =
                        mRemoteInputManager.getController().isSpinning(entryKey)
                        mRemoteInputManager.isSpinning(entryKey)
                                && !FORCE_REMOTE_INPUT_HISTORY;
                mHeadsUpManager.removeNotification(entry.getKey(), removeImmediatelyForRemoteInput);
            }
+1 −1
Original line number Diff line number Diff line
@@ -152,7 +152,7 @@ public class HeadsUpController {
            // Also we should not defer the removal if reordering isn't allowed since otherwise
            // some notifications can't disappear before the panel is closed.
            boolean ignoreEarliestRemovalTime =
                    mRemoteInputManager.getController().isSpinning(key)
                    mRemoteInputManager.isSpinning(key)
                            && !FORCE_REMOTE_INPUT_HISTORY
                            || !mVisualStabilityManager.isReorderingAllowed();
            mHeadsUpManager.removeNotification(key, ignoreEarliestRemovalTime);
Loading