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
This commit is contained in:
Arthur Hung
2021-07-02 16:08:51 +08:00
parent c5532b030c
commit b5ce699d0d
3 changed files with 25 additions and 39 deletions

View File

@@ -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.
*/

View File

@@ -904,7 +904,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
}
} else {
// handled by single key or another power key policy.
mSingleKeyGestureDetector.reset();
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;
}

View File

@@ -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() {