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

Commit 20907d86 authored by Steve Kondik's avatar Steve Kondik Committed by Steve Kondik
Browse files

livedisplay: Fix boot-time race condition

 * Use systemReady() callbacks so that we know that our dependencies are
   ready to party.

Change-Id: Ic922410616c3fa24a8a99c8e154249b3c172573c
parent 428793e4
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -279,6 +279,8 @@ public final class DisplayManagerService extends SystemService {
            mOnlyCore = onlyCore;
        }

        mDisplayPowerController.systemReady();

        mHandler.sendEmptyMessage(MSG_REGISTER_ADDITIONAL_DISPLAY_ADAPTERS);
    }

+4 −0
Original line number Diff line number Diff line
@@ -1165,6 +1165,10 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        return MathUtils.constrain(value, PowerManager.BRIGHTNESS_OFF, PowerManager.BRIGHTNESS_ON);
    }

    void systemReady() {
        mLiveDisplayController.systemReady();
    }

    private final class DisplayControllerHandler extends Handler {
        public DisplayControllerHandler(Looper looper) {
            super(looper, null, true /*async*/);
+20 −9
Original line number Diff line number Diff line
@@ -76,7 +76,8 @@ public class LiveDisplayController {

    private final Context mContext;
    private final Handler mHandler;
    private final CMHardwareManager mHardware;

    private CMHardwareManager mHardware;

    private int mDayTemperature;
    private int mNightTemperature;
@@ -88,16 +89,18 @@ public class LiveDisplayController {
    private final float[] mColorAdjustment = new float[] { 1.0f, 1.0f, 1.0f };
    private final float[] mRGB = new float[] { 0.0f, 0.0f, 0.0f };

    private final TwilightManager mTwilightManager;
    private TwilightManager mTwilightManager;
    private boolean mSunset = false;

    private final SettingsObserver mObserver;
    private SettingsObserver mObserver;

    private ValueAnimator mAnimator;

    private final int mDefaultDayTemperature;
    private final int mDefaultNightTemperature;
    private final int mDefaultOutdoorLux;
    private int mDefaultDayTemperature;
    private int mDefaultNightTemperature;
    private int mDefaultOutdoorLux;

    private boolean mInitialized = false;

    private static final int MSG_UPDATE_LIVE_DISPLAY = 1;

@@ -115,10 +118,10 @@ public class LiveDisplayController {
    LiveDisplayController(Context context, Looper looper) {
        mContext = context;
        mHandler = new LiveDisplayHandler(looper);
        mHardware = CMHardwareManager.getInstance(context);
    }

        mTwilightManager = LocalServices.getService(TwilightManager.class);
        mTwilightManager.registerListener(mTwilightListener, mHandler);
    void systemReady() {
        mHardware = CMHardwareManager.getInstance(mContext);

        mDefaultDayTemperature = mContext.getResources().getInteger(
                com.android.internal.R.integer.config_dayColorTemperature);
@@ -158,6 +161,11 @@ public class LiveDisplayController {
        PowerManagerInternal pmi = LocalServices.getService(PowerManagerInternal.class);
        pmi.registerLowPowerModeObserver(mLowPowerModeListener);
        mLowPerformance = pmi.getLowPowerModeEnabled();

        mTwilightManager = LocalServices.getService(TwilightManager.class);
        mTwilightManager.registerListener(mTwilightListener, mHandler);

        mInitialized = true;
    }

    private void updateSettings() {
@@ -570,6 +578,9 @@ public class LiveDisplayController {
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case MSG_UPDATE_LIVE_DISPLAY:
                    if (!mInitialized) {
                        break;
                    }
                    TwilightState twilight = mTwilightManager.getCurrentState();

                    updateColorTemperature(twilight);