Merge "Add fallback ID checking for DisplayDeviceConfig"
This commit is contained in:
committed by
Android (Google) Code Review
commit
38da3cb7ec
@@ -18,6 +18,7 @@ package com.android.server.display;
|
||||
|
||||
import android.os.Environment;
|
||||
import android.util.Slog;
|
||||
import android.view.DisplayAddress;
|
||||
|
||||
import com.android.server.display.config.DisplayConfiguration;
|
||||
import com.android.server.display.config.NitsMap;
|
||||
@@ -31,6 +32,7 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.datatype.DatatypeConfigurationException;
|
||||
@@ -45,7 +47,11 @@ public class DisplayDeviceConfig {
|
||||
|
||||
private static final String ETC_DIR = "etc";
|
||||
private static final String DISPLAY_CONFIG_DIR = "displayconfig";
|
||||
private static final String CONFIG_FILE_FORMAT = "display_%d.xml";
|
||||
private static final String CONFIG_FILE_FORMAT = "display_%s.xml";
|
||||
private static final String PORT_SUFFIX_FORMAT = "port_%d";
|
||||
private static final String STABLE_ID_SUFFIX_FORMAT = "id_%d";
|
||||
private static final String NO_SUFFIX_FORMAT = "%d";
|
||||
private static final long STABLE_FLAG = 1L << 62;
|
||||
|
||||
private float[] mNits;
|
||||
private float[] mBrightness;
|
||||
@@ -55,17 +61,43 @@ public class DisplayDeviceConfig {
|
||||
|
||||
/**
|
||||
* Creates an instance for the specified display.
|
||||
*
|
||||
* Tries to find a file with identifier in the following priority order:
|
||||
* <ol>
|
||||
* <li>physicalDisplayId</li>
|
||||
* <li>physicalDisplayId without a stable flag (old system)</li>
|
||||
* <li>portId</li>
|
||||
* </ol>
|
||||
* @param physicalDisplayId The display ID for which to load the configuration.
|
||||
* @return A configuration instance for the specified display.
|
||||
*/
|
||||
public static DisplayDeviceConfig create(long physicalDisplayId) {
|
||||
final DisplayDeviceConfig config = new DisplayDeviceConfig();
|
||||
final String filename = String.format(CONFIG_FILE_FORMAT, physicalDisplayId);
|
||||
DisplayDeviceConfig config;
|
||||
|
||||
// Create config using filename from physical ID (including "stable" bit).
|
||||
config = getConfigFromSuffix(STABLE_ID_SUFFIX_FORMAT, physicalDisplayId);
|
||||
if (config != null) {
|
||||
return config;
|
||||
}
|
||||
|
||||
// Create config using filename from physical ID (excluding "stable" bit).
|
||||
final long withoutStableFlag = physicalDisplayId & ~STABLE_FLAG;
|
||||
config = getConfigFromSuffix(NO_SUFFIX_FORMAT, withoutStableFlag);
|
||||
if (config != null) {
|
||||
return config;
|
||||
}
|
||||
|
||||
// Create config using filename from port ID.
|
||||
final DisplayAddress.Physical physicalAddress =
|
||||
DisplayAddress.fromPhysicalDisplayId(physicalDisplayId);
|
||||
int port = physicalAddress.getPort();
|
||||
config = getConfigFromSuffix(PORT_SUFFIX_FORMAT, port);
|
||||
if (config != null) {
|
||||
return config;
|
||||
}
|
||||
|
||||
// None of these files exist.
|
||||
return null;
|
||||
|
||||
config.initFromFile(Environment.buildPath(
|
||||
Environment.getProductDirectory(), ETC_DIR, DISPLAY_CONFIG_DIR, filename));
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,6 +118,30 @@ public class DisplayDeviceConfig {
|
||||
return mBrightness;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String str = "DisplayDeviceConfig{"
|
||||
+ "mBrightness=" + Arrays.toString(mBrightness)
|
||||
+ ", mNits=" + Arrays.toString(mNits)
|
||||
+ "}";
|
||||
return str;
|
||||
}
|
||||
|
||||
private static DisplayDeviceConfig getConfigFromSuffix(String suffixFormat, long idNumber) {
|
||||
|
||||
final String suffix = String.format(suffixFormat, idNumber);
|
||||
final String filename = String.format(CONFIG_FILE_FORMAT, suffix);
|
||||
final File filePath = Environment.buildPath(
|
||||
Environment.getProductDirectory(), ETC_DIR, DISPLAY_CONFIG_DIR, filename);
|
||||
|
||||
if (filePath.exists()) {
|
||||
final DisplayDeviceConfig config = new DisplayDeviceConfig();
|
||||
config.initFromFile(filePath);
|
||||
return config;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void initFromFile(File configFile) {
|
||||
if (!configFile.exists()) {
|
||||
// Display configuration files aren't required to exist.
|
||||
@@ -121,13 +177,13 @@ public class DisplayDeviceConfig {
|
||||
if (i > 0) {
|
||||
if (nits[i] < nits[i - 1]) {
|
||||
Slog.e(TAG, "screenBrightnessMap must be non-decreasing, ignoring rest "
|
||||
+ " of configuration. Nits: " + nits[i] + " < " + nits[i - 1]);
|
||||
+ " of configuration. Nits: " + nits[i] + " < " + nits[i - 1]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (backlight[i] < backlight[i - 1]) {
|
||||
Slog.e(TAG, "screenBrightnessMap must be non-decreasing, ignoring rest "
|
||||
+ " of configuration. Value: " + backlight[i] + " < "
|
||||
+ " of configuration. Value: " + backlight[i] + " < "
|
||||
+ backlight[i - 1]);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -391,11 +391,11 @@ final class LocalDisplayAdapter extends DisplayAdapter {
|
||||
Spline sysToNits = null;
|
||||
|
||||
// Load the mapping from nits to HAL brightness range (display-device-config.xml)
|
||||
DisplayDeviceConfig config = DisplayDeviceConfig.create(mPhysicalDisplayId);
|
||||
mDisplayDeviceConfig = config;
|
||||
if (config == null) {
|
||||
mDisplayDeviceConfig = DisplayDeviceConfig.create(mPhysicalDisplayId);
|
||||
if (mDisplayDeviceConfig == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final float[] halNits = mDisplayDeviceConfig.getNits();
|
||||
final float[] halBrightness = mDisplayDeviceConfig.getBrightness();
|
||||
if (halNits == null || halBrightness == null) {
|
||||
@@ -942,7 +942,8 @@ final class LocalDisplayAdapter extends DisplayAdapter {
|
||||
for (int i = 0; i < mSupportedModes.size(); i++) {
|
||||
pw.println(" " + mSupportedModes.valueAt(i));
|
||||
}
|
||||
pw.print("mSupportedColorModes=" + mSupportedColorModes.toString());
|
||||
pw.println("mSupportedColorModes=" + mSupportedColorModes.toString());
|
||||
pw.print("mDisplayDeviceConfig=" + mDisplayDeviceConfig);
|
||||
}
|
||||
|
||||
private int findDisplayConfigIdLocked(int modeId, int configGroup) {
|
||||
|
||||
Reference in New Issue
Block a user