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

Commit da7ac01b authored by Danesh M's avatar Danesh M
Browse files

Add config_autoBrightnessAmbientLightHorizon overlay

CYNGNOS-1475

Change-Id: I92bf8cfbb0eebb746622de123d3e065f4e47ed97
parent 0f799064
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -1071,6 +1071,9 @@
         to reduce it to preserve the battery. Value of 100% means no scaling. -->
    <fraction name="config_screenAutoBrightnessDozeScaleFactor">100%</fraction>

    <!-- Period of time in which to consider light samples in milliseconds. -->
    <integer name="config_autoBrightnessAmbientLightHorizon">10000</integer>

    <!-- When the screen is turned on, the previous estimate of the ambient light level at the time
         the screen was turned off is restored and is used to determine the initial screen
         brightness.
+1 −0
Original line number Diff line number Diff line
@@ -1696,6 +1696,7 @@
  <java-symbol type="integer" name="config_autoBrightnessBrighteningLightDebounce"/>
  <java-symbol type="integer" name="config_autoBrightnessDarkeningLightDebounce"/>
  <java-symbol type="integer" name="config_autoBrightnessLightSensorRate"/>
  <java-symbol type="integer" name="config_autoBrightnessAmbientLightHorizon"/>
  <java-symbol type="integer" name="config_carDockKeepsScreenOn" />
  <java-symbol type="integer" name="config_criticalBatteryWarningLevel" />
  <java-symbol type="integer" name="config_datause_notification_type" />
+19 −17
Original line number Diff line number Diff line
@@ -55,19 +55,12 @@ class AutomaticBrightnessController {
    // auto-brightness adjustment setting.
    private static final float SCREEN_AUTO_BRIGHTNESS_ADJUSTMENT_MAX_GAMMA = 3.0f;

    // Period of time in which to consider light samples in milliseconds.
    private static final int AMBIENT_LIGHT_HORIZON = 10000;

    // Hysteresis constraints for brightening or darkening.
    // The recent lux must have changed by at least this fraction relative to the
    // current ambient lux before a change will be considered.
    private static final float BRIGHTENING_LIGHT_HYSTERESIS = 0.10f;
    private static final float DARKENING_LIGHT_HYSTERESIS = 0.20f;

    // The intercept used for the weighting calculation. This is used in order to keep all possible
    // weighting values positive.
    private static final int WEIGHTING_INTERCEPT = AMBIENT_LIGHT_HORIZON;

    // How long the current sensor reading is assumed to be valid beyond the current time.
    // This provides a bit of prediction, as well as ensures that the weight for the last sample is
    // non-zero, which in turn ensures that the total weight is non-zero.
@@ -198,6 +191,13 @@ class AutomaticBrightnessController {
    // Night mode color temperature adjustments
    private final LiveDisplayController mLiveDisplay;

    // Period of time in which to consider light samples in milliseconds.
    private int mAmbientLightHorizon;

    // The intercept used for the weighting calculation. This is used in order to keep all possible
    // weighting values positive.
    private int mWeightingIntercept;

    private final Context mContext;

    public AutomaticBrightnessController(Context context, Callbacks callbacks, Looper looper,
@@ -205,7 +205,7 @@ class AutomaticBrightnessController {
            int brightnessMin, int brightnessMax, float dozeScaleFactor,
            int lightSensorRate, long brighteningLightDebounceConfig,
            long darkeningLightDebounceConfig, boolean resetAmbientLuxAfterWarmUpConfig,
            LiveDisplayController ldc) {
            int ambientLightHorizon, LiveDisplayController ldc) {
        mContext = context;
        mCallbacks = callbacks;
        mTwilight = LocalServices.getService(TwilightManager.class);
@@ -220,9 +220,11 @@ class AutomaticBrightnessController {
        mDarkeningLightDebounceConfig = darkeningLightDebounceConfig;
        mResetAmbientLuxAfterWarmUpConfig = resetAmbientLuxAfterWarmUpConfig;
        mLiveDisplay = ldc;
        mAmbientLightHorizon = ambientLightHorizon;
        mWeightingIntercept = ambientLightHorizon;

        mHandler = new AutomaticBrightnessHandler(looper);
        mAmbientLightRingBuffer = new AmbientLightRingBuffer(mLightSensorRate);
        mAmbientLightRingBuffer = new AmbientLightRingBuffer(mLightSensorRate, mAmbientLightHorizon);

        if (!DEBUG_PRETEND_LIGHT_SENSOR_ABSENT) {
            mLightSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
@@ -319,7 +321,7 @@ class AutomaticBrightnessController {

    private void applyLightSensorMeasurement(long time, float lux) {
        mRecentLightSamples++;
        mAmbientLightRingBuffer.prune(time - AMBIENT_LIGHT_HORIZON);
        mAmbientLightRingBuffer.prune(time - mAmbientLightHorizon);
        mAmbientLightRingBuffer.push(time, lux);

        // Remember this sample value.
@@ -370,14 +372,14 @@ class AutomaticBrightnessController {
        return sum / totalWeight;
    }

    private static float calculateWeight(long startDelta, long endDelta) {
    private float calculateWeight(long startDelta, long endDelta) {
        return weightIntegral(endDelta) - weightIntegral(startDelta);
    }

    // Evaluates the integral of y = x + WEIGHTING_INTERCEPT. This is always positive for the
    // Evaluates the integral of y = x + mWeightIntercept. This is always positive for the
    // horizon we're looking at and provides a non-linear weighting for light samples.
    private static float weightIntegral(long x) {
        return x * (x * 0.5f + WEIGHTING_INTERCEPT);
    private float weightIntegral(long x) {
        return x * (x * 0.5f + mWeightingIntercept);
    }

    private long nextAmbientLightBrighteningTransition(long time) {
@@ -406,7 +408,7 @@ class AutomaticBrightnessController {

    private void updateAmbientLux() {
        long time = SystemClock.uptimeMillis();
        mAmbientLightRingBuffer.prune(time - AMBIENT_LIGHT_HORIZON);
        mAmbientLightRingBuffer.prune(time - mAmbientLightHorizon);
        updateAmbientLux(time);
    }

@@ -666,8 +668,8 @@ class AutomaticBrightnessController {
        private int mEnd;
        private int mCount;

        public AmbientLightRingBuffer(long lightSensorRate) {
            mCapacity = (int) Math.ceil(AMBIENT_LIGHT_HORIZON * BUFFER_SLACK / lightSensorRate);
        public AmbientLightRingBuffer(long lightSensorRate, int ambientLightHorizon) {
            mCapacity = (int) Math.ceil(ambientLightHorizon * BUFFER_SLACK / lightSensorRate);
            mRingLux = new float[mCapacity];
            mRingTime = new long[mCapacity];
        }
+4 −1
Original line number Diff line number Diff line
@@ -321,6 +321,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                com.android.internal.R.integer.config_autoBrightnessDarkeningLightDebounce);
        boolean autoBrightnessResetAmbientLuxAfterWarmUp = resources.getBoolean(
                com.android.internal.R.bool.config_autoBrightnessResetAmbientLuxAfterWarmUp);
        int ambientLightHorizon = resources.getInteger(
                com.android.internal.R.integer.config_autoBrightnessAmbientLightHorizon);

        if (mUseSoftwareAutoBrightnessConfig) {
            int[] lux = resources.getIntArray(
@@ -358,7 +360,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                        lightSensorWarmUpTimeConfig, screenBrightnessRangeMinimum,
                        mScreenBrightnessRangeMaximum, dozeScaleFactor, lightSensorRate,
                        brighteningLightDebounce, darkeningLightDebounce,
                        autoBrightnessResetAmbientLuxAfterWarmUp, mLiveDisplayController);
                        autoBrightnessResetAmbientLuxAfterWarmUp, ambientLightHorizon,
                        mLiveDisplayController);
            }
        }