Merge "Add throttlingDataId to deviceConfig" into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
cd791d5ad2
@@ -1758,10 +1758,12 @@ public final class DisplayManager {
|
||||
/**
|
||||
* Key for the brightness throttling data as a String formatted:
|
||||
* <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
|
||||
* for each display, separated by a semicolon.
|
||||
* [,<throttlingId>]?
|
||||
* 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:
|
||||
* 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";
|
||||
}
|
||||
|
||||
@@ -16,7 +16,10 @@
|
||||
|
||||
package com.android.server.display;
|
||||
|
||||
import static com.android.server.display.DisplayDeviceConfig.DEFAULT_ID;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.content.Context;
|
||||
import android.hardware.display.BrightnessInfo;
|
||||
import android.hardware.display.DisplayManager;
|
||||
@@ -63,8 +66,16 @@ class BrightnessThrottler {
|
||||
private final DeviceConfigInterface mDeviceConfig;
|
||||
|
||||
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 mDdcThrottlingData;
|
||||
|
||||
private float mBrightnessCap = PowerManager.BRIGHTNESS_MAX;
|
||||
private @BrightnessInfo.BrightnessMaxReason int mBrightnessMaxReason =
|
||||
BrightnessInfo.BRIGHTNESS_MAX_REASON_NONE;
|
||||
@@ -73,35 +84,45 @@ class BrightnessThrottler {
|
||||
// The most recent string that has been set from DeviceConfig
|
||||
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
|
||||
// the DeviceConfig. This will always take priority over the display device config data.
|
||||
private HashMap<String, BrightnessThrottlingData> mBrightnessThrottlingDataOverride =
|
||||
new HashMap<>(1);
|
||||
// We need to store the data for every display device, so we do not need to update this each
|
||||
// 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,
|
||||
Runnable throttlingChangeCallback, String uniqueDisplayId) {
|
||||
this(new Injector(), handler, handler, throttlingData, throttlingChangeCallback,
|
||||
uniqueDisplayId);
|
||||
BrightnessThrottler(Handler handler, Runnable throttlingChangeCallback, String uniqueDisplayId,
|
||||
String throttlingDataId,
|
||||
@NonNull HashMap<String, BrightnessThrottlingData> brightnessThrottlingDataMap) {
|
||||
this(new Injector(), handler, handler, throttlingChangeCallback,
|
||||
uniqueDisplayId, throttlingDataId, brightnessThrottlingDataMap);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
BrightnessThrottler(Injector injector, Handler handler, Handler deviceConfigHandler,
|
||||
BrightnessThrottlingData throttlingData, Runnable throttlingChangeCallback,
|
||||
String uniqueDisplayId) {
|
||||
Runnable throttlingChangeCallback, String uniqueDisplayId, String throttlingDataId,
|
||||
@NonNull HashMap<String, BrightnessThrottlingData> brightnessThrottlingDataMap) {
|
||||
mInjector = injector;
|
||||
|
||||
mHandler = handler;
|
||||
mDeviceConfigHandler = deviceConfigHandler;
|
||||
mThrottlingData = throttlingData;
|
||||
mDdcThrottlingData = throttlingData;
|
||||
mDdcThrottlingDataMap = brightnessThrottlingDataMap;
|
||||
mThrottlingChangeCallback = throttlingChangeCallback;
|
||||
mSkinThermalStatusObserver = new SkinThermalStatusObserver(mInjector, mHandler);
|
||||
|
||||
mUniqueDisplayId = uniqueDisplayId;
|
||||
mDeviceConfig = injector.getDeviceConfig();
|
||||
mDeviceConfigListener = new DeviceConfigListener();
|
||||
|
||||
resetThrottlingData(mThrottlingData, mUniqueDisplayId);
|
||||
mBrightnessThrottlingDataId = throttlingDataId;
|
||||
mDdcThrottlingDataMap = brightnessThrottlingDataMap;
|
||||
loadBrightnessThrottlingDataFromDeviceConfig();
|
||||
loadBrightnessThrottlingDataFromDisplayDeviceConfig(mDdcThrottlingDataMap,
|
||||
mBrightnessThrottlingDataId, mUniqueDisplayId);
|
||||
}
|
||||
|
||||
boolean deviceSupportsThrottling() {
|
||||
@@ -133,23 +154,14 @@ class BrightnessThrottler {
|
||||
mThrottlingStatus = THROTTLING_INVALID;
|
||||
}
|
||||
|
||||
private void resetThrottlingData() {
|
||||
resetThrottlingData(mDdcThrottlingData, mUniqueDisplayId);
|
||||
}
|
||||
|
||||
void resetThrottlingData(BrightnessThrottlingData throttlingData, String displayId) {
|
||||
stop();
|
||||
|
||||
mUniqueDisplayId = displayId;
|
||||
mDdcThrottlingData = throttlingData;
|
||||
mDeviceConfigListener.startListening();
|
||||
reloadBrightnessThrottlingDataOverride();
|
||||
mThrottlingData = mBrightnessThrottlingDataOverride.getOrDefault(mUniqueDisplayId,
|
||||
throttlingData);
|
||||
|
||||
if (deviceSupportsThrottling()) {
|
||||
mSkinThermalStatusObserver.startObserving();
|
||||
}
|
||||
void loadBrightnessThrottlingDataFromDisplayDeviceConfig(
|
||||
HashMap<String, BrightnessThrottlingData> ddcThrottlingDataMap,
|
||||
String brightnessThrottlingDataId,
|
||||
String uniqueDisplayId) {
|
||||
mDdcThrottlingDataMap = ddcThrottlingDataMap;
|
||||
mBrightnessThrottlingDataId = brightnessThrottlingDataId;
|
||||
mUniqueDisplayId = uniqueDisplayId;
|
||||
resetThrottlingData();
|
||||
}
|
||||
|
||||
private float verifyAndConstrainBrightnessCap(float brightness) {
|
||||
@@ -183,7 +195,7 @@ class BrightnessThrottler {
|
||||
float brightnessCap = PowerManager.BRIGHTNESS_MAX;
|
||||
int brightnessMaxReason = BrightnessInfo.BRIGHTNESS_MAX_REASON_NONE;
|
||||
|
||||
if (mThrottlingStatus != THROTTLING_INVALID) {
|
||||
if (mThrottlingStatus != THROTTLING_INVALID && mThrottlingData != null) {
|
||||
// Throttling levels are sorted by increasing severity
|
||||
for (ThrottlingLevel level : mThrottlingData.throttlingLevels) {
|
||||
if (level.thermalStatus <= mThrottlingStatus) {
|
||||
@@ -218,13 +230,14 @@ class BrightnessThrottler {
|
||||
|
||||
private void dumpLocal(PrintWriter pw) {
|
||||
pw.println("BrightnessThrottler:");
|
||||
pw.println(" mBrightnessThrottlingDataId=" + mBrightnessThrottlingDataId);
|
||||
pw.println(" mThrottlingData=" + mThrottlingData);
|
||||
pw.println(" mDdcThrottlingData=" + mDdcThrottlingData);
|
||||
pw.println(" mUniqueDisplayId=" + mUniqueDisplayId);
|
||||
pw.println(" mThrottlingStatus=" + mThrottlingStatus);
|
||||
pw.println(" mBrightnessCap=" + mBrightnessCap);
|
||||
pw.println(" mBrightnessMaxReason=" +
|
||||
BrightnessInfo.briMaxReasonToString(mBrightnessMaxReason));
|
||||
pw.println(" mDdcThrottlingDataMap=" + mDdcThrottlingDataMap);
|
||||
pw.println(" mBrightnessThrottlingDataOverride=" + mBrightnessThrottlingDataOverride);
|
||||
pw.println(" mBrightnessThrottlingDataString=" + mBrightnessThrottlingDataString);
|
||||
|
||||
@@ -237,8 +250,18 @@ class BrightnessThrottler {
|
||||
/* defaultValue= */ null);
|
||||
}
|
||||
|
||||
private boolean parseAndSaveData(@NonNull String strArray,
|
||||
@NonNull HashMap<String, BrightnessThrottlingData> tempBrightnessThrottlingData) {
|
||||
// The brightness throttling data id may or may not be specified in the string that is passed
|
||||
// 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;
|
||||
String[] items = strArray.split(",");
|
||||
int i = 0;
|
||||
@@ -254,29 +277,42 @@ class BrightnessThrottler {
|
||||
for (int j = 0; j < noOfThrottlingPoints; j++) {
|
||||
String severity = items[i++];
|
||||
int status = parseThermalStatus(severity);
|
||||
|
||||
float brightnessPoint = parseBrightness(items[i++]);
|
||||
|
||||
throttlingLevels.add(new ThrottlingLevel(status, brightnessPoint));
|
||||
}
|
||||
BrightnessThrottlingData toSave =
|
||||
|
||||
String throttlingDataId = (i < items.length) ? items[i++] : DEFAULT_ID;
|
||||
BrightnessThrottlingData throttlingLevelsData =
|
||||
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
|
||||
| UnknownThermalStatusException e) {
|
||||
validConfig = false;
|
||||
Slog.e(TAG, "Throttling data is invalid array: '" + strArray + "'", e);
|
||||
validConfig = false;
|
||||
}
|
||||
|
||||
if (i != items.length) {
|
||||
validConfig = false;
|
||||
}
|
||||
|
||||
return validConfig;
|
||||
}
|
||||
|
||||
public void reloadBrightnessThrottlingDataOverride() {
|
||||
HashMap<String, BrightnessThrottlingData> tempBrightnessThrottlingData =
|
||||
private void loadBrightnessThrottlingDataFromDeviceConfig() {
|
||||
HashMap<String, HashMap<String, BrightnessThrottlingData>> tempThrottlingData =
|
||||
new HashMap<>(1);
|
||||
mBrightnessThrottlingDataString = getBrightnessThrottlingDataString();
|
||||
boolean validConfig = true;
|
||||
@@ -284,15 +320,15 @@ class BrightnessThrottler {
|
||||
if (mBrightnessThrottlingDataString != null) {
|
||||
String[] throttlingDataSplits = mBrightnessThrottlingDataString.split(";");
|
||||
for (String s : throttlingDataSplits) {
|
||||
if (!parseAndSaveData(s, tempBrightnessThrottlingData)) {
|
||||
if (!parseAndAddData(s, tempThrottlingData)) {
|
||||
validConfig = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (validConfig) {
|
||||
mBrightnessThrottlingDataOverride.putAll(tempBrightnessThrottlingData);
|
||||
tempBrightnessThrottlingData.clear();
|
||||
mBrightnessThrottlingDataOverride.putAll(tempThrottlingData);
|
||||
tempThrottlingData.clear();
|
||||
}
|
||||
|
||||
} 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
|
||||
* DisplayManager#KEY_BRIGHTNESS_THROTTLING_DATA.
|
||||
* The format should be a string similar to: "local:4619827677550801152,2,moderate,0.5,severe,
|
||||
* 0.379518072;local:4619827677550801151,1,moderate,0.75"
|
||||
* In this order:
|
||||
* <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
|
||||
* for each display, separated by a semicolon.
|
||||
* <displayId>,<no of throttling levels>,[<severity as string>,<brightness cap>][,throttlingId]?
|
||||
* Where [<severity as string>,<brightness cap>] is repeated for each throttling level, and the
|
||||
* entirety is repeated for each display & throttling data id, separated by a semicolon.
|
||||
*/
|
||||
public class DeviceConfigListener implements DeviceConfig.OnPropertiesChangedListener {
|
||||
public Executor mExecutor = new HandlerExecutor(mDeviceConfigHandler);
|
||||
@@ -320,7 +391,7 @@ class BrightnessThrottler {
|
||||
|
||||
@Override
|
||||
public void onPropertiesChanged(DeviceConfig.Properties properties) {
|
||||
reloadBrightnessThrottlingDataOverride();
|
||||
loadBrightnessThrottlingDataFromDeviceConfig();
|
||||
resetThrottlingData();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,17 +143,17 @@ import javax.xml.datatype.DatatypeConfigurationException;
|
||||
* <brightness>0.01</brightness>
|
||||
* </brightnessThrottlingPoint>
|
||||
* </brightnessThrottlingMap>
|
||||
* <concurrentDisplaysBrightnessThrottlingMap>
|
||||
* <brightnessThrottlingPoint>
|
||||
* <thermalStatus>severe</thermalStatus>
|
||||
* <brightness>0.07</brightness>
|
||||
* </brightnessThrottlingPoint>
|
||||
* <brightnessThrottlingPoint>
|
||||
* <thermalStatus>critical</thermalStatus>
|
||||
* <brightness>0.005</brightness>
|
||||
* </brightnessThrottlingPoint>
|
||||
* </concurrentDisplaysBrightnessThrottlingMap>
|
||||
* <refreshRateThrottlingMap>
|
||||
* <brightnessThrottlingMap id="id_2"> // optional attribute, leave blank for default
|
||||
* <brightnessThrottlingPoint>
|
||||
* <thermalStatus>moderate</thermalStatus>
|
||||
* <brightness>0.2</brightness>
|
||||
* </brightnessThrottlingPoint>
|
||||
* <brightnessThrottlingPoint>
|
||||
* <thermalStatus>severe</thermalStatus>
|
||||
* <brightness>0.1</brightness>
|
||||
* </brightnessThrottlingPoint>
|
||||
* </brightnessThrottlingMap>
|
||||
<refreshRateThrottlingMap>
|
||||
* <refreshRateThrottlingPoint>
|
||||
* <thermalStatus>critical</thermalStatus>
|
||||
* <refreshRateRange>
|
||||
@@ -687,8 +687,8 @@ public class DisplayDeviceConfig {
|
||||
private int[] mHighDisplayBrightnessThresholds = DEFAULT_BRIGHTNESS_THRESHOLDS;
|
||||
private int[] mHighAmbientBrightnessThresholds = DEFAULT_BRIGHTNESS_THRESHOLDS;
|
||||
|
||||
private final Map<String, BrightnessThrottlingData> mBrightnessThrottlingDataMap =
|
||||
new HashMap<>();
|
||||
private final HashMap<String, BrightnessThrottlingData>
|
||||
mBrightnessThrottlingDataMapByThrottlingId = new HashMap<>();
|
||||
|
||||
private final Map<String, SparseArray<SurfaceControl.RefreshRateRange>>
|
||||
mRefreshRateThrottlingMap = new HashMap<>();
|
||||
@@ -1346,11 +1346,11 @@ public class DisplayDeviceConfig {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id The ID of the throttling data
|
||||
* @return brightness throttling configuration data for the display.
|
||||
* @return brightness throttling configuration data for this display, for each throttling id.
|
||||
*/
|
||||
public BrightnessThrottlingData getBrightnessThrottlingData(String id) {
|
||||
return BrightnessThrottlingData.create(mBrightnessThrottlingDataMap.get(id));
|
||||
public HashMap<String, BrightnessThrottlingData>
|
||||
getBrightnessThrottlingDataMapByThrottlingId() {
|
||||
return mBrightnessThrottlingDataMapByThrottlingId;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1525,7 +1525,8 @@ public class DisplayDeviceConfig {
|
||||
+ ", isHbmEnabled=" + mIsHighBrightnessModeEnabled
|
||||
+ ", mHbmData=" + mHbmData
|
||||
+ ", mSdrToHdrRatioSpline=" + mSdrToHdrRatioSpline
|
||||
+ ", mBrightnessThrottlingData=" + mBrightnessThrottlingDataMap
|
||||
+ ", mBrightnessThrottlingDataMapByThrottlingId="
|
||||
+ mBrightnessThrottlingDataMapByThrottlingId
|
||||
+ "\n"
|
||||
+ ", mBrightnessRampFastDecrease=" + mBrightnessRampFastDecrease
|
||||
+ ", mBrightnessRampFastIncrease=" + mBrightnessRampFastIncrease
|
||||
@@ -1918,11 +1919,11 @@ public class DisplayDeviceConfig {
|
||||
if (!badConfig) {
|
||||
String id = map.getId() == null ? DEFAULT_ID
|
||||
: map.getId();
|
||||
if (mBrightnessThrottlingDataMap.containsKey(id)) {
|
||||
if (mBrightnessThrottlingDataMapByThrottlingId.containsKey(id)) {
|
||||
throw new RuntimeException("Brightness throttling data with ID " + id
|
||||
+ " already exists");
|
||||
}
|
||||
mBrightnessThrottlingDataMap.put(id,
|
||||
mBrightnessThrottlingDataMapByThrottlingId.put(id,
|
||||
BrightnessThrottlingData.create(throttlingLevels));
|
||||
}
|
||||
}
|
||||
@@ -1971,8 +1972,8 @@ public class DisplayDeviceConfig {
|
||||
));
|
||||
}
|
||||
if (refreshRates.size() == 0) {
|
||||
Slog.w(TAG, "RefreshRateThrottling: no valid throttling points fond for map, mapId="
|
||||
+ id);
|
||||
Slog.w(TAG, "RefreshRateThrottling: no valid throttling points found for map, "
|
||||
+ "mapId=" + id);
|
||||
continue;
|
||||
}
|
||||
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) {
|
||||
if (throttlingLevels == null || throttlingLevels.size() == 0) {
|
||||
@@ -3120,15 +3121,6 @@ public class DisplayDeviceConfig {
|
||||
return new BrightnessThrottlingData(throttlingLevels);
|
||||
}
|
||||
|
||||
static public BrightnessThrottlingData create(BrightnessThrottlingData other) {
|
||||
if (other == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return BrightnessThrottlingData.create(other.throttlingLevels);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BrightnessThrottlingData{"
|
||||
|
||||
@@ -505,7 +505,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
|
||||
|
||||
private DisplayDeviceConfig mDisplayDeviceConfig;
|
||||
|
||||
// Identifiers for suspend blocker acuisition requests
|
||||
// Identifiers for suspend blocker acquisition requests
|
||||
private final String mSuspendBlockerIdUnfinishedBusiness;
|
||||
private final String mSuspendBlockerIdOnStateChanged;
|
||||
private final String mSuspendBlockerIdProxPositive;
|
||||
@@ -515,6 +515,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
|
||||
private boolean mIsEnabled;
|
||||
private boolean mIsInTransition;
|
||||
|
||||
// The id of the brightness throttling policy that should be used.
|
||||
private String mBrightnessThrottlingDataId;
|
||||
|
||||
// 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();
|
||||
|
||||
/// 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.
|
||||
mPowerState.resetScreenState();
|
||||
} else if (!mBrightnessThrottlingDataId.equals(brightnessThrottlingDataId)) {
|
||||
changed = true;
|
||||
mBrightnessThrottlingDataId = brightnessThrottlingDataId;
|
||||
mBrightnessThrottler.resetThrottlingData(
|
||||
config.getBrightnessThrottlingData(mBrightnessThrottlingDataId),
|
||||
mBrightnessThrottler.loadBrightnessThrottlingDataFromDisplayDeviceConfig(
|
||||
config.getBrightnessThrottlingDataMapByThrottlingId(),
|
||||
mBrightnessThrottlingDataId,
|
||||
mUniqueDisplayId);
|
||||
}
|
||||
if (mIsEnabled != isEnabled || mIsInTransition != isInTransition) {
|
||||
@@ -981,9 +983,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
|
||||
sdrBrightness, maxDesiredHdrSdrRatio);
|
||||
}
|
||||
});
|
||||
mBrightnessThrottler.resetThrottlingData(
|
||||
mDisplayDeviceConfig.getBrightnessThrottlingData(mBrightnessThrottlingDataId),
|
||||
mUniqueDisplayId);
|
||||
mBrightnessThrottler.loadBrightnessThrottlingDataFromDisplayDeviceConfig(
|
||||
mDisplayDeviceConfig.getBrightnessThrottlingDataMapByThrottlingId(),
|
||||
mBrightnessThrottlingDataId, mUniqueDisplayId);
|
||||
}
|
||||
|
||||
private void sendUpdatePowerState() {
|
||||
@@ -2116,11 +2118,11 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
|
||||
final DisplayDevice device = mLogicalDisplay.getPrimaryDisplayDeviceLocked();
|
||||
final DisplayDeviceConfig ddConfig = device.getDisplayDeviceConfig();
|
||||
return new BrightnessThrottler(mHandler,
|
||||
ddConfig.getBrightnessThrottlingData(mBrightnessThrottlingDataId),
|
||||
() -> {
|
||||
sendUpdatePowerState();
|
||||
postBrightnessChangeRunnable();
|
||||
}, mUniqueDisplayId);
|
||||
}, mUniqueDisplayId, mLogicalDisplay.getBrightnessThrottlingDataIdLocked(),
|
||||
ddConfig.getBrightnessThrottlingDataMapByThrottlingId());
|
||||
}
|
||||
|
||||
private void blockScreenOn() {
|
||||
|
||||
@@ -400,6 +400,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
|
||||
private boolean mIsEnabled;
|
||||
private boolean mIsInTransition;
|
||||
|
||||
// The id of the brightness throttling policy that should be used.
|
||||
private String mBrightnessThrottlingDataId;
|
||||
|
||||
// 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);
|
||||
|
||||
// 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.
|
||||
mPowerState.resetScreenState();
|
||||
} else if (!mBrightnessThrottlingDataId.equals(brightnessThrottlingDataId)) {
|
||||
changed = true;
|
||||
mBrightnessThrottlingDataId = brightnessThrottlingDataId;
|
||||
mBrightnessThrottler.resetThrottlingData(
|
||||
config.getBrightnessThrottlingData(mBrightnessThrottlingDataId),
|
||||
mBrightnessThrottler.loadBrightnessThrottlingDataFromDisplayDeviceConfig(
|
||||
config.getBrightnessThrottlingDataMapByThrottlingId(),
|
||||
mBrightnessThrottlingDataId,
|
||||
mUniqueDisplayId);
|
||||
}
|
||||
if (mIsEnabled != isEnabled || mIsInTransition != isInTransition) {
|
||||
@@ -795,9 +797,9 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
|
||||
sdrBrightness, maxDesiredHdrSdrRatio);
|
||||
}
|
||||
});
|
||||
mBrightnessThrottler.resetThrottlingData(
|
||||
mDisplayDeviceConfig.getBrightnessThrottlingData(mBrightnessThrottlingDataId),
|
||||
mUniqueDisplayId);
|
||||
mBrightnessThrottler.loadBrightnessThrottlingDataFromDisplayDeviceConfig(
|
||||
mDisplayDeviceConfig.getBrightnessThrottlingDataMapByThrottlingId(),
|
||||
mBrightnessThrottlingDataId, mUniqueDisplayId);
|
||||
}
|
||||
|
||||
private void sendUpdatePowerState() {
|
||||
@@ -1757,11 +1759,11 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
|
||||
final DisplayDevice device = mLogicalDisplay.getPrimaryDisplayDeviceLocked();
|
||||
final DisplayDeviceConfig ddConfig = device.getDisplayDeviceConfig();
|
||||
return new BrightnessThrottler(mHandler,
|
||||
ddConfig.getBrightnessThrottlingData(mBrightnessThrottlingDataId),
|
||||
() -> {
|
||||
sendUpdatePowerState();
|
||||
postBrightnessChangeRunnable();
|
||||
}, mUniqueDisplayId);
|
||||
}, mUniqueDisplayId, mLogicalDisplay.getBrightnessThrottlingDataIdLocked(),
|
||||
ddConfig.getBrightnessThrottlingDataMapByThrottlingId());
|
||||
}
|
||||
|
||||
private void blockScreenOn() {
|
||||
|
||||
@@ -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() {
|
||||
return mBrightnessThrottlingMapId;
|
||||
|
||||
@@ -54,6 +54,7 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@SmallTest
|
||||
@@ -122,8 +123,6 @@ public class BrightnessThrottlerTest {
|
||||
BrightnessThrottlingData data;
|
||||
data = BrightnessThrottlingData.create((List<ThrottlingLevel>)null);
|
||||
assertEquals(data, null);
|
||||
data = BrightnessThrottlingData.create((BrightnessThrottlingData)null);
|
||||
assertEquals(data, null);
|
||||
data = BrightnessThrottlingData.create(new ArrayList<ThrottlingLevel>());
|
||||
assertEquals(data, null);
|
||||
data = BrightnessThrottlingData.create(unsortedThermalLevels);
|
||||
@@ -146,7 +145,7 @@ public class BrightnessThrottlerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThrottlingUnsupported() throws Exception {
|
||||
public void testThrottlingUnsupported() {
|
||||
final BrightnessThrottler throttler = createThrottlerUnsupported();
|
||||
assertFalse(throttler.deviceSupportsThrottling());
|
||||
|
||||
@@ -307,37 +306,18 @@ public class BrightnessThrottlerTest {
|
||||
verify(mThermalServiceMock).registerThermalEventListenerWithType(
|
||||
mThermalEventListenerCaptor.capture(), eq(Temperature.TYPE_SKIN));
|
||||
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
|
||||
mDeviceConfigFake.setBrightnessThrottlingData("123,1,critical,0.8");
|
||||
testThrottling(throttler, listener, PowerManager.BRIGHTNESS_MAX, 0.8f);
|
||||
|
||||
// Set status too low to trigger throttling
|
||||
listener.notifyThrottling(getSkinTemp(newLevel.thermalStatus - 1));
|
||||
mTestLooper.dispatchAll();
|
||||
assertEquals(PowerManager.BRIGHTNESS_MAX, throttler.getBrightnessCap(), 0f);
|
||||
assertFalse(throttler.isThrottled());
|
||||
|
||||
// Set status high enough to trigger throttling
|
||||
listener.notifyThrottling(getSkinTemp(newLevel.thermalStatus));
|
||||
mTestLooper.dispatchAll();
|
||||
assertEquals(newLevel.brightness, throttler.getBrightnessCap(), 0f);
|
||||
assertTrue(throttler.isThrottled());
|
||||
mDeviceConfigFake.setBrightnessThrottlingData(
|
||||
"123,1,critical,0.75;123,1,critical,0.99,id_2");
|
||||
testThrottling(throttler, listener, PowerManager.BRIGHTNESS_MAX, 0.75f);
|
||||
mDeviceConfigFake.setBrightnessThrottlingData(
|
||||
"123,1,critical,0.8,default;123,1,critical,0.99,id_2");
|
||||
testThrottling(throttler, listener, PowerManager.BRIGHTNESS_MAX, 0.8f);
|
||||
}
|
||||
|
||||
@Test public void testInvalidThrottlingStrings() throws Exception {
|
||||
@@ -370,6 +350,18 @@ public class BrightnessThrottlerTest {
|
||||
testThrottling(throttler, listener, PowerManager.BRIGHTNESS_MAX, 0.25f);
|
||||
mDeviceConfigFake.setBrightnessThrottlingData(""); // Invalid format
|
||||
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,
|
||||
@@ -472,13 +464,17 @@ public class BrightnessThrottlerTest {
|
||||
}
|
||||
|
||||
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) {
|
||||
assertNotNull(data);
|
||||
HashMap<String, BrightnessThrottlingData> throttlingDataMap = new HashMap<>(1);
|
||||
throttlingDataMap.put("default", data);
|
||||
return new BrightnessThrottler(mInjectorMock, mHandler, BackgroundThread.getHandler(),
|
||||
data, () -> {}, "123");
|
||||
() -> {}, "123", "default", throttlingDataMap);
|
||||
}
|
||||
|
||||
private Temperature getSkinTemp(@ThrottlingStatus int status) {
|
||||
|
||||
@@ -50,6 +50,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@SmallTest
|
||||
@@ -186,50 +187,72 @@ public final class DisplayDeviceConfigTest {
|
||||
assertArrayEquals(new int[]{-1, 10, 20, 30, 40},
|
||||
mDisplayDeviceConfig.getScreenOffBrightnessSensorValueToLux());
|
||||
|
||||
List<DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel> throttlingLevels =
|
||||
new ArrayList();
|
||||
throttlingLevels.add(new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
|
||||
List<DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel>
|
||||
defaultThrottlingLevels = new ArrayList<>();
|
||||
defaultThrottlingLevels.add(
|
||||
new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
|
||||
DisplayDeviceConfig.convertThermalStatus(ThermalStatus.light), 0.4f
|
||||
));
|
||||
throttlingLevels.add(new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
|
||||
defaultThrottlingLevels.add(
|
||||
new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
|
||||
DisplayDeviceConfig.convertThermalStatus(ThermalStatus.moderate), 0.3f
|
||||
));
|
||||
throttlingLevels.add(new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
|
||||
defaultThrottlingLevels.add(
|
||||
new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
|
||||
DisplayDeviceConfig.convertThermalStatus(ThermalStatus.severe), 0.2f
|
||||
));
|
||||
throttlingLevels.add(new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
|
||||
defaultThrottlingLevels.add(
|
||||
new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
|
||||
DisplayDeviceConfig.convertThermalStatus(ThermalStatus.critical), 0.1f
|
||||
));
|
||||
throttlingLevels.add(new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
|
||||
defaultThrottlingLevels.add(
|
||||
new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
|
||||
DisplayDeviceConfig.convertThermalStatus(ThermalStatus.emergency), 0.05f
|
||||
));
|
||||
throttlingLevels.add(new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
|
||||
defaultThrottlingLevels.add(
|
||||
new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
|
||||
DisplayDeviceConfig.convertThermalStatus(ThermalStatus.shutdown), 0.025f
|
||||
));
|
||||
assertEquals(new DisplayDeviceConfig.BrightnessThrottlingData(throttlingLevels),
|
||||
mDisplayDeviceConfig.getBrightnessThrottlingData("default"));
|
||||
|
||||
throttlingLevels.clear();
|
||||
throttlingLevels.add(new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
|
||||
DisplayDeviceConfig.BrightnessThrottlingData defaultThrottlingData =
|
||||
new DisplayDeviceConfig.BrightnessThrottlingData(defaultThrottlingLevels);
|
||||
|
||||
List<DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel>
|
||||
concurrentThrottlingLevels = new ArrayList<>();
|
||||
concurrentThrottlingLevels.add(
|
||||
new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
|
||||
DisplayDeviceConfig.convertThermalStatus(ThermalStatus.light), 0.2f
|
||||
));
|
||||
throttlingLevels.add(new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
|
||||
concurrentThrottlingLevels.add(
|
||||
new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
|
||||
DisplayDeviceConfig.convertThermalStatus(ThermalStatus.moderate), 0.15f
|
||||
));
|
||||
throttlingLevels.add(new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
|
||||
concurrentThrottlingLevels.add(
|
||||
new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
|
||||
DisplayDeviceConfig.convertThermalStatus(ThermalStatus.severe), 0.1f
|
||||
));
|
||||
throttlingLevels.add(new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
|
||||
concurrentThrottlingLevels.add(
|
||||
new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
|
||||
DisplayDeviceConfig.convertThermalStatus(ThermalStatus.critical), 0.05f
|
||||
));
|
||||
throttlingLevels.add(new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
|
||||
concurrentThrottlingLevels.add(
|
||||
new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
|
||||
DisplayDeviceConfig.convertThermalStatus(ThermalStatus.emergency), 0.025f
|
||||
));
|
||||
throttlingLevels.add(new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
|
||||
concurrentThrottlingLevels.add(
|
||||
new DisplayDeviceConfig.BrightnessThrottlingData.ThrottlingLevel(
|
||||
DisplayDeviceConfig.convertThermalStatus(ThermalStatus.shutdown), 0.0125f
|
||||
));
|
||||
assertEquals(new DisplayDeviceConfig.BrightnessThrottlingData(throttlingLevels),
|
||||
mDisplayDeviceConfig.getBrightnessThrottlingData("concurrent"));
|
||||
DisplayDeviceConfig.BrightnessThrottlingData concurrentThrottlingData =
|
||||
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());
|
||||
assertEquals(mDisplayDeviceConfig.getHostUsiVersion().getMajorVersion(), 2);
|
||||
@@ -246,8 +269,7 @@ public final class DisplayDeviceConfigTest {
|
||||
mDisplayDeviceConfig.getHdrBrightnessFromSdr(0.62f, 1.25f),
|
||||
SMALL_DELTA);
|
||||
|
||||
|
||||
// Todo: Add asserts for BrightnessThrottlingData, DensityMapping,
|
||||
// Todo: Add asserts for DensityMapping,
|
||||
// HighBrightnessModeData AmbientLightSensor, RefreshRateLimitations and ProximitySensor.
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user