From 6212a49a9475768316a999596ffc4dd0f4ce96e5 Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Fri, 7 Mar 2014 13:58:47 -0800 Subject: [PATCH] Declare KEYCODE_SLEEP and KEYCODE_WAKEUP. These new keys behave in similarly to KEYCODE_POWER but do not simply toggle between awake and asleep states. Sleep puts the device to sleep if it is awake. Wakeup wakes up the device if it is asleep. Bug: 12938999 Change-Id: I260fb918cc858882fe06fa880910df5763a76c5d --- api/current.txt | 2 ++ core/java/android/view/KeyEvent.java | 14 ++++++++++++-- core/res/res/values/attrs.xml | 2 ++ data/keyboards/Generic.kl | 4 ++-- .../internal/policy/impl/PhoneWindowManager.java | 16 +++++++++++++++- 5 files changed, 33 insertions(+), 5 deletions(-) diff --git a/api/current.txt b/api/current.txt index e0b49990e6705..67eb6ea6acba1 100644 --- a/api/current.txt +++ b/api/current.txt @@ -26903,6 +26903,7 @@ package android.view { field public static final int KEYCODE_SHIFT_LEFT = 59; // 0x3b field public static final int KEYCODE_SHIFT_RIGHT = 60; // 0x3c field public static final int KEYCODE_SLASH = 76; // 0x4c + field public static final int KEYCODE_SLEEP = 223; // 0xdf field public static final int KEYCODE_SOFT_LEFT = 1; // 0x1 field public static final int KEYCODE_SOFT_RIGHT = 2; // 0x2 field public static final int KEYCODE_SPACE = 62; // 0x3e @@ -26924,6 +26925,7 @@ package android.view { field public static final int KEYCODE_VOLUME_MUTE = 164; // 0xa4 field public static final int KEYCODE_VOLUME_UP = 24; // 0x18 field public static final int KEYCODE_W = 51; // 0x33 + field public static final int KEYCODE_WAKEUP = 224; // 0xe0 field public static final int KEYCODE_WINDOW = 171; // 0xab field public static final int KEYCODE_X = 52; // 0x34 field public static final int KEYCODE_Y = 53; // 0x35 diff --git a/core/java/android/view/KeyEvent.java b/core/java/android/view/KeyEvent.java index 5a5fc1021d2ce..6a6c1271a8239 100644 --- a/core/java/android/view/KeyEvent.java +++ b/core/java/android/view/KeyEvent.java @@ -629,11 +629,19 @@ public class KeyEvent extends InputEvent implements Parcelable { /** Key code constant: Brightness Up key. * Adjusts the screen brightness up. */ public static final int KEYCODE_BRIGHTNESS_UP = 221; - /** Key code constant: Audio Track key + /** Key code constant: Audio Track key. * Switches the audio tracks. */ public static final int KEYCODE_MEDIA_AUDIO_TRACK = 222; + /** Key code constant: Sleep key. + * Puts the device to sleep. Behaves somewhat like {@link #KEYCODE_POWER} but it + * has no effect if the device is already asleep. */ + public static final int KEYCODE_SLEEP = 223; + /** Key code constant: Wakeup key. + * Wakes up the device. Behaves somewhat like {@link #KEYCODE_POWER} but it + * has no effect if the device is already awake. */ + public static final int KEYCODE_WAKEUP = 224; - private static final int LAST_KEYCODE = KEYCODE_MEDIA_AUDIO_TRACK; + private static final int LAST_KEYCODE = KEYCODE_WAKEUP; // NOTE: If you add a new keycode here you must also add it to: // isSystem() @@ -878,6 +886,8 @@ public class KeyEvent extends InputEvent implements Parcelable { names.append(KEYCODE_BRIGHTNESS_DOWN, "KEYCODE_BRIGHTNESS_DOWN"); names.append(KEYCODE_BRIGHTNESS_UP, "KEYCODE_BRIGHTNESS_UP"); names.append(KEYCODE_MEDIA_AUDIO_TRACK, "KEYCODE_MEDIA_AUDIO_TRACK"); + names.append(KEYCODE_SLEEP, "KEYCODE_SLEEP"); + names.append(KEYCODE_WAKEUP, "KEYCODE_WAKEUP"); }; // Symbolic names of all metakeys in bit order from least significant to most significant. diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index 24ebff3fdd8f3..1eb75d89edb67 100644 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -1571,6 +1571,8 @@ + + diff --git a/data/keyboards/Generic.kl b/data/keyboards/Generic.kl index 1413319c2fd08..b6a48991c57b1 100644 --- a/data/keyboards/Generic.kl +++ b/data/keyboards/Generic.kl @@ -161,8 +161,8 @@ key 128 MEDIA_STOP key 139 MENU WAKE_DROPPED key 140 CALCULATOR # key 141 "KEY_SETUP" -key 142 POWER WAKE -key 143 POWER WAKE +key 142 SLEEP WAKE +key 143 WAKEUP WAKE # key 144 "KEY_FILE" # key 145 "KEY_SENDFILE" # key 146 "KEY_DELETEFILE" diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java index 5e90c11c05241..f53868bdc694f 100644 --- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java +++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java @@ -3816,7 +3816,9 @@ public class PhoneWindowManager implements WindowManagerPolicy { mKeyguardDelegate.isShowingAndNotHidden() : mKeyguardDelegate.isShowing())); - if (keyCode == KeyEvent.KEYCODE_POWER) { + if (keyCode == KeyEvent.KEYCODE_POWER + || keyCode == KeyEvent.KEYCODE_SLEEP + || keyCode == KeyEvent.KEYCODE_WAKEUP) { policyFlags |= WindowManagerPolicy.FLAG_WAKE; } @@ -4013,6 +4015,18 @@ public class PhoneWindowManager implements WindowManagerPolicy { break; } + case KeyEvent.KEYCODE_SLEEP: { + result &= ~ACTION_PASS_TO_USER; + mPowerManager.goToSleep(event.getEventTime()); + isWakeKey = false; + break; + } + + case KeyEvent.KEYCODE_WAKEUP: { + result &= ~ACTION_PASS_TO_USER; + break; + } + case KeyEvent.KEYCODE_MEDIA_PLAY: case KeyEvent.KEYCODE_MEDIA_PAUSE: case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: