OSDN Git Service

PhoneWindowManager: Allow torch and track skip during ambient display
authorezio84 <brabus84@gmail.com>
Sat, 7 Jul 2018 16:29:23 +0000 (18:29 +0200)
committerBasil Gello <vasek.gello@gmail.com>
Wed, 25 Jul 2018 10:50:43 +0000 (12:50 +0200)
(Backport to cm-14.1)

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: I75f46a0dbfbc2308e51bca73fbaa9e646f73d9ab

services/core/java/com/android/server/policy/PhoneWindowManager.java

index be564d9..33ff2de 100644 (file)
@@ -1494,7 +1494,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());
             }
         }
@@ -1676,11 +1677,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;
@@ -7073,6 +7087,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;
@@ -7088,14 +7108,8 @@ 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() && !dreamManager.isDozing()) {
-                return true;
-            }
-        } catch (RemoteException e) {
-            Slog.e(TAG, "RemoteException when checking if dreaming", e);
+        if (isDozing) {
+            return true;
         }
 
         // Otherwise, consume events since the user can't see what is being
@@ -7103,6 +7117,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
         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;