Fix screen turns off once triggering long press power behavior

If the long press or very long press behavior had been handled, we
should indicate the key had been handled by long press and skip the
short press processing.

Bug: 286742461
Test: atest SingleKeyGestureTests
Change-Id: I5e99388cdfb30eaeb3fcbcfdf5d97c3287adddf4
This commit is contained in:
Arthur Hung
2023-06-27 09:06:37 +00:00
parent bf1b4aa1bf
commit 7155f5e59e
2 changed files with 15 additions and 1 deletions

View File

@@ -314,7 +314,9 @@ public final class SingleKeyGestureDetector {
if (eventTime < mLastDownTime + mActiveRule.getVeryLongPressTimeoutMs()) {
mHandler.removeMessages(MSG_KEY_VERY_LONG_PRESS);
} else {
mHandledByLongPress = mActiveRule.supportVeryLongPress();
// If long press or very long press (~3.5s) had been handled, we should skip the
// short press behavior.
mHandledByLongPress |= mActiveRule.supportVeryLongPress();
}
}

View File

@@ -316,4 +316,16 @@ public class SingleKeyGestureTests {
pressKey(KEYCODE_POWER, 0 /* pressTime */);
assertTrue(mShortPressed.await(mWaitTimeout, TimeUnit.MILLISECONDS));
}
// Verify short press should not be triggered if no very long press behavior defined but the
// press time exceeded the very long press timeout.
@Test
public void testTimeoutExceedVeryLongPress() throws InterruptedException {
mVeryLongPressOnPowerBehavior = false;
pressKey(KEYCODE_POWER, mVeryLongPressTime + 50);
assertTrue(mLongPressed.await(mWaitTimeout, TimeUnit.MILLISECONDS));
assertEquals(mVeryLongPressed.getCount(), 1);
assertEquals(mShortPressed.getCount(), 1);
}
}