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

Commit d204bb7c authored by Fiona Campbell's avatar Fiona Campbell Committed by Automerger Merge Worker
Browse files

Merge "Add idle threshold levels to ddc" into tm-qpr-dev am: d639c8ee

parents b5d7a02f d639c8ee
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -592,10 +592,14 @@ class AutomaticBrightnessController {
        }

        pw.println();
        pw.println("  mAmbientBrightnessThresholds=");
        mAmbientBrightnessThresholds.dump(pw);
        pw.println("  mScreenBrightnessThresholds=");
        mScreenBrightnessThresholds.dump(pw);
        pw.println("  mScreenBrightnessThresholdsIdle=");
        mScreenBrightnessThresholdsIdle.dump(pw);
        mScreenBrightnessThresholdsIdle.dump(pw);
        pw.println("  mAmbientBrightnessThresholdsIdle=");
        mAmbientBrightnessThresholdsIdle.dump(pw);
    }

    private String configStateToString(int state) {
@@ -860,6 +864,7 @@ class AutomaticBrightnessController {
                Slog.d(TAG, "updateAmbientLux: "
                        + ((mFastAmbientLux > mAmbientLux) ? "Brightened" : "Darkened") + ": "
                        + "mBrighteningLuxThreshold=" + mAmbientBrighteningThreshold + ", "
                        + "mAmbientDarkeningThreshold=" + mAmbientDarkeningThreshold + ", "
                        + "mAmbientLightRingBuffer=" + mAmbientLightRingBuffer + ", "
                        + "mAmbientLux=" + mAmbientLux);
            }
+738 −109

File changed.

Preview size limit exceeded, changes collapsed.

+51 −27
Original line number Diff line number Diff line
@@ -956,54 +956,78 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                    com.android.internal.R.fraction.config_screenAutoBrightnessDozeScaleFactor,
                    1, 1);

            int[] ambientBrighteningThresholds = resources.getIntArray(
                    com.android.internal.R.array.config_ambientBrighteningThresholds);
            int[] ambientDarkeningThresholds = resources.getIntArray(
                    com.android.internal.R.array.config_ambientDarkeningThresholds);
            int[] ambientThresholdLevels = resources.getIntArray(
                    com.android.internal.R.array.config_ambientThresholdLevels);
            // Ambient Lux - Active Mode Brightness Thresholds
            float[] ambientBrighteningThresholds =
                    mDisplayDeviceConfig.getAmbientBrighteningPercentages();
            float[] ambientDarkeningThresholds =
                    mDisplayDeviceConfig.getAmbientDarkeningPercentages();
            float[] ambientBrighteningLevels =
                    mDisplayDeviceConfig.getAmbientBrighteningLevels();
            float[] ambientDarkeningLevels =
                    mDisplayDeviceConfig.getAmbientDarkeningLevels();
            float ambientDarkeningMinThreshold =
                    mDisplayDeviceConfig.getAmbientLuxDarkeningMinThreshold();
            float ambientBrighteningMinThreshold =
                    mDisplayDeviceConfig.getAmbientLuxBrighteningMinThreshold();
            HysteresisLevels ambientBrightnessThresholds = new HysteresisLevels(
                    ambientBrighteningThresholds, ambientDarkeningThresholds,
                    ambientThresholdLevels, ambientDarkeningMinThreshold,
                    ambientBrighteningLevels, ambientDarkeningLevels, ambientDarkeningMinThreshold,
                    ambientBrighteningMinThreshold);

            int[] screenBrighteningThresholds = resources.getIntArray(
                    com.android.internal.R.array.config_screenBrighteningThresholds);
            int[] screenDarkeningThresholds = resources.getIntArray(
                    com.android.internal.R.array.config_screenDarkeningThresholds);
            float[] screenThresholdLevels = BrightnessMappingStrategy.getFloatArray(resources
                    .obtainTypedArray(com.android.internal.R.array.config_screenThresholdLevels));
            // Display - Active Mode Brightness Thresholds
            float[] screenBrighteningThresholds =
                    mDisplayDeviceConfig.getScreenBrighteningPercentages();
            float[] screenDarkeningThresholds =
                    mDisplayDeviceConfig.getScreenDarkeningPercentages();
            float[] screenBrighteningLevels =
                    mDisplayDeviceConfig.getScreenBrighteningLevels();
            float[] screenDarkeningLevels =
                    mDisplayDeviceConfig.getScreenDarkeningLevels();
            float screenDarkeningMinThreshold =
                    mDisplayDeviceConfig.getScreenDarkeningMinThreshold();
            float screenBrighteningMinThreshold =
                    mDisplayDeviceConfig.getScreenBrighteningMinThreshold();
            HysteresisLevels screenBrightnessThresholds = new HysteresisLevels(
                    screenBrighteningThresholds, screenDarkeningThresholds, screenThresholdLevels,
                    screenDarkeningMinThreshold, screenBrighteningMinThreshold);
                    screenBrighteningThresholds, screenDarkeningThresholds,
                    screenBrighteningLevels, screenDarkeningLevels, screenDarkeningMinThreshold,
                    screenBrighteningMinThreshold);

            // Idle screen thresholds
            // Ambient Lux - Idle Screen Brightness Thresholds
            float ambientDarkeningMinThresholdIdle =
                    mDisplayDeviceConfig.getAmbientLuxDarkeningMinThresholdIdle();
            float ambientBrighteningMinThresholdIdle =
                    mDisplayDeviceConfig.getAmbientLuxBrighteningMinThresholdIdle();
            float[] ambientBrighteningThresholdsIdle =
                    mDisplayDeviceConfig.getAmbientBrighteningPercentagesIdle();
            float[] ambientDarkeningThresholdsIdle =
                    mDisplayDeviceConfig.getAmbientDarkeningPercentagesIdle();
            float[] ambientBrighteningLevelsIdle =
                    mDisplayDeviceConfig.getAmbientBrighteningLevelsIdle();
            float[] ambientDarkeningLevelsIdle =
                    mDisplayDeviceConfig.getAmbientDarkeningLevelsIdle();
            HysteresisLevels ambientBrightnessThresholdsIdle = new HysteresisLevels(
                    ambientBrighteningThresholdsIdle, ambientDarkeningThresholdsIdle,
                    ambientBrighteningLevelsIdle, ambientDarkeningLevelsIdle,
                    ambientDarkeningMinThresholdIdle, ambientBrighteningMinThresholdIdle);

            // Display - Idle Screen Brightness Thresholds
            float screenDarkeningMinThresholdIdle =
                    mDisplayDeviceConfig.getScreenDarkeningMinThresholdIdle();
            float screenBrighteningMinThresholdIdle =
                    mDisplayDeviceConfig.getScreenBrighteningMinThresholdIdle();
            float[] screenBrighteningThresholdsIdle =
                    mDisplayDeviceConfig.getScreenBrighteningPercentagesIdle();
            float[] screenDarkeningThresholdsIdle =
                    mDisplayDeviceConfig.getScreenDarkeningPercentagesIdle();
            float[] screenBrighteningLevelsIdle =
                    mDisplayDeviceConfig.getScreenBrighteningLevelsIdle();
            float[] screenDarkeningLevelsIdle =
                    mDisplayDeviceConfig.getScreenDarkeningLevelsIdle();
            HysteresisLevels screenBrightnessThresholdsIdle = new HysteresisLevels(
                    screenBrighteningThresholds, screenDarkeningThresholds, screenThresholdLevels,
                    screenBrighteningThresholdsIdle, screenDarkeningThresholdsIdle,
                    screenBrighteningLevelsIdle, screenDarkeningLevelsIdle,
                    screenDarkeningMinThresholdIdle, screenBrighteningMinThresholdIdle);

            // Idle ambient thresholds
            float ambientDarkeningMinThresholdIdle =
                    mDisplayDeviceConfig.getAmbientLuxDarkeningMinThresholdIdle();
            float ambientBrighteningMinThresholdIdle =
                    mDisplayDeviceConfig.getAmbientLuxBrighteningMinThresholdIdle();
            HysteresisLevels ambientBrightnessThresholdsIdle = new HysteresisLevels(
                    ambientBrighteningThresholds, ambientDarkeningThresholds,
                    ambientThresholdLevels, ambientDarkeningMinThresholdIdle,
                    ambientBrighteningMinThresholdIdle);

            long brighteningLightDebounce = mDisplayDeviceConfig
                    .getAutoBrightnessBrighteningLightDebounce();
            long darkeningLightDebounce = mDisplayDeviceConfig
+45 −77
Original line number Diff line number Diff line
@@ -29,52 +29,38 @@ public class HysteresisLevels {

    private static final boolean DEBUG = false;

    private final float[] mBrighteningThresholds;
    private final float[] mDarkeningThresholds;
    private final float[] mThresholdLevels;
    private final float[] mBrighteningThresholdsPercentages;
    private final float[] mDarkeningThresholdsPercentages;
    private final float[] mBrighteningThresholdLevels;
    private final float[] mDarkeningThresholdLevels;
    private final float mMinDarkening;
    private final float mMinBrightening;

    /**
     * Creates a {@code HysteresisLevels} object for ambient brightness.
     * @param brighteningThresholds an array of brightening hysteresis constraint constants.
     * @param darkeningThresholds an array of darkening hysteresis constraint constants.
     * @param thresholdLevels a monotonically increasing array of threshold levels.
     * Creates a {@code HysteresisLevels} object with the given equal-length
     * float arrays.
     * @param brighteningThresholdsPercentages 0-100 of thresholds
     * @param darkeningThresholdsPercentages 0-100 of thresholds
     * @param brighteningThresholdLevels float array of brightness values in the relevant units
     * @param darkeningThresholdLevels float array of brightness values in the relevant units
     * @param minBrighteningThreshold the minimum value for which the brightening value needs to
     *                                return.
     * @param minDarkeningThreshold the minimum value for which the darkening value needs to return.
     */
    HysteresisLevels(int[] brighteningThresholds, int[] darkeningThresholds,
            int[] thresholdLevels, float minDarkeningThreshold, float minBrighteningThreshold) {
        if (brighteningThresholds.length != darkeningThresholds.length
                || darkeningThresholds.length != thresholdLevels.length + 1) {
    HysteresisLevels(float[] brighteningThresholdsPercentages,
            float[] darkeningThresholdsPercentages,
            float[] brighteningThresholdLevels, float[] darkeningThresholdLevels,
            float minDarkeningThreshold, float minBrighteningThreshold) {
        if (brighteningThresholdsPercentages.length != brighteningThresholdLevels.length
                || darkeningThresholdsPercentages.length != darkeningThresholdLevels.length) {
            throw new IllegalArgumentException("Mismatch between hysteresis array lengths.");
        }
        mBrighteningThresholds = setArrayFormat(brighteningThresholds, 1000.0f);
        mDarkeningThresholds = setArrayFormat(darkeningThresholds, 1000.0f);
        mThresholdLevels = setArrayFormat(thresholdLevels, 1.0f);
        mMinDarkening = minDarkeningThreshold;
        mMinBrightening = minBrighteningThreshold;
    }

    /**
     * Creates a {@code HysteresisLevels} object for screen brightness.
     * @param brighteningThresholds an array of brightening hysteresis constraint constants.
     * @param darkeningThresholds an array of darkening hysteresis constraint constants.
     * @param thresholdLevels a monotonically increasing array of threshold levels.
     * @param minBrighteningThreshold the minimum value for which the brightening value needs to
     *                                return.
     * @param minDarkeningThreshold the minimum value for which the darkening value needs to return.
     */
    HysteresisLevels(int[] brighteningThresholds, int[] darkeningThresholds,
            float[] thresholdLevels, float minDarkeningThreshold, float minBrighteningThreshold) {
        if (brighteningThresholds.length != darkeningThresholds.length
                || darkeningThresholds.length != thresholdLevels.length + 1) {
            throw new IllegalArgumentException("Mismatch between hysteresis array lengths.");
        }
        mBrighteningThresholds = setArrayFormat(brighteningThresholds, 1000.0f);
        mDarkeningThresholds = setArrayFormat(darkeningThresholds, 1000.0f);
        mThresholdLevels = constraintInRangeIfNeeded(thresholdLevels);
        mBrighteningThresholdsPercentages =
                setArrayFormat(brighteningThresholdsPercentages, 100.0f);
        mDarkeningThresholdsPercentages =
                setArrayFormat(darkeningThresholdsPercentages, 100.0f);
        mBrighteningThresholdLevels = setArrayFormat(brighteningThresholdLevels, 1.0f);
        mDarkeningThresholdLevels = setArrayFormat(darkeningThresholdLevels, 1.0f);
        mMinDarkening = minDarkeningThreshold;
        mMinBrightening = minBrighteningThreshold;
    }
@@ -83,7 +69,9 @@ public class HysteresisLevels {
     * Return the brightening hysteresis threshold for the given value level.
     */
    public float getBrighteningThreshold(float value) {
        final float brightConstant = getReferenceLevel(value, mBrighteningThresholds);
        final float brightConstant = getReferenceLevel(value,
                mBrighteningThresholdLevels, mBrighteningThresholdsPercentages);

        float brightThreshold = value * (1.0f + brightConstant);
        if (DEBUG) {
            Slog.d(TAG, "bright hysteresis constant=" + brightConstant + ", threshold="
@@ -98,7 +86,8 @@ public class HysteresisLevels {
     * Return the darkening hysteresis threshold for the given value level.
     */
    public float getDarkeningThreshold(float value) {
        final float darkConstant = getReferenceLevel(value, mDarkeningThresholds);
        final float darkConstant = getReferenceLevel(value,
                mDarkeningThresholdLevels, mDarkeningThresholdsPercentages);
        float darkThreshold = value * (1.0f - darkConstant);
        if (DEBUG) {
            Slog.d(TAG, "dark hysteresis constant=: " + darkConstant + ", threshold="
@@ -111,60 +100,39 @@ public class HysteresisLevels {
    /**
     * Return the hysteresis constant for the closest threshold value from the given array.
     */
    private float getReferenceLevel(float value, float[] referenceLevels) {
    private float getReferenceLevel(float value, float[] thresholdLevels,
            float[] thresholdPercentages) {
        if (thresholdLevels == null || thresholdLevels.length == 0 || value < thresholdLevels[0]) {
            return 0.0f;
        }
        int index = 0;
        while (mThresholdLevels.length > index && value >= mThresholdLevels[index]) {
            ++index;
        while (index < thresholdLevels.length - 1 && value >= thresholdLevels[index + 1]) {
            index++;
        }
        return referenceLevels[index];
        return thresholdPercentages[index];
    }

    /**
     * Return a float array where each i-th element equals {@code configArray[i]/divideFactor}.
     */
    private float[] setArrayFormat(int[] configArray, float divideFactor) {
    private float[] setArrayFormat(float[] configArray, float divideFactor) {
        float[] levelArray = new float[configArray.length];
        for (int index = 0; levelArray.length > index; ++index) {
            levelArray[index] = (float) configArray[index] / divideFactor;
            levelArray[index] = configArray[index] / divideFactor;
        }
        return levelArray;
    }

    /**
     * This check is due to historical reasons, where screen thresholdLevels used to be
     * integer values in the range of [0-255], but then was changed to be float values from [0,1].
     * To accommodate both the possibilities, we first check if all the thresholdLevels are in [0,
     * 1], and if not, we divide all the levels with 255 to bring them down to the same scale.
     */
    private float[] constraintInRangeIfNeeded(float[] thresholdLevels) {
        if (isAllInRange(thresholdLevels, /* minValueInclusive = */ 0.0f, /* maxValueInclusive = */
                1.0f)) {
            return thresholdLevels;
        }

        Slog.w(TAG, "Detected screen thresholdLevels on a deprecated brightness scale");
        float[] thresholdLevelsScaled = new float[thresholdLevels.length];
        for (int index = 0; thresholdLevels.length > index; ++index) {
            thresholdLevelsScaled[index] = thresholdLevels[index] / 255.0f;
        }
        return thresholdLevelsScaled;
    }

    private boolean isAllInRange(float[] configArray, float minValueInclusive,
            float maxValueInclusive) {
        int configArraySize = configArray.length;
        for (int index = 0; configArraySize > index; ++index) {
            if (configArray[index] < minValueInclusive || configArray[index] > maxValueInclusive) {
                return false;
            }
        }
        return true;
    }

    void dump(PrintWriter pw) {
        pw.println("HysteresisLevels");
        pw.println("  mBrighteningThresholds=" + Arrays.toString(mBrighteningThresholds));
        pw.println("  mDarkeningThresholds=" + Arrays.toString(mDarkeningThresholds));
        pw.println("  mThresholdLevels=" + Arrays.toString(mThresholdLevels));
        pw.println("  mBrighteningThresholdLevels=" + Arrays.toString(mBrighteningThresholdLevels));
        pw.println("  mBrighteningThresholdsPercentages="
                + Arrays.toString(mBrighteningThresholdsPercentages));
        pw.println("  mMinBrightening=" + mMinBrightening);
        pw.println("  mDarkeningThresholdLevels=" + Arrays.toString(mDarkeningThresholdLevels));
        pw.println("  mDarkeningThresholdsPercentages="
                + Arrays.toString(mDarkeningThresholdsPercentages));
        pw.println("  mMinDarkening=" + mMinDarkening);
    }
}
+29 −0
Original line number Diff line number Diff line
@@ -351,6 +351,35 @@
            <xs:annotation name="nonnull"/>
            <xs:annotation name="final"/>
        </xs:element>
        <xs:sequence>
            <!--  Thresholds as tenths of percent of current brightness level, at each level of
                brightness -->
            <xs:element name="brightnessThresholdPoints" type="thresholdPoints" maxOccurs="1" minOccurs="0">
                <xs:annotation name="final"/>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="thresholdPoints">
        <xs:sequence>
            <xs:element type="thresholdPoint" name="brightnessThresholdPoint" maxOccurs="unbounded" minOccurs="1">
                <xs:annotation name="nonnull"/>
                <xs:annotation name="final"/>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="thresholdPoint">
        <xs:sequence>
            <xs:element type="nonNegativeDecimal" name="threshold">
                <xs:annotation name="nonnull"/>
                <xs:annotation name="final"/>
            </xs:element>
            <xs:element type="nonNegativeDecimal" name="percentage">
                <xs:annotation name="nonnull"/>
                <xs:annotation name="final"/>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="autoBrightness">
Loading