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

Commit c55ccda3 authored by Oleg Petsjonkin's avatar Oleg Petsjonkin
Browse files

Moving followers slow change flag to FollowerStrategy

Part of clampers and ABS/ABC imorovement work. Strategy need to decide on slowChange and clamper could override it.

Bug: b/263362199
Test: atest FollowerBrightnessStrategyTest
Change-Id: Ib72cfe6b27b973f1d3e98cdeafdc2285d7d6f211
parent 649012b8
Loading
Loading
Loading
Loading
+33 −3
Original line number Diff line number Diff line
@@ -33,12 +33,15 @@ public final class DisplayBrightnessState {
    private final String mDisplayBrightnessStrategyName;
    private final boolean mShouldUseAutoBrightness;

    private final boolean mIsSlowChange;

    private DisplayBrightnessState(Builder builder) {
        mBrightness = builder.getBrightness();
        mSdrBrightness = builder.getSdrBrightness();
        mBrightnessReason = builder.getBrightnessReason();
        mDisplayBrightnessStrategyName = builder.getDisplayBrightnessStrategyName();
        mShouldUseAutoBrightness = builder.getShouldUseAutoBrightness();
        mIsSlowChange = builder.isSlowChange();
    }

    /**
@@ -77,6 +80,13 @@ public final class DisplayBrightnessState {
        return mShouldUseAutoBrightness;
    }

    /**
     * @return {@code true} if the should transit to new state slowly
     */
    public boolean isSlowChange() {
        return mIsSlowChange;
    }

    @Override
    public String toString() {
        StringBuilder stringBuilder = new StringBuilder("DisplayBrightnessState:");
@@ -88,6 +98,8 @@ public final class DisplayBrightnessState {
        stringBuilder.append(getBrightnessReason());
        stringBuilder.append("\n    shouldUseAutoBrightness:");
        stringBuilder.append(getShouldUseAutoBrightness());
        stringBuilder.append("\n    isSlowChange:");
        stringBuilder.append(mIsSlowChange);
        return stringBuilder.toString();
    }

@@ -111,13 +123,14 @@ public final class DisplayBrightnessState {
                && mBrightnessReason.equals(otherState.getBrightnessReason())
                && TextUtils.equals(mDisplayBrightnessStrategyName,
                        otherState.getDisplayBrightnessStrategyName())
                && mShouldUseAutoBrightness == otherState.getShouldUseAutoBrightness();
                && mShouldUseAutoBrightness == otherState.getShouldUseAutoBrightness()
                && mIsSlowChange == otherState.isSlowChange();
    }

    @Override
    public int hashCode() {
        return Objects.hash(
                mBrightness, mSdrBrightness, mBrightnessReason, mShouldUseAutoBrightness);
        return Objects.hash(mBrightness, mSdrBrightness, mBrightnessReason,
                mShouldUseAutoBrightness, mIsSlowChange);
    }

    /**
@@ -129,6 +142,7 @@ public final class DisplayBrightnessState {
        private BrightnessReason mBrightnessReason = new BrightnessReason();
        private String mDisplayBrightnessStrategyName;
        private boolean mShouldUseAutoBrightness;
        private boolean mIsSlowChange;

        /**
         * Create a builder starting with the values from the specified {@link
@@ -143,6 +157,7 @@ public final class DisplayBrightnessState {
            builder.setBrightnessReason(state.getBrightnessReason());
            builder.setDisplayBrightnessStrategyName(state.getDisplayBrightnessStrategyName());
            builder.setShouldUseAutoBrightness(state.getShouldUseAutoBrightness());
            builder.setIsSlowChange(state.isSlowChange());
            return builder;
        }

@@ -236,6 +251,21 @@ public final class DisplayBrightnessState {
            return mShouldUseAutoBrightness;
        }

        /**
         * See {@link DisplayBrightnessState#isSlowChange()}.
         */
        public Builder setIsSlowChange(boolean shouldUseAutoBrightness) {
            this.mIsSlowChange = shouldUseAutoBrightness;
            return this;
        }

        /**
         * See {@link DisplayBrightnessState#isSlowChange()}.
         */
        public boolean isSlowChange() {
            return mIsSlowChange;
        }

        /**
         * This is used to construct an immutable DisplayBrightnessState object from its builder
         */
+7 −14
Original line number Diff line number Diff line
@@ -438,9 +438,6 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
    @Nullable
    private BrightnessMappingStrategy mIdleModeBrightnessMapper;

    // Indicates whether we should ramp slowly to the brightness value to follow.
    private boolean mBrightnessToFollowSlowChange;

    private boolean mIsRbcActive;

    // Animators.
@@ -1283,7 +1280,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
        // actual state instead of the desired one.
        animateScreenStateChange(state, mDisplayStateController.shouldPerformScreenOffTransition());
        state = mPowerState.getScreenState();
        boolean slowChange = false;

        final boolean userSetBrightnessChanged = mDisplayBrightnessController
                .updateUserSetScreenBrightness();

@@ -1292,11 +1289,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
        float brightnessState = displayBrightnessState.getBrightness();
        float rawBrightnessState = displayBrightnessState.getBrightness();
        mBrightnessReasonTemp.set(displayBrightnessState.getBrightnessReason());

        if (displayBrightnessState.getBrightnessReason().getReason()
                == BrightnessReason.REASON_FOLLOWER) {
            slowChange = mBrightnessToFollowSlowChange;
        }
        boolean slowChange = displayBrightnessState.isSlowChange();

        // Set up the ScreenOff controller used when coming out of SCREEN_OFF and the ALS sensor
        // doesn't yet have a valid lux value to use with auto-brightness.
@@ -1346,6 +1339,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
                            .getRawAutomaticScreenBrightness();
                    brightnessState = clampScreenBrightness(brightnessState);
                    // slowly adapt to auto-brightness
                    // TODO(b/253226419): slowChange should be decided by strategy.updateBrightness
                    slowChange = mAutomaticBrightnessStrategy.hasAppliedAutoBrightness()
                            && !mAutomaticBrightnessStrategy.getAutoBrightnessAdjustmentChanged();
                    brightnessAdjustmentFlags =
@@ -2224,17 +2218,17 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
            boolean slowChange) {
        mBrightnessRangeController.onAmbientLuxChange(ambientLux);
        if (nits < 0) {
            mDisplayBrightnessController.setBrightnessToFollow(leadDisplayBrightness);
            mDisplayBrightnessController.setBrightnessToFollow(leadDisplayBrightness, slowChange);
        } else {
            float brightness = mDisplayBrightnessController.convertToFloatScale(nits);
            if (BrightnessUtils.isValidBrightnessValue(brightness)) {
                mDisplayBrightnessController.setBrightnessToFollow(brightness);
                mDisplayBrightnessController.setBrightnessToFollow(brightness, slowChange);
            } else {
                // The device does not support nits
                mDisplayBrightnessController.setBrightnessToFollow(leadDisplayBrightness);
                mDisplayBrightnessController.setBrightnessToFollow(leadDisplayBrightness,
                        slowChange);
            }
        }
        mBrightnessToFollowSlowChange = slowChange;
        sendUpdatePowerState();
    }

@@ -2374,7 +2368,6 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
        pw.println("  mReportedToPolicy="
                + reportedToPolicyToString(mReportedScreenStateToPolicy));
        pw.println("  mIsRbcActive=" + mIsRbcActive);
        pw.println("  mBrightnessToFollowSlowChange=" + mBrightnessToFollowSlowChange);
        IndentingPrintWriter ipw = new IndentingPrintWriter(pw, "    ");
        mAutomaticBrightnessStrategy.dump(ipw);

+11 −0
Original line number Diff line number Diff line
@@ -54,6 +54,16 @@ public final class BrightnessUtils {
    public static DisplayBrightnessState constructDisplayBrightnessState(
            int brightnessChangeReason, float brightness, float sdrBrightness,
            String displayBrightnessStrategyName) {
        return constructDisplayBrightnessState(brightnessChangeReason, brightness, sdrBrightness,
                displayBrightnessStrategyName, /* slowChange= */ false);
    }

    /**
     * A utility to construct the DisplayBrightnessState
     */
    public static DisplayBrightnessState constructDisplayBrightnessState(
            int brightnessChangeReason, float brightness, float sdrBrightness,
            String displayBrightnessStrategyName, boolean slowChange) {
        BrightnessReason brightnessReason = new BrightnessReason();
        brightnessReason.setReason(brightnessChangeReason);
        return new DisplayBrightnessState.Builder()
@@ -61,6 +71,7 @@ public final class BrightnessUtils {
                .setSdrBrightness(sdrBrightness)
                .setBrightnessReason(brightnessReason)
                .setDisplayBrightnessStrategyName(displayBrightnessStrategyName)
                .setIsSlowChange(slowChange)
                .build();
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -164,10 +164,10 @@ public final class DisplayBrightnessController {
    /**
     * Sets the brightness to follow
     */
    public void setBrightnessToFollow(Float brightnessToFollow) {
    public void setBrightnessToFollow(float brightnessToFollow, boolean slowChange) {
        synchronized (mLock) {
            mDisplayBrightnessStrategySelector.getFollowerDisplayBrightnessStrategy()
                    .setBrightnessToFollow(brightnessToFollow);
                    .setBrightnessToFollow(brightnessToFollow, slowChange);
        }
    }

+11 −2
Original line number Diff line number Diff line
@@ -37,9 +37,13 @@ public class FollowerBrightnessStrategy implements DisplayBrightnessStrategy {
    // Set to PowerManager.BRIGHTNESS_INVALID_FLOAT when there's no brightness to follow set.
    private float mBrightnessToFollow;

    // Indicates whether we should ramp slowly to the brightness value to follow.
    private boolean mBrightnessToFollowSlowChange;

    public FollowerBrightnessStrategy(int displayId) {
        mDisplayId = displayId;
        mBrightnessToFollow = PowerManager.BRIGHTNESS_INVALID_FLOAT;
        mBrightnessToFollowSlowChange = false;
    }

    @Override
@@ -48,7 +52,7 @@ public class FollowerBrightnessStrategy implements DisplayBrightnessStrategy {
        // Todo(b/241308599): Introduce a validator class and add validations before setting
        // the brightness
        return BrightnessUtils.constructDisplayBrightnessState(BrightnessReason.REASON_FOLLOWER,
                mBrightnessToFollow, mBrightnessToFollow, getName());
                mBrightnessToFollow, mBrightnessToFollow, getName(), mBrightnessToFollowSlowChange);
    }

    @Override
@@ -60,8 +64,12 @@ public class FollowerBrightnessStrategy implements DisplayBrightnessStrategy {
        return mBrightnessToFollow;
    }

    public void setBrightnessToFollow(float brightnessToFollow) {
    /**
     * Updates brightness value and brightness slowChange flag
     **/
    public void setBrightnessToFollow(float brightnessToFollow, boolean slowChange) {
        mBrightnessToFollow = brightnessToFollow;
        mBrightnessToFollowSlowChange = slowChange;
    }

    /**
@@ -71,5 +79,6 @@ public class FollowerBrightnessStrategy implements DisplayBrightnessStrategy {
        writer.println("FollowerBrightnessStrategy:");
        writer.println("  mDisplayId=" + mDisplayId);
        writer.println("  mBrightnessToFollow:" + mBrightnessToFollow);
        writer.println("  mBrightnessToFollowSlowChange:" + mBrightnessToFollowSlowChange);
    }
}
Loading