Skip to content

Commit

Permalink
PowerManager: Allow to distinguish different keypresses
Browse files Browse the repository at this point in the history
* Use keypress info to exclude pressing volume keys from
  illuminating HW buttons in config_buttonLightOnKeypressOnly
  mode.

Change-Id: I6bfc7ddd075e12e1ad10c3663a63e80c8d7f983d
Signed-off-by: Corinna Vinschen <[email protected]>
  • Loading branch information
github-cygwin authored and sbwml committed Dec 23, 2019
1 parent cea7234 commit 2ff414b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
8 changes: 8 additions & 0 deletions core/java/android/os/PowerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class NativeInputManager : public virtual RefBase,
const KeyEvent* keyEvent, uint32_t policyFlags);
virtual bool dispatchUnhandledKey(const sp<IBinder>& 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<IBinder>& touchedToken);
Expand Down Expand Up @@ -1207,9 +1207,9 @@ bool NativeInputManager::dispatchUnhandledKey(const sp<IBinder>& 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);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <utils/misc.h>
#include <utils/String8.h>
#include <utils/Log.h>
#include <android/keycodes.h>

#include "com_android_server_power_PowerManagerService.h"

Expand Down Expand Up @@ -152,7 +153,8 @@ static void sendPowerHint(PowerHint hintId, uint32_t data) {
SurfaceComposerClient::notifyPowerHint(static_cast<int32_t>(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
Expand All @@ -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");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 2ff414b

Please sign in to comment.