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

Commit 041d7269 authored by Mark Renouf's avatar Mark Renouf
Browse files

Forward StatusBar.onBackPressed to Bubbles when expanded

StatusBarWindowView is the root of the StatusBar window
and handles all key events at dispatchKeyEvent

All keys dispatched to the StatusBar window flow through
StatusBarWindowView#dispatchKeyEvent. A BACK key event
is forwarded to StatusBar.onBackPressed()

If StatusBar#canPanelBeCollapsed() is false, the action is
passed to BubbleController which forwards to the expanded
bubble by calling to ActivityView#performBackPress().

Bug: 123631742
Test: manual, go/bubbles-app
Change-Id: I0ccafc02f876c973ebc267055162621109b2dcc0
parent 5641b634
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -29,12 +29,17 @@ import android.content.Intent;
import android.graphics.Insets;
import android.hardware.display.DisplayManager;
import android.hardware.display.VirtualDisplay;
import android.hardware.input.InputManager;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.UserHandle;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.IWindowManager;
import android.view.InputDevice;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.SurfaceControl;
import android.view.SurfaceHolder;
import android.view.SurfaceSession;
@@ -346,6 +351,32 @@ public class ActivityView extends ViewGroup {
        mSurfaceView.setVisibility(visibility);
    }

    /**
     * Injects a pair of down/up key events with keycode {@link KeyEvent#KEYCODE_BACK} to the
     * virtual display.
     */
    public void performBackPress() {
        if (mVirtualDisplay == null) {
            return;
        }
        final int displayId = mVirtualDisplay.getDisplay().getDisplayId();
        final InputManager im = InputManager.getInstance();
        im.injectInputEvent(createKeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK, displayId),
                InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
        im.injectInputEvent(createKeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK, displayId),
                InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
    }

    private static KeyEvent createKeyEvent(int action, int code, int displayId) {
        long when = SystemClock.uptimeMillis();
        final KeyEvent ev = new KeyEvent(when, when, action, code, 0 /* repeat */,
                0 /* metaState */, KeyCharacterMap.VIRTUAL_KEYBOARD, 0 /* scancode */,
                KeyEvent.FLAG_FROM_SYSTEM | KeyEvent.FLAG_VIRTUAL_HARD_KEY,
                InputDevice.SOURCE_KEYBOARD);
        ev.setDisplayId(displayId);
        return ev;
    }

    private void initVirtualDisplay(SurfaceSession surfaceSession) {
        if (mVirtualDisplay != null) {
            throw new IllegalStateException("Trying to initialize for the second time.");
+10 −0
Original line number Diff line number Diff line
@@ -242,6 +242,16 @@ public class BubbleController implements BubbleExpandedView.OnBubbleBlockedListe
        mNotificationEntryManager.updateNotifications();
    }

    /**
     * Directs a back gesture at the bubble stack. When opened, the current expanded bubble
     * is forwarded a back key down/up pair.
     */
    public void performBackPressIfNeeded() {
        if (mStackView != null) {
            mStackView.performBackPressIfNeeded();
        }
    }

    /**
     * Adds or updates a bubble associated with the provided notification entry.
     *
+8 −0
Original line number Diff line number Diff line
@@ -335,6 +335,14 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
        updateView();
    }

    boolean performBackPressIfNeeded() {
        if (mActivityView == null || !usingActivityView()) {
            return false;
        }
        mActivityView.performBackPress();
        return true;
    }

    @Override
    public void onClick(View view) {
        if (mEntry == null) {
+11 −0
Original line number Diff line number Diff line
@@ -815,4 +815,15 @@ public class BubbleStackView extends FrameLayout {
                    getNormalizedYPosition());
        }
    }

    /**
     * Called when a back gesture should be directed to the Bubbles stack. When expanded,
     * a back key down/up event pair is forwarded to the bubble Activity.
     */
    boolean performBackPressIfNeeded() {
        if (!isExpanded()) {
            return false;
        }
        return mExpandedBubble.expandedView.performBackPressIfNeeded();
    }
}
+5 −1
Original line number Diff line number Diff line
@@ -3261,7 +3261,11 @@ public class StatusBar extends SystemUI implements DemoMode,
            return true;
        }
        if (mState != StatusBarState.KEYGUARD && mState != StatusBarState.SHADE_LOCKED) {
            if (mNotificationPanel.canPanelBeCollapsed()) {
                animateCollapsePanels();
            } else {
                mBubbleController.performBackPressIfNeeded();
            }
            return true;
        }
        if (mKeyguardUserSwitcher != null && mKeyguardUserSwitcher.hideIfNotSimple(true)) {