Added utils for migrating blocking zone configs to DDC
Bug: 193892229 Test: atest DisplayDeviceConfigTest DisplayModeDirectorTest Change-Id: I27b3865fb4c4ea455fcf3594c3b778a8e592f949
This commit is contained in:
@@ -1193,6 +1193,60 @@ public class DisplayDeviceConfig {
|
||||
return mBrightnessLevelsNits;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Default peak refresh rate of the associated display
|
||||
*/
|
||||
public int getDefaultPeakRefreshRate() {
|
||||
return mContext.getResources().getInteger(R.integer.config_defaultPeakRefreshRate);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Default refresh rate of the associated display
|
||||
*/
|
||||
public int getDefaultRefreshRate() {
|
||||
return mContext.getResources().getInteger(R.integer.config_defaultRefreshRate);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return An array of lower display brightness thresholds. This, in combination with lower
|
||||
* ambient brightness thresholds help define buckets in which the refresh rate switching is not
|
||||
* allowed
|
||||
*/
|
||||
public int[] getLowDisplayBrightnessThresholds() {
|
||||
return mContext.getResources().getIntArray(
|
||||
R.array.config_brightnessThresholdsOfPeakRefreshRate);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return An array of lower ambient brightness thresholds. This, in combination with lower
|
||||
* display brightness thresholds help define buckets in which the refresh rate switching is not
|
||||
* allowed
|
||||
*/
|
||||
public int[] getLowAmbientBrightnessThresholds() {
|
||||
return mContext.getResources().getIntArray(
|
||||
R.array.config_ambientThresholdsOfPeakRefreshRate);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return An array of high display brightness thresholds. This, in combination with high
|
||||
* ambient brightness thresholds help define buckets in which the refresh rate switching is not
|
||||
* allowed
|
||||
*/
|
||||
public int[] getHighDisplayBrightnessThresholds() {
|
||||
return mContext.getResources().getIntArray(
|
||||
R.array.config_highDisplayBrightnessThresholdsOfFixedRefreshRate);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return An array of high ambient brightness thresholds. This, in combination with high
|
||||
* display brightness thresholds help define buckets in which the refresh rate switching is not
|
||||
* allowed
|
||||
*/
|
||||
public int[] getHighAmbientBrightnessThresholds() {
|
||||
return mContext.getResources().getIntArray(
|
||||
R.array.config_highAmbientBrightnessThresholdsOfFixedRefreshRate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DisplayDeviceConfig{"
|
||||
|
||||
@@ -1523,6 +1523,7 @@ public final class DisplayManagerService extends SystemService {
|
||||
display.setUserDisabledHdrTypes(mUserDisabledHdrTypes);
|
||||
}
|
||||
if (isDefault) {
|
||||
notifyDefaultDisplayDeviceUpdated(display);
|
||||
recordStableDisplayStatsIfNeededLocked(display);
|
||||
recordTopInsetLocked(display);
|
||||
}
|
||||
@@ -1617,6 +1618,10 @@ public final class DisplayManagerService extends SystemService {
|
||||
mHandler.post(work);
|
||||
}
|
||||
final int displayId = display.getDisplayIdLocked();
|
||||
|
||||
if (displayId == Display.DEFAULT_DISPLAY) {
|
||||
notifyDefaultDisplayDeviceUpdated(display);
|
||||
}
|
||||
DisplayPowerControllerInterface dpc = mDisplayPowerControllers.get(displayId);
|
||||
if (dpc != null) {
|
||||
dpc.onDisplayChanged();
|
||||
@@ -1626,6 +1631,11 @@ public final class DisplayManagerService extends SystemService {
|
||||
handleLogicalDisplayChangedLocked(display);
|
||||
}
|
||||
|
||||
private void notifyDefaultDisplayDeviceUpdated(LogicalDisplay display) {
|
||||
mDisplayModeDirector.defaultDisplayDeviceUpdated(display.getPrimaryDisplayDeviceLocked()
|
||||
.mDisplayDeviceConfig);
|
||||
}
|
||||
|
||||
private void handleLogicalDisplayDeviceStateTransitionLocked(@NonNull LogicalDisplay display) {
|
||||
final int displayId = display.getDisplayIdLocked();
|
||||
final DisplayPowerControllerInterface dpc = mDisplayPowerControllers.get(displayId);
|
||||
|
||||
@@ -79,6 +79,7 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* The DisplayModeDirector is responsible for determining what modes are allowed to be automatically
|
||||
@@ -153,8 +154,10 @@ public class DisplayModeDirector {
|
||||
mSupportedModesByDisplay = new SparseArray<>();
|
||||
mDefaultModeByDisplay = new SparseArray<>();
|
||||
mAppRequestObserver = new AppRequestObserver();
|
||||
mSettingsObserver = new SettingsObserver(context, handler);
|
||||
mDisplayObserver = new DisplayObserver(context, handler);
|
||||
mDeviceConfig = injector.getDeviceConfig();
|
||||
mDeviceConfigDisplaySettings = new DeviceConfigDisplaySettings();
|
||||
mSettingsObserver = new SettingsObserver(context, handler);
|
||||
mBrightnessObserver = new BrightnessObserver(context, handler, injector);
|
||||
mUdfpsObserver = new UdfpsObserver();
|
||||
final BallotBox ballotBox = (displayId, priority, vote) -> {
|
||||
@@ -164,10 +167,8 @@ public class DisplayModeDirector {
|
||||
};
|
||||
mSensorObserver = new SensorObserver(context, ballotBox, injector);
|
||||
mSkinThermalStatusObserver = new SkinThermalStatusObserver(injector, ballotBox);
|
||||
mDeviceConfigDisplaySettings = new DeviceConfigDisplaySettings();
|
||||
mHbmObserver = new HbmObserver(injector, ballotBox, BackgroundThread.getHandler(),
|
||||
mDeviceConfigDisplaySettings);
|
||||
mDeviceConfig = injector.getDeviceConfig();
|
||||
mAlwaysRespectAppRequest = false;
|
||||
}
|
||||
|
||||
@@ -517,6 +518,15 @@ public class DisplayModeDirector {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A utility to make this class aware of the new display configs whenever the default display is
|
||||
* changed
|
||||
*/
|
||||
public void defaultDisplayDeviceUpdated(DisplayDeviceConfig displayDeviceConfig) {
|
||||
mSettingsObserver.setRefreshRates(displayDeviceConfig);
|
||||
mBrightnessObserver.updateBlockingZoneThresholds(displayDeviceConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* When enabled the app requested display mode is always selected and all
|
||||
* other votes will be ignored. This is used for testing purposes.
|
||||
@@ -1132,10 +1142,19 @@ public class DisplayModeDirector {
|
||||
SettingsObserver(@NonNull Context context, @NonNull Handler handler) {
|
||||
super(handler);
|
||||
mContext = context;
|
||||
mDefaultPeakRefreshRate = (float) context.getResources().getInteger(
|
||||
R.integer.config_defaultPeakRefreshRate);
|
||||
setRefreshRates(/* displayDeviceConfig= */ null);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is used to update the refresh rate configs from the DeviceConfig, which
|
||||
* if missing from DisplayDeviceConfig, and finally fallback to config.xml.
|
||||
*/
|
||||
public void setRefreshRates(DisplayDeviceConfig displayDeviceConfig) {
|
||||
setDefaultPeakRefreshRate(displayDeviceConfig);
|
||||
mDefaultRefreshRate =
|
||||
(float) context.getResources().getInteger(R.integer.config_defaultRefreshRate);
|
||||
(displayDeviceConfig == null) ? (float) mContext.getResources().getInteger(
|
||||
R.integer.config_defaultRefreshRate)
|
||||
: (float) displayDeviceConfig.getDefaultRefreshRate();
|
||||
}
|
||||
|
||||
public void observe() {
|
||||
@@ -1196,6 +1215,23 @@ public class DisplayModeDirector {
|
||||
}
|
||||
}
|
||||
|
||||
private void setDefaultPeakRefreshRate(DisplayDeviceConfig displayDeviceConfig) {
|
||||
Float defaultPeakRefreshRate = null;
|
||||
try {
|
||||
defaultPeakRefreshRate =
|
||||
mDeviceConfigDisplaySettings.getDefaultPeakRefreshRate();
|
||||
} catch (Exception exception) {
|
||||
// Do nothing
|
||||
}
|
||||
if (defaultPeakRefreshRate == null) {
|
||||
defaultPeakRefreshRate =
|
||||
(displayDeviceConfig == null) ? (float) mContext.getResources().getInteger(
|
||||
R.integer.config_defaultPeakRefreshRate)
|
||||
: (float) displayDeviceConfig.getDefaultPeakRefreshRate();
|
||||
}
|
||||
mDefaultPeakRefreshRate = defaultPeakRefreshRate;
|
||||
}
|
||||
|
||||
private void updateLowPowerModeSettingLocked() {
|
||||
boolean inLowPowerMode = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.LOW_POWER_MODE, 0 /*default*/) != 0;
|
||||
@@ -1508,12 +1544,31 @@ public class DisplayModeDirector {
|
||||
mContext = context;
|
||||
mHandler = handler;
|
||||
mInjector = injector;
|
||||
updateBlockingZoneThresholds(/* displayDeviceConfig= */ null);
|
||||
mRefreshRateInHighZone = context.getResources().getInteger(
|
||||
R.integer.config_fixedRefreshRateInHighZone);
|
||||
}
|
||||
|
||||
mLowDisplayBrightnessThresholds = context.getResources().getIntArray(
|
||||
R.array.config_brightnessThresholdsOfPeakRefreshRate);
|
||||
mLowAmbientBrightnessThresholds = context.getResources().getIntArray(
|
||||
R.array.config_ambientThresholdsOfPeakRefreshRate);
|
||||
/**
|
||||
* This is used to update the blocking zone thresholds from the DeviceConfig, which
|
||||
* if missing from DisplayDeviceConfig, and finally fallback to config.xml.
|
||||
*/
|
||||
public void updateBlockingZoneThresholds(DisplayDeviceConfig displayDeviceConfig) {
|
||||
loadLowBrightnessThresholds(displayDeviceConfig);
|
||||
loadHighBrightnessThresholds(displayDeviceConfig);
|
||||
}
|
||||
|
||||
private void loadLowBrightnessThresholds(DisplayDeviceConfig displayDeviceConfig) {
|
||||
mLowDisplayBrightnessThresholds = loadBrightnessThresholds(
|
||||
() -> mDeviceConfigDisplaySettings.getLowDisplayBrightnessThresholds(),
|
||||
() -> displayDeviceConfig.getLowDisplayBrightnessThresholds(),
|
||||
R.array.config_brightnessThresholdsOfPeakRefreshRate,
|
||||
displayDeviceConfig);
|
||||
mLowAmbientBrightnessThresholds = loadBrightnessThresholds(
|
||||
() -> mDeviceConfigDisplaySettings.getLowAmbientBrightnessThresholds(),
|
||||
() -> displayDeviceConfig.getLowAmbientBrightnessThresholds(),
|
||||
R.array.config_ambientThresholdsOfPeakRefreshRate,
|
||||
displayDeviceConfig);
|
||||
if (mLowDisplayBrightnessThresholds.length != mLowAmbientBrightnessThresholds.length) {
|
||||
throw new RuntimeException("display low brightness threshold array and ambient "
|
||||
+ "brightness threshold array have different length: "
|
||||
@@ -1522,11 +1577,19 @@ public class DisplayModeDirector {
|
||||
+ ", ambientBrightnessThresholds="
|
||||
+ Arrays.toString(mLowAmbientBrightnessThresholds));
|
||||
}
|
||||
}
|
||||
|
||||
mHighDisplayBrightnessThresholds = context.getResources().getIntArray(
|
||||
R.array.config_highDisplayBrightnessThresholdsOfFixedRefreshRate);
|
||||
mHighAmbientBrightnessThresholds = context.getResources().getIntArray(
|
||||
R.array.config_highAmbientBrightnessThresholdsOfFixedRefreshRate);
|
||||
private void loadHighBrightnessThresholds(DisplayDeviceConfig displayDeviceConfig) {
|
||||
mHighDisplayBrightnessThresholds = loadBrightnessThresholds(
|
||||
() -> mDeviceConfigDisplaySettings.getHighDisplayBrightnessThresholds(),
|
||||
() -> displayDeviceConfig.getHighDisplayBrightnessThresholds(),
|
||||
R.array.config_highDisplayBrightnessThresholdsOfFixedRefreshRate,
|
||||
displayDeviceConfig);
|
||||
mHighAmbientBrightnessThresholds = loadBrightnessThresholds(
|
||||
() -> mDeviceConfigDisplaySettings.getHighAmbientBrightnessThresholds(),
|
||||
() -> displayDeviceConfig.getHighAmbientBrightnessThresholds(),
|
||||
R.array.config_highAmbientBrightnessThresholdsOfFixedRefreshRate,
|
||||
displayDeviceConfig);
|
||||
if (mHighDisplayBrightnessThresholds.length
|
||||
!= mHighAmbientBrightnessThresholds.length) {
|
||||
throw new RuntimeException("display high brightness threshold array and ambient "
|
||||
@@ -1536,8 +1599,32 @@ public class DisplayModeDirector {
|
||||
+ ", ambientBrightnessThresholds="
|
||||
+ Arrays.toString(mHighAmbientBrightnessThresholds));
|
||||
}
|
||||
mRefreshRateInHighZone = context.getResources().getInteger(
|
||||
R.integer.config_fixedRefreshRateInHighZone);
|
||||
}
|
||||
|
||||
private int[] loadBrightnessThresholds(
|
||||
Callable<int[]> loadFromDeviceConfigDisplaySettingsCallable,
|
||||
Callable<int[]> loadFromDisplayDeviceConfigCallable,
|
||||
int brightnessThresholdOfFixedRefreshRateKey,
|
||||
DisplayDeviceConfig displayDeviceConfig) {
|
||||
int[] brightnessThresholds = null;
|
||||
try {
|
||||
brightnessThresholds =
|
||||
loadFromDeviceConfigDisplaySettingsCallable.call();
|
||||
} catch (Exception exception) {
|
||||
// Do nothing
|
||||
}
|
||||
if (brightnessThresholds == null) {
|
||||
try {
|
||||
brightnessThresholds =
|
||||
(displayDeviceConfig == null) ? mContext.getResources().getIntArray(
|
||||
brightnessThresholdOfFixedRefreshRateKey)
|
||||
: loadFromDisplayDeviceConfigCallable.call();
|
||||
} catch (Exception e) {
|
||||
Slog.e(TAG, "Unexpectedly failed to load display brightness threshold");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return brightnessThresholds;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1590,7 +1677,6 @@ public class DisplayModeDirector {
|
||||
mLowAmbientBrightnessThresholds = lowAmbientBrightnessThresholds;
|
||||
}
|
||||
|
||||
|
||||
int[] highDisplayBrightnessThresholds =
|
||||
mDeviceConfigDisplaySettings.getHighDisplayBrightnessThresholds();
|
||||
int[] highAmbientBrightnessThresholds =
|
||||
|
||||
@@ -47,6 +47,13 @@ import java.nio.file.Path;
|
||||
@SmallTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public final class DisplayDeviceConfigTest {
|
||||
private static final int DEFAULT_PEAK_REFRESH_RATE = 75;
|
||||
private static final int DEFAULT_REFRESH_RATE = 120;
|
||||
private static final int[] LOW_BRIGHTNESS_THRESHOLD_OF_PEAK_REFRESH_RATE = new int[]{10, 30};
|
||||
private static final int[] LOW_AMBIENT_THRESHOLD_OF_PEAK_REFRESH_RATE = new int[]{1, 21};
|
||||
private static final int[] HIGH_BRIGHTNESS_THRESHOLD_OF_PEAK_REFRESH_RATE = new int[]{160};
|
||||
private static final int[] HIGH_AMBIENT_THRESHOLD_OF_PEAK_REFRESH_RATE = new int[]{30000};
|
||||
|
||||
private DisplayDeviceConfig mDisplayDeviceConfig;
|
||||
private static final float ZERO_DELTA = 0.0f;
|
||||
private static final float SMALL_DELTA = 0.0001f;
|
||||
@@ -200,8 +207,16 @@ public final class DisplayDeviceConfigTest {
|
||||
mDisplayDeviceConfig.getAmbientDarkeningLevelsIdle(), ZERO_DELTA);
|
||||
assertArrayEquals(new float[]{29, 30, 31},
|
||||
mDisplayDeviceConfig.getAmbientDarkeningPercentagesIdle(), ZERO_DELTA);
|
||||
|
||||
|
||||
assertEquals(mDisplayDeviceConfig.getDefaultRefreshRate(), DEFAULT_REFRESH_RATE);
|
||||
assertEquals(mDisplayDeviceConfig.getDefaultPeakRefreshRate(), DEFAULT_PEAK_REFRESH_RATE);
|
||||
assertArrayEquals(mDisplayDeviceConfig.getLowDisplayBrightnessThresholds(),
|
||||
LOW_BRIGHTNESS_THRESHOLD_OF_PEAK_REFRESH_RATE);
|
||||
assertArrayEquals(mDisplayDeviceConfig.getLowAmbientBrightnessThresholds(),
|
||||
LOW_AMBIENT_THRESHOLD_OF_PEAK_REFRESH_RATE);
|
||||
assertArrayEquals(mDisplayDeviceConfig.getHighDisplayBrightnessThresholds(),
|
||||
HIGH_BRIGHTNESS_THRESHOLD_OF_PEAK_REFRESH_RATE);
|
||||
assertArrayEquals(mDisplayDeviceConfig.getHighAmbientBrightnessThresholds(),
|
||||
HIGH_AMBIENT_THRESHOLD_OF_PEAK_REFRESH_RATE);
|
||||
// Todo(brup): Add asserts for BrightnessThrottlingData, DensityMapping,
|
||||
// HighBrightnessModeData AmbientLightSensor, RefreshRateLimitations and ProximitySensor.
|
||||
}
|
||||
@@ -463,6 +478,21 @@ public final class DisplayDeviceConfigTest {
|
||||
when(mResources.getIntArray(R.array.config_screenDarkeningThresholds))
|
||||
.thenReturn(new int[]{370, 380, 390});
|
||||
|
||||
// Configs related to refresh rates and blocking zones
|
||||
when(mResources.getInteger(com.android.internal.R.integer.config_defaultPeakRefreshRate))
|
||||
.thenReturn(DEFAULT_PEAK_REFRESH_RATE);
|
||||
when(mResources.getInteger(com.android.internal.R.integer.config_defaultRefreshRate))
|
||||
.thenReturn(DEFAULT_REFRESH_RATE);
|
||||
when(mResources.getIntArray(R.array.config_brightnessThresholdsOfPeakRefreshRate))
|
||||
.thenReturn(LOW_BRIGHTNESS_THRESHOLD_OF_PEAK_REFRESH_RATE);
|
||||
when(mResources.getIntArray(R.array.config_ambientThresholdsOfPeakRefreshRate))
|
||||
.thenReturn(LOW_AMBIENT_THRESHOLD_OF_PEAK_REFRESH_RATE);
|
||||
when(mResources.getIntArray(
|
||||
R.array.config_highDisplayBrightnessThresholdsOfFixedRefreshRate))
|
||||
.thenReturn(HIGH_BRIGHTNESS_THRESHOLD_OF_PEAK_REFRESH_RATE);
|
||||
when(mResources.getIntArray(
|
||||
R.array.config_highAmbientBrightnessThresholdsOfFixedRefreshRate))
|
||||
.thenReturn(HIGH_AMBIENT_THRESHOLD_OF_PEAK_REFRESH_RATE);
|
||||
mDisplayDeviceConfig = DisplayDeviceConfig.create(mContext, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -1853,6 +1853,20 @@ public class DisplayModeDirectorTest {
|
||||
assertNull(vote);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotifyDefaultDisplayDeviceUpdated() {
|
||||
DisplayDeviceConfig displayDeviceConfig = mock(DisplayDeviceConfig.class);
|
||||
when(displayDeviceConfig.getLowDisplayBrightnessThresholds()).thenReturn(new int[]{});
|
||||
when(displayDeviceConfig.getLowAmbientBrightnessThresholds()).thenReturn(new int[]{});
|
||||
when(displayDeviceConfig.getHighDisplayBrightnessThresholds()).thenReturn(new int[]{});
|
||||
when(displayDeviceConfig.getHighAmbientBrightnessThresholds()).thenReturn(new int[]{});
|
||||
DisplayModeDirector director =
|
||||
createDirectorFromRefreshRateArray(new float[]{60.0f, 90.0f}, 0);
|
||||
director.defaultDisplayDeviceUpdated(displayDeviceConfig);
|
||||
verify(displayDeviceConfig).getDefaultRefreshRate();
|
||||
verify(displayDeviceConfig).getDefaultPeakRefreshRate();
|
||||
}
|
||||
|
||||
private Temperature getSkinTemp(@Temperature.ThrottlingStatus int status) {
|
||||
return new Temperature(30.0f, Temperature.TYPE_SKIN, "test_skin_temp", status);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user