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

Commit 0441c140 authored by Arthur Hung's avatar Arthur Hung
Browse files

Skip power press if power button ends call enabled

We should skip the SingleGestureDector to process power key if it
already handled by another policy.

Bug: 198477453
Test: atest PowerKeyGestureTests
Change-Id: Ifbefd769c8e0ed6acd31aa29ffcdc3dcd67745a4
parent d0274980
Loading
Loading
Loading
Loading
+2 −6
Original line number Diff line number Diff line
@@ -918,7 +918,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();
            }
        }
@@ -932,11 +933,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();
+14 −0
Original line number Diff line number Diff line
@@ -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();
    }
}
+12 −0
Original line number Diff line number Diff line
@@ -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.
     */