summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Rupesh Bansal <brup@google.com> 2022-10-19 14:38:22 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2022-10-19 14:38:22 +0000
commit646ab46e924a45ee6ac6d9617fbcc979e68239b5 (patch)
tree1f585560593acc1803a1a733b1d01d5e816c189f
parenta8e2e55474debf55f6e2825a21c6f225ab21d967 (diff)
parentf897ad78c495edeca75cbee44a66b682c68087c5 (diff)
Merge "Added utils for migrating blocking zone configs to DDC" into tm-qpr-dev
-rw-r--r--services/core/java/com/android/server/display/DisplayDeviceConfig.java54
-rw-r--r--services/core/java/com/android/server/display/DisplayManagerService.java11
-rw-r--r--services/core/java/com/android/server/display/DisplayModeDirector.java122
-rw-r--r--services/tests/servicestests/src/com/android/server/display/DisplayDeviceConfigTest.java32
-rw-r--r--services/tests/servicestests/src/com/android/server/display/DisplayModeDirectorTest.java14
5 files changed, 215 insertions, 18 deletions
diff --git a/services/core/java/com/android/server/display/DisplayDeviceConfig.java b/services/core/java/com/android/server/display/DisplayDeviceConfig.java
index 7858516bab67..687d03d4f774 100644
--- a/services/core/java/com/android/server/display/DisplayDeviceConfig.java
+++ b/services/core/java/com/android/server/display/DisplayDeviceConfig.java
@@ -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{"
diff --git a/services/core/java/com/android/server/display/DisplayManagerService.java b/services/core/java/com/android/server/display/DisplayManagerService.java
index a1490e564787..b8ff6ed93666 100644
--- a/services/core/java/com/android/server/display/DisplayManagerService.java
+++ b/services/core/java/com/android/server/display/DisplayManagerService.java
@@ -1519,6 +1519,7 @@ public final class DisplayManagerService extends SystemService {
display.setUserDisabledHdrTypes(mUserDisabledHdrTypes);
}
if (isDefault) {
+ notifyDefaultDisplayDeviceUpdated(display);
recordStableDisplayStatsIfNeededLocked(display);
recordTopInsetLocked(display);
}
@@ -1612,6 +1613,11 @@ public final class DisplayManagerService extends SystemService {
mHandler.post(work);
}
final int displayId = display.getDisplayIdLocked();
+
+ if (displayId == Display.DEFAULT_DISPLAY) {
+ notifyDefaultDisplayDeviceUpdated(display);
+ }
+
DisplayPowerController dpc = mDisplayPowerControllers.get(displayId);
if (dpc != null) {
dpc.onDisplayChanged();
@@ -1621,6 +1627,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 DisplayPowerController dpc = mDisplayPowerControllers.get(displayId);
diff --git a/services/core/java/com/android/server/display/DisplayModeDirector.java b/services/core/java/com/android/server/display/DisplayModeDirector.java
index ac72b1725432..912b1b2e8da2 100644
--- a/services/core/java/com/android/server/display/DisplayModeDirector.java
+++ b/services/core/java/com/android/server/display/DisplayModeDirector.java
@@ -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;
}
@@ -518,6 +519,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 =
diff --git a/services/tests/servicestests/src/com/android/server/display/DisplayDeviceConfigTest.java b/services/tests/servicestests/src/com/android/server/display/DisplayDeviceConfigTest.java
index a719f526a1d8..30024fb5c221 100644
--- a/services/tests/servicestests/src/com/android/server/display/DisplayDeviceConfigTest.java
+++ b/services/tests/servicestests/src/com/android/server/display/DisplayDeviceConfigTest.java
@@ -49,6 +49,13 @@ import java.nio.file.Path;
@Presubmit
@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;
@@ -204,6 +211,16 @@ public final class DisplayDeviceConfigTest {
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.
}
@@ -465,6 +482,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);
}
diff --git a/services/tests/servicestests/src/com/android/server/display/DisplayModeDirectorTest.java b/services/tests/servicestests/src/com/android/server/display/DisplayModeDirectorTest.java
index 968e1d8c546b..18dd264558ac 100644
--- a/services/tests/servicestests/src/com/android/server/display/DisplayModeDirectorTest.java
+++ b/services/tests/servicestests/src/com/android/server/display/DisplayModeDirectorTest.java
@@ -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);
}