Merge "Skip power press if power button ends call enabled"

This commit is contained in:
Arthur Hung
2022-09-01 01:06:46 +00:00
committed by Android (Google) Code Review
3 changed files with 28 additions and 6 deletions

View File

@@ -917,7 +917,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
}
} else {
// handled by another power key policy.
if (!mSingleKeyGestureDetector.isKeyIntercepted(KEYCODE_POWER)) {
if (mSingleKeyGestureDetector.isKeyIntercepted(KEYCODE_POWER)) {
Slog.d(TAG, "Skip power key gesture for other policy has handled it.");
mSingleKeyGestureDetector.reset();
}
}
@@ -931,11 +932,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
// Abort possibly stuck animations only when power key up without long press case.
mHandler.post(mWindowManagerFuncs::triggerAnimationFailsafe);
}
} else {
// handled by single key or another power key policy.
if (!mSingleKeyGestureDetector.isKeyIntercepted(KEYCODE_POWER)) {
mSingleKeyGestureDetector.reset();
}
}
finishPowerKeyPress();

View File

@@ -21,6 +21,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 android.provider.Settings;
import android.view.Display;
import org.junit.Test;
@@ -81,4 +82,17 @@ public class PowerKeyGestureTests extends ShortcutKeyTestBase {
sendKeyCombination(new int[]{KEYCODE_POWER, KEYCODE_VOLUME_UP}, 0);
mPhoneWindowManager.assertNoPowerSleep();
}
/**
* When a phone call is active, and INCALL_POWER_BUTTON_BEHAVIOR_HANGUP is enabled, then the
* power button should only stop phone call. The screen should not be turned off (power sleep
* should not be activated).
*/
@Test
public void testIgnoreSinglePressWhenEndCall() {
mPhoneWindowManager.overrideIncallPowerBehavior(
Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP);
sendKey(KEYCODE_POWER);
mPhoneWindowManager.assertNoPowerSleep();
}
}

View File

@@ -298,6 +298,18 @@ class TestPhoneWindowManager {
Mockito.reset(mPowerManager);
}
void overrideIncallPowerBehavior(int behavior) {
mPhoneWindowManager.mIncallPowerBehavior = behavior;
setPhoneCallIsInProgress();
}
void setPhoneCallIsInProgress() {
// Let device has an ongoing phone call.
doReturn(false).when(mTelecomManager).isRinging();
doReturn(true).when(mTelecomManager).isInCall();
doReturn(true).when(mTelecomManager).endCall();
}
/**
* Below functions will check the policy behavior could be invoked.
*/