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

Commit 543223fd authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Port autobrightness brightnening and darkening light debounce config...

Merge "Port autobrightness brightnening and darkening light debounce config from per device to per display configs" into tm-qpr-dev
parents cf93bf71 17be5b6f
Loading
Loading
Loading
Loading
+121 −41
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.view.DisplayAddress;
import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.display.BrightnessSynchronizer;
import com.android.server.display.config.AutoBrightness;
import com.android.server.display.config.BrightnessThresholds;
import com.android.server.display.config.BrightnessThrottlingMap;
import com.android.server.display.config.BrightnessThrottlingPoint;
@@ -69,8 +70,7 @@ import java.util.List;
import javax.xml.datatype.DatatypeConfigurationException;

/**
 *  Reads and stores display-specific configurations.
 *  File format:
 * Reads and stores display-specific configurations. File format:
 * <pre>
 *  {@code
 *    <displayConfiguration>
@@ -147,6 +147,15 @@ import javax.xml.datatype.DatatypeConfigurationException;
 *       <quirk>canSetBrightnessViaHwc</quirk>
 *      </quirks>
 *
 *      <autoBrightness>
 *           <brighteningLightDebounceMillis>
 *              2000
 *           </brighteningLightDebounceMillis>
 *          <darkeningLightDebounceMillis>
 *              1000
 *          </darkeningLightDebounceMillis>
 *      </autoBrightness>
 *
 *      <screenBrightnessRampFastDecrease>0.01</screenBrightnessRampFastDecrease>
 *      <screenBrightnessRampFastIncrease>0.02</screenBrightnessRampFastIncrease>
 *      <screenBrightnessRampSlowDecrease>0.03</screenBrightnessRampSlowDecrease>
@@ -224,6 +233,9 @@ public class DisplayDeviceConfig {
    // Length of the ambient light horizon used to calculate short-term estimate of ambient light.
    private static final int AMBIENT_LIGHT_SHORT_HORIZON_MILLIS = 2000;

    // Invalid value of AutoBrightness brightening and darkening light debounce
    private static final int INVALID_AUTO_BRIGHTNESS_LIGHT_DEBOUNCE = -1;

    @VisibleForTesting
    static final float HDR_PERCENT_OF_SCREEN_REQUIRED_DEFAULT = 0.5f;

@@ -281,6 +293,14 @@ public class DisplayDeviceConfig {
    private String mLoadedFrom = null;
    private Spline mSdrToHdrRatioSpline;

    // Represents the auto-brightness brightening light debounce.
    private long mAutoBrightnessBrighteningLightDebounce =
            INVALID_AUTO_BRIGHTNESS_LIGHT_DEBOUNCE;

    // Represents the auto-brightness darkening light debounce.
    private long mAutoBrightnessDarkeningLightDebounce =
            INVALID_AUTO_BRIGHTNESS_LIGHT_DEBOUNCE;

    // Brightness Throttling data may be updated via the DeviceConfig. Here we store the original
    // data, which comes from the ddc, and the current one, which may be the DeviceConfig
    // overwritten value.
@@ -293,8 +313,8 @@ public class DisplayDeviceConfig {
    }

    /**
     * Creates an instance for the specified display.
     * Tries to find a file with identifier in the following priority order:
     * Creates an instance for the specified display. Tries to find a file with identifier in the
     * following priority order:
     * <ol>
     *     <li>physicalDisplayId</li>
     *     <li>physicalDisplayId without a stable flag (old system)</li>
@@ -314,11 +334,12 @@ public class DisplayDeviceConfig {
    }

    /**
     * Creates an instance using global values since no display device config xml exists.
     * Uses values from config or PowerManager.
     * Creates an instance using global values since no display device config xml exists. Uses
     * values from config or PowerManager.
     *
     * @param context
     * @param useConfigXml
     * @param context      The context from which the DisplayDeviceConfig is to be constructed.
     * @param useConfigXml A flag indicating if values are to be loaded from the configuration file,
     *                     or the default values.
     * @return A configuration instance.
     */
    public static DisplayDeviceConfig create(Context context, boolean useConfigXml) {
@@ -450,8 +471,8 @@ public class DisplayDeviceConfig {
    }

    /**
     * Calculates the backlight value, as recognised by the HAL, from the brightness value
     * given that the rest of the system deals with.
     * Calculates the backlight value, as recognised by the HAL, from the brightness value given
     * that the rest of the system deals with.
     *
     * @param brightness value on the framework scale of 0-1
     * @return backlight value on the HAL scale of 0-1
@@ -590,8 +611,8 @@ public class DisplayDeviceConfig {

    /**
     * @param quirkValue The quirk to test.
     * @return {@code true} if the specified quirk is present in this configuration,
     * {@code false} otherwise.
     * @return {@code true} if the specified quirk is present in this configuration, {@code false}
     * otherwise.
     */
    public boolean hasQuirk(String quirkValue) {
        return mQuirks != null && mQuirks.contains(quirkValue);
@@ -625,6 +646,20 @@ public class DisplayDeviceConfig {
        return BrightnessThrottlingData.create(mBrightnessThrottlingData);
    }

    /**
     * @return Auto brightness darkening light debounce
     */
    public long getAutoBrightnessDarkeningLightDebounce() {
        return mAutoBrightnessDarkeningLightDebounce;
    }

    /**
     * @return Auto brightness brightening light debounce
     */
    public long getAutoBrightnessBrighteningLightDebounce() {
        return mAutoBrightnessBrighteningLightDebounce;
    }

    @Override
    public String toString() {
        return "DisplayDeviceConfig{"
@@ -663,6 +698,10 @@ public class DisplayDeviceConfig {
                + ", mProximitySensor=" + mProximitySensor
                + ", mRefreshRateLimitations= " + Arrays.toString(mRefreshRateLimitations.toArray())
                + ", mDensityMapping= " + mDensityMapping
                + ", mAutoBrightnessBrighteningLightDebounce= "
                + mAutoBrightnessBrighteningLightDebounce
                + ", mAutoBrightnessDarkeningLightDebounce= "
                + mAutoBrightnessDarkeningLightDebounce
                + "}";
    }

@@ -719,6 +758,7 @@ public class DisplayDeviceConfig {
                loadProxSensorFromDdc(config);
                loadAmbientHorizonFromDdc(config);
                loadBrightnessChangeThresholds(config);
                loadAutoBrightnessConfigValues(config);
            } else {
                Slog.w(TAG, "DisplayDeviceConfig file is null");
            }
@@ -947,6 +987,41 @@ public class DisplayDeviceConfig {
        }
    }

    private void loadAutoBrightnessConfigValues(DisplayConfiguration config) {
        loadAutoBrightnessBrighteningLightDebounce(config.getAutoBrightness());
        loadAutoBrightnessDarkeningLightDebounce(config.getAutoBrightness());
    }

    /**
     * Loads the auto-brightness brightening light debounce. Internally, this takes care of loading
     * the value from the display config, and if not present, falls back to config.xml.
     */
    private void loadAutoBrightnessBrighteningLightDebounce(AutoBrightness autoBrightnessConfig) {
        if (autoBrightnessConfig == null
                || autoBrightnessConfig.getBrighteningLightDebounceMillis() == null) {
            mAutoBrightnessBrighteningLightDebounce = mContext.getResources().getInteger(
                    com.android.internal.R.integer.config_autoBrightnessBrighteningLightDebounce);
        } else {
            mAutoBrightnessBrighteningLightDebounce =
                    autoBrightnessConfig.getBrighteningLightDebounceMillis().intValue();
        }
    }

    /**
     * Loads the auto-brightness darkening light debounce. Internally, this takes care of loading
     * the value from the display config, and if not present, falls back to config.xml.
     */
    private void loadAutoBrightnessDarkeningLightDebounce(AutoBrightness autoBrightnessConfig) {
        if (autoBrightnessConfig == null
                || autoBrightnessConfig.getDarkeningLightDebounceMillis() == null) {
            mAutoBrightnessDarkeningLightDebounce = mContext.getResources().getInteger(
                    com.android.internal.R.integer.config_autoBrightnessDarkeningLightDebounce);
        } else {
            mAutoBrightnessDarkeningLightDebounce =
                    autoBrightnessConfig.getDarkeningLightDebounceMillis().intValue();
        }
    }

    private void loadBrightnessMapFromConfigXml() {
        // Use the config.xml mapping
        final Resources res = mContext.getResources();
@@ -1330,8 +1405,8 @@ public class DisplayDeviceConfig {
        }

        /**
         * @return True if the sensor matches both the specified name and type, or one if only
         * one is specified (not-empty). Always returns false if both parameters are null or empty.
         * @return True if the sensor matches both the specified name and type, or one if only one
         * is specified (not-empty). Always returns false if both parameters are null or empty.
         */
        public boolean matches(String sensorName, String sensorType) {
            final boolean isNameSpecified = !TextUtils.isEmpty(sensorName);
@@ -1446,6 +1521,7 @@ public class DisplayDeviceConfig {
                return otherThrottlingLevel.thermalStatus == this.thermalStatus
                        && otherThrottlingLevel.brightness == this.brightness;
            }

            @Override
            public int hashCode() {
                int result = 1;
@@ -1455,8 +1531,11 @@ public class DisplayDeviceConfig {
            }
        }

        static public BrightnessThrottlingData create(List<ThrottlingLevel> throttlingLevels)
        {

        /**
         * Creates multiple teperature based throttling levels of brightness
         */
        public static BrightnessThrottlingData create(List<ThrottlingLevel> throttlingLevels) {
            if (throttlingLevels == null || throttlingLevels.size() == 0) {
                Slog.e(TAG, "BrightnessThrottlingData received null or empty throttling levels");
                return null;
@@ -1498,8 +1577,9 @@ public class DisplayDeviceConfig {
        }

        static public BrightnessThrottlingData create(BrightnessThrottlingData other) {
            if (other == null)
            if (other == null) {
                return null;
            }

            return BrightnessThrottlingData.create(other.throttlingLevels);
        }
+4 −4
Original line number Diff line number Diff line
@@ -985,10 +985,10 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                    screenBrighteningThresholds, screenDarkeningThresholds, screenThresholdLevels,
                    screenDarkeningMinThreshold, screenBrighteningMinThreshold);

            long brighteningLightDebounce = resources.getInteger(
                    com.android.internal.R.integer.config_autoBrightnessBrighteningLightDebounce);
            long darkeningLightDebounce = resources.getInteger(
                    com.android.internal.R.integer.config_autoBrightnessDarkeningLightDebounce);
            long brighteningLightDebounce = mDisplayDeviceConfig
                    .getAutoBrightnessBrighteningLightDebounce();
            long darkeningLightDebounce = mDisplayDeviceConfig
                    .getAutoBrightnessDarkeningLightDebounce();
            boolean autoBrightnessResetAmbientLuxAfterWarmUp = resources.getBoolean(
                    com.android.internal.R.bool.config_autoBrightnessResetAmbientLuxAfterWarmUp);

+17 −1
Original line number Diff line number Diff line
@@ -45,6 +45,8 @@
                <xs:element type="highBrightnessMode" name="highBrightnessMode" minOccurs="0"
                            maxOccurs="1"/>
                <xs:element type="displayQuirks" name="quirks" minOccurs="0" maxOccurs="1" />
                <xs:element type="autoBrightness" name="autoBrightness" minOccurs="0"
                            maxOccurs="1" />
                <xs:element type="nonNegativeDecimal" name="screenBrightnessRampFastDecrease">
                    <xs:annotation name="final"/>
                </xs:element>
@@ -101,6 +103,21 @@

    <!-- Type definitions -->

    <xs:complexType name="autoBrightness">
        <xs:sequence>
            <!-- Sets the debounce for autoBrightness brightening in millis-->
            <xs:element name="brighteningLightDebounceMillis" type="xs:nonNegativeInteger"
                        minOccurs="0" maxOccurs="1">
                <xs:annotation name="final"/>
            </xs:element>
            <!-- Sets the debounce for autoBrightness darkening in millis-->
            <xs:element name="darkeningLightDebounceMillis" type="xs:nonNegativeInteger"
                        minOccurs="0" maxOccurs="1">
                <xs:annotation name="final"/>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="displayQuirks">
        <xs:sequence>
            <xs:element name="quirk" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
@@ -341,5 +358,4 @@
            <xs:annotation name="final"/>
        </xs:element>
    </xs:complexType>

</xs:schema>
+10 −0
Original line number Diff line number Diff line
// Signature format: 2.0
package com.android.server.display.config {

  public class AutoBrightness {
    ctor public AutoBrightness();
    method public final java.math.BigInteger getBrighteningLightDebounceMillis();
    method public final java.math.BigInteger getDarkeningLightDebounceMillis();
    method public final void setBrighteningLightDebounceMillis(java.math.BigInteger);
    method public final void setDarkeningLightDebounceMillis(java.math.BigInteger);
  }

  public class BrightnessThresholds {
    ctor public BrightnessThresholds();
    method @NonNull public final java.math.BigDecimal getMinimum();
@@ -40,6 +48,7 @@ package com.android.server.display.config {
    method @NonNull public final com.android.server.display.config.Thresholds getAmbientBrightnessChangeThresholds();
    method public final java.math.BigInteger getAmbientLightHorizonLong();
    method public final java.math.BigInteger getAmbientLightHorizonShort();
    method public com.android.server.display.config.AutoBrightness getAutoBrightness();
    method @Nullable public final com.android.server.display.config.DensityMapping getDensityMapping();
    method @NonNull public final com.android.server.display.config.Thresholds getDisplayBrightnessChangeThresholds();
    method public com.android.server.display.config.HighBrightnessMode getHighBrightnessMode();
@@ -58,6 +67,7 @@ package com.android.server.display.config {
    method public final void setAmbientBrightnessChangeThresholds(@NonNull com.android.server.display.config.Thresholds);
    method public final void setAmbientLightHorizonLong(java.math.BigInteger);
    method public final void setAmbientLightHorizonShort(java.math.BigInteger);
    method public void setAutoBrightness(com.android.server.display.config.AutoBrightness);
    method public final void setDensityMapping(@Nullable com.android.server.display.config.DensityMapping);
    method public final void setDisplayBrightnessChangeThresholds(@NonNull com.android.server.display.config.Thresholds);
    method public void setHighBrightnessMode(com.android.server.display.config.HighBrightnessMode);
+6 −0
Original line number Diff line number Diff line
@@ -86,6 +86,8 @@ public final class DisplayDeviceConfigTest {
                0.0f);
        assertEquals(mDisplayDeviceConfig.getScreenBrighteningMinThreshold(), 0.001, 0.000001f);
        assertEquals(mDisplayDeviceConfig.getScreenDarkeningMinThreshold(), 0.002, 0.000001f);
        assertEquals(mDisplayDeviceConfig.getAutoBrightnessBrighteningLightDebounce(), 2000);
        assertEquals(mDisplayDeviceConfig.getAutoBrightnessDarkeningLightDebounce(), 1000);

        // Todo(brup): Add asserts for BrightnessThrottlingData, DensityMapping,
        // HighBrightnessModeData AmbientLightSensor, RefreshRateLimitations and ProximitySensor.
@@ -109,6 +111,10 @@ public final class DisplayDeviceConfigTest {
                +           "<nits>800.0</nits>\n"
                +       "</point>\n"
                +   "</screenBrightnessMap>\n"
                +   "<autoBrightness>\n"
                +       "<brighteningLightDebounceMillis>2000</brighteningLightDebounceMillis>\n"
                +       "<darkeningLightDebounceMillis>1000</darkeningLightDebounceMillis>\n"
                +   "</autoBrightness>\n"
                +   "<highBrightnessMode enabled=\"true\">\n"
                +       "<transitionPoint>0.62</transitionPoint>\n"
                +       "<minimumLux>10000</minimumLux>\n"