Merge "Change configuration's color mode based on the display's color mode"

This commit is contained in:
TreeHugger Robot
2017-01-26 18:56:19 +00:00
committed by Android (Google) Code Review
9 changed files with 33 additions and 16 deletions

View File

@@ -1232,7 +1232,7 @@ public class PackageParser {
XmlResourceParser parser = null;
try {
res = new Resources(assets, mMetrics, null);
assets.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
assets.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Build.VERSION.RESOURCES_SDK_INT);
parser = assets.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);
@@ -1568,7 +1568,7 @@ public class PackageParser {
private static AssetManager newConfiguredAssetManager() {
AssetManager assetManager = new AssetManager();
assetManager.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
assetManager.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Build.VERSION.RESOURCES_SDK_INT);
return assetManager;
}

View File

@@ -65,7 +65,7 @@ public class DefaultSplitAssetLoader implements SplitAssetLoader {
AssetManager assets = new AssetManager();
try {
assets.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
assets.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Build.VERSION.RESOURCES_SDK_INT);
loadApkIntoAssetManager(assets, mBaseCodePath, mFlags);

View File

@@ -83,7 +83,7 @@ public class SplitAssetDependencyLoader
throws PackageParser.PackageParserException {
final AssetManager assets = new AssetManager();
try {
assets.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
assets.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Build.VERSION.RESOURCES_SDK_INT);
for (String assetPath : assetPaths) {

View File

@@ -759,7 +759,7 @@ public final class AssetManager implements AutoCloseable {
int orientation, int touchscreen, int density, int keyboard,
int keyboardHidden, int navigation, int screenWidth, int screenHeight,
int smallestScreenWidthDp, int screenWidthDp, int screenHeightDp,
int screenLayout, int uiMode, int majorVersion);
int screenLayout, int uiMode, int colorMode, int majorVersion);
/**
* Retrieve the resource identifier for the given resource name.

View File

@@ -420,7 +420,7 @@ public class ResourcesImpl {
mConfiguration.smallestScreenWidthDp,
mConfiguration.screenWidthDp, mConfiguration.screenHeightDp,
mConfiguration.screenLayout, mConfiguration.uiMode,
Build.VERSION.RESOURCES_SDK_INT);
mConfiguration.colorMode, Build.VERSION.RESOURCES_SDK_INT);
if (DEBUG_CONFIG) {
Slog.i(TAG, "**** Updating config of " + this + ": final config is "

View File

@@ -777,8 +777,7 @@ public final class Display {
public boolean isHdr() {
synchronized (this) {
updateDisplayInfoLocked();
int[] types = mDisplayInfo.hdrCapabilities.getSupportedHdrTypes();
return types != null && types.length > 0;
return mDisplayInfo.isHdr();
}
}
@@ -788,12 +787,7 @@ public final class Display {
public boolean isWideColorGamut() {
synchronized (this) {
updateDisplayInfoLocked();
for (int colorMode : mDisplayInfo.supportedColorModes) {
if (colorMode == COLOR_MODE_DCI_P3 || colorMode > COLOR_MODE_SRGB) {
return true;
}
}
return false;
return mDisplayInfo.isWideColorGamut();
}
}

View File

@@ -519,6 +519,20 @@ public final class DisplayInfo implements Parcelable {
logicalHeight : logicalWidth;
}
public boolean isHdr() {
int[] types = hdrCapabilities.getSupportedHdrTypes();
return types != null && types.length > 0;
}
public boolean isWideColorGamut() {
for (int colorMode : supportedColorModes) {
if (colorMode == Display.COLOR_MODE_DCI_P3 || colorMode > Display.COLOR_MODE_SRGB) {
return true;
}
}
return false;
}
/**
* Returns true if the specified UID has access to this display.
*/

View File

@@ -681,7 +681,7 @@ static void android_content_AssetManager_setConfiguration(JNIEnv* env, jobject c
jint smallestScreenWidthDp,
jint screenWidthDp, jint screenHeightDp,
jint screenLayout, jint uiMode,
jint sdkVersion)
jint colorMode, jint sdkVersion)
{
AssetManager* am = assetManagerForJavaObject(env, clazz);
if (am == NULL) {
@@ -712,6 +712,7 @@ static void android_content_AssetManager_setConfiguration(JNIEnv* env, jobject c
config.screenHeightDp = (uint16_t)screenHeightDp;
config.screenLayout = (uint8_t)screenLayout;
config.uiMode = (uint8_t)uiMode;
config.colorMode = (uint8_t)colorMode;
config.sdkVersion = (uint16_t)sdkVersion;
config.minorVersion = 0;
@@ -1691,7 +1692,7 @@ static const JNINativeMethod gAssetManagerMethods[] = {
{ "getSizeConfigurations", "()[Landroid/content/res/Configuration;",
(void*) android_content_AssetManager_getSizeConfigurations },
// @FastNative
{ "setConfiguration", "(IILjava/lang/String;IIIIIIIIIIIIII)V",
{ "setConfiguration", "(IILjava/lang/String;IIIIIIIIIIIIIII)V",
(void*) android_content_AssetManager_setConfiguration },
// @FastNative
{ "getResourceIdentifier","(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I",

View File

@@ -4826,6 +4826,14 @@ public class WindowManagerService extends IWindowManager.Stub
mDisplayMetrics, dw, dh, displayId);
config.densityDpi = displayInfo.logicalDensityDpi;
config.colorMode =
(displayInfo.isHdr()
? Configuration.COLOR_MODE_HDR_YES
: Configuration.COLOR_MODE_HDR_NO)
| (displayInfo.isWideColorGamut()
? Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_YES
: Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_NO);
// Update the configuration based on available input devices, lid switch,
// and platform configuration.
config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;