diff options
author | Filip Gruszczynski <gruszczy@google.com> | 2015-03-13 17:39:31 -0700 |
---|---|---|
committer | Filip Gruszczynski <gruszczy@google.com> | 2015-03-16 08:57:17 -0700 |
commit | 9779e128d611f13cdb44d31b0509ff43c62a35f6 (patch) | |
tree | d9ee53aaaa38ed1a6e54b67006b6aac0f0291de7 | |
parent | 5be1afedd8f2289ba047473b242cd0535a4493fe (diff) | |
download | frameworks_base-9779e128d611f13cdb44d31b0509ff43c62a35f6.zip frameworks_base-9779e128d611f13cdb44d31b0509ff43c62a35f6.tar.gz frameworks_base-9779e128d611f13cdb44d31b0509ff43c62a35f6.tar.bz2 |
Option for going home when going to sleep for devices without physical button.
Bug: 19623388
Change-Id: Iec16f83c64646ded12ec97d4b540510b7f9dfd47
-rw-r--r-- | core/java/android/os/PowerManager.java | 6 | ||||
-rwxr-xr-x | core/res/res/values/config.xml | 6 | ||||
-rwxr-xr-x | core/res/res/values/symbols.xml | 1 | ||||
-rw-r--r-- | policy/src/com/android/internal/policy/impl/PhoneWindowManager.java | 47 | ||||
-rw-r--r-- | services/core/java/com/android/server/power/PowerManagerService.java | 3 |
5 files changed, 53 insertions, 10 deletions
diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java index e303f61..de970cb 100644 --- a/core/java/android/os/PowerManager.java +++ b/core/java/android/os/PowerManager.java @@ -364,6 +364,12 @@ public final class PowerManager { public static final int GO_TO_SLEEP_REASON_HDMI = 5; /** + * Go to sleep reason code: Going to sleep due to the sleep button being pressed. + * @hide + */ + public static final int GO_TO_SLEEP_REASON_SLEEP_BUTTON = 6; + + /** * Go to sleep flag: Skip dozing state and directly go to full sleep. * @hide */ diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 4fab5ab..3f020fd 100755 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -671,6 +671,12 @@ --> <integer name="config_triplePressOnPowerBehavior">0</integer> + <!-- Control the behavior when the user presses the sleep button. + 0 - Go to sleep (doze) + 1 - Go to sleep (doze) and go home + --> + <integer name="config_shortPressOnSleepBehavior">0</integer> + <!-- Package name for default keyguard appwidget [DO NOT TRANSLATE] --> <string name="widget_default_package_name"></string> diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index e7bd90a..26f8009 100755 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -368,6 +368,7 @@ <java-symbol type="integer" name="config_shortPressOnPowerBehavior" /> <java-symbol type="integer" name="config_toastDefaultGravity" /> <java-symbol type="integer" name="config_triplePressOnPowerBehavior" /> + <java-symbol type="integer" name="config_shortPressOnSleepBehavior" /> <java-symbol type="integer" name="config_wifi_framework_scan_interval" /> <java-symbol type="integer" name="config_wifi_supplicant_scan_interval" /> <java-symbol type="integer" name="config_wifi_scan_interval_p2p_connected" /> diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java index f2578a5..aa872a4 100644 --- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java +++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java @@ -175,6 +175,9 @@ public class PhoneWindowManager implements WindowManagerPolicy { static final int DOUBLE_TAP_HOME_NOTHING = 0; static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1; + static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0; + static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1; + static final int APPLICATION_MEDIA_SUBLAYER = -2; static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1; static final int APPLICATION_PANEL_SUBLAYER = 1; @@ -370,6 +373,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { int mLongPressOnPowerBehavior; int mDoublePressOnPowerBehavior; int mTriplePressOnPowerBehavior; + int mShortPressOnSleepBehavior; boolean mAwake; boolean mScreenOnEarly; boolean mScreenOnFully; @@ -1059,6 +1063,20 @@ public class PhoneWindowManager implements WindowManagerPolicy { } } + private void sleepPress(KeyEvent event) { + switch (mShortPressOnSleepBehavior) { + case SHORT_PRESS_SLEEP_GO_TO_SLEEP: + mPowerManager.goToSleep(event.getEventTime(), + PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0); + break; + case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME: + launchHomeFromHotKey(false /* awakenDreams */); + mPowerManager.goToSleep(event.getEventTime(), + PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0); + break; + } + } + private int getResolvedLongPressOnPowerBehavior() { if (FactoryTest.isLongPressOnPowerOffEnabled()) { return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM; @@ -1324,6 +1342,8 @@ public class PhoneWindowManager implements WindowManagerPolicy { com.android.internal.R.integer.config_doublePressOnPowerBehavior); mTriplePressOnPowerBehavior = mContext.getResources().getInteger( com.android.internal.R.integer.config_triplePressOnPowerBehavior); + mShortPressOnSleepBehavior = mContext.getResources().getInteger( + com.android.internal.R.integer.config_shortPressOnSleepBehavior); readConfigurationDependentBehaviors(); @@ -3035,11 +3055,15 @@ public class PhoneWindowManager implements WindowManagerPolicy { } } + void launchHomeFromHotKey() { + launchHomeFromHotKey(true /* awakenFromDreams */); + } + /** * A home key -> launch home action was detected. Take the appropriate action * given the situation with the keyguard. */ - void launchHomeFromHotKey() { + void launchHomeFromHotKey(final boolean awakenFromDreams) { if (isKeyguardShowingAndNotOccluded()) { // don't launch home if keyguard showing } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) { @@ -3054,7 +3078,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { } catch (RemoteException e) { } sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); - startDockOrHome(true /*fromHomeKey*/); + startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); } } }); @@ -3066,13 +3090,15 @@ public class PhoneWindowManager implements WindowManagerPolicy { } if (mRecentsVisible) { // Hide Recents and notify it to launch Home - awakenDreams(); + if (awakenFromDreams) { + awakenDreams(); + } sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); hideRecentApps(false, true); } else { // Otherwise, just launch Home sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); - startDockOrHome(true /*fromHomeKey*/); + startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); } } } @@ -4729,12 +4755,11 @@ public class PhoneWindowManager implements WindowManagerPolicy { case KeyEvent.KEYCODE_SLEEP: { result &= ~ACTION_PASS_TO_USER; + isWakeKey = false; if (!mPowerManager.isInteractive()) { useHapticFeedback = false; // suppress feedback if already non-interactive } - mPowerManager.goToSleep(event.getEventTime(), - PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); - isWakeKey = false; + sleepPress(event); break; } @@ -5884,8 +5909,10 @@ public class PhoneWindowManager implements WindowManagerPolicy { return null; } - void startDockOrHome(boolean fromHomeKey) { - awakenDreams(); + void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) { + if (awakenFromDreams) { + awakenDreams(); + } Intent dock = createHomeDockIntent(); if (dock != null) { @@ -5923,7 +5950,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { } catch (RemoteException e) { } sendCloseSystemWindows(); - startDockOrHome(false /*fromHomeKey*/); + startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */); } else { // This code brings home to the front or, if it is already // at the front, puts the device to sleep. diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java index 66c2f5f..9e373b7 100644 --- a/services/core/java/com/android/server/power/PowerManagerService.java +++ b/services/core/java/com/android/server/power/PowerManagerService.java @@ -1080,6 +1080,9 @@ public final class PowerManagerService extends SystemService case PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON: Slog.i(TAG, "Going to sleep due to power button (uid " + uid +")..."); break; + case PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON: + Slog.i(TAG, "Going to sleep due to sleep button (uid " + uid +")..."); + break; case PowerManager.GO_TO_SLEEP_REASON_HDMI: Slog.i(TAG, "Going to sleep due to HDMI standby (uid " + uid +")..."); break; |