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

Unverified Commit 369c6918 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 a2024f9f
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -406,6 +406,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 −2
Original line number Diff line number Diff line
@@ -2200,8 +2200,9 @@ public final class PowerManagerService extends SystemService
                if (eventTime > powerGroup.getLastUserActivityTimeLocked()) {
                    powerGroup.setButtonPressedLocked(
                            event == PowerManager.USER_ACTIVITY_EVENT_BUTTON);
                    if ((mButtonLightOnKeypressOnly && powerGroup.getButtonPressedLocked())
                            || eventTime == powerGroup.getLastWakeTimeLocked()) {
                    if (eventTime == powerGroup.getLastWakeTimeLocked() ||
                            (mButtonLightOnKeypressOnly && powerGroup.getButtonPressedLocked() &&
                            (flags & PowerManager.USER_ACTIVITY_FLAG_NO_BUTTON_LIGHTS) == 0)) {
                        powerGroup.setButtonPressedLocked(true);
                        powerGroup.setLastButtonActivityTimeLocked(eventTime);
                    }
+5 −3
Original line number Diff line number Diff line
@@ -354,7 +354,8 @@ public:
                                          uint32_t policyFlags) override;
    std::optional<KeyEvent> dispatchUnhandledKey(const sp<IBinder>& token, const KeyEvent& keyEvent,
                                                 uint32_t policyFlags) 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;
    void onPointerDownOutsideFocus(const sp<IBinder>& touchedToken) override;
    void setPointerCapture(const PointerCaptureRequest& request) override;
    void notifyDropWindow(const sp<IBinder>& token, float x, float y) override;
@@ -1528,9 +1529,10 @@ std::optional<KeyEvent> NativeInputManager::dispatchUnhandledKey(const sp<IBinde
    return fallbackEvent;
}

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);
}

void NativeInputManager::onPointerDownOutsideFocus(const sp<IBinder>& touchedToken) {
+8 −2
Original line number Diff line number Diff line
@@ -24,6 +24,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/ISuspendControlService.h>
#include <android/system/suspend/internal/ISuspendControlServiceInternal.h>
#include <nativehelper/JNIHelp.h>
@@ -106,7 +107,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
@@ -128,9 +129,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