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
This commit is contained in:
Oleg Petsjonkin
2023-07-17 12:32:14 +00:00
parent 649012b8d8
commit c55ccda345
7 changed files with 71 additions and 24 deletions

View File

@@ -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
*/

View File

@@ -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);

View File

@@ -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();
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -21,8 +21,8 @@ import static org.junit.Assert.assertEquals;
import android.hardware.display.DisplayManagerInternal;
import android.view.Display;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import com.android.server.display.DisplayBrightnessState;
import com.android.server.display.brightness.BrightnessReason;
@@ -46,7 +46,8 @@ public class FollowerBrightnessStrategyTest {
DisplayManagerInternal.DisplayPowerRequest
displayPowerRequest = new DisplayManagerInternal.DisplayPowerRequest();
float brightnessToFollow = 0.2f;
mFollowerBrightnessStrategy.setBrightnessToFollow(brightnessToFollow);
boolean slowChange = true;
mFollowerBrightnessStrategy.setBrightnessToFollow(brightnessToFollow, slowChange);
BrightnessReason brightnessReason = new BrightnessReason();
brightnessReason.setReason(BrightnessReason.REASON_FOLLOWER);
DisplayBrightnessState expectedDisplayBrightnessState =
@@ -55,6 +56,7 @@ public class FollowerBrightnessStrategyTest {
.setBrightnessReason(brightnessReason)
.setSdrBrightness(brightnessToFollow)
.setDisplayBrightnessStrategyName(mFollowerBrightnessStrategy.getName())
.setIsSlowChange(slowChange)
.build();
DisplayBrightnessState updatedDisplayBrightnessState =
mFollowerBrightnessStrategy.updateBrightness(displayPowerRequest);

View File

@@ -86,7 +86,9 @@ public class DisplayBrightnessStateTest {
.append("\n brightnessReason:")
.append(displayBrightnessState.getBrightnessReason())
.append("\n shouldUseAutoBrightness:")
.append(displayBrightnessState.getShouldUseAutoBrightness());
.append(displayBrightnessState.getShouldUseAutoBrightness())
.append("\n isSlowChange:")
.append(displayBrightnessState.isSlowChange());
return sb.toString();
}
}