Skip to content

Commit

Permalink
Reintroduce button-backlight (and respective inactivity timeout)
Browse files Browse the repository at this point in the history
The power manager rewrite from Change I1d7a52e98f0449f76d70bf421f6a7f245957d1d7
completely removed support for control of the button backlights, which makes
all capacitive buttons out there stay dark. The commit message in that change
mentions it hasn't been implemented _yet_, so this fix should be temporary
until upstream does their own implementation

[RC: Updated to 5.0]

Change-Id: I6094c446e0b8c23f57d30652a3cbd35dee5e821a
  • Loading branch information
rmcc authored and sam3000 committed Feb 10, 2018
1 parent a97b251 commit f3d5b2d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.android.internal.app.IBatteryStats;
import com.android.server.LocalServices;
import com.android.server.am.BatteryStatsService;
import com.android.server.lights.LightsManager;

import android.animation.Animator;
import android.animation.ObjectAnimator;
Expand Down Expand Up @@ -129,6 +130,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
// Battery stats.
private final IBatteryStats mBatteryStats;

// The lights service.
private final LightsManager mLights;

// The sensor manager.
private final SensorManager mSensorManager;

Expand Down Expand Up @@ -300,6 +304,7 @@ public DisplayPowerController(Context context,
mCallbacks = callbacks;

mBatteryStats = BatteryStatsService.getService();
mLights = LocalServices.getService(LightsManager.class);
mSensorManager = sensorManager;
mWindowManagerPolicy = LocalServices.getService(WindowManagerPolicy.class);
mBlanker = blanker;
Expand Down Expand Up @@ -678,6 +683,12 @@ private void updatePowerState() {
// Use zero brightness when screen is off.
if (state == Display.STATE_OFF) {
brightness = PowerManager.BRIGHTNESS_OFF;
mLights.getLight(LightsManager.LIGHT_ID_BUTTONS).setBrightness(brightness);
}

// Disable button lights when dozing
if (state == Display.STATE_DOZE || state == Display.STATE_DOZE_SUSPEND) {
mLights.getLight(LightsManager.LIGHT_ID_BUTTONS).setBrightness(PowerManager.BRIGHTNESS_OFF);
}

// Configure auto-brightness.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ public final class PowerManagerService extends SystemService
private static final int HALT_MODE_REBOOT = 1;
private static final int HALT_MODE_REBOOT_SAFE_MODE = 2;

private static final int BUTTON_ON_DURATION = 5 * 1000;

// File location for last reboot reason
private static final String LAST_REBOOT_LOCATION = "/data/misc/reboot/last_reboot_reason";

Expand All @@ -240,6 +242,7 @@ public final class PowerManagerService extends SystemService
private SettingsObserver mSettingsObserver;
private DreamManagerInternal mDreamManager;
private Light mAttentionLight;
private Light mButtonsLight;

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

Expand Down Expand Up @@ -747,6 +750,7 @@ mAppOps, createSuspendBlockerLocked("PowerManagerService.Broadcasts"),

mLightsManager = getLocalService(LightsManager.class);
mAttentionLight = mLightsManager.getLight(LightsManager.LIGHT_ID_ATTENTION);
mButtonsLight = mLightsManager.getLight(LightsManager.LIGHT_ID_BUTTONS);

// Initialize display power management.
mDisplayManagerInternal.initPowerManagement(
Expand Down Expand Up @@ -1947,6 +1951,12 @@ private void updateUserActivitySummaryLocked(long now, int dirty) {
nextTimeout = mLastUserActivityTime
+ screenOffTimeout - screenDimDuration;
if (now < nextTimeout) {
if (now > mLastUserActivityTime + BUTTON_ON_DURATION) {
mButtonsLight.setBrightness(0);
} else {
mButtonsLight.setBrightness(mDisplayPowerRequest.screenBrightness);
nextTimeout = now + BUTTON_ON_DURATION;
}
mUserActivitySummary = USER_ACTIVITY_SCREEN_BRIGHT;
} else {
nextTimeout = mLastUserActivityTime + screenOffTimeout;
Expand Down

0 comments on commit f3d5b2d

Please sign in to comment.