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

Commit af7c4714 authored by Fiona Campbell's avatar Fiona Campbell Committed by Android (Google) Code Review
Browse files

Merge "Create LowLuxBrightnessModifier" into main

parents cb715528 bf9f4225
Loading
Loading
Loading
Loading
+29 −1
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ public final class DisplayBrightnessState {
    private final float mSdrBrightness;

    private final float mMaxBrightness;
    private final float mMinBrightness;
    private final BrightnessReason mBrightnessReason;
    private final String mDisplayBrightnessStrategyName;
    private final boolean mShouldUseAutoBrightness;
@@ -50,6 +51,7 @@ public final class DisplayBrightnessState {
        mShouldUseAutoBrightness = builder.getShouldUseAutoBrightness();
        mIsSlowChange = builder.isSlowChange();
        mMaxBrightness = builder.getMaxBrightness();
        mMinBrightness = builder.getMinBrightness();
        mCustomAnimationRate = builder.getCustomAnimationRate();
        mShouldUpdateScreenBrightnessSetting = builder.shouldUpdateScreenBrightnessSetting();
    }
@@ -104,6 +106,13 @@ public final class DisplayBrightnessState {
        return mMaxBrightness;
    }

    /**
     * @return minimum allowed brightness
     */
    public float getMinBrightness() {
        return mMinBrightness;
    }

    /**
     * @return custom animation rate
     */
@@ -131,6 +140,7 @@ public final class DisplayBrightnessState {
        stringBuilder.append(getShouldUseAutoBrightness());
        stringBuilder.append("\n    isSlowChange:").append(mIsSlowChange);
        stringBuilder.append("\n    maxBrightness:").append(mMaxBrightness);
        stringBuilder.append("\n    minBrightness:").append(mMinBrightness);
        stringBuilder.append("\n    customAnimationRate:").append(mCustomAnimationRate);
        stringBuilder.append("\n    shouldUpdateScreenBrightnessSetting:")
                .append(mShouldUpdateScreenBrightnessSetting);
@@ -160,6 +170,7 @@ public final class DisplayBrightnessState {
                && mShouldUseAutoBrightness == otherState.getShouldUseAutoBrightness()
                && mIsSlowChange == otherState.isSlowChange()
                && mMaxBrightness == otherState.getMaxBrightness()
                && mMinBrightness == otherState.getMinBrightness()
                && mCustomAnimationRate == otherState.getCustomAnimationRate()
                && mShouldUpdateScreenBrightnessSetting
                    == otherState.shouldUpdateScreenBrightnessSetting();
@@ -168,7 +179,8 @@ public final class DisplayBrightnessState {
    @Override
    public int hashCode() {
        return Objects.hash(mBrightness, mSdrBrightness, mBrightnessReason,
                mShouldUseAutoBrightness, mIsSlowChange, mMaxBrightness, mCustomAnimationRate,
                mShouldUseAutoBrightness, mIsSlowChange, mMaxBrightness, mMinBrightness,
                mCustomAnimationRate,
                mShouldUpdateScreenBrightnessSetting);
    }

@@ -190,6 +202,7 @@ public final class DisplayBrightnessState {
        private boolean mShouldUseAutoBrightness;
        private boolean mIsSlowChange;
        private float mMaxBrightness;
        private float mMinBrightness;
        private float mCustomAnimationRate = CUSTOM_ANIMATION_RATE_NOT_SET;
        private boolean mShouldUpdateScreenBrightnessSetting;

@@ -208,6 +221,7 @@ public final class DisplayBrightnessState {
            builder.setShouldUseAutoBrightness(state.getShouldUseAutoBrightness());
            builder.setIsSlowChange(state.isSlowChange());
            builder.setMaxBrightness(state.getMaxBrightness());
            builder.setMinBrightness(state.getMinBrightness());
            builder.setCustomAnimationRate(state.getCustomAnimationRate());
            builder.setShouldUpdateScreenBrightnessSetting(
                    state.shouldUpdateScreenBrightnessSetting());
@@ -334,6 +348,20 @@ public final class DisplayBrightnessState {
            return mMaxBrightness;
        }

        /**
         * See {@link DisplayBrightnessState#getMinBrightness()}.
         */
        public Builder setMinBrightness(float minBrightness) {
            this.mMinBrightness = minBrightness;
            return this;
        }

        /**
         * See {@link DisplayBrightnessState#getMinBrightness()}.
         */
        public float getMinBrightness() {
            return mMinBrightness;
        }

        /**
         * See {@link DisplayBrightnessState#getCustomAnimationRate()}.
+11 −10
Original line number Diff line number Diff line
@@ -1508,7 +1508,6 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
        // Note throttling effectively changes the allowed brightness range, so, similarly to HBM,
        // we broadcast this change through setting.
        final float unthrottledBrightnessState = brightnessState;

        DisplayBrightnessState clampedState = mBrightnessClamperController.clamp(mPowerRequest,
                brightnessState, slowChange);

@@ -1522,11 +1521,12 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
        if (updateScreenBrightnessSetting) {
            // Tell the rest of the system about the new brightness in case we had to change it
            // for things like auto-brightness or high-brightness-mode. Note that we do this
            // only considering maxBrightness (ignroing brightness modifiers like low power or dim)
            // only considering maxBrightness (ignoring brightness modifiers like low power or dim)
            // so that the slider accurately represents the full possible range,
            // even if they range changes what it means in absolute terms.
            mDisplayBrightnessController.updateScreenBrightnessSetting(
                    Math.min(unthrottledBrightnessState, clampedState.getMaxBrightness()));
                    MathUtils.constrain(unthrottledBrightnessState,
                            clampedState.getMinBrightness(), clampedState.getMaxBrightness()));
        }

        // The current brightness to use has been calculated at this point, and HbmController should
@@ -1935,8 +1935,9 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
            @Nullable DisplayBrightnessState state) {
        synchronized (mCachedBrightnessInfo) {
            float stateMax = state != null ? state.getMaxBrightness() : PowerManager.BRIGHTNESS_MAX;
            final float minBrightness = Math.min(
                    mBrightnessRangeController.getCurrentBrightnessMin(), stateMax);
            float stateMin = state != null ? state.getMinBrightness() : PowerManager.BRIGHTNESS_MAX;
            final float minBrightness = Math.max(stateMin, Math.min(
                    mBrightnessRangeController.getCurrentBrightnessMin(), stateMax));
            final float maxBrightness = Math.min(
                    mBrightnessRangeController.getCurrentBrightnessMax(), stateMax);
            boolean changed = false;
@@ -1962,7 +1963,6 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
            changed |=
                    mCachedBrightnessInfo.checkAndSetInt(mCachedBrightnessInfo.brightnessMaxReason,
                            mBrightnessClamperController.getBrightnessMaxReason());

            return changed;
        }
    }
@@ -2880,6 +2880,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
                    event.getHbmMode() == BrightnessInfo.HIGH_BRIGHTNESS_MODE_HDR,
                    (modifier & BrightnessReason.MODIFIER_LOW_POWER) > 0,
                    mBrightnessClamperController.getBrightnessMaxReason(),
                    // TODO: (flc) add brightnessMinReason here too.
                    (modifier & BrightnessReason.MODIFIER_DIMMED) > 0,
                    event.isRbcEnabled(),
                    (flags & BrightnessEvent.FLAG_INVALID_LUX) > 0,
+9 −1
Original line number Diff line number Diff line
@@ -46,8 +46,10 @@ public final class BrightnessReason {
    public static final int MODIFIER_LOW_POWER = 0x2;
    public static final int MODIFIER_HDR = 0x4;
    public static final int MODIFIER_THROTTLED = 0x8;
    public static final int MODIFIER_MIN_LUX = 0x10;
    public static final int MODIFIER_MIN_USER_SET_LOWER_BOUND = 0x20;
    public static final int MODIFIER_MASK = MODIFIER_DIMMED | MODIFIER_LOW_POWER | MODIFIER_HDR
            | MODIFIER_THROTTLED;
            | MODIFIER_THROTTLED | MODIFIER_MIN_LUX | MODIFIER_MIN_USER_SET_LOWER_BOUND;

    // ADJUSTMENT_*
    // These things can happen at any point, even if the main brightness reason doesn't
@@ -131,6 +133,12 @@ public final class BrightnessReason {
        if ((mModifier & MODIFIER_THROTTLED) != 0) {
            sb.append(" throttled");
        }
        if ((mModifier & MODIFIER_MIN_LUX) != 0) {
            sb.append(" lux_lower_bound");
        }
        if ((mModifier & MODIFIER_MIN_USER_SET_LOWER_BOUND) != 0) {
            sb.append(" user_min_pref");
        }
        int strlen = sb.length();
        if (sb.charAt(strlen - 1) == '[') {
            sb.setLength(strlen - 2);
+1 −1
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import java.io.PrintWriter;
abstract class BrightnessClamper<T> {

    protected float mBrightnessCap = PowerManager.BRIGHTNESS_MAX;

    protected boolean mIsActive = false;

    @NonNull
@@ -75,6 +76,5 @@ abstract class BrightnessClamper<T> {
        THERMAL,
        POWER,
        BEDTIME_MODE,
        LUX,
    }
}
+14 −10
Original line number Diff line number Diff line
@@ -58,13 +58,14 @@ public class BrightnessClamperController {
    private final Executor mExecutor;
    private final List<BrightnessClamper<? super DisplayDeviceData>> mClampers;

    private final List<BrightnessModifier> mModifiers;
    private final List<BrightnessStateModifier> mModifiers;
    private final DeviceConfig.OnPropertiesChangedListener mOnPropertiesChangedListener;
    private float mBrightnessCap = PowerManager.BRIGHTNESS_MAX;

    private float mCustomAnimationRate = DisplayBrightnessState.CUSTOM_ANIMATION_RATE_NOT_SET;
    @Nullable
    private Type mClamperType = null;

    private boolean mClamperApplied = false;

    public BrightnessClamperController(Handler handler,
@@ -92,7 +93,7 @@ public class BrightnessClamperController {

        mClampers = injector.getClampers(handler, clamperChangeListenerInternal, data, flags,
                context);
        mModifiers = injector.getModifiers(context);
        mModifiers = injector.getModifiers(flags, context, handler, clamperChangeListener);
        mOnPropertiesChangedListener =
                properties -> mClampers.forEach(BrightnessClamper::onDeviceConfigChanged);
        start();
@@ -165,9 +166,10 @@ public class BrightnessClamperController {
     * Used to dump ClampersController state.
     */
    public void dump(PrintWriter writer) {
        writer.println("BrightnessClampersController:");
        writer.println("BrightnessClamperController:");
        writer.println("  mBrightnessCap: " + mBrightnessCap);
        writer.println("  mClamperType: " + mClamperType);
        writer.println("  mClamperApplied: " + mClamperApplied);
        IndentingPrintWriter ipw = new IndentingPrintWriter(writer, "    ");
        mClampers.forEach(clamper -> clamper.dump(ipw));
        mModifiers.forEach(modifier -> modifier.dump(ipw));
@@ -181,6 +183,7 @@ public class BrightnessClamperController {
        mDeviceConfigParameterProvider.removeOnPropertiesChangedListener(
                mOnPropertiesChangedListener);
        mClampers.forEach(BrightnessClamper::stop);
        mModifiers.forEach(BrightnessStateModifier::stop);
    }


@@ -201,14 +204,14 @@ public class BrightnessClamperController {
            customAnimationRate = minClamper.getCustomAnimationRate();
        }

        if (mBrightnessCap != brightnessCap || mClamperType != clamperType
        if (mBrightnessCap != brightnessCap
                || mClamperType != clamperType
                || mCustomAnimationRate != customAnimationRate) {
            mBrightnessCap = brightnessCap;
            mClamperType = clamperType;
            mCustomAnimationRate = customAnimationRate;
            mClamperChangeListenerExternal.onChanged();
        }

    }

    private void start() {
@@ -248,16 +251,17 @@ public class BrightnessClamperController {
                clampers.add(new BrightnessWearBedtimeModeClamper(handler, context,
                        clamperChangeListener, data));
            }
            if (flags.isEvenDimmerEnabled()) {
                clampers.add(new BrightnessMinClamper(handler, clamperChangeListener, context));
            }
            return clampers;
        }

        List<BrightnessModifier> getModifiers(Context context) {
            List<BrightnessModifier> modifiers = new ArrayList<>();
        List<BrightnessStateModifier> getModifiers(DisplayManagerFlags flags, Context context,
                Handler handler, ClamperChangeListener listener) {
            List<BrightnessStateModifier> modifiers = new ArrayList<>();
            modifiers.add(new DisplayDimModifier(context));
            modifiers.add(new BrightnessLowPowerModeModifier());
            if (flags.isEvenDimmerEnabled()) {
                modifiers.add(new BrightnessLowLuxModifier(handler, listener, context));
            }
            return modifiers;
        }
    }
Loading