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

Commit 569a46d2 authored by Mike Lockwood's avatar Mike Lockwood
Browse files

Keep automatic screen brightness monotonically increasing until screen is turned off.



This is an experimental change to avoid the light sensor screen fluctuation problem.
We only do this when undocked to since the lighting should be stable in the docked case
and since the dock keeps the screen on we need to be able to adjust the lighting.

Change-Id: I03454cf3b5ad8d6d6335862f0683ff0daa22209a
BUG: 2387223
Signed-off-by: default avatarMike Lockwood <lockwood@android.com>
parent 56285d8f
Loading
Loading
Loading
Loading
+42 −1
Original line number Diff line number Diff line
@@ -209,9 +209,11 @@ class PowerManagerService extends IPowerManager.Stub
    private Sensor mLightSensor;
    private boolean mLightSensorEnabled;
    private float mLightSensorValue = -1;
    private int mHighestLightSensorValue = -1;
    private float mLightSensorPendingValue = -1;
    private int mLightSensorBrightness = -1;
    private boolean mDimScreen = true;
    private boolean mIsDocked = false;
    private long mNextTimeout;
    private volatile int mPokey = 0;
    private volatile boolean mPokeAwakeOnSet = false;
@@ -361,6 +363,15 @@ class PowerManagerService extends IPowerManager.Stub
        }
    }

    private final class DockReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            int state = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
                    Intent.EXTRA_DOCK_STATE_UNDOCKED);
            dockStateChanged(state);
        }
    }

    /**
     * Set the setting that determines whether the device stays on when plugged in.
     * The argument is a bit string, with each bit specifying a power source that,
@@ -511,6 +522,9 @@ class PowerManagerService extends IPowerManager.Stub
        filter = new IntentFilter();
        filter.addAction(Intent.ACTION_BOOT_COMPLETED);
        mContext.registerReceiver(new BootCompletedReceiver(), filter);
        filter = new IntentFilter();
        filter.addAction(Intent.ACTION_DOCK_EVENT);
        mContext.registerReceiver(new DockReceiver(), filter);

        // Listen for Gservices changes
        IntentFilter gservicesChangedFilter =
@@ -1360,6 +1374,8 @@ class PowerManagerService extends IPowerManager.Stub
                    // clear current value so we will update based on the new conditions
                    // when the sensor is reenabled.
                    mLightSensorValue = -1;
                    // reset our highest light sensor value when the screen turns off
                    mHighestLightSensorValue = -1;
                }
            }
        }
@@ -2002,15 +2018,40 @@ class PowerManagerService extends IPowerManager.Stub
        }
    };

    private void dockStateChanged(int state) {
        synchronized (mLocks) {
            mIsDocked = (state != Intent.EXTRA_DOCK_STATE_UNDOCKED);
            if (mIsDocked) {
                mHighestLightSensorValue = -1;
            }
            if ((mPowerState & SCREEN_ON_BIT) != 0) {
                // force lights recalculation
                int value = (int)mLightSensorValue;
                mLightSensorValue = -1;
                lightSensorChangedLocked(value);
            }
        }
    }

    private void lightSensorChangedLocked(int value) {
        if (mDebugLightSensor) {
            Log.d(TAG, "lightSensorChangedLocked " + value);
        }

        // do not allow light sensor value to decrease
        if (mHighestLightSensorValue < value) {
            mHighestLightSensorValue = value;
        }

        if (mLightSensorValue != value) {
            mLightSensorValue = value;
            if ((mPowerState & BATTERY_LOW_BIT) == 0) {
                int lcdValue = getAutoBrightnessValue(value, mLcdBacklightValues);
                // use maximum light sensor value seen since screen went on for LCD to avoid flicker
                // we only do this if we are undocked, since lighting should be stable when
                // stationary in a dock.
                int lcdValue = getAutoBrightnessValue(
                        (mIsDocked ? value : mHighestLightSensorValue),
                        mLcdBacklightValues);
                int buttonValue = getAutoBrightnessValue(value, mButtonBacklightValues);
                int keyboardValue;
                if (mKeyboardVisible) {