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

Commit c856333c authored by Corinna Vinschen's avatar Corinna Vinschen Committed by Sam Mortimer
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 6db969dc
Loading
Loading
Loading
Loading
+9 −0
Original line number Original line Diff line number Diff line
@@ -369,6 +369,15 @@ public final class PowerManager {
     */
     */
    public static final int GO_TO_SLEEP_REASON_MIN = 0;
    public static final int GO_TO_SLEEP_REASON_MIN = 0;


    /**
     * @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;

    /**
    /**
     * Go to sleep reason code: Going to sleep due by application request.
     * Go to sleep reason code: Going to sleep due by application request.
     * @hide
     * @hide
+4 −2
Original line number Original line Diff line number Diff line
@@ -1492,8 +1492,10 @@ public final class PowerManagerService extends SystemService
            } else {
            } else {
                if (eventTime > mLastUserActivityTime) {
                if (eventTime > mLastUserActivityTime) {
                    mButtonPressed = event == PowerManager.USER_ACTIVITY_EVENT_BUTTON;
                    mButtonPressed = event == PowerManager.USER_ACTIVITY_EVENT_BUTTON;
                    if ((mButtonLightOnKeypressOnly && mButtonPressed)
                    if (eventTime == mLastWakeTime ||
                            || eventTime == mLastWakeTime) {
                            (mButtonLightOnKeypressOnly && mButtonPressed &&
                                    (flags & PowerManager.USER_ACTIVITY_FLAG_NO_BUTTON_LIGHTS)
                                            == 0)) {
                        mButtonPressed = true;
                        mButtonPressed = true;
                        mLastButtonActivityTime = eventTime;
                        mLastButtonActivityTime = eventTime;
                    }
                    }
+3 −3
Original line number Original line Diff line number Diff line
@@ -260,7 +260,7 @@ public:
            const KeyEvent* keyEvent, uint32_t policyFlags);
            const KeyEvent* keyEvent, uint32_t policyFlags);
    virtual bool dispatchUnhandledKey(const sp<IBinder>& token,
    virtual bool dispatchUnhandledKey(const sp<IBinder>& token,
            const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent);
            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(
    virtual bool checkInjectEventsPermissionNonReentrant(
            int32_t injectorPid, int32_t injectorUid);
            int32_t injectorPid, int32_t injectorUid);
    virtual void onPointerDownOutsideFocus(const sp<IBinder>& touchedToken);
    virtual void onPointerDownOutsideFocus(const sp<IBinder>& touchedToken);
@@ -1207,9 +1207,9 @@ bool NativeInputManager::dispatchUnhandledKey(const sp<IBinder>& token,
    return result;
    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();
    ATRACE_CALL();
    android_server_PowerManagerService_userActivity(eventTime, eventType);
    android_server_PowerManagerService_userActivity(eventTime, eventType, keyCode);
}
}




+9 −2
Original line number Original line Diff line number Diff line
@@ -41,6 +41,7 @@
#include <utils/misc.h>
#include <utils/misc.h>
#include <utils/String8.h>
#include <utils/String8.h>
#include <utils/Log.h>
#include <utils/Log.h>
#include <android/keycodes.h>


#include "com_android_server_power_PowerManagerService.h"
#include "com_android_server_power_PowerManagerService.h"


@@ -178,7 +179,8 @@ static void sendPowerHint(PowerHint hintId, uint32_t data) {
    SurfaceComposerClient::notifyPowerHint(static_cast<int32_t>(hintId));
    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) {
    if (gPowerManagerServiceObj) {
        // Throttle calls into user activity by event type.
        // Throttle calls into user activity by event type.
        // We're a little conservative about argument checking here in case the caller
        // We're a little conservative about argument checking here in case the caller
@@ -200,9 +202,14 @@ void android_server_PowerManagerService_userActivity(nsecs_t eventTime, int32_t


        JNIEnv* env = AndroidRuntime::getJNIEnv();
        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,
        env->CallVoidMethod(gPowerManagerServiceObj,
                gPowerManagerServiceClassInfo.userActivityFromNative,
                gPowerManagerServiceClassInfo.userActivityFromNative,
                nanoseconds_to_milliseconds(eventTime), eventType, 0);
                nanoseconds_to_milliseconds(eventTime), eventType, flags);
        checkAndClearExceptionFromCallback(env, "userActivityFromNative");
        checkAndClearExceptionFromCallback(env, "userActivityFromNative");
    }
    }
}
}
+2 −1
Original line number Original line Diff line number Diff line
@@ -24,7 +24,8 @@


namespace android {
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
} // namespace android