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

Commit 8931470a authored by Arthur Hung's avatar Arthur Hung
Browse files

Fix double tap power key to launch camera locks phone

If user enabled double tap power to launch camera, we should return the
correct value of 'MaxMultiPressPowerCount' so single tap power detector
could wait for multi press timeout instead triggering 'powerPress'
immediately.

Test: double tap power to launch camera
Bug: 188247996
Change-Id: I4ca28c42c4affd9c48219e3c68630ea0ce1d5409
parent 0def7266
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -520,6 +520,14 @@ public class GestureLauncherService extends SystemService {
        return intercept && isUserSetupComplete();
    }

    public boolean isCameraDoubleTapPowerEnabled() {
        return mCameraDoubleTapPowerEnabled;
    }

    public boolean isEmergencyGestureEnabled() {
        return mEmergencyGestureEnabled;
    }

    /**
     * @return true if camera was launched, false otherwise.
     */
+18 −5
Original line number Diff line number Diff line
@@ -596,6 +596,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {

    private KeyCombinationManager mKeyCombinationManager;
    private SingleKeyGestureDetector mSingleKeyGestureDetector;
    private GestureLauncherService mGestureLauncherService;

    private boolean mLockNowPending = false;

@@ -917,6 +918,7 @@ 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.");
@@ -1066,12 +1068,24 @@ 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
        }

        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;
    }

@@ -3825,15 +3839,13 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    // The camera gesture will be detected by GestureLauncherService.
    private boolean handleCameraGesture(KeyEvent event, boolean interactive) {
        // camera gesture.
        GestureLauncherService gestureService = LocalServices.getService(
                GestureLauncherService.class);
        if (gestureService == null) {
        if (mGestureLauncherService == null) {
            return false;
        }

        final MutableBoolean outLaunched = new MutableBoolean(false);
        final boolean gesturedServiceIntercepted = gestureService.interceptPowerKeyDown(event,
                interactive, outLaunched);
        final boolean gesturedServiceIntercepted = mGestureLauncherService.interceptPowerKeyDown(
                event, interactive, outLaunched);
        if (outLaunched.value) {
            mCameraGestureTriggered = true;
        }
@@ -4689,6 +4701,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }

        mAutofillManagerInternal = LocalServices.getService(AutofillManagerInternal.class);
        mGestureLauncherService = LocalServices.getService(GestureLauncherService.class);
    }

    /** {@inheritDoc} */