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

Commit 20a3c7c4 authored by Anas Karbila's avatar Anas Karbila Committed by Arne Coucheron
Browse files

PowerManagerService: add a config 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 config in order to make this behavior
   consistent to stock ROMs for some devices.

Change-Id: I3bc214d9062f6762ebe5ab0fff949da0460a0fec
parent bf088b80
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -108,4 +108,7 @@

    <!-- Whether notify fingerprint client of successful cancelled authentication -->
    <java-symbol type="bool" name="config_notifyClientOnFingerprintCancelSuccess" />

    <!-- Whether light up buttons only when pressed -->
    <java-symbol type="bool" name="config_buttonLightOnKeypressOnly" />
</resources>
+4 −0
Original line number Diff line number Diff line
@@ -2947,4 +2947,8 @@

    <!-- Whether notify fingerprint client of successful cancelled authentication -->
    <bool name="config_notifyClientOnFingerprintCancelSuccess">false</bool>

    <!-- If enabled, capacitive keys will only light up when pressed.
         Otherwise, the buttons will light up whenever the user interacts with the device -->
    <bool name="config_buttonLightOnKeypressOnly">false</bool>
</resources>
+16 −2
Original line number Diff line number Diff line
@@ -226,6 +226,9 @@ public final class PowerManagerService extends SystemService
    private int mKeyboardBrightness;
    private int mKeyboardBrightnessSettingDefault;

    private boolean mButtonPressed = false;
    private boolean mButtonLightOnKeypressOnly;

    private final Object mLock = new Object();

    // A bitfield that indicates what parts of the power state have
@@ -272,6 +275,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;

@@ -826,6 +830,8 @@ public final class PowerManagerService extends SystemService
            mProximityWakeLock = ((PowerManager) mContext.getSystemService(Context.POWER_SERVICE))
                    .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ProximityWakeLock");
        }
        mButtonLightOnKeypressOnly = resources.getBoolean(
                com.android.internal.R.bool.config_buttonLightOnKeypressOnly);
    }

    private void updateSettingsLocked() {
@@ -1308,6 +1314,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;
                    return true;
@@ -1866,12 +1876,16 @@ public final class PowerManagerService extends SystemService

                            mKeyboardLight.setBrightness(mKeyboardVisible ?
                                    keyboardBrightness : 0);
                            mLastButtonActivityTime = mButtonLightOnKeypressOnly ?
                                    mLastButtonActivityTime : mLastUserActivityTime;
                            if (mButtonTimeout != 0
                                    && now > mLastUserActivityTime + mButtonTimeout) {
                                    && 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;
                                    }