Add tests for dreaming on short power button press.

This also adds a test for not locking the device when double-tapping the
power button to show the camera.

Bug: 264892168
Test: atest WmTests:PowerKeyGestureTests
Change-Id: I54450a5c3320cd75717c496a9ca6bd5b02c138ee
This commit is contained in:
Will Leshner
2023-02-08 09:58:27 -08:00
parent 23b25b07d3
commit a6f4eeb629
3 changed files with 54 additions and 1 deletions

View File

@@ -590,7 +590,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
private int mDoubleTapOnHomeBehavior;
// Whether to lock the device after the next app transition has finished.
private boolean mLockAfterAppTransitionFinished;
boolean mLockAfterAppTransitionFinished;
// Allowed theater mode wake actions
private boolean mAllowTheaterModeWakeFromKey;

View File

@@ -20,6 +20,7 @@ import static android.view.KeyEvent.KEYCODE_VOLUME_UP;
import static com.android.server.policy.PhoneWindowManager.LONG_PRESS_POWER_ASSISTANT;
import static com.android.server.policy.PhoneWindowManager.LONG_PRESS_POWER_GLOBAL_ACTIONS;
import static com.android.server.policy.PhoneWindowManager.SHORT_PRESS_POWER_DREAM_OR_SLEEP;
import android.provider.Settings;
import android.view.Display;
@@ -48,6 +49,32 @@ public class PowerKeyGestureTests extends ShortcutKeyTestBase {
mPhoneWindowManager.assertNoPowerSleep();
}
/**
* Power single press to start dreaming when so configured.
*/
@Test
public void testPowerSinglePressRequestsDream() {
mPhoneWindowManager.overrideShortPressOnPower(SHORT_PRESS_POWER_DREAM_OR_SLEEP);
mPhoneWindowManager.overrideCanStartDreaming(true);
sendKey(KEYCODE_POWER);
mPhoneWindowManager.assertDreamRequest();
mPhoneWindowManager.assertLockedAfterAppTransitionFinished();
}
/**
* Power double-press to launch camera does not lock device when the single press behavior is to
* dream.
*/
@Test
public void testPowerDoublePressWillNotLockDevice() {
mPhoneWindowManager.overrideShortPressOnPower(SHORT_PRESS_POWER_DREAM_OR_SLEEP);
mPhoneWindowManager.overrideCanStartDreaming(false);
sendKey(KEYCODE_POWER);
sendKey(KEYCODE_POWER);
mPhoneWindowManager.assertCameraLaunch();
mPhoneWindowManager.assertWillNotLockAfterAppTransitionFinished();
}
/**
* Power double press to trigger camera.
*/

View File

@@ -84,6 +84,7 @@ import com.android.server.wm.ActivityTaskManagerInternal;
import com.android.server.wm.DisplayPolicy;
import com.android.server.wm.DisplayRotation;
import com.android.server.wm.WindowManagerInternal;
import com.android.server.wm.WindowManagerInternal.AppTransitionListener;
import junit.framework.Assert;
@@ -289,6 +290,10 @@ class TestPhoneWindowManager {
}
}
void overrideShortPressOnPower(int behavior) {
mPhoneWindowManager.mShortPressOnPowerBehavior = behavior;
}
// Override assist perform function.
void overrideLongPressOnPower(int behavior) {
mPhoneWindowManager.mLongPressOnPowerBehavior = behavior;
@@ -311,6 +316,10 @@ class TestPhoneWindowManager {
}
}
void overrideCanStartDreaming(boolean canDream) {
doReturn(canDream).when(mDreamManagerInternal).canStartDreaming(anyBoolean());
}
void overrideDisplayState(int state) {
doReturn(state).when(mDisplay).getState();
Mockito.reset(mPowerManager);
@@ -374,6 +383,10 @@ class TestPhoneWindowManager {
timeout(SHORTCUT_KEY_DELAY_MILLIS)).performAccessibilityShortcut();
}
void assertDreamRequest() {
verify(mDreamManagerInternal).requestDream();
}
void assertPowerSleep() {
waitForIdle();
verify(mPowerManager,
@@ -454,4 +467,17 @@ class TestPhoneWindowManager {
waitForIdle();
verify(mInputManagerInternal).toggleCapsLock(anyInt());
}
void assertWillNotLockAfterAppTransitionFinished() {
Assert.assertFalse(mPhoneWindowManager.mLockAfterAppTransitionFinished);
}
void assertLockedAfterAppTransitionFinished() {
ArgumentCaptor<AppTransitionListener> transitionCaptor =
ArgumentCaptor.forClass(AppTransitionListener.class);
verify(mWindowManagerInternal).registerAppTransitionListener(
transitionCaptor.capture());
transitionCaptor.getValue().onAppTransitionFinishedLocked(any());
verify(mPhoneWindowManager).lockNow(null);
}
}