Load default wallpaper by device's CMF color

Load default wallpaper by device's CMF color in WallpaperManager. The
fallback is to use default wallpaper if no matching wallpaper with
corresponding CMF color.

Bug: 178161042
Test: Build ROM and manual test
Change-Id: Iea818784f05f730e3cde79e95771a84db1b39225
This commit is contained in:
Ching-Sung Li
2021-03-11 20:19:22 +08:00
committed by Ching Sung Li
parent e32f0d1c01
commit 0f77a1a084

View File

@@ -57,6 +57,7 @@ import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.DeadSystemException;
import android.os.Environment;
import android.os.FileUtils;
import android.os.Handler;
import android.os.IBinder;
@@ -120,6 +121,8 @@ public class WallpaperManager {
/** {@hide} */
private static final String VALUE_CMF_COLOR =
android.os.SystemProperties.get("ro.boot.hardware.color");
/** {@hide} */
private static final String WALLPAPER_CMF_PATH = "/wallpaper/image/";
/**
* Activity Action: Show settings for choosing wallpaper. Do not use directly to construct
@@ -2066,22 +2069,17 @@ public class WallpaperManager {
return null;
} else {
whichProp = PROP_WALLPAPER;
final int defaultColorResId = context.getResources().getIdentifier(
"default_wallpaper_" + VALUE_CMF_COLOR, "drawable", "android");
defaultResId =
defaultColorResId == 0 ? com.android.internal.R.drawable.default_wallpaper
: defaultColorResId;
defaultResId = com.android.internal.R.drawable.default_wallpaper;
}
final String path = SystemProperties.get(whichProp);
if (!TextUtils.isEmpty(path)) {
final File file = new File(path);
if (file.exists()) {
try {
return new FileInputStream(file);
} catch (IOException e) {
// Ignored, fall back to platform default below
}
}
final InputStream wallpaperInputStream = getWallpaperInputStream(path);
if (wallpaperInputStream != null) {
return wallpaperInputStream;
}
final String cmfPath = getCmfWallpaperPath();
final InputStream cmfWallpaperInputStream = getWallpaperInputStream(cmfPath);
if (cmfWallpaperInputStream != null) {
return cmfWallpaperInputStream;
}
try {
return context.getResources().openRawResource(defaultResId);
@@ -2091,6 +2089,25 @@ public class WallpaperManager {
return null;
}
private static InputStream getWallpaperInputStream(String path) {
if (!TextUtils.isEmpty(path)) {
final File file = new File(path);
if (file.exists()) {
try {
return new FileInputStream(file);
} catch (IOException e) {
// Ignored, fall back to platform default
}
}
}
return null;
}
private static String getCmfWallpaperPath() {
return Environment.getProductDirectory() + WALLPAPER_CMF_PATH + "default_wallpaper_"
+ VALUE_CMF_COLOR;
}
/**
* Return {@link ComponentName} of the default live wallpaper, or
* {@code null} if none is defined.