From 2ff414b63156d7b91ff3652fa5e06efcdbe32d0f Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Sat, 12 Aug 2017 13:42:58 +0200 Subject: [PATCH] PowerManager: Allow to distinguish different keypresses * Use keypress info to exclude pressing volume keys from illuminating HW buttons in config_buttonLightOnKeypressOnly mode. Change-Id: I6bfc7ddd075e12e1ad10c3663a63e80c8d7f983d Signed-off-by: Corinna Vinschen --- core/java/android/os/PowerManager.java | 8 ++++++++ .../com/android/server/power/PowerManagerService.java | 6 ++++-- .../com_android_server_input_InputManagerService.cpp | 6 +++--- .../com_android_server_power_PowerManagerService.cpp | 11 +++++++++-- .../com_android_server_power_PowerManagerService.h | 3 ++- 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java index 1d488cc2d7e1b..92616ca078205 100644 --- a/core/java/android/os/PowerManager.java +++ b/core/java/android/os/PowerManager.java @@ -364,6 +364,14 @@ public final class PowerManager { @SystemApi public static final int USER_ACTIVITY_FLAG_INDIRECT = 1 << 1; + /** + * User activity flag: Certain hardware buttons are not supposed to + * activate hardware button illumination. This flag indicates a + * button event from one of those buttons. + * @hide + */ + public static final int USER_ACTIVITY_FLAG_NO_BUTTON_LIGHTS = 1 << 2; + /** * @hide */ diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java index f62bbebcefac3..fa00fc943ae60 100644 --- a/services/core/java/com/android/server/power/PowerManagerService.java +++ b/services/core/java/com/android/server/power/PowerManagerService.java @@ -1488,8 +1488,10 @@ private boolean userActivityNoUpdateLocked(long eventTime, int event, int flags, } else { if (eventTime > mLastUserActivityTime) { mButtonPressed = event == PowerManager.USER_ACTIVITY_EVENT_BUTTON; - if ((mButtonLightOnKeypressOnly && mButtonPressed) - || eventTime == mLastWakeTime) { + if (eventTime == mLastWakeTime || + (mButtonLightOnKeypressOnly && mButtonPressed && + (flags & PowerManager.USER_ACTIVITY_FLAG_NO_BUTTON_LIGHTS) + == 0)) { mButtonPressed = true; mLastButtonActivityTime = eventTime; } diff --git a/services/core/jni/com_android_server_input_InputManagerService.cpp b/services/core/jni/com_android_server_input_InputManagerService.cpp index fb3076ba9ddd6..f87141be5aaa0 100644 --- a/services/core/jni/com_android_server_input_InputManagerService.cpp +++ b/services/core/jni/com_android_server_input_InputManagerService.cpp @@ -260,7 +260,7 @@ class NativeInputManager : public virtual RefBase, const KeyEvent* keyEvent, uint32_t policyFlags); virtual bool dispatchUnhandledKey(const sp& token, const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent); - virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType); + virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType, int32_t keyCode); virtual bool checkInjectEventsPermissionNonReentrant( int32_t injectorPid, int32_t injectorUid); virtual void onPointerDownOutsideFocus(const sp& touchedToken); @@ -1207,9 +1207,9 @@ bool NativeInputManager::dispatchUnhandledKey(const sp& token, return result; } -void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType) { +void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType, int32_t keyCode) { ATRACE_CALL(); - android_server_PowerManagerService_userActivity(eventTime, eventType); + android_server_PowerManagerService_userActivity(eventTime, eventType, keyCode); } diff --git a/services/core/jni/com_android_server_power_PowerManagerService.cpp b/services/core/jni/com_android_server_power_PowerManagerService.cpp index 73bb579bd2740..6ddedba213295 100644 --- a/services/core/jni/com_android_server_power_PowerManagerService.cpp +++ b/services/core/jni/com_android_server_power_PowerManagerService.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include "com_android_server_power_PowerManagerService.h" @@ -152,7 +153,8 @@ static void sendPowerHint(PowerHint hintId, uint32_t data) { SurfaceComposerClient::notifyPowerHint(static_cast(hintId)); } -void android_server_PowerManagerService_userActivity(nsecs_t eventTime, int32_t eventType) { +void android_server_PowerManagerService_userActivity(nsecs_t eventTime, int32_t eventType, + int32_t keyCode) { if (gPowerManagerServiceObj) { // Throttle calls into user activity by event type. // We're a little conservative about argument checking here in case the caller @@ -174,9 +176,14 @@ void android_server_PowerManagerService_userActivity(nsecs_t eventTime, int32_t JNIEnv* env = AndroidRuntime::getJNIEnv(); + int flags = 0; + if (keyCode == AKEYCODE_VOLUME_UP || keyCode == AKEYCODE_VOLUME_DOWN) { + flags |= USER_ACTIVITY_FLAG_NO_BUTTON_LIGHTS; + } + env->CallVoidMethod(gPowerManagerServiceObj, gPowerManagerServiceClassInfo.userActivityFromNative, - nanoseconds_to_milliseconds(eventTime), eventType, 0); + nanoseconds_to_milliseconds(eventTime), eventType, flags); checkAndClearExceptionFromCallback(env, "userActivityFromNative"); } } diff --git a/services/core/jni/com_android_server_power_PowerManagerService.h b/services/core/jni/com_android_server_power_PowerManagerService.h index a17fd650522b0..1dfd7bbca0e98 100644 --- a/services/core/jni/com_android_server_power_PowerManagerService.h +++ b/services/core/jni/com_android_server_power_PowerManagerService.h @@ -24,7 +24,8 @@ namespace android { -extern void android_server_PowerManagerService_userActivity(nsecs_t eventTime, int32_t eventType); +extern void android_server_PowerManagerService_userActivity(nsecs_t eventTime, int32_t eventType, + int32_t keyCode); } // namespace android