Update LightsService to use low-persistence mode.
Bug: 26274041
Bug: 26217194
Change-Id: I4cbee11d0936b6df5b8aed9dfab8d9d1d928f9c3
diff --git a/services/core/java/com/android/server/lights/LightsService.java b/services/core/java/com/android/server/lights/LightsService.java
index ed884ef..257c7da 100644
--- a/services/core/java/com/android/server/lights/LightsService.java
+++ b/services/core/java/com/android/server/lights/LightsService.java
@@ -17,6 +17,8 @@
package com.android.server.lights;
import com.android.server.SystemService;
+import com.android.server.vr.VrManagerInternal;
+import com.android.server.vr.VrStateListener;
import android.content.Context;
import android.os.Handler;
@@ -72,6 +74,9 @@
@Override
public void pulse(int color, int onMS) {
synchronized (this) {
+ if (mBrightnessMode == BRIGHTNESS_MODE_LOW_PERSISTENCE) {
+ return;
+ }
if (mColor == 0 && !mFlashing) {
setLightLocked(color, LIGHT_FLASH_HARDWARE, onMS, 1000, BRIGHTNESS_MODE_USER);
mColor = 0;
@@ -87,6 +92,20 @@
}
}
+ void enableLowPersistence() {
+ synchronized(this) {
+ setLightLocked(0, LIGHT_FLASH_NONE, 0, 0, BRIGHTNESS_MODE_LOW_PERSISTENCE);
+ mLocked = true;
+ }
+ }
+
+ void disableLowPersistence() {
+ synchronized(this) {
+ mLocked = false;
+ setLightLocked(mLastColor, LIGHT_FLASH_NONE, 0, 0, mLastBrightnessMode);
+ }
+ }
+
private void stopFlashing() {
synchronized (this) {
setLightLocked(mColor, LIGHT_FLASH_NONE, 0, 0, BRIGHTNESS_MODE_USER);
@@ -94,13 +113,17 @@
}
private void setLightLocked(int color, int mode, int onMS, int offMS, int brightnessMode) {
- if (color != mColor || mode != mMode || onMS != mOnMS || offMS != mOffMS) {
+ if (!mLocked && (color != mColor || mode != mMode || onMS != mOnMS || offMS != mOffMS ||
+ mBrightnessMode != brightnessMode)) {
if (DEBUG) Slog.v(TAG, "setLight #" + mId + ": color=#"
- + Integer.toHexString(color));
+ + Integer.toHexString(color) + ": brightnessMode=" + brightnessMode);
+ mLastColor = mColor;
mColor = color;
mMode = mode;
mOnMS = onMS;
mOffMS = offMS;
+ mLastBrightnessMode = mBrightnessMode;
+ mBrightnessMode = brightnessMode;
Trace.traceBegin(Trace.TRACE_TAG_POWER, "setLight(" + mId + ", 0x"
+ Integer.toHexString(color) + ")");
try {
@@ -117,6 +140,10 @@
private int mOnMS;
private int mOffMS;
private boolean mFlashing;
+ private int mBrightnessMode;
+ private int mLastBrightnessMode;
+ private int mLastColor;
+ private boolean mLocked;
}
public LightsService(Context context) {
@@ -134,6 +161,28 @@
publishLocalService(LightsManager.class, mService);
}
+ @Override
+ public void onBootPhase(int phase) {
+ if (phase == PHASE_SYSTEM_SERVICES_READY) {
+ getLocalService(VrManagerInternal.class).registerListener(mVrStateListener);
+ }
+ }
+
+ private final VrStateListener mVrStateListener = new VrStateListener() {
+ @Override
+ public void onVrStateChanged(boolean enabled) {
+ LightImpl l = mLights[LightsManager.LIGHT_ID_BACKLIGHT];
+ if (enabled) {
+ if (DEBUG) Slog.v(TAG, "VR mode enabled, setting brightness to low persistence");
+ l.enableLowPersistence();
+
+ } else {
+ if (DEBUG) Slog.v(TAG, "VR mode disabled, resetting brightnes");
+ l.disableLowPersistence();
+ }
+ }
+ };
+
private final LightsManager mService = new LightsManager() {
@Override
public Light getLight(int id) {