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

Commit 17a56694 authored by Steve Kondik's avatar Steve Kondik
Browse files

input: Wake on navigation button

Take #3 at this infernal feature.

 - Create a new policy interceptNavigationButtonBeforeQueueing which
   sends the event to the window manager when the screen is off and the
   key is down.
 - Remove previous code which only worked for devices that treated this
   as a keypress.
 - Remove some dead code in the window manager for music-skipping which
   is no longer used by CM

Change-Id: I953095884e4848c3cde2de7b6ab301ee5128699b
parent 83e50528
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -300,6 +300,10 @@ public:
     */
    virtual void interceptGenericBeforeQueueing(nsecs_t when, uint32_t& policyFlags) = 0;

    /* Intercepts a navigation button press before queueing it
     */
    virtual void interceptNavigationButtonBeforeQueueing(nsecs_t when, uint32_t& policyFlags, bool down) = 0;

    /* Allows the policy a chance to intercept a key before dispatching. */
    virtual bool interceptKeyBeforeDispatching(const sp<InputChannel>& inputChannel,
            const KeyEvent* keyEvent, uint32_t policyFlags) = 0;
+5 −0
Original line number Diff line number Diff line
@@ -2125,6 +2125,11 @@ void InputDispatcher::notifyMotion(nsecs_t eventTime, int32_t deviceId, int32_t
    }

    policyFlags |= POLICY_FLAG_TRUSTED;
    if ((source & AINPUT_SOURCE_CLASS_NAVIGATION) &&
                    (action == AMOTION_EVENT_ACTION_DOWN || action == AMOTION_EVENT_ACTION_UP)) {
            mPolicy->interceptNavigationButtonBeforeQueueing(eventTime, policyFlags,
                            action == AMOTION_EVENT_ACTION_DOWN);
    }
    mPolicy->interceptGenericBeforeQueueing(eventTime, /*byref*/ policyFlags);

    bool needWake;
+0 −3
Original line number Diff line number Diff line
@@ -897,9 +897,6 @@ void KeyboardInputMapper::process(const RawEvent* rawEvent) {
        if (isKeyboardOrGamepadKey(scanCode)) {
            processKey(rawEvent->when, rawEvent->value != 0, rawEvent->keyCode, scanCode,
                    rawEvent->flags);
        } else if (scanCode == BTN_MOUSE) {
            processKey(rawEvent->when, rawEvent->value != 0, BTN_MOUSE, scanCode,
                    rawEvent->flags);
        }
        break;
    }
+3 −0
Original line number Diff line number Diff line
@@ -59,6 +59,9 @@ private:
            uint32_t& policyFlags) {
    }

    virtual void interceptNavigationButtonBeforeQueueing(nsecs_t when, uint32_t& policyFlags, bool down) {
    }

    virtual void interceptGenericBeforeQueueing(nsecs_t when, uint32_t& policyFlags) {
    }

+1 −34
Original line number Diff line number Diff line
@@ -240,7 +240,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    int mPointerLocationMode = 0;
    PointerLocationView mPointerLocationView = null;
    InputChannel mPointerLocationInputChannel;
    Long mTrackballHitTime;
    boolean mVolumeUpPressed;
    boolean mVolumeDownPressed;
    static final long NEXT_DURATION = 400;
@@ -1968,15 +1967,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_RELEASED, false);
        }

        boolean isBtnMouse = (keyCode == BTN_MOUSE);
        if (isBtnMouse) {
            // BTN_MOUSE is handled as Motion event only.
            result &= ~ACTION_PASS_TO_USER;
        }

        final boolean isWakeKey = (policyFlags
                & (WindowManagerPolicy.FLAG_WAKE | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0
                || (isBtnMouse && mTrackballWakeScreen);
                || ((keyCode == BTN_MOUSE) && mTrackballWakeScreen);
        
        // If the key is injected, pretend that the screen is on and don't let the
        // device go to sleep.  This feature is mainly used for testing purposes.
@@ -2022,32 +2015,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                        handleVolumeKeyUp(keyCode);
                    }
                }

                if (isBtnMouse && down && isMusicActive()) {
                    long time = SystemClock.elapsedRealtime();
                    if (mTrackballHitTime == null) {
                        mTrackballHitTime = time;
                    } else {
                        long timeBetweenHits;
                        if (time > mTrackballHitTime) {
                            timeBetweenHits = time - mTrackballHitTime;
                        } else {
                            timeBetweenHits = time + (Long.MAX_VALUE - mTrackballHitTime);
                        }
                        if (timeBetweenHits < NEXT_DURATION) {
                            Intent i = new Intent("com.android.music.musicservicecommand");
                            i.putExtra("command", "next");
                            i.putExtra("trackball", true);

                            mContext.sendBroadcast(i);
                            // Force another double-tap for next skip
                            mTrackballHitTime = null;
                        } else {
                        // Base double-tap off last hit.
                            mTrackballHitTime = time;
                        }
                    }
                }
            }
        } else if (!isScreenOn) {
            // If we are in-call with screen off and keyguard is not showing,
Loading