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

Commit 64991987 authored by ezio84's avatar ezio84 Committed by Bruno Martins
Browse files

PhoneWindowManager: Allow torch and track skip during ambient display

This allows long press power button for torch and long press
volume buttons for track skip to work during ambient display.

sam3000/razorloves: partial pick from:

Author: ezio84 <brabus84@gmail.com>
Date:   Fri Feb 2 01:24:34 2018 -0500
    base: Support binding the power button to flashlight
    Thanks to beanstown106 for the initial longpress action calls in
    PhoneWindowManager (improved by lineage guys)
    [cut]
    Allow torch action also on ambient display
    Change-Id: I12da044f86c7b625872607529cf8524615cf576b

Author: ezio84 <brabus84@gmail.com>
Date:   Sun, 7 Jan 2018 21:24:53 +0100
    Fix volume rocker skip track on Ambient Display and Lift to Wake
    we need to check if dream service is dozing before checking
    keyguard status
    Change-Id: Ic3a6c830496188bb6edf27043cd24eb2d553bb82

Change-Id: I2463579e056364652b549524bc9775da4fa35b1f
parent f2b3961a
Loading
Loading
Loading
Loading
+25 −10
Original line number Original line Diff line number Diff line
@@ -1184,7 +1184,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            mPowerKeyHandled = true;
            mPowerKeyHandled = true;
            mHandler.removeMessages(MSG_POWER_LONG_PRESS);
            mHandler.removeMessages(MSG_POWER_LONG_PRESS);
            // See if we deferred screen wake because long press power for torch is enabled
            // See if we deferred screen wake because long press power for torch is enabled
            if (mResolvedLongPressOnPowerBehavior == LONG_PRESS_POWER_TORCH && !isScreenOn()) {
            if (mResolvedLongPressOnPowerBehavior == LONG_PRESS_POWER_TORCH &&
                    (!isScreenOn() || isDozeMode())) {
                wakeUpFromPowerKey(SystemClock.uptimeMillis());
                wakeUpFromPowerKey(SystemClock.uptimeMillis());
            }
            }
        }
        }
@@ -1442,11 +1443,24 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }
        }
    }
    }


    private boolean isDozeMode() {
        IDreamManager dreamManager = getDreamManager();

        try {
            if (dreamManager != null && dreamManager.isDreaming()) {
                return true;
            }
        } catch (RemoteException e) {
            Slog.e(TAG, "RemoteException when checking if dreaming", e);
        }
        return false;
    }

    private int getResolvedLongPressOnPowerBehavior() {
    private int getResolvedLongPressOnPowerBehavior() {
        if (FactoryTest.isLongPressOnPowerOffEnabled()) {
        if (FactoryTest.isLongPressOnPowerOffEnabled()) {
            return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
            return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
        }
        }
        if (mTorchLongPressPowerEnabled && !isScreenOn()) {
        if (mTorchLongPressPowerEnabled && (!isScreenOn() || isDozeMode())) {
            return LONG_PRESS_POWER_TORCH;
            return LONG_PRESS_POWER_TORCH;
        }
        }
        return mLongPressOnPowerBehavior;
        return mLongPressOnPowerBehavior;
@@ -4685,6 +4699,13 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            return false;
            return false;
        }
        }


        final boolean isDozing = isDozeMode();

        if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP)
                && isDozing) {
            return false;
        }

        // Send events to keyguard while the screen is on and it's showing.
        // Send events to keyguard while the screen is on and it's showing.
        if (isKeyguardShowingAndNotOccluded() && !displayOff) {
        if (isKeyguardShowingAndNotOccluded() && !displayOff) {
            return true;
            return true;
@@ -4700,15 +4721,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        if (isDefaultDisplay) {
        if (isDefaultDisplay) {
            // Send events to a dozing dream even if the screen is off since the dream
            // Send events to a dozing dream even if the screen is off since the dream
            // is in control of the state of the screen.
            // is in control of the state of the screen.
            IDreamManager dreamManager = getDreamManager();
            if (isDozing) {

            try {
                if (dreamManager != null && dreamManager.isDreaming()) {
                return true;
                return true;
            }
            }
            } catch (RemoteException e) {
                Slog.e(TAG, "RemoteException when checking if dreaming", e);
            }
        }
        }
        // Otherwise, consume events since the user can't see what is being
        // Otherwise, consume events since the user can't see what is being
        // interacted with.
        // interacted with.