Skip to content

Commit

Permalink
livedisplay: Don't depend on automatic brightness
Browse files Browse the repository at this point in the history
 * Some devices will have this disabled or unavailable. Create the
   controller from DisplayPowerManager and give it a kick during
   screen power changes.

Change-Id: I02af7e1bb3087bcf458a8238560b3c25b02637ac
  • Loading branch information
Steve Kondik authored and arco committed Mar 29, 2015
1 parent 23ce100 commit 62f8caf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ class AutomaticBrightnessController {

public AutomaticBrightnessController(Context context, Callbacks callbacks, Looper looper,
SensorManager sensorManager, Spline autoBrightnessSpline,
int lightSensorWarmUpTime, int brightnessMin, int brightnessMax) {
int lightSensorWarmUpTime, int brightnessMin, int brightnessMax,
LiveDisplayController ldc) {
mContext = context;
mCallbacks = callbacks;
mTwilight = LocalServices.getService(TwilightManager.class);
Expand All @@ -188,6 +189,7 @@ public AutomaticBrightnessController(Context context, Callbacks callbacks, Loope
mScreenBrightnessRangeMinimum = brightnessMin;
mScreenBrightnessRangeMaximum = brightnessMax;
mLightSensorWarmUpTimeConfig = lightSensorWarmUpTime;
mLiveDisplay = ldc;

mHandler = new AutomaticBrightnessHandler(looper);
mAmbientLightRingBuffer = new AmbientLightRingBuffer();
Expand All @@ -199,7 +201,6 @@ public AutomaticBrightnessController(Context context, Callbacks callbacks, Loope
if (USE_TWILIGHT_ADJUSTMENT) {
mTwilight.registerListener(mTwilightListener, mHandler);
}
mLiveDisplay = new LiveDisplayController(mContext, looper);
}

public int getAutomaticScreenBrightness() {
Expand Down Expand Up @@ -238,8 +239,6 @@ public void dump(PrintWriter pw) {
pw.println(" mScreenAutoBrightness=" + mScreenAutoBrightness);
pw.println(" mScreenAutoBrightnessAdjustment=" + mScreenAutoBrightnessAdjustment);
pw.println(" mLastScreenAutoBrightnessGamma=" + mLastScreenAutoBrightnessGamma);

mLiveDisplay.dump(pw);;
}

private boolean setLightSensorEnabled(boolean enable) {
Expand Down Expand Up @@ -442,6 +441,7 @@ private void updateAutoBrightness(boolean sendUpdate) {
}
}

// Update LiveDisplay with the current lux
mLiveDisplay.updateLiveDisplay(mAmbientLux);

if (USE_TWILIGHT_ADJUSTMENT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
// The controller for the automatic brightness level.
private AutomaticBrightnessController mAutomaticBrightnessController;

// The controller for LiveDisplay
private final LiveDisplayController mLiveDisplayController;

// Animators.
private ObjectAnimator mColorFadeOnAnimator;
private ObjectAnimator mColorFadeOffAnimator;
Expand All @@ -263,6 +266,8 @@ public DisplayPowerController(Context context,
mBlanker = blanker;
mContext = context;

mLiveDisplayController = new LiveDisplayController(context, handler.getLooper());

final Resources resources = context.getResources();
final int screenBrightnessSettingMinimum = clampAbsoluteBrightness(resources.getInteger(
com.android.internal.R.integer.config_screenBrightnessSettingMinimum));
Expand Down Expand Up @@ -326,7 +331,7 @@ public DisplayPowerController(Context context,
mAutomaticBrightnessController = new AutomaticBrightnessController(mContext, this,
handler.getLooper(), sensorManager, screenAutoBrightnessSpline,
lightSensorWarmUpTimeConfig, screenBrightnessRangeMinimum,
mScreenBrightnessRangeMaximum);
mScreenBrightnessRangeMaximum, mLiveDisplayController);
}
}

Expand Down Expand Up @@ -656,6 +661,9 @@ private void updatePowerState() {
animateScreenBrightness(brightness, 0);
}

// Update LiveDisplay now
mLiveDisplayController.updateLiveDisplay();

// Determine whether the display is ready for use in the newly requested state.
// Note that we do not wait for the brightness ramp animation to complete before
// reporting the display is ready because we only need to ensure the screen is in the
Expand Down Expand Up @@ -1076,6 +1084,7 @@ private void dumpLocal(PrintWriter pw) {
mAutomaticBrightnessController.dump(pw);
}

mLiveDisplayController.dump(pw);
}

private static String proximityToString(int state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ public void onChange(boolean selfChange, Uri uri) {
}
}

public void updateLiveDisplay() {
updateLiveDisplay(mCurrentLux);
}

public synchronized void updateLiveDisplay(float lux) {
mCurrentLux = lux;
mHandler.removeMessages(MSG_UPDATE_LIVE_DISPLAY);
Expand Down

0 comments on commit 62f8caf

Please sign in to comment.