diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java index cd0fb44ac753fc5b3241b2b4decc36ca2e520550..2ac2d70c90d757c3e0b05dc83575c3afe190bbc3 100644 --- a/core/java/android/os/PowerManager.java +++ b/core/java/android/os/PowerManager.java @@ -353,6 +353,15 @@ public final class PowerManager { @SystemApi public static final int USER_ACTIVITY_FLAG_INDIRECT = 1 << 1; + /** + * @hide + * 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 3c1d7488793373a8a7bda7e48cd49f0c0af79161..3522653b67ed8f3323aac55105eea6b99f547308 100644 --- a/services/core/java/com/android/server/power/PowerManagerService.java +++ b/services/core/java/com/android/server/power/PowerManagerService.java @@ -1885,9 +1885,9 @@ public final class PowerManagerService extends SystemService groupId)) { mDisplayGroupPowerStateMapper.setButtonPressedLocked( groupId, event == PowerManager.USER_ACTIVITY_EVENT_BUTTON); - if ((mButtonLightOnKeypressOnly && - mDisplayGroupPowerStateMapper.getButtonPressedLocked(groupId)) - || eventTime == mLastWakeTime) { + if (eventTime == mLastWakeTime || (mButtonLightOnKeypressOnly && + mDisplayGroupPowerStateMapper.getButtonPressedLocked(groupId) && + (flags & PowerManager.USER_ACTIVITY_FLAG_NO_BUTTON_LIGHTS) == 0)) { mDisplayGroupPowerStateMapper.setButtonPressedLocked(groupId, true); mDisplayGroupPowerStateMapper.setLastButtonActivityTimeLocked( groupId, eventTime); diff --git a/services/core/jni/com_android_server_input_InputManagerService.cpp b/services/core/jni/com_android_server_input_InputManagerService.cpp index c1e6e0494658ea200f2848bd964884e085b56fdb..f1e335cc79db7f05cb5612a7b343d2f4ade7565b 100644 --- a/services/core/jni/com_android_server_input_InputManagerService.cpp +++ b/services/core/jni/com_android_server_input_InputManagerService.cpp @@ -335,7 +335,7 @@ public: uint32_t policyFlags) override; bool dispatchUnhandledKey(const sp<IBinder>& token, const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) override; - void pokeUserActivity(nsecs_t eventTime, int32_t eventType, int32_t displayId) override; + void pokeUserActivity(nsecs_t eventTime, int32_t eventType, int32_t displayId, int32_t keyCode) override; bool checkInjectEventsPermissionNonReentrant(int32_t injectorPid, int32_t injectorUid) override; void onPointerDownOutsideFocus(const sp<IBinder>& touchedToken) override; void setPointerCapture(const PointerCaptureRequest& request) override; @@ -1379,9 +1379,9 @@ bool NativeInputManager::dispatchUnhandledKey(const sp<IBinder>& token, return result; } -void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType, int32_t displayId) { +void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType, int32_t displayId, int32_t keyCode) { ATRACE_CALL(); - android_server_PowerManagerService_userActivity(eventTime, eventType, displayId); + android_server_PowerManagerService_userActivity(eventTime, eventType, displayId, keyCode); } bool NativeInputManager::checkInjectEventsPermissionNonReentrant( diff --git a/services/core/jni/com_android_server_power_PowerManagerService.cpp b/services/core/jni/com_android_server_power_PowerManagerService.cpp index ae7ea3cd90e8ae73385a67e755f15847d9b6f43a..c3332e5cd3b16d943951bca891f13e680cc65ebd 100644 --- a/services/core/jni/com_android_server_power_PowerManagerService.cpp +++ b/services/core/jni/com_android_server_power_PowerManagerService.cpp @@ -22,6 +22,7 @@ #include <android/hardware/power/Boost.h> #include <android/hardware/power/IPower.h> #include <android/hardware/power/Mode.h> +#include <android/keycodes.h> #include <android/system/suspend/1.0/ISystemSuspend.h> #include <android/system/suspend/ISuspendControlService.h> #include <android/system/suspend/internal/ISuspendControlServiceInternal.h> @@ -104,7 +105,7 @@ static bool setPowerMode(Mode mode, bool enabled) { } void android_server_PowerManagerService_userActivity(nsecs_t eventTime, int32_t eventType, - int32_t displayId) { + int32_t displayId, 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 @@ -126,9 +127,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, displayId, 0); + nanoseconds_to_milliseconds(eventTime), eventType, displayId, 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 a2f335c74870e21a2f5bb523ab1162bbe26bebb4..1d8f9d43b85132ec2ad3b640f30c09c4aa22cb66 100644 --- a/services/core/jni/com_android_server_power_PowerManagerService.h +++ b/services/core/jni/com_android_server_power_PowerManagerService.h @@ -25,7 +25,7 @@ namespace android { extern void android_server_PowerManagerService_userActivity(nsecs_t eventTime, int32_t eventType, - int32_t displayId); + int32_t displayId, int32_t keyCode); } // namespace android