Merge "Add throttlingDataId to deviceConfig" into udc-dev

This commit is contained in:
Manali Bhutiyani
2023-04-05 17:19:12 +00:00
committed by Android (Google) Code Review
8 changed files with 243 additions and 154 deletions

View File

@@ -1758,10 +1758,12 @@ public final class DisplayManager {
/** /**
* Key for the brightness throttling data as a String formatted: * Key for the brightness throttling data as a String formatted:
* <displayId>,<no of throttling levels>,[<severity as string>,<brightness cap>] * <displayId>,<no of throttling levels>,[<severity as string>,<brightness cap>]
* Where the latter part is repeated for each throttling level, and the entirety is repeated * [,<throttlingId>]?
* for each display, separated by a semicolon. * Where [<severity as string>,<brightness cap>] is repeated for each throttling level.
* The entirety is repeated for each display and throttling id, separated by a semicolon.
* For example: * For example:
* 123,1,critical,0.8;456,2,moderate,0.9,critical,0.7 * 123,1,critical,0.8;456,2,moderate,0.9,critical,0.7
* 123,1,critical,0.8,default;123,1,moderate,0.6,id_2;456,2,moderate,0.9,critical,0.7
*/ */
String KEY_BRIGHTNESS_THROTTLING_DATA = "brightness_throttling_data"; String KEY_BRIGHTNESS_THROTTLING_DATA = "brightness_throttling_data";
} }

View File

@@ -16,7 +16,10 @@
package com.android.server.display; package com.android.server.display;
import static com.android.server.display.DisplayDeviceConfig.DEFAULT_ID;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context; import android.content.Context;
import android.hardware.display.BrightnessInfo; import android.hardware.display.BrightnessInfo;
import android.hardware.display.DisplayManager; import android.hardware.display.DisplayManager;
@@ -63,8 +66,16 @@ class BrightnessThrottler {
private final DeviceConfigInterface mDeviceConfig; private final DeviceConfigInterface mDeviceConfig;
private int mThrottlingStatus; private int mThrottlingStatus;
// Maps the throttling ID to the data. Sourced from DisplayDeviceConfig.
@NonNull
private HashMap<String, BrightnessThrottlingData> mDdcThrottlingDataMap;
// Current throttling data being used.
// Null if we do not support throttling.
@Nullable
private BrightnessThrottlingData mThrottlingData; private BrightnessThrottlingData mThrottlingData;
private BrightnessThrottlingData mDdcThrottlingData;
private float mBrightnessCap = PowerManager.BRIGHTNESS_MAX; private float mBrightnessCap = PowerManager.BRIGHTNESS_MAX;
private @BrightnessInfo.BrightnessMaxReason int mBrightnessMaxReason = private @BrightnessInfo.BrightnessMaxReason int mBrightnessMaxReason =
BrightnessInfo.BRIGHTNESS_MAX_REASON_NONE; BrightnessInfo.BRIGHTNESS_MAX_REASON_NONE;
@@ -73,35 +84,45 @@ class BrightnessThrottler {
// The most recent string that has been set from DeviceConfig // The most recent string that has been set from DeviceConfig
private String mBrightnessThrottlingDataString; private String mBrightnessThrottlingDataString;
// The brightness throttling configuration that should be used.
private String mBrightnessThrottlingDataId;
// This is a collection of brightness throttling data that has been written as overrides from // This is a collection of brightness throttling data that has been written as overrides from
// the DeviceConfig. This will always take priority over the display device config data. // the DeviceConfig. This will always take priority over the display device config data.
private HashMap<String, BrightnessThrottlingData> mBrightnessThrottlingDataOverride = // We need to store the data for every display device, so we do not need to update this each
new HashMap<>(1); // time the underlying display device changes.
// This map is indexed by uniqueDisplayId, to provide maps for throttlingId -> throttlingData.
// HashMap< uniqueDisplayId, HashMap< throttlingDataId, BrightnessThrottlingData >>
private final HashMap<String, HashMap<String, BrightnessThrottlingData>>
mBrightnessThrottlingDataOverride = new HashMap<>(1);
BrightnessThrottler(Handler handler, BrightnessThrottlingData throttlingData, BrightnessThrottler(Handler handler, Runnable throttlingChangeCallback, String uniqueDisplayId,
Runnable throttlingChangeCallback, String uniqueDisplayId) { String throttlingDataId,
this(new Injector(), handler, handler, throttlingData, throttlingChangeCallback, @NonNull HashMap<String, BrightnessThrottlingData> brightnessThrottlingDataMap) {
uniqueDisplayId); this(new Injector(), handler, handler, throttlingChangeCallback,
uniqueDisplayId, throttlingDataId, brightnessThrottlingDataMap);
} }
@VisibleForTesting @VisibleForTesting
BrightnessThrottler(Injector injector, Handler handler, Handler deviceConfigHandler, BrightnessThrottler(Injector injector, Handler handler, Handler deviceConfigHandler,
BrightnessThrottlingData throttlingData, Runnable throttlingChangeCallback, Runnable throttlingChangeCallback, String uniqueDisplayId, String throttlingDataId,
String uniqueDisplayId) { @NonNull HashMap<String, BrightnessThrottlingData> brightnessThrottlingDataMap) {
mInjector = injector; mInjector = injector;
mHandler = handler; mHandler = handler;
mDeviceConfigHandler = deviceConfigHandler; mDeviceConfigHandler = deviceConfigHandler;
mThrottlingData = throttlingData; mDdcThrottlingDataMap = brightnessThrottlingDataMap;
mDdcThrottlingData = throttlingData;
mThrottlingChangeCallback = throttlingChangeCallback; mThrottlingChangeCallback = throttlingChangeCallback;
mSkinThermalStatusObserver = new SkinThermalStatusObserver(mInjector, mHandler); mSkinThermalStatusObserver = new SkinThermalStatusObserver(mInjector, mHandler);
mUniqueDisplayId = uniqueDisplayId; mUniqueDisplayId = uniqueDisplayId;
mDeviceConfig = injector.getDeviceConfig(); mDeviceConfig = injector.getDeviceConfig();
mDeviceConfigListener = new DeviceConfigListener(); mDeviceConfigListener = new DeviceConfigListener();
mBrightnessThrottlingDataId = throttlingDataId;
resetThrottlingData(mThrottlingData, mUniqueDisplayId); mDdcThrottlingDataMap = brightnessThrottlingDataMap;
loadBrightnessThrottlingDataFromDeviceConfig();
loadBrightnessThrottlingDataFromDisplayDeviceConfig(mDdcThrottlingDataMap,
mBrightnessThrottlingDataId, mUniqueDisplayId);
} }
boolean deviceSupportsThrottling() { boolean deviceSupportsThrottling() {
@@ -133,23 +154,14 @@ class BrightnessThrottler {
mThrottlingStatus = THROTTLING_INVALID; mThrottlingStatus = THROTTLING_INVALID;
} }
private void resetThrottlingData() { void loadBrightnessThrottlingDataFromDisplayDeviceConfig(
resetThrottlingData(mDdcThrottlingData, mUniqueDisplayId); HashMap<String, BrightnessThrottlingData> ddcThrottlingDataMap,
} String brightnessThrottlingDataId,
String uniqueDisplayId) {
void resetThrottlingData(BrightnessThrottlingData throttlingData, String displayId) { mDdcThrottlingDataMap = ddcThrottlingDataMap;
stop(); mBrightnessThrottlingDataId = brightnessThrottlingDataId;
mUniqueDisplayId = uniqueDisplayId;
mUniqueDisplayId = displayId; resetThrottlingData();
mDdcThrottlingData = throttlingData;
mDeviceConfigListener.startListening();
reloadBrightnessThrottlingDataOverride();
mThrottlingData = mBrightnessThrottlingDataOverride.getOrDefault(mUniqueDisplayId,
throttlingData);
if (deviceSupportsThrottling()) {
mSkinThermalStatusObserver.startObserving();
}
} }
private float verifyAndConstrainBrightnessCap(float brightness) { private float verifyAndConstrainBrightnessCap(float brightness) {
@@ -183,7 +195,7 @@ class BrightnessThrottler {
float brightnessCap = PowerManager.BRIGHTNESS_MAX; float brightnessCap = PowerManager.BRIGHTNESS_MAX;
int brightnessMaxReason = BrightnessInfo.BRIGHTNESS_MAX_REASON_NONE; int brightnessMaxReason = BrightnessInfo.BRIGHTNESS_MAX_REASON_NONE;
if (mThrottlingStatus != THROTTLING_INVALID) { if (mThrottlingStatus != THROTTLING_INVALID && mThrottlingData != null) {
// Throttling levels are sorted by increasing severity // Throttling levels are sorted by increasing severity
for (ThrottlingLevel level : mThrottlingData.throttlingLevels) { for (ThrottlingLevel level : mThrottlingData.throttlingLevels) {
if (level.thermalStatus <= mThrottlingStatus) { if (level.thermalStatus <= mThrottlingStatus) {
@@ -218,13 +230,14 @@ class BrightnessThrottler {
private void dumpLocal(PrintWriter pw) { private void dumpLocal(PrintWriter pw) {
pw.println("BrightnessThrottler:"); pw.println("BrightnessThrottler:");
pw.println(" mBrightnessThrottlingDataId=" + mBrightnessThrottlingDataId);
pw.println(" mThrottlingData=" + mThrottlingData); pw.println(" mThrottlingData=" + mThrottlingData);
pw.println(" mDdcThrottlingData=" + mDdcThrottlingData);
pw.println(" mUniqueDisplayId=" + mUniqueDisplayId); pw.println(" mUniqueDisplayId=" + mUniqueDisplayId);
pw.println(" mThrottlingStatus=" + mThrottlingStatus); pw.println(" mThrottlingStatus=" + mThrottlingStatus);
pw.println(" mBrightnessCap=" + mBrightnessCap); pw.println(" mBrightnessCap=" + mBrightnessCap);
pw.println(" mBrightnessMaxReason=" + pw.println(" mBrightnessMaxReason=" +
BrightnessInfo.briMaxReasonToString(mBrightnessMaxReason)); BrightnessInfo.briMaxReasonToString(mBrightnessMaxReason));
pw.println(" mDdcThrottlingDataMap=" + mDdcThrottlingDataMap);
pw.println(" mBrightnessThrottlingDataOverride=" + mBrightnessThrottlingDataOverride); pw.println(" mBrightnessThrottlingDataOverride=" + mBrightnessThrottlingDataOverride);
pw.println(" mBrightnessThrottlingDataString=" + mBrightnessThrottlingDataString); pw.println(" mBrightnessThrottlingDataString=" + mBrightnessThrottlingDataString);
@@ -237,8 +250,18 @@ class BrightnessThrottler {
/* defaultValue= */ null); /* defaultValue= */ null);
} }
private boolean parseAndSaveData(@NonNull String strArray, // The brightness throttling data id may or may not be specified in the string that is passed
@NonNull HashMap<String, BrightnessThrottlingData> tempBrightnessThrottlingData) { // in, if there is none specified, we assume it is for the default case. Each string passed in
// here must be for one display and one throttling id.
// 123,1,critical,0.8
// 456,2,moderate,0.9,critical,0.7
// 456,2,moderate,0.9,critical,0.7,default
// 456,2,moderate,0.9,critical,0.7,id_2
// displayId, number, <state, val> * number
// displayId, <number, <state, val> * number>, throttlingId
private boolean parseAndAddData(@NonNull String strArray,
@NonNull HashMap<String, HashMap<String, BrightnessThrottlingData>>
displayIdToThrottlingIdToBtd) {
boolean validConfig = true; boolean validConfig = true;
String[] items = strArray.split(","); String[] items = strArray.split(",");
int i = 0; int i = 0;
@@ -254,29 +277,42 @@ class BrightnessThrottler {
for (int j = 0; j < noOfThrottlingPoints; j++) { for (int j = 0; j < noOfThrottlingPoints; j++) {
String severity = items[i++]; String severity = items[i++];
int status = parseThermalStatus(severity); int status = parseThermalStatus(severity);
float brightnessPoint = parseBrightness(items[i++]); float brightnessPoint = parseBrightness(items[i++]);
throttlingLevels.add(new ThrottlingLevel(status, brightnessPoint)); throttlingLevels.add(new ThrottlingLevel(status, brightnessPoint));
} }
BrightnessThrottlingData toSave =
String throttlingDataId = (i < items.length) ? items[i++] : DEFAULT_ID;
BrightnessThrottlingData throttlingLevelsData =
DisplayDeviceConfig.BrightnessThrottlingData.create(throttlingLevels); DisplayDeviceConfig.BrightnessThrottlingData.create(throttlingLevels);
tempBrightnessThrottlingData.put(uniqueDisplayId, toSave);
// Add throttlingLevelsData to inner map where necessary.
HashMap<String, BrightnessThrottlingData> throttlingMapForDisplay =
displayIdToThrottlingIdToBtd.get(uniqueDisplayId);
if (throttlingMapForDisplay == null) {
throttlingMapForDisplay = new HashMap<>();
throttlingMapForDisplay.put(throttlingDataId, throttlingLevelsData);
displayIdToThrottlingIdToBtd.put(uniqueDisplayId, throttlingMapForDisplay);
} else if (throttlingMapForDisplay.containsKey(throttlingDataId)) {
Slog.e(TAG, "Throttling data for display " + uniqueDisplayId
+ "contains duplicate throttling ids: '" + throttlingDataId + "'");
return false;
} else {
throttlingMapForDisplay.put(throttlingDataId, throttlingLevelsData);
}
} catch (NumberFormatException | IndexOutOfBoundsException } catch (NumberFormatException | IndexOutOfBoundsException
| UnknownThermalStatusException e) { | UnknownThermalStatusException e) {
validConfig = false;
Slog.e(TAG, "Throttling data is invalid array: '" + strArray + "'", e); Slog.e(TAG, "Throttling data is invalid array: '" + strArray + "'", e);
validConfig = false;
} }
if (i != items.length) { if (i != items.length) {
validConfig = false; validConfig = false;
} }
return validConfig; return validConfig;
} }
public void reloadBrightnessThrottlingDataOverride() { private void loadBrightnessThrottlingDataFromDeviceConfig() {
HashMap<String, BrightnessThrottlingData> tempBrightnessThrottlingData = HashMap<String, HashMap<String, BrightnessThrottlingData>> tempThrottlingData =
new HashMap<>(1); new HashMap<>(1);
mBrightnessThrottlingDataString = getBrightnessThrottlingDataString(); mBrightnessThrottlingDataString = getBrightnessThrottlingDataString();
boolean validConfig = true; boolean validConfig = true;
@@ -284,15 +320,15 @@ class BrightnessThrottler {
if (mBrightnessThrottlingDataString != null) { if (mBrightnessThrottlingDataString != null) {
String[] throttlingDataSplits = mBrightnessThrottlingDataString.split(";"); String[] throttlingDataSplits = mBrightnessThrottlingDataString.split(";");
for (String s : throttlingDataSplits) { for (String s : throttlingDataSplits) {
if (!parseAndSaveData(s, tempBrightnessThrottlingData)) { if (!parseAndAddData(s, tempThrottlingData)) {
validConfig = false; validConfig = false;
break; break;
} }
} }
if (validConfig) { if (validConfig) {
mBrightnessThrottlingDataOverride.putAll(tempBrightnessThrottlingData); mBrightnessThrottlingDataOverride.putAll(tempThrottlingData);
tempBrightnessThrottlingData.clear(); tempThrottlingData.clear();
} }
} else { } else {
@@ -300,15 +336,50 @@ class BrightnessThrottler {
} }
} }
private void resetThrottlingData() {
stop();
mDeviceConfigListener.startListening();
// Get throttling data for this id, if it exists
mThrottlingData = getConfigFromId(mBrightnessThrottlingDataId);
// Fallback to default id otherwise.
if (!DEFAULT_ID.equals(mBrightnessThrottlingDataId) && mThrottlingData == null) {
mThrottlingData = getConfigFromId(DEFAULT_ID);
Slog.d(TAG, "Falling back to default throttling Id");
}
if (deviceSupportsThrottling()) {
mSkinThermalStatusObserver.startObserving();
}
}
private BrightnessThrottlingData getConfigFromId(String id) {
BrightnessThrottlingData returnValue;
// Fallback pattern for fetching correct throttling data for this display and id.
// 1) throttling data from device config for this throttling data id
returnValue = mBrightnessThrottlingDataOverride.get(mUniqueDisplayId) == null
? null
: mBrightnessThrottlingDataOverride.get(mUniqueDisplayId).get(id);
// 2) throttling data from ddc for this throttling data id
returnValue = returnValue == null
? mDdcThrottlingDataMap.get(id)
: returnValue;
return returnValue;
}
/** /**
* Listens to config data change and updates the brightness throttling data using * Listens to config data change and updates the brightness throttling data using
* DisplayManager#KEY_BRIGHTNESS_THROTTLING_DATA. * DisplayManager#KEY_BRIGHTNESS_THROTTLING_DATA.
* The format should be a string similar to: "local:4619827677550801152,2,moderate,0.5,severe, * The format should be a string similar to: "local:4619827677550801152,2,moderate,0.5,severe,
* 0.379518072;local:4619827677550801151,1,moderate,0.75" * 0.379518072;local:4619827677550801151,1,moderate,0.75"
* In this order: * In this order:
* <displayId>,<no of throttling levels>,[<severity as string>,<brightness cap>] * <displayId>,<no of throttling levels>,[<severity as string>,<brightness cap>][,throttlingId]?
* Where the latter part is repeated for each throttling level, and the entirety is repeated * Where [<severity as string>,<brightness cap>] is repeated for each throttling level, and the
* for each display, separated by a semicolon. * entirety is repeated for each display & throttling data id, separated by a semicolon.
*/ */
public class DeviceConfigListener implements DeviceConfig.OnPropertiesChangedListener { public class DeviceConfigListener implements DeviceConfig.OnPropertiesChangedListener {
public Executor mExecutor = new HandlerExecutor(mDeviceConfigHandler); public Executor mExecutor = new HandlerExecutor(mDeviceConfigHandler);
@@ -320,7 +391,7 @@ class BrightnessThrottler {
@Override @Override
public void onPropertiesChanged(DeviceConfig.Properties properties) { public void onPropertiesChanged(DeviceConfig.Properties properties) {
reloadBrightnessThrottlingDataOverride(); loadBrightnessThrottlingDataFromDeviceConfig();
resetThrottlingData(); resetThrottlingData();
} }
} }

View File

@@ -143,17 +143,17 @@ import javax.xml.datatype.DatatypeConfigurationException;
* <brightness>0.01</brightness> * <brightness>0.01</brightness>
* </brightnessThrottlingPoint> * </brightnessThrottlingPoint>
* </brightnessThrottlingMap> * </brightnessThrottlingMap>
* <concurrentDisplaysBrightnessThrottlingMap> * <brightnessThrottlingMap id="id_2"> // optional attribute, leave blank for default
* <brightnessThrottlingPoint> * <brightnessThrottlingPoint>
* <thermalStatus>severe</thermalStatus> * <thermalStatus>moderate</thermalStatus>
* <brightness>0.07</brightness> * <brightness>0.2</brightness>
* </brightnessThrottlingPoint> * </brightnessThrottlingPoint>
* <brightnessThrottlingPoint> * <brightnessThrottlingPoint>
* <thermalStatus>critical</thermalStatus> * <thermalStatus>severe</thermalStatus>
* <brightness>0.005</brightness> * <brightness>0.1</brightness>
* </brightnessThrottlingPoint> * </brightnessThrottlingPoint>
* </concurrentDisplaysBrightnessThrottlingMap> * </brightnessThrottlingMap>
* <refreshRateThrottlingMap> <refreshRateThrottlingMap>
* <refreshRateThrottlingPoint> * <refreshRateThrottlingPoint>
* <thermalStatus>critical</thermalStatus> * <thermalStatus>critical</thermalStatus>
* <refreshRateRange> * <refreshRateRange>
@@ -687,8 +687,8 @@ public class DisplayDeviceConfig {
private int[] mHighDisplayBrightnessThresholds = DEFAULT_BRIGHTNESS_THRESHOLDS; private int[] mHighDisplayBrightnessThresholds = DEFAULT_BRIGHTNESS_THRESHOLDS;
private int[] mHighAmbientBrightnessThresholds = DEFAULT_BRIGHTNESS_THRESHOLDS; private int[] mHighAmbientBrightnessThresholds = DEFAULT_BRIGHTNESS_THRESHOLDS;
private final Map<String, BrightnessThrottlingData> mBrightnessThrottlingDataMap = private final HashMap<String, BrightnessThrottlingData>
new HashMap<>(); mBrightnessThrottlingDataMapByThrottlingId = new HashMap<>();
private final Map<String, SparseArray<SurfaceControl.RefreshRateRange>> private final Map<String, SparseArray<SurfaceControl.RefreshRateRange>>
mRefreshRateThrottlingMap = new HashMap<>(); mRefreshRateThrottlingMap = new HashMap<>();
@@ -1346,11 +1346,11 @@ public class DisplayDeviceConfig {
} }
/** /**
* @param id The ID of the throttling data * @return brightness throttling configuration data for this display, for each throttling id.
* @return brightness throttling configuration data for the display.
*/ */
public BrightnessThrottlingData getBrightnessThrottlingData(String id) { public HashMap<String, BrightnessThrottlingData>
return BrightnessThrottlingData.create(mBrightnessThrottlingDataMap.get(id)); getBrightnessThrottlingDataMapByThrottlingId() {
return mBrightnessThrottlingDataMapByThrottlingId;
} }
/** /**
@@ -1525,7 +1525,8 @@ public class DisplayDeviceConfig {
+ ", isHbmEnabled=" + mIsHighBrightnessModeEnabled + ", isHbmEnabled=" + mIsHighBrightnessModeEnabled
+ ", mHbmData=" + mHbmData + ", mHbmData=" + mHbmData
+ ", mSdrToHdrRatioSpline=" + mSdrToHdrRatioSpline + ", mSdrToHdrRatioSpline=" + mSdrToHdrRatioSpline
+ ", mBrightnessThrottlingData=" + mBrightnessThrottlingDataMap + ", mBrightnessThrottlingDataMapByThrottlingId="
+ mBrightnessThrottlingDataMapByThrottlingId
+ "\n" + "\n"
+ ", mBrightnessRampFastDecrease=" + mBrightnessRampFastDecrease + ", mBrightnessRampFastDecrease=" + mBrightnessRampFastDecrease
+ ", mBrightnessRampFastIncrease=" + mBrightnessRampFastIncrease + ", mBrightnessRampFastIncrease=" + mBrightnessRampFastIncrease
@@ -1918,11 +1919,11 @@ public class DisplayDeviceConfig {
if (!badConfig) { if (!badConfig) {
String id = map.getId() == null ? DEFAULT_ID String id = map.getId() == null ? DEFAULT_ID
: map.getId(); : map.getId();
if (mBrightnessThrottlingDataMap.containsKey(id)) { if (mBrightnessThrottlingDataMapByThrottlingId.containsKey(id)) {
throw new RuntimeException("Brightness throttling data with ID " + id throw new RuntimeException("Brightness throttling data with ID " + id
+ " already exists"); + " already exists");
} }
mBrightnessThrottlingDataMap.put(id, mBrightnessThrottlingDataMapByThrottlingId.put(id,
BrightnessThrottlingData.create(throttlingLevels)); BrightnessThrottlingData.create(throttlingLevels));
} }
} }
@@ -1971,8 +1972,8 @@ public class DisplayDeviceConfig {
)); ));
} }
if (refreshRates.size() == 0) { if (refreshRates.size() == 0) {
Slog.w(TAG, "RefreshRateThrottling: no valid throttling points fond for map, mapId=" Slog.w(TAG, "RefreshRateThrottling: no valid throttling points found for map, "
+ id); + "mapId=" + id);
continue; continue;
} }
mRefreshRateThrottlingMap.put(id, refreshRates); mRefreshRateThrottlingMap.put(id, refreshRates);
@@ -3077,7 +3078,7 @@ public class DisplayDeviceConfig {
/** /**
* Creates multiple teperature based throttling levels of brightness * Creates multiple temperature based throttling levels of brightness
*/ */
public static BrightnessThrottlingData create(List<ThrottlingLevel> throttlingLevels) { public static BrightnessThrottlingData create(List<ThrottlingLevel> throttlingLevels) {
if (throttlingLevels == null || throttlingLevels.size() == 0) { if (throttlingLevels == null || throttlingLevels.size() == 0) {
@@ -3120,15 +3121,6 @@ public class DisplayDeviceConfig {
return new BrightnessThrottlingData(throttlingLevels); return new BrightnessThrottlingData(throttlingLevels);
} }
static public BrightnessThrottlingData create(BrightnessThrottlingData other) {
if (other == null) {
return null;
}
return BrightnessThrottlingData.create(other.throttlingLevels);
}
@Override @Override
public String toString() { public String toString() {
return "BrightnessThrottlingData{" return "BrightnessThrottlingData{"

View File

@@ -505,7 +505,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
private DisplayDeviceConfig mDisplayDeviceConfig; private DisplayDeviceConfig mDisplayDeviceConfig;
// Identifiers for suspend blocker acuisition requests // Identifiers for suspend blocker acquisition requests
private final String mSuspendBlockerIdUnfinishedBusiness; private final String mSuspendBlockerIdUnfinishedBusiness;
private final String mSuspendBlockerIdOnStateChanged; private final String mSuspendBlockerIdOnStateChanged;
private final String mSuspendBlockerIdProxPositive; private final String mSuspendBlockerIdProxPositive;
@@ -515,6 +515,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
private boolean mIsEnabled; private boolean mIsEnabled;
private boolean mIsInTransition; private boolean mIsInTransition;
// The id of the brightness throttling policy that should be used.
private String mBrightnessThrottlingDataId; private String mBrightnessThrottlingDataId;
// DPCs following the brightness of this DPC. This is used in concurrent displays mode - there // DPCs following the brightness of this DPC. This is used in concurrent displays mode - there
@@ -905,14 +906,15 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
loadNitBasedBrightnessSetting(); loadNitBasedBrightnessSetting();
/// Since the underlying display-device changed, we really don't know the /// Since the underlying display-device changed, we really don't know the
// last command that was sent to change it's state. Lets assume it is unknown so // last command that was sent to change it's state. Let's assume it is unknown so
// that we trigger a change immediately. // that we trigger a change immediately.
mPowerState.resetScreenState(); mPowerState.resetScreenState();
} else if (!mBrightnessThrottlingDataId.equals(brightnessThrottlingDataId)) { } else if (!mBrightnessThrottlingDataId.equals(brightnessThrottlingDataId)) {
changed = true; changed = true;
mBrightnessThrottlingDataId = brightnessThrottlingDataId; mBrightnessThrottlingDataId = brightnessThrottlingDataId;
mBrightnessThrottler.resetThrottlingData( mBrightnessThrottler.loadBrightnessThrottlingDataFromDisplayDeviceConfig(
config.getBrightnessThrottlingData(mBrightnessThrottlingDataId), config.getBrightnessThrottlingDataMapByThrottlingId(),
mBrightnessThrottlingDataId,
mUniqueDisplayId); mUniqueDisplayId);
} }
if (mIsEnabled != isEnabled || mIsInTransition != isInTransition) { if (mIsEnabled != isEnabled || mIsInTransition != isInTransition) {
@@ -981,9 +983,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
sdrBrightness, maxDesiredHdrSdrRatio); sdrBrightness, maxDesiredHdrSdrRatio);
} }
}); });
mBrightnessThrottler.resetThrottlingData( mBrightnessThrottler.loadBrightnessThrottlingDataFromDisplayDeviceConfig(
mDisplayDeviceConfig.getBrightnessThrottlingData(mBrightnessThrottlingDataId), mDisplayDeviceConfig.getBrightnessThrottlingDataMapByThrottlingId(),
mUniqueDisplayId); mBrightnessThrottlingDataId, mUniqueDisplayId);
} }
private void sendUpdatePowerState() { private void sendUpdatePowerState() {
@@ -2116,11 +2118,11 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
final DisplayDevice device = mLogicalDisplay.getPrimaryDisplayDeviceLocked(); final DisplayDevice device = mLogicalDisplay.getPrimaryDisplayDeviceLocked();
final DisplayDeviceConfig ddConfig = device.getDisplayDeviceConfig(); final DisplayDeviceConfig ddConfig = device.getDisplayDeviceConfig();
return new BrightnessThrottler(mHandler, return new BrightnessThrottler(mHandler,
ddConfig.getBrightnessThrottlingData(mBrightnessThrottlingDataId),
() -> { () -> {
sendUpdatePowerState(); sendUpdatePowerState();
postBrightnessChangeRunnable(); postBrightnessChangeRunnable();
}, mUniqueDisplayId); }, mUniqueDisplayId, mLogicalDisplay.getBrightnessThrottlingDataIdLocked(),
ddConfig.getBrightnessThrottlingDataMapByThrottlingId());
} }
private void blockScreenOn() { private void blockScreenOn() {

View File

@@ -400,6 +400,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
private boolean mIsEnabled; private boolean mIsEnabled;
private boolean mIsInTransition; private boolean mIsInTransition;
// The id of the brightness throttling policy that should be used.
private String mBrightnessThrottlingDataId; private String mBrightnessThrottlingDataId;
// DPCs following the brightness of this DPC. This is used in concurrent displays mode - there // DPCs following the brightness of this DPC. This is used in concurrent displays mode - there
@@ -722,14 +723,15 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
mDisplayPowerProximityStateController.notifyDisplayDeviceChanged(config); mDisplayPowerProximityStateController.notifyDisplayDeviceChanged(config);
// Since the underlying display-device changed, we really don't know the // Since the underlying display-device changed, we really don't know the
// last command that was sent to change it's state. Lets assume it is unknown so // last command that was sent to change it's state. Let's assume it is unknown so
// that we trigger a change immediately. // that we trigger a change immediately.
mPowerState.resetScreenState(); mPowerState.resetScreenState();
} else if (!mBrightnessThrottlingDataId.equals(brightnessThrottlingDataId)) { } else if (!mBrightnessThrottlingDataId.equals(brightnessThrottlingDataId)) {
changed = true; changed = true;
mBrightnessThrottlingDataId = brightnessThrottlingDataId; mBrightnessThrottlingDataId = brightnessThrottlingDataId;
mBrightnessThrottler.resetThrottlingData( mBrightnessThrottler.loadBrightnessThrottlingDataFromDisplayDeviceConfig(
config.getBrightnessThrottlingData(mBrightnessThrottlingDataId), config.getBrightnessThrottlingDataMapByThrottlingId(),
mBrightnessThrottlingDataId,
mUniqueDisplayId); mUniqueDisplayId);
} }
if (mIsEnabled != isEnabled || mIsInTransition != isInTransition) { if (mIsEnabled != isEnabled || mIsInTransition != isInTransition) {
@@ -795,9 +797,9 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
sdrBrightness, maxDesiredHdrSdrRatio); sdrBrightness, maxDesiredHdrSdrRatio);
} }
}); });
mBrightnessThrottler.resetThrottlingData( mBrightnessThrottler.loadBrightnessThrottlingDataFromDisplayDeviceConfig(
mDisplayDeviceConfig.getBrightnessThrottlingData(mBrightnessThrottlingDataId), mDisplayDeviceConfig.getBrightnessThrottlingDataMapByThrottlingId(),
mUniqueDisplayId); mBrightnessThrottlingDataId, mUniqueDisplayId);
} }
private void sendUpdatePowerState() { private void sendUpdatePowerState() {
@@ -1757,11 +1759,11 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
final DisplayDevice device = mLogicalDisplay.getPrimaryDisplayDeviceLocked(); final DisplayDevice device = mLogicalDisplay.getPrimaryDisplayDeviceLocked();
final DisplayDeviceConfig ddConfig = device.getDisplayDeviceConfig(); final DisplayDeviceConfig ddConfig = device.getDisplayDeviceConfig();
return new BrightnessThrottler(mHandler, return new BrightnessThrottler(mHandler,
ddConfig.getBrightnessThrottlingData(mBrightnessThrottlingDataId),
() -> { () -> {
sendUpdatePowerState(); sendUpdatePowerState();
postBrightnessChangeRunnable(); postBrightnessChangeRunnable();
}, mUniqueDisplayId); }, mUniqueDisplayId, mLogicalDisplay.getBrightnessThrottlingDataIdLocked(),
ddConfig.getBrightnessThrottlingDataMapByThrottlingId());
} }
private void blockScreenOn() { private void blockScreenOn() {

View File

@@ -338,7 +338,9 @@ public class Layout {
} }
/** /**
* @return The ID of the brightness throttling map that this display should use. * Gets the id of the brightness throttling map that should be used.
* @return The ID of the brightness throttling map that this display should use, null if
* unspecified, will fall back to default.
*/ */
public String getBrightnessThrottlingMapId() { public String getBrightnessThrottlingMapId() {
return mBrightnessThrottlingMapId; return mBrightnessThrottlingMapId;

View File

@@ -54,6 +54,7 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
@SmallTest @SmallTest
@@ -122,8 +123,6 @@ public class BrightnessThrottlerTest {
BrightnessThrottlingData data; BrightnessThrottlingData data;
data = BrightnessThrottlingData.create((List<ThrottlingLevel>)null); data = BrightnessThrottlingData.create((List<ThrottlingLevel>)null);
assertEquals(data, null); assertEquals(data, null);
data = BrightnessThrottlingData.create((BrightnessThrottlingData)null);
assertEquals(data, null);
data = BrightnessThrottlingData.create(new ArrayList<ThrottlingLevel>()); data = BrightnessThrottlingData.create(new ArrayList<ThrottlingLevel>());
assertEquals(data, null); assertEquals(data, null);
data = BrightnessThrottlingData.create(unsortedThermalLevels); data = BrightnessThrottlingData.create(unsortedThermalLevels);
@@ -146,7 +145,7 @@ public class BrightnessThrottlerTest {
} }
@Test @Test
public void testThrottlingUnsupported() throws Exception { public void testThrottlingUnsupported() {
final BrightnessThrottler throttler = createThrottlerUnsupported(); final BrightnessThrottler throttler = createThrottlerUnsupported();
assertFalse(throttler.deviceSupportsThrottling()); assertFalse(throttler.deviceSupportsThrottling());
@@ -307,37 +306,18 @@ public class BrightnessThrottlerTest {
verify(mThermalServiceMock).registerThermalEventListenerWithType( verify(mThermalServiceMock).registerThermalEventListenerWithType(
mThermalEventListenerCaptor.capture(), eq(Temperature.TYPE_SKIN)); mThermalEventListenerCaptor.capture(), eq(Temperature.TYPE_SKIN));
final IThermalEventListener listener = mThermalEventListenerCaptor.getValue(); final IThermalEventListener listener = mThermalEventListenerCaptor.getValue();
testThrottling(throttler, listener, PowerManager.BRIGHTNESS_MAX, 0.4f);
// Set status too low to trigger throttling
listener.notifyThrottling(getSkinTemp(level.thermalStatus - 1));
mTestLooper.dispatchAll();
assertEquals(PowerManager.BRIGHTNESS_MAX, throttler.getBrightnessCap(), 0f);
assertFalse(throttler.isThrottled());
// Set status high enough to trigger throttling
listener.notifyThrottling(getSkinTemp(level.thermalStatus));
mTestLooper.dispatchAll();
assertEquals(0.4f, throttler.getBrightnessCap(), 0f);
assertTrue(throttler.isThrottled());
// Update thresholds
// This data is equivalent to the string "123,1,critical,0.8", passed below
final ThrottlingLevel newLevel = new ThrottlingLevel(PowerManager.THERMAL_STATUS_CRITICAL,
0.8f);
// Set new (valid) data from device config // Set new (valid) data from device config
mDeviceConfigFake.setBrightnessThrottlingData("123,1,critical,0.8"); mDeviceConfigFake.setBrightnessThrottlingData("123,1,critical,0.8");
testThrottling(throttler, listener, PowerManager.BRIGHTNESS_MAX, 0.8f);
// Set status too low to trigger throttling mDeviceConfigFake.setBrightnessThrottlingData(
listener.notifyThrottling(getSkinTemp(newLevel.thermalStatus - 1)); "123,1,critical,0.75;123,1,critical,0.99,id_2");
mTestLooper.dispatchAll(); testThrottling(throttler, listener, PowerManager.BRIGHTNESS_MAX, 0.75f);
assertEquals(PowerManager.BRIGHTNESS_MAX, throttler.getBrightnessCap(), 0f); mDeviceConfigFake.setBrightnessThrottlingData(
assertFalse(throttler.isThrottled()); "123,1,critical,0.8,default;123,1,critical,0.99,id_2");
testThrottling(throttler, listener, PowerManager.BRIGHTNESS_MAX, 0.8f);
// Set status high enough to trigger throttling
listener.notifyThrottling(getSkinTemp(newLevel.thermalStatus));
mTestLooper.dispatchAll();
assertEquals(newLevel.brightness, throttler.getBrightnessCap(), 0f);
assertTrue(throttler.isThrottled());
} }
@Test public void testInvalidThrottlingStrings() throws Exception { @Test public void testInvalidThrottlingStrings() throws Exception {
@@ -370,6 +350,18 @@ public class BrightnessThrottlerTest {
testThrottling(throttler, listener, PowerManager.BRIGHTNESS_MAX, 0.25f); testThrottling(throttler, listener, PowerManager.BRIGHTNESS_MAX, 0.25f);
mDeviceConfigFake.setBrightnessThrottlingData(""); // Invalid format mDeviceConfigFake.setBrightnessThrottlingData(""); // Invalid format
testThrottling(throttler, listener, PowerManager.BRIGHTNESS_MAX, 0.25f); testThrottling(throttler, listener, PowerManager.BRIGHTNESS_MAX, 0.25f);
// Invalid string format
mDeviceConfigFake.setBrightnessThrottlingData(
"123,default,1,critical,0.75,1,critical,0.99");
testThrottling(throttler, listener, PowerManager.BRIGHTNESS_MAX, 0.25f);
// Invalid level string and number string
mDeviceConfigFake.setBrightnessThrottlingData(
"123,1,1,critical,0.75,id_2,1,critical,0.99");
testThrottling(throttler, listener, PowerManager.BRIGHTNESS_MAX, 0.25f);
// Invalid format - (two default ids for same display)
mDeviceConfigFake.setBrightnessThrottlingData(
"123,1,critical,0.75,default;123,1,critical,0.99");
testThrottling(throttler, listener, PowerManager.BRIGHTNESS_MAX, 0.25f);
} }
private void testThrottling(BrightnessThrottler throttler, IThermalEventListener listener, private void testThrottling(BrightnessThrottler throttler, IThermalEventListener listener,
@@ -472,13 +464,17 @@ public class BrightnessThrottlerTest {
} }
private BrightnessThrottler createThrottlerUnsupported() { private BrightnessThrottler createThrottlerUnsupported() {
return new BrightnessThrottler(mInjectorMock, mHandler, mHandler, null, () -> {}, null); return new BrightnessThrottler(mInjectorMock, mHandler, mHandler,
/* throttlingChangeCallback= */ () -> {}, /* uniqueDisplayId= */ null,
/* throttlingDataId= */ null, /* throttlingDataMap= */ new HashMap<>(1));
} }
private BrightnessThrottler createThrottlerSupported(BrightnessThrottlingData data) { private BrightnessThrottler createThrottlerSupported(BrightnessThrottlingData data) {
assertNotNull(data); assertNotNull(data);
HashMap<String, BrightnessThrottlingData> throttlingDataMap = new HashMap<>(1);
throttlingDataMap.put("default", data);
return new BrightnessThrottler(mInjectorMock, mHandler, BackgroundThread.getHandler(), return new BrightnessThrottler(mInjectorMock, mHandler, BackgroundThread.getHandler(),
data, () -> {}, "123"); () -> {}, "123", "default", throttlingDataMap);
} }
private Temperature getSkinTemp(@ThrottlingStatus int status) { private Temperature getSkinTemp(@ThrottlingStatus int status) {

View File

@@ -50,6 +50,7 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
@SmallTest @SmallTest
@@ -186,50 +187,72 @@ public final class DisplayDeviceConfigTest {
assertArrayEquals(new int[]{-1, 10, 20, 30, 40}, assertArrayEquals(new int[]{-1, 10, 20, 30, 40},
mDisplayDeviceConfig.getScreenOffBrightnessSensorValueToLux()); mDisplayDeviceConfig.getScreenOffBrightnessSensorValueToLux());
List<DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel> throttlingLevels = List<DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel>
new ArrayList(); defaultThrottlingLevels = new ArrayList<>();
throttlingLevels.add(new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel( defaultThrottlingLevels.add(
new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
DisplayDeviceConfig.convertThermalStatus(ThermalStatus.light), 0.4f DisplayDeviceConfig.convertThermalStatus(ThermalStatus.light), 0.4f
)); ));
throttlingLevels.add(new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel( defaultThrottlingLevels.add(
new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
DisplayDeviceConfig.convertThermalStatus(ThermalStatus.moderate), 0.3f DisplayDeviceConfig.convertThermalStatus(ThermalStatus.moderate), 0.3f
)); ));
throttlingLevels.add(new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel( defaultThrottlingLevels.add(
new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
DisplayDeviceConfig.convertThermalStatus(ThermalStatus.severe), 0.2f DisplayDeviceConfig.convertThermalStatus(ThermalStatus.severe), 0.2f
)); ));
throttlingLevels.add(new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel( defaultThrottlingLevels.add(
new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
DisplayDeviceConfig.convertThermalStatus(ThermalStatus.critical), 0.1f DisplayDeviceConfig.convertThermalStatus(ThermalStatus.critical), 0.1f
)); ));
throttlingLevels.add(new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel( defaultThrottlingLevels.add(
new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
DisplayDeviceConfig.convertThermalStatus(ThermalStatus.emergency), 0.05f DisplayDeviceConfig.convertThermalStatus(ThermalStatus.emergency), 0.05f
)); ));
throttlingLevels.add(new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel( defaultThrottlingLevels.add(
new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
DisplayDeviceConfig.convertThermalStatus(ThermalStatus.shutdown), 0.025f DisplayDeviceConfig.convertThermalStatus(ThermalStatus.shutdown), 0.025f
)); ));
assertEquals(new DisplayDeviceConfig.BrightnessThrottlingData(throttlingLevels),
mDisplayDeviceConfig.getBrightnessThrottlingData("default"));
throttlingLevels.clear(); DisplayDeviceConfig.BrightnessThrottlingData defaultThrottlingData =
throttlingLevels.add(new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel( new DisplayDeviceConfig.BrightnessThrottlingData(defaultThrottlingLevels);
List<DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel>
concurrentThrottlingLevels = new ArrayList<>();
concurrentThrottlingLevels.add(
new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
DisplayDeviceConfig.convertThermalStatus(ThermalStatus.light), 0.2f DisplayDeviceConfig.convertThermalStatus(ThermalStatus.light), 0.2f
)); ));
throttlingLevels.add(new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel( concurrentThrottlingLevels.add(
new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
DisplayDeviceConfig.convertThermalStatus(ThermalStatus.moderate), 0.15f DisplayDeviceConfig.convertThermalStatus(ThermalStatus.moderate), 0.15f
)); ));
throttlingLevels.add(new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel( concurrentThrottlingLevels.add(
new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
DisplayDeviceConfig.convertThermalStatus(ThermalStatus.severe), 0.1f DisplayDeviceConfig.convertThermalStatus(ThermalStatus.severe), 0.1f
)); ));
throttlingLevels.add(new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel( concurrentThrottlingLevels.add(
new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
DisplayDeviceConfig.convertThermalStatus(ThermalStatus.critical), 0.05f DisplayDeviceConfig.convertThermalStatus(ThermalStatus.critical), 0.05f
)); ));
throttlingLevels.add(new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel( concurrentThrottlingLevels.add(
new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
DisplayDeviceConfig.convertThermalStatus(ThermalStatus.emergency), 0.025f DisplayDeviceConfig.convertThermalStatus(ThermalStatus.emergency), 0.025f
)); ));
throttlingLevels.add(new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel( concurrentThrottlingLevels.add(
new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
DisplayDeviceConfig.convertThermalStatus(ThermalStatus.shutdown), 0.0125f DisplayDeviceConfig.convertThermalStatus(ThermalStatus.shutdown), 0.0125f
)); ));
assertEquals(new DisplayDeviceConfig.BrightnessThrottlingData(throttlingLevels), DisplayDeviceConfig.BrightnessThrottlingData concurrentThrottlingData =
mDisplayDeviceConfig.getBrightnessThrottlingData("concurrent")); new DisplayDeviceConfig.BrightnessThrottlingData(concurrentThrottlingLevels);
HashMap<String, DisplayDeviceConfig.BrightnessThrottlingData> throttlingDataMap =
new HashMap<>(2);
throttlingDataMap.put("default", defaultThrottlingData);
throttlingDataMap.put("concurrent", concurrentThrottlingData);
assertEquals(throttlingDataMap,
mDisplayDeviceConfig.getBrightnessThrottlingDataMapByThrottlingId());
assertNotNull(mDisplayDeviceConfig.getHostUsiVersion()); assertNotNull(mDisplayDeviceConfig.getHostUsiVersion());
assertEquals(mDisplayDeviceConfig.getHostUsiVersion().getMajorVersion(), 2); assertEquals(mDisplayDeviceConfig.getHostUsiVersion().getMajorVersion(), 2);
@@ -246,8 +269,7 @@ public final class DisplayDeviceConfigTest {
mDisplayDeviceConfig.getHdrBrightnessFromSdr(0.62f, 1.25f), mDisplayDeviceConfig.getHdrBrightnessFromSdr(0.62f, 1.25f),
SMALL_DELTA); SMALL_DELTA);
// Todo: Add asserts for DensityMapping,
// Todo: Add asserts for BrightnessThrottlingData, DensityMapping,
// HighBrightnessModeData AmbientLightSensor, RefreshRateLimitations and ProximitySensor. // HighBrightnessModeData AmbientLightSensor, RefreshRateLimitations and ProximitySensor.
} }