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

Commit b5ce699d authored by Arthur Hung's avatar Arthur Hung
Browse files

Allow double tap power to trigger camera during device is sleeping

In previous patch (ag/14791880), we fixed double tap power to launch
camera by returning the 'MaxMultiPressPowerCount' value, that would
tell the single key detector to detect a single tap or multi taps by
the timeout (MULTI_PRESS_TIMEOUT=300ms), that would defer
the screen off action cause user feel the suspend response time is
worse than before.

This CL would allow the action of triggering camera by double tap when
device is going to sleep started in first tap, then it could wake the
device when receive 'screenTurnedOff'.

It would also fix the single key detector that process the power key
for single tap and multi taps and make sure that are runing at policy
thread.

Bug: 191214622
Test: manual with the combinations of screen on/off, aod, security
keyguard, double tap/single tap power.

Change-Id: I6ec73818adbd4eff91500460df7337fdf61ac08b
parent c5532b03
Loading
Loading
Loading
Loading
+0 −9
Original line number Diff line number Diff line
@@ -519,15 +519,6 @@ public class GestureLauncherService extends SystemService {
        // user has completed setup.
        return intercept && isUserSetupComplete();
    }

    public boolean isCameraDoubleTapPowerEnabled() {
        return mCameraDoubleTapPowerEnabled;
    }

    public boolean isEmergencyGestureEnabled() {
        return mEmergencyGestureEnabled;
    }

    /**
     * @return true if camera was launched, false otherwise.
     */
+20 −24
Original line number Diff line number Diff line
@@ -904,8 +904,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            }
        } else {
            // handled by single key or another power key policy.
            if (!mSingleKeyGestureDetector.isKeyIntercepted(KEYCODE_POWER)) {
                mSingleKeyGestureDetector.reset();
            }
        }

        finishPowerKeyPress();
    }
@@ -918,7 +920,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    }

    private void powerPress(long eventTime, int count, boolean beganFromNonInteractive) {
        mCameraGestureTriggered = false;
        if (mDefaultDisplayPolicy.isScreenOnEarly() && !mDefaultDisplayPolicy.isScreenOnFully()) {
            Slog.i(TAG, "Suppressed redundant power key press while "
                    + "already in the process of turning the screen on.");
@@ -1068,24 +1069,18 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    }

    private int getMaxMultiPressPowerCount() {
        // GestureLauncherService could handle power multi tap gesture.
        if (mGestureLauncherService != null
                && mGestureLauncherService.isEmergencyGestureEnabled()) {
            return 5; // EMERGENCY_GESTURE_POWER_TAP_COUNT_THRESHOLD
        }

        // The actual max power button press count is 5
        // (EMERGENCY_GESTURE_POWER_TAP_COUNT_THRESHOLD), which is coming from
        // GestureLauncherService.
        // To speed up the handling of single-press of power button inside SingleKeyGestureDetector,
        // however, we limit the max count to the number of button presses actually handled by the
        // SingleKeyGestureDetector.
        if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
            return 3;
        }
        if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
            return 2;
        }

        if (mGestureLauncherService != null
                && mGestureLauncherService.isCameraDoubleTapPowerEnabled()) {
            return 2; // CAMERA_POWER_TAP_COUNT_THRESHOLD
        }

        return 1;
    }

@@ -1972,7 +1967,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        void onPress(long downTime) {
            powerPress(downTime, 1 /*count*/,
                    mSingleKeyGestureDetector.beganFromNonInteractive());
            finishPowerKeyPress();
        }

        @Override
@@ -1995,7 +1989,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        @Override
        void onMultiPress(long downTime, int count) {
            powerPress(downTime, count, mSingleKeyGestureDetector.beganFromNonInteractive());
            finishPowerKeyPress();
        }
    }

@@ -3849,17 +3842,17 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        if (mGestureLauncherService == null) {
            return false;
        }

        mCameraGestureTriggered = false;
        final MutableBoolean outLaunched = new MutableBoolean(false);
        final boolean gesturedServiceIntercepted = mGestureLauncherService.interceptPowerKeyDown(
                event, interactive, outLaunched);
        if (outLaunched.value) {
            mCameraGestureTriggered = true;
        mGestureLauncherService.interceptPowerKeyDown(event, interactive, outLaunched);
        if (!outLaunched.value) {
            return false;
        }
        if (outLaunched.value && mRequestedOrSleepingDefaultDisplay) {
        mCameraGestureTriggered = true;
        if (mRequestedOrSleepingDefaultDisplay) {
            mCameraGestureTriggeredDuringGoingToSleep = true;
        }
        return gesturedServiceIntercepted;
        return true;
    }

    /**
@@ -4232,7 +4225,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        mDefaultDisplayRotation.updateOrientationListener();

        if (mKeyguardDelegate != null) {
            mKeyguardDelegate.onFinishedGoingToSleep(pmSleepReason, mCameraGestureTriggered);
            mKeyguardDelegate.onFinishedGoingToSleep(pmSleepReason,
                    mCameraGestureTriggeredDuringGoingToSleep);
        }
        if (mDisplayFoldController != null) {
            mDisplayFoldController.finishedGoingToSleep();
@@ -4428,6 +4422,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    // Called on the DisplayManager's DisplayPowerController thread.
    @Override
    public void screenTurnedOn(int displayId) {
        if (DEBUG_WAKEUP) Slog.i(TAG, "Display " + displayId + " turned on...");

        if (displayId != DEFAULT_DISPLAY) {
            return;
        }
+5 −6
Original line number Diff line number Diff line
@@ -272,8 +272,10 @@ public final class SingleKeyGestureDetector {
                if (DEBUG) {
                    Log.i(TAG, "press key " + KeyEvent.keyCodeToString(event.getKeyCode()));
                }
                mActiveRule.onPress(downTime);
                reset();
                Message msg = mHandler.obtainMessage(MSG_KEY_DELAYED_PRESS, mActiveRule.mKeyCode,
                        1, downTime);
                msg.setAsynchronous(true);
                mHandler.sendMessage(msg);
                return true;
            }

@@ -316,10 +318,7 @@ public final class SingleKeyGestureDetector {
    }

    boolean isKeyIntercepted(int keyCode) {
        if (mActiveRule != null && mActiveRule.shouldInterceptKey(keyCode)) {
            return mHandledByLongPress;
        }
        return false;
        return mActiveRule != null && mActiveRule.shouldInterceptKey(keyCode);
    }

    boolean beganFromNonInteractive() {