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

Commit 5855e940 authored by Tanguy Pruvot's avatar Tanguy Pruvot Committed by Steve Kondik
Browse files

wake phone with volume keys

From CM71, for devices where power button is hard to press

Change-Id: I402394d2599e18b70283a7e8b9d5d6c8ce1e38c7
parent b98591a7
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -2192,6 +2192,13 @@ public final class Settings {
         */
        public static final String MENU_UNLOCK_SCREEN = "menu_unlock_screen";

        /**
         * Whether to wake the screen with the volume keys, the value is boolean.
         * @hide
         */
        public static final String VOLUME_WAKE_SCREEN = "volume_wake_screen";


        /**
         * Settings to backup. This is here so that it's in the same place as the settings
         * keys and easy to update.
+17 −2
Original line number Diff line number Diff line
@@ -352,6 +352,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    WindowState mFocusedWindow;
    IApplicationToken mFocusedApp;

    // Behavior of volume wake
    boolean mVolumeWakeScreen;

    private final InputHandler mPointerLocationInputHandler = new BaseInputHandler() {
        @Override
        public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) {
@@ -478,6 +481,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    Settings.System.END_BUTTON_BEHAVIOR), false, this);
            resolver.registerContentObserver(Settings.Secure.getUriFor(
                    Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this);
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.VOLUME_WAKE_SCREEN), false, this);
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.ACCELEROMETER_ROTATION), false, this);
            resolver.registerContentObserver(Settings.System.getUriFor(
@@ -949,6 +954,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            mIncallPowerBehavior = Settings.Secure.getInt(resolver,
                    Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
                    Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT);
            mVolumeWakeScreen = (Settings.System.getInt(resolver,
                    Settings.System.VOLUME_WAKE_SCREEN, 0) == 1);
            int accelerometerDefault = Settings.System.getInt(resolver,
                    Settings.System.ACCELEROMETER_ROTATION, DEFAULT_ACCELEROMETER_ROTATION);
            
@@ -2745,7 +2752,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) {
        final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
        final boolean canceled = event.isCanceled();
        final int keyCode = event.getKeyCode();
        int keyCode = event.getKeyCode();

        final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;

@@ -2790,7 +2797,15 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            result = 0;

            final boolean isWakeKey = (policyFlags
                    & (WindowManagerPolicy.FLAG_WAKE | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0;
                    & (WindowManagerPolicy.FLAG_WAKE | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0
                    || ((keyCode == KeyEvent.KEYCODE_VOLUME_UP) && mVolumeWakeScreen)
                    || ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) && mVolumeWakeScreen);

            // make sure keyevent get's handled as power key on volume-wake
            if(!isScreenOn && mVolumeWakeScreen && isWakeKey && ((keyCode == KeyEvent.KEYCODE_VOLUME_UP)
                    || (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)))
                keyCode=KeyEvent.KEYCODE_POWER;

            if (down && isWakeKey) {
                if (keyguardActive) {
                    // If the keyguard is showing, let it decide what to do with the wake key.