Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 85f87c45 authored by Corinna Vinschen's avatar Corinna Vinschen Committed by Christopher N. Hesse
Browse files

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: default avatarCorinna Vinschen <xda@vinschen.de>
parent c43051c2
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -333,6 +333,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;

    /**
     * Go to sleep reason code: Going to sleep due by application request.
     * @hide
+5 −2
Original line number Diff line number Diff line
@@ -1316,8 +1316,11 @@ public final class PowerManagerService extends SystemService
            } 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;
                    }
+3 −3
Original line number Diff line number Diff line
@@ -240,7 +240,7 @@ public:
            const KeyEvent* keyEvent, uint32_t policyFlags);
    virtual bool dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
            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);

@@ -1078,8 +1078,8 @@ bool NativeInputManager::dispatchUnhandledKey(const sp<InputWindowHandle>& input
    return result;
}

void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType) {
    android_server_PowerManagerService_userActivity(eventTime, eventType);
void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType, int32_t keyCode) {
    android_server_PowerManagerService_userActivity(eventTime, eventType, keyCode);
}


+9 −2
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@
#include <hardware/power.h>
#include <hardware_legacy/power.h>
#include <suspend/autosuspend.h>
#include <android/keycodes.h>

#include "com_android_server_power_PowerManagerService.h"

@@ -67,7 +68,8 @@ static bool checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodNa
    return false;
}

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) {
    // Tell the power HAL when user activity occurs.
    if (gPowerModule && gPowerModule->powerHint) {
        gPowerModule->powerHint(gPowerModule, POWER_HINT_INTERACTION, NULL);
@@ -91,9 +93,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");
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@

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