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

Commit 5b152846 authored by Santos Cordon's avatar Santos Cordon Committed by Automerger Merge Worker
Browse files

Merge "Apply a maximum time to Screen brightness RampAnimator." into tm-dev...

Merge "Apply a maximum time to Screen brightness RampAnimator." into tm-dev am: 7cda9b01 am: f9a5d08a am: ef7dfe00

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17707268



Change-Id: I33128e71a0cf88788d91ab7d1a2d95fbb72c2f6c
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents eedfddb0 ef7dfe00
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -152,6 +152,9 @@ import javax.xml.datatype.DatatypeConfigurationException;
 *      <screenBrightnessRampSlowDecrease>0.03</screenBrightnessRampSlowDecrease>
 *      <screenBrightnessRampSlowIncrease>0.04</screenBrightnessRampSlowIncrease>
 *
 *      <screenBrightnessRampIncreaseMaxMillis>2000</screenBrightnessRampIncreaseMaxMillis>
 *      <screenBrightnessRampDecreaseMaxMillis>3000</screenBrightnessRampDecreaseMaxMillis>
 *
 *      <lightSensor>
 *        <type>android.sensor.light</type>
 *        <name>1234 Ambient Light Sensor</name>
@@ -259,6 +262,8 @@ public class DisplayDeviceConfig {
    private float mBrightnessRampFastIncrease = Float.NaN;
    private float mBrightnessRampSlowDecrease = Float.NaN;
    private float mBrightnessRampSlowIncrease = Float.NaN;
    private long mBrightnessRampDecreaseMaxMillis = 0;
    private long mBrightnessRampIncreaseMaxMillis = 0;
    private int mAmbientHorizonLong = AMBIENT_LIGHT_LONG_HORIZON_MILLIS;
    private int mAmbientHorizonShort = AMBIENT_LIGHT_SHORT_HORIZON_MILLIS;
    private float mScreenBrighteningMinThreshold = 0.0f;     // Retain behaviour as though there is
@@ -534,6 +539,14 @@ public class DisplayDeviceConfig {
        return mBrightnessRampSlowIncrease;
    }

    public long getBrightnessRampDecreaseMaxMillis() {
        return mBrightnessRampDecreaseMaxMillis;
    }

    public long getBrightnessRampIncreaseMaxMillis() {
        return mBrightnessRampIncreaseMaxMillis;
    }

    public int getAmbientHorizonLong() {
        return mAmbientHorizonLong;
    }
@@ -628,6 +641,8 @@ public class DisplayDeviceConfig {
                + ", mBrightnessRampFastIncrease=" + mBrightnessRampFastIncrease
                + ", mBrightnessRampSlowDecrease=" + mBrightnessRampSlowDecrease
                + ", mBrightnessRampSlowIncrease=" + mBrightnessRampSlowIncrease
                + ", mBrightnessRampDecreaseMaxMillis=" + mBrightnessRampDecreaseMaxMillis
                + ", mBrightnessRampIncreaseMaxMillis=" + mBrightnessRampIncreaseMaxMillis
                + ", mAmbientHorizonLong=" + mAmbientHorizonLong
                + ", mAmbientHorizonShort=" + mAmbientHorizonShort
                + ", mScreenDarkeningMinThreshold=" + mScreenDarkeningMinThreshold
@@ -725,6 +740,8 @@ public class DisplayDeviceConfig {
        mBrightnessRampFastIncrease = PowerManager.BRIGHTNESS_MAX;
        mBrightnessRampSlowDecrease = PowerManager.BRIGHTNESS_MAX;
        mBrightnessRampSlowIncrease = PowerManager.BRIGHTNESS_MAX;
        mBrightnessRampDecreaseMaxMillis = 0;
        mBrightnessRampIncreaseMaxMillis = 0;
        setSimpleMappingStrategyValues();
        loadAmbientLightSensorFromConfigXml();
        setProxSensorUnspecified();
@@ -1115,6 +1132,15 @@ public class DisplayDeviceConfig {
            }
            loadBrightnessRampsFromConfigXml();
        }

        final BigInteger increaseMax = config.getScreenBrightnessRampIncreaseMaxMillis();
        if (increaseMax != null) {
            mBrightnessRampIncreaseMaxMillis = increaseMax.intValue();
        }
        final BigInteger decreaseMax = config.getScreenBrightnessRampDecreaseMaxMillis();
        if (decreaseMax != null) {
            mBrightnessRampDecreaseMaxMillis = decreaseMax.intValue();
        }
    }

    private void loadBrightnessRampsFromConfigXml() {
+16 −2
Original line number Diff line number Diff line
@@ -255,6 +255,10 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
    // to reach the final state.
    private final boolean mBrightnessBucketsInDozeConfig;

    //  Maximum time a ramp animation can take.
    private long mBrightnessRampIncreaseMaxTimeMillis;
    private long mBrightnessRampDecreaseMaxTimeMillis;

    // The pending power request.
    // Initially null until the first call to requestPowerState.
    @GuardedBy("mLock")
@@ -507,7 +511,6 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call

        final Resources resources = context.getResources();


        // DOZE AND DIM SETTINGS
        mScreenBrightnessDozeConfig = clampAbsoluteBrightness(
                pm.getBrightnessConstraint(PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_DOZE));
@@ -641,7 +644,6 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        mIsRbcActive = mCdsi.isReduceBrightColorsActivated();
        mAutomaticBrightnessController.recalculateSplines(mIsRbcActive, adjustedNits);


        // If rbc is turned on, off or there is a change in strength, we want to reset the short
        // term model. Since the nits range at which brightness now operates has changed due to
        // RBC/strength change, any short term model based on the previous range should be
@@ -837,6 +839,11 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        loadNitsRange(mContext.getResources());
        setUpAutoBrightness(mContext.getResources(), mHandler);
        reloadReduceBrightColours();
        if (mScreenBrightnessRampAnimator != null) {
            mScreenBrightnessRampAnimator.setAnimationTimeLimits(
                    mBrightnessRampIncreaseMaxTimeMillis,
                    mBrightnessRampDecreaseMaxTimeMillis);
        }
        mHbmController.resetHbmData(info.width, info.height, token, info.uniqueId,
                mDisplayDeviceConfig.getHighBrightnessModeData(),
                new HighBrightnessModeController.HdrBrightnessDeviceConfig() {
@@ -883,6 +890,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        mScreenBrightnessRampAnimator = new DualRampAnimator<>(mPowerState,
                DisplayPowerState.SCREEN_BRIGHTNESS_FLOAT,
                DisplayPowerState.SCREEN_SDR_BRIGHTNESS_FLOAT);
        mScreenBrightnessRampAnimator.setAnimationTimeLimits(
                mBrightnessRampIncreaseMaxTimeMillis,
                mBrightnessRampDecreaseMaxTimeMillis);
        mScreenBrightnessRampAnimator.setListener(mRampAnimatorListener);

        noteScreenState(mPowerState.getScreenState());
@@ -1007,6 +1017,10 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        mBrightnessRampRateFastIncrease = mDisplayDeviceConfig.getBrightnessRampFastIncrease();
        mBrightnessRampRateSlowDecrease = mDisplayDeviceConfig.getBrightnessRampSlowDecrease();
        mBrightnessRampRateSlowIncrease = mDisplayDeviceConfig.getBrightnessRampSlowIncrease();
        mBrightnessRampDecreaseMaxTimeMillis =
                mDisplayDeviceConfig.getBrightnessRampDecreaseMaxMillis();
        mBrightnessRampIncreaseMaxTimeMillis =
                mDisplayDeviceConfig.getBrightnessRampIncreaseMaxMillis();
    }

    private void loadNitsRange(Resources resources) {
+34 −1
Original line number Diff line number Diff line
@@ -34,6 +34,8 @@ class RampAnimator<T> {
    private float mCurrentValue;
    private float mTargetValue;
    private float mRate;
    private float mAnimationIncreaseMaxTimeSecs;
    private float mAnimationDecreaseMaxTimeSecs;

    private boolean mAnimating;
    private float mAnimatedValue; // higher precision copy of mCurrentValue
@@ -43,12 +45,23 @@ class RampAnimator<T> {

    private Listener mListener;

    public RampAnimator(T object, FloatProperty<T> property) {
    RampAnimator(T object, FloatProperty<T> property) {
        mObject = object;
        mProperty = property;
        mChoreographer = Choreographer.getInstance();
    }

    /**
     * Sets the maximum time that a brightness animation can take.
     */
    public void setAnimationTimeLimits(long animationRampIncreaseMaxTimeMillis,
            long animationRampDecreaseMaxTimeMillis) {
        mAnimationIncreaseMaxTimeSecs = (animationRampIncreaseMaxTimeMillis > 0)
                ? (animationRampIncreaseMaxTimeMillis / 1000.0f) : 0.0f;
        mAnimationDecreaseMaxTimeSecs = (animationRampDecreaseMaxTimeMillis > 0)
                ? (animationRampDecreaseMaxTimeMillis / 1000.0f) : 0.0f;
    }

    /**
     * Starts animating towards the specified value.
     *
@@ -83,6 +96,15 @@ class RampAnimator<T> {
            return false;
        }

        // Adjust the rate so that we do not exceed our maximum animation time.
        if (target > mCurrentValue && mAnimationIncreaseMaxTimeSecs > 0.0f
                && ((target - mCurrentValue) / rate) > mAnimationIncreaseMaxTimeSecs) {
            rate = (target - mCurrentValue) / mAnimationIncreaseMaxTimeSecs;
        } else if (target < mCurrentValue && mAnimationDecreaseMaxTimeSecs > 0.0f
                && ((mCurrentValue - target) / rate) > mAnimationDecreaseMaxTimeSecs) {
            rate = (mCurrentValue - target) / mAnimationDecreaseMaxTimeSecs;
        }

        // Adjust the rate based on the closest target.
        // If a faster rate is specified, then use the new rate so that we converge
        // more rapidly based on the new request.
@@ -208,6 +230,17 @@ class RampAnimator<T> {
            mSecond.setListener(mInternalListener);
        }

        /**
         * Sets the maximum time that a brightness animation can take.
         */
        public void setAnimationTimeLimits(long animationRampIncreaseMaxTimeMillis,
                long animationRampDecreaseMaxTimeMillis) {
            mFirst.setAnimationTimeLimits(animationRampIncreaseMaxTimeMillis,
                    animationRampDecreaseMaxTimeMillis);
            mSecond.setAnimationTimeLimits(animationRampIncreaseMaxTimeMillis,
                    animationRampDecreaseMaxTimeMillis);
        }

        /**
         * Starts animating towards the specified values.
         *
+10 −0
Original line number Diff line number Diff line
@@ -57,6 +57,16 @@
                <xs:element type="nonNegativeDecimal" name="screenBrightnessRampSlowIncrease">
                    <xs:annotation name="final"/>
                </xs:element>
                <!-- Maximum time in milliseconds that a brightness increase animation
                     can take. -->
                <xs:element type="xs:nonNegativeInteger" name="screenBrightnessRampIncreaseMaxMillis">
                    <xs:annotation name="final"/>
                </xs:element>
                <!-- Maximum time in milliseconds that a brightness decrease animation
                     can take. -->
                <xs:element type="xs:nonNegativeInteger" name="screenBrightnessRampDecreaseMaxMillis">
                    <xs:annotation name="final"/>
                </xs:element>
                <xs:element type="sensorDetails" name="lightSensor">
                    <xs:annotation name="final"/>
                </xs:element>
+4 −0
Original line number Diff line number Diff line
@@ -48,8 +48,10 @@ package com.android.server.display.config {
    method public com.android.server.display.config.DisplayQuirks getQuirks();
    method @NonNull public final java.math.BigDecimal getScreenBrightnessDefault();
    method @NonNull public final com.android.server.display.config.NitsMap getScreenBrightnessMap();
    method public final java.math.BigInteger getScreenBrightnessRampDecreaseMaxMillis();
    method public final java.math.BigDecimal getScreenBrightnessRampFastDecrease();
    method public final java.math.BigDecimal getScreenBrightnessRampFastIncrease();
    method public final java.math.BigInteger getScreenBrightnessRampIncreaseMaxMillis();
    method public final java.math.BigDecimal getScreenBrightnessRampSlowDecrease();
    method public final java.math.BigDecimal getScreenBrightnessRampSlowIncrease();
    method @NonNull public final com.android.server.display.config.ThermalThrottling getThermalThrottling();
@@ -64,8 +66,10 @@ package com.android.server.display.config {
    method public void setQuirks(com.android.server.display.config.DisplayQuirks);
    method public final void setScreenBrightnessDefault(@NonNull java.math.BigDecimal);
    method public final void setScreenBrightnessMap(@NonNull com.android.server.display.config.NitsMap);
    method public final void setScreenBrightnessRampDecreaseMaxMillis(java.math.BigInteger);
    method public final void setScreenBrightnessRampFastDecrease(java.math.BigDecimal);
    method public final void setScreenBrightnessRampFastIncrease(java.math.BigDecimal);
    method public final void setScreenBrightnessRampIncreaseMaxMillis(java.math.BigInteger);
    method public final void setScreenBrightnessRampSlowDecrease(java.math.BigDecimal);
    method public final void setScreenBrightnessRampSlowIncrease(java.math.BigDecimal);
    method public final void setThermalThrottling(@NonNull com.android.server.display.config.ThermalThrottling);