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

Commit e8c1c7cb authored by Mike Kasick's avatar Mike Kasick Committed by Ricardo Cerqueira
Browse files

PowerManagerService: Implement setButtonBrightnessOverrideFromWindowManager method

Differs from Android 4.1 (and earlier) implementation in that the
overridden button light still turns off after BUTTON_ON_DURATION instead of
staying on until screen off.  However, button lights are annoying, and
really the purpose of this is to allow apps (e.g., Screen Filter) to
_disable_ the button lights altogether.
parent 53464779
Loading
Loading
Loading
Loading
+29 −4
Original line number Diff line number Diff line
@@ -354,6 +354,11 @@ public final class PowerManagerService extends IPowerManager.Stub
    // Use -1 to disable.
    private int mScreenBrightnessOverrideFromWindowManager = -1;

    // The button brightness setting override from the window manager
    // to allow the current foreground activity to override the button brightness.
    // Use -1 to disable.
    private int mButtonBrightnessOverrideFromWindowManager = -1;

    // The user activity timeout override from the window manager
    // to allow the current foreground activity to override the user activity timeout.
    // Use -1 to disable.
@@ -1360,9 +1365,14 @@ public final class PowerManagerService extends IPowerManager.Stub
                        if (now > mLastUserActivityTime + BUTTON_ON_DURATION) {
                            mButtonsLight.setBrightness(0);
                        } else {
                            mButtonsLight.setBrightness(mDisplayPowerRequest.screenBrightness);
                            int brightness = mButtonBrightnessOverrideFromWindowManager >= 0
                                    ? mButtonBrightnessOverrideFromWindowManager
                                    : mDisplayPowerRequest.screenBrightness;
                            mButtonsLight.setBrightness(brightness);
                            if (brightness != 0) {
                                nextTimeout = now + BUTTON_ON_DURATION;
                            }
                        }
                        mUserActivitySummary |= USER_ACTIVITY_SCREEN_BRIGHT;
                    } else {
                        nextTimeout = mLastUserActivityTime + screenOffTimeout;
@@ -2135,9 +2145,24 @@ public final class PowerManagerService extends IPowerManager.Stub
     * @param brightness The overridden brightness, or -1 to disable the override.
     */
    public void setButtonBrightnessOverrideFromWindowManager(int brightness) {
        // Do nothing.
        // Button lights are not currently supported in the new implementation.
        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);

        final long ident = Binder.clearCallingIdentity();
        try {
            setButtonBrightnessOverrideFromWindowManagerInternal(brightness);
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    }

    private void setButtonBrightnessOverrideFromWindowManagerInternal(int brightness) {
        synchronized (mLock) {
            if (mButtonBrightnessOverrideFromWindowManager != brightness) {
                mButtonBrightnessOverrideFromWindowManager = brightness;
                mDirty |= DIRTY_SETTINGS;
                updatePowerStateLocked();
            }
        }
    }

    /**