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

Commit 70af00ab authored by Michael Wright's avatar Michael Wright
Browse files

Allow for event dispatching when in non-interactive states.

We need to allow for event dispatching in non-interactive states so
that we can enable a richer set of interactions when a device is
dozing (i.e. is in a low power state with an Always-on-Display).

Bug: 17167296
Change-Id: I8ae0f544a8106cb91ff38c2309b8b57cbe2f2c72
parent d06cd2b1
Loading
Loading
Loading
Loading
+3 −2
Original line number Original line Diff line number Diff line
@@ -761,7 +761,8 @@ public interface WindowManagerPolicy {
    public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags);
    public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags);


    /**
    /**
     * Called from the input reader thread before a motion is enqueued when the screen is off.
     * Called from the input reader thread before a motion is enqueued when the device is in a
     * non-interactive state.
     *
     *
     * <p>There are some actions that need to be handled here because they
     * <p>There are some actions that need to be handled here because they
     * affect the power state of the device, for example, waking on motions.
     * affect the power state of the device, for example, waking on motions.
@@ -771,7 +772,7 @@ public interface WindowManagerPolicy {
     *
     *
     * @return Actions flags: may be {@link #ACTION_PASS_TO_USER}.
     * @return Actions flags: may be {@link #ACTION_PASS_TO_USER}.
     */
     */
    public int interceptWakeMotionBeforeQueueing(long whenNanos, int policyFlags);
    public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags);


    /**
    /**
     * Called from the input dispatcher thread before a key is dispatched to a window.
     * Called from the input dispatcher thread before a key is dispatched to a window.
+19 −7
Original line number Original line Diff line number Diff line
@@ -4203,8 +4203,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        int result;
        int result;
        boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
        boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
                || event.isWakeKey();
                || event.isWakeKey();
        if (interactive || (isInjected && !isWakeKey)) {
        if (interactive
            // When the screen is on or if the key is injected pass the key to the application.
                || (isInjected && !isWakeKey)
                || (!interactive && shouldDispatchInputWhenNonInteractive())) {
            // When the device is interactive, the key is injected, or we're currently dozing in a
            // non-interactive state with the screen on and the keyguard showing,  pass the key to
            // the application.
            result = ACTION_PASS_TO_USER;
            result = ACTION_PASS_TO_USER;
            isWakeKey = false;
            isWakeKey = false;
        } else {
        } else {
@@ -4511,13 +4515,21 @@ public class PhoneWindowManager implements WindowManagerPolicy {


    /** {@inheritDoc} */
    /** {@inheritDoc} */
    @Override
    @Override
    public int interceptWakeMotionBeforeQueueing(long whenNanos, int policyFlags) {
    public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
        // We already know this is a wake motion so just wake up.
        if ((policyFlags & FLAG_WAKE) != 0) {
        // Note that we would observe policyFlags containing
        // FLAG_WAKE and FLAG_INTERACTIVE here.
            mPowerManager.wakeUp(whenNanos / 1000000);
            mPowerManager.wakeUp(whenNanos / 1000000);
            return 0;
            return 0;
        }
        }
        if (shouldDispatchInputWhenNonInteractive()) {
            return ACTION_PASS_TO_USER;
        }
        return 0;
    }

    private boolean shouldDispatchInputWhenNonInteractive() {
        return keyguardIsShowingTq() && mDisplay != null &&
                mDisplay.getState() != Display.STATE_OFF;
    }


    void dispatchMediaKeyWithWakeLock(KeyEvent event) {
    void dispatchMediaKeyWithWakeLock(KeyEvent event) {
        if (DEBUG_INPUT) {
        if (DEBUG_INPUT) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -9883,7 +9883,7 @@ public final class ActivityManagerService extends ActivityManagerNative
    }
    }
    private void updateEventDispatchingLocked() {
    private void updateEventDispatchingLocked() {
        mWindowManager.setEventDispatching(mBooted && !mWentToSleep && !mShuttingDown);
        mWindowManager.setEventDispatching(mBooted && !mShuttingDown);
    }
    }
    public void setLockScreenShown(boolean shown) {
    public void setLockScreenShown(boolean shown) {
+3 −3
Original line number Original line Diff line number Diff line
@@ -1420,8 +1420,8 @@ public class InputManagerService extends IInputManager.Stub
    }
    }


    // Native callback.
    // Native callback.
    private int interceptWakeMotionBeforeQueueing(long whenNanos, int policyFlags) {
    private int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
        return mWindowManagerCallbacks.interceptWakeMotionBeforeQueueing(
        return mWindowManagerCallbacks.interceptMotionBeforeQueueingNonInteractive(
                whenNanos, policyFlags);
                whenNanos, policyFlags);
    }
    }


@@ -1582,7 +1582,7 @@ public class InputManagerService extends IInputManager.Stub


        public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags);
        public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags);


        public int interceptWakeMotionBeforeQueueing(long whenNanos, int policyFlags);
        public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags);


        public long interceptKeyBeforeDispatching(InputWindowHandle focus,
        public long interceptKeyBeforeDispatching(InputWindowHandle focus,
                KeyEvent event, int policyFlags);
                KeyEvent event, int policyFlags);
+5 −4
Original line number Original line Diff line number Diff line
@@ -359,12 +359,13 @@ final class InputMonitor implements InputManagerService.WindowManagerCallbacks {
        return mService.mPolicy.interceptKeyBeforeQueueing(event, policyFlags);
        return mService.mPolicy.interceptKeyBeforeQueueing(event, policyFlags);
    }
    }


    /* Provides an opportunity for the window manager policy to intercept early
    /* Provides an opportunity for the window manager policy to intercept early motion event
     * motion event processing when the screen is off since these events are normally
     * processing when the device is in a non-interactive state since these events are normally
     * dropped. */
     * dropped. */
    @Override
    @Override
    public int interceptWakeMotionBeforeQueueing(long whenNanos, int policyFlags) {
    public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
        return mService.mPolicy.interceptWakeMotionBeforeQueueing(whenNanos, policyFlags);
        return mService.mPolicy.interceptMotionBeforeQueueingNonInteractive(
                whenNanos, policyFlags);
    }
    }


    /* Provides an opportunity for the window manager policy to process a key before
    /* Provides an opportunity for the window manager policy to process a key before
Loading