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

Commit 2360e604 authored by Anas Karbila's avatar Anas Karbila Committed by Bruno Martins
Browse files

PowerManagerService: Allow to light up buttons only when pressed

 * Right now capactive, lit hardware keys are being
   lit every time you either touch them or the screen.

   But some devices handle this differently on stock:

   Display touch => buttons not lit
   Buttons touch => buttons lit

 * Thus, add a setting in order to allow the user
   to choose the preferred behavior.

Change-Id: I35ac71a8274568901f962c9692788d1c682a98dd
parent f11147df
Loading
Loading
Loading
Loading
+21 −2
Original line number Diff line number Diff line
@@ -259,6 +259,9 @@ public final class PowerManagerService extends SystemService
    private int mButtonBrightness;
    private int mButtonBrightnessSettingDefault;

    private boolean mButtonPressed;
    private boolean mButtonLightOnKeypressOnly;

    private final Object mLock = LockGuard.installNewLock(LockGuard.INDEX_POWER);

    // A bitfield that indicates what parts of the power state have
@@ -305,6 +308,7 @@ public final class PowerManagerService extends SystemService
    private long mLastSleepTime;

    // Timestamp of the last call to user activity.
    private long mLastButtonActivityTime;
    private long mLastUserActivityTime;
    private long mLastUserActivityTimeNoChangeLights;

@@ -876,6 +880,9 @@ public final class PowerManagerService extends SystemService
        resolver.registerContentObserver(LineageSettings.Global.getUriFor(
                LineageSettings.Global.WAKE_WHEN_PLUGGED_OR_UNPLUGGED),
                false, mSettingsObserver, UserHandle.USER_ALL);
        resolver.registerContentObserver(LineageSettings.System.getUriFor(
                LineageSettings.System.BUTTON_BACKLIGHT_ONLY_WHEN_PRESSED),
                false, mSettingsObserver, UserHandle.USER_ALL);
        IVrManager vrManager = (IVrManager) getBinderService(Context.VR_SERVICE);
        if (vrManager != null) {
            try {
@@ -1050,6 +1057,9 @@ public final class PowerManagerService extends SystemService
        mButtonBrightness = LineageSettings.Secure.getIntForUser(resolver,
                LineageSettings.Secure.BUTTON_BRIGHTNESS, mButtonBrightnessSettingDefault,
                UserHandle.USER_CURRENT);
        mButtonLightOnKeypressOnly = LineageSettings.System.getIntForUser(resolver,
                LineageSettings.System.BUTTON_BACKLIGHT_ONLY_WHEN_PRESSED,
                0, UserHandle.USER_CURRENT) == 1;

        mDirty |= DIRTY_SETTINGS;
    }
@@ -1460,6 +1470,10 @@ public final class PowerManagerService extends SystemService
                }
            } else {
                if (eventTime > mLastUserActivityTime) {
                    mButtonPressed = event == PowerManager.USER_ACTIVITY_EVENT_BUTTON;
                    if (mButtonLightOnKeypressOnly && mButtonPressed) {
                        mLastButtonActivityTime = eventTime;
                    }
                    mLastUserActivityTime = eventTime;
                    mDirty |= DIRTY_USER_ACTIVITY;
                    if (event == PowerManager.USER_ACTIVITY_EVENT_BUTTON) {
@@ -2050,11 +2064,16 @@ public final class PowerManagerService extends SystemService
                                }
                            }

                            if (mButtonTimeout != 0 && now > mLastUserActivityTime + mButtonTimeout) {
                            mLastButtonActivityTime = mButtonLightOnKeypressOnly ?
                                    mLastButtonActivityTime : mLastUserActivityTime;
                            if (mButtonTimeout != 0 &&
                                    now > mLastButtonActivityTime + mButtonTimeout) {
                                mButtonsLight.setBrightness(0);
                            } else {
                                if (!mProximityPositive) {
                                if ((!mButtonLightOnKeypressOnly || mButtonPressed) &&
                                        !mProximityPositive) {
                                    mButtonsLight.setBrightness(buttonBrightness);
                                    mButtonPressed = false;
                                    if (buttonBrightness != 0 && mButtonTimeout != 0) {
                                        nextTimeout = now + mButtonTimeout;
                                    }