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

Unverified Commit 9243440c authored by Corinna Vinschen's avatar Corinna Vinschen Committed by Michael Bestas
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 93ea7160
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -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
     */
+3 −3
Original line number Diff line number Diff line
@@ -1891,9 +1891,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);
+3 −3
Original line number Diff line number Diff line
@@ -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(
+8 −2
Original line number Diff line number Diff line
@@ -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");
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -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