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

Commit 62f8caf2 authored by Steve Kondik's avatar Steve Kondik Committed by Arne Coucheron
Browse files

livedisplay: Don't depend on automatic brightness

 * 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
parent 23ce1003
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -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);
@@ -188,6 +189,7 @@ class AutomaticBrightnessController {
        mScreenBrightnessRangeMinimum = brightnessMin;
        mScreenBrightnessRangeMaximum = brightnessMax;
        mLightSensorWarmUpTimeConfig = lightSensorWarmUpTime;
        mLiveDisplay = ldc;

        mHandler = new AutomaticBrightnessHandler(looper);
        mAmbientLightRingBuffer = new AmbientLightRingBuffer();
@@ -199,7 +201,6 @@ class AutomaticBrightnessController {
        if (USE_TWILIGHT_ADJUSTMENT) {
            mTwilight.registerListener(mTwilightListener, mHandler);
        }
        mLiveDisplay = new LiveDisplayController(mContext, looper);
    }

    public int getAutomaticScreenBrightness() {
@@ -238,8 +239,6 @@ class AutomaticBrightnessController {
        pw.println("  mScreenAutoBrightness=" + mScreenAutoBrightness);
        pw.println("  mScreenAutoBrightnessAdjustment=" + mScreenAutoBrightnessAdjustment);
        pw.println("  mLastScreenAutoBrightnessGamma=" + mLastScreenAutoBrightnessGamma);

        mLiveDisplay.dump(pw);;
    }

    private boolean setLightSensorEnabled(boolean enable) {
@@ -442,6 +441,7 @@ class AutomaticBrightnessController {
            }
        }

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

        if (USE_TWILIGHT_ADJUSTMENT) {
+10 −1
Original line number Diff line number Diff line
@@ -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;
@@ -263,6 +266,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        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));
@@ -326,7 +331,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                mAutomaticBrightnessController = new AutomaticBrightnessController(mContext, this,
                        handler.getLooper(), sensorManager, screenAutoBrightnessSpline,
                        lightSensorWarmUpTimeConfig, screenBrightnessRangeMinimum,
                        mScreenBrightnessRangeMaximum);
                        mScreenBrightnessRangeMaximum, mLiveDisplayController);
            }
        }

@@ -656,6 +661,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
            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
@@ -1076,6 +1084,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
            mAutomaticBrightnessController.dump(pw);
        }

        mLiveDisplayController.dump(pw);
    }

    private static String proximityToString(int state) {
+4 −0
Original line number Diff line number Diff line
@@ -270,6 +270,10 @@ public class LiveDisplayController {
        }
    }

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

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