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

Commit 7fb32a0b authored by ezio84's avatar ezio84 Committed by Sam Mortimer
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 c5773c26
Loading
Loading
Loading
Loading
+29 −10
Original line number Diff line number Diff line
@@ -1579,7 +1579,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            mPowerKeyHandled = true;
            mHandler.removeMessages(MSG_POWER_LONG_PRESS);
            // 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());
            }
        }
@@ -1786,11 +1787,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() {
        if (FactoryTest.isLongPressOnPowerOffEnabled()) {
            return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
        }
        if (mTorchLongPressPowerEnabled && !isScreenOn()) {
        if (mTorchLongPressPowerEnabled && (!isScreenOn() || isDozeMode())) {
            return LONG_PRESS_POWER_TORCH;
        }
        return mLongPressOnPowerBehavior;
@@ -7138,6 +7152,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            return false;
        }

        final boolean isDozing = isDozeMode();

        if (event != null && isVolumeKey(event) && isDozing) {
            return false;
        }

        // Send events to keyguard while the screen is on and it's showing.
        if (isKeyguardShowingAndNotOccluded() && !displayOff) {
            return true;
@@ -7153,21 +7173,20 @@ public class PhoneWindowManager implements WindowManagerPolicy {

        // Send events to a dozing dream even if the screen is off since the dream
        // is in control of the state of the screen.
        IDreamManager dreamManager = getDreamManager();

        try {
            if (dreamManager != null && dreamManager.isDreaming()) {
        if (isDozing) {
            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
        // interacted with.
        return false;
    }

    private boolean isVolumeKey(KeyEvent event) {
        return event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN
                || event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP;
    }

    private void dispatchDirectAudioEvent(KeyEvent event) {
        if (event.getAction() != KeyEvent.ACTION_DOWN) {
            return;