From 0f77a1a0840afa564b67c33869bab82e0054a816 Mon Sep 17 00:00:00 2001 From: Ching-Sung Li Date: Thu, 11 Mar 2021 20:19:22 +0800 Subject: [PATCH] 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 --- core/java/android/app/WallpaperManager.java | 45 ++++++++++++++------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/core/java/android/app/WallpaperManager.java b/core/java/android/app/WallpaperManager.java index 8e53b5ba1c9f3..7dbbc54665e99 100644 --- a/core/java/android/app/WallpaperManager.java +++ b/core/java/android/app/WallpaperManager.java @@ -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.