Fix specified wallpaper color option missing after reboot
Not only check latest wallpaper type (FLAG_SYSTEM, FLAG_LOCK) but also check if the wallpaper color is specified to determine if we reset the theme overlay setting. Bug: 198449419 Test: atest ThemeOverlayControllerTest Change-Id: Ic10c10c6fbccee0f330c67ae8b9bacb947c5e035
This commit is contained in:
committed by
Ching Sung Li
parent
02183c88aa
commit
94568f1e74
@@ -176,6 +176,34 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
|
|||||||
? WallpaperManager.FLAG_LOCK : WallpaperManager.FLAG_SYSTEM;
|
? WallpaperManager.FLAG_LOCK : WallpaperManager.FLAG_SYSTEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isSeedColorSet(JSONObject jsonObject, WallpaperColors newWallpaperColors) {
|
||||||
|
if (newWallpaperColors == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Gets the color that was overridden in the theme setting if any.
|
||||||
|
String sysPaletteColor = (String) jsonObject.opt(OVERLAY_CATEGORY_SYSTEM_PALETTE);
|
||||||
|
if (sysPaletteColor == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!sysPaletteColor.startsWith("#")) {
|
||||||
|
sysPaletteColor = "#" + sysPaletteColor;
|
||||||
|
}
|
||||||
|
final int systemPaletteColorArgb = Color.parseColor(sysPaletteColor);
|
||||||
|
// Gets seed colors from incoming {@link WallpaperColors} instance.
|
||||||
|
List<Integer> seedColors = ColorScheme.getSeedColors(newWallpaperColors);
|
||||||
|
for (int seedColor : seedColors) {
|
||||||
|
// The seed color from incoming {@link WallpaperColors} instance
|
||||||
|
// was set as color override.
|
||||||
|
if (seedColor == systemPaletteColorArgb) {
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.d(TAG, "Same as previous set system palette: " + sysPaletteColor);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private void handleWallpaperColors(WallpaperColors wallpaperColors, int flags) {
|
private void handleWallpaperColors(WallpaperColors wallpaperColors, int flags) {
|
||||||
final boolean hadWallpaperColors = mCurrentColors != null;
|
final boolean hadWallpaperColors = mCurrentColors != null;
|
||||||
int latestWallpaperType = getLatestWallpaperType();
|
int latestWallpaperType = getLatestWallpaperType();
|
||||||
@@ -213,8 +241,11 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
|
|||||||
try {
|
try {
|
||||||
JSONObject jsonObject = (overlayPackageJson == null) ? new JSONObject()
|
JSONObject jsonObject = (overlayPackageJson == null) ? new JSONObject()
|
||||||
: new JSONObject(overlayPackageJson);
|
: new JSONObject(overlayPackageJson);
|
||||||
|
// The latest applied wallpaper should be the source of system colors when:
|
||||||
|
// There is not preset color applied and the incoming wallpaper color is not applied
|
||||||
if (!COLOR_SOURCE_PRESET.equals(jsonObject.optString(OVERLAY_COLOR_SOURCE))
|
if (!COLOR_SOURCE_PRESET.equals(jsonObject.optString(OVERLAY_COLOR_SOURCE))
|
||||||
&& ((flags & latestWallpaperType) != 0)) {
|
&& ((flags & latestWallpaperType) != 0 && !isSeedColorSet(jsonObject,
|
||||||
|
wallpaperColors))) {
|
||||||
mSkipSettingChange = true;
|
mSkipSettingChange = true;
|
||||||
if (jsonObject.has(OVERLAY_CATEGORY_ACCENT_COLOR) || jsonObject.has(
|
if (jsonObject.has(OVERLAY_CATEGORY_ACCENT_COLOR) || jsonObject.has(
|
||||||
OVERLAY_CATEGORY_SYSTEM_PALETTE)) {
|
OVERLAY_CATEGORY_SYSTEM_PALETTE)) {
|
||||||
|
|||||||
@@ -248,8 +248,9 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
|
|||||||
Color.valueOf(Color.BLUE), null);
|
Color.valueOf(Color.BLUE), null);
|
||||||
|
|
||||||
String jsonString =
|
String jsonString =
|
||||||
"{\"android.theme.customization.system_palette\":\"override.package.name\","
|
"{\"android.theme.customization.color_source\":\"home_wallpaper\","
|
||||||
+ "\"android.theme.customization.color_source\":\"home_wallpaper\","
|
+ "\"android.theme.customization.system_palette\":\"A16B00\","
|
||||||
|
+ "\"android.theme.customization.accent_color\":\"A16B00\","
|
||||||
+ "\"android.theme.customization.color_index\":\"2\"}";
|
+ "\"android.theme.customization.color_index\":\"2\"}";
|
||||||
|
|
||||||
when(mSecureSettings.getStringForUser(
|
when(mSecureSettings.getStringForUser(
|
||||||
@@ -274,14 +275,15 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onWallpaperColorsChanged_ResetThemeWithDifferentWallpapers() {
|
public void onWallpaperColorsChanged_ResetThemeWithNewHomeWallpapers() {
|
||||||
// Should ask for a new theme when wallpaper colors change
|
// Should ask for a new theme when wallpaper colors change
|
||||||
WallpaperColors mainColors = new WallpaperColors(Color.valueOf(Color.RED),
|
WallpaperColors mainColors = new WallpaperColors(Color.valueOf(Color.RED),
|
||||||
Color.valueOf(Color.BLUE), null);
|
Color.valueOf(Color.BLUE), null);
|
||||||
|
|
||||||
String jsonString =
|
String jsonString =
|
||||||
"{\"android.theme.customization.system_palette\":\"override.package.name\","
|
"{\"android.theme.customization.color_source\":\"home_wallpaper\","
|
||||||
+ "\"android.theme.customization.color_source\":\"home_wallpaper\","
|
+ "\"android.theme.customization.system_palette\":\"A16B00\","
|
||||||
|
+ "\"android.theme.customization.accent_color\":\"A16B00\","
|
||||||
+ "\"android.theme.customization.color_index\":\"2\"}";
|
+ "\"android.theme.customization.color_index\":\"2\"}";
|
||||||
|
|
||||||
when(mSecureSettings.getStringForUser(
|
when(mSecureSettings.getStringForUser(
|
||||||
@@ -304,14 +306,15 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onWallpaperColorsChanged_ResetThemeWithSameWallpaper() {
|
public void onWallpaperColorsChanged_ResetThemeWithNewHomeAndLockWallpaper() {
|
||||||
// Should ask for a new theme when wallpaper colors change
|
// Should ask for a new theme when wallpaper colors change
|
||||||
WallpaperColors mainColors = new WallpaperColors(Color.valueOf(Color.RED),
|
WallpaperColors mainColors = new WallpaperColors(Color.valueOf(Color.RED),
|
||||||
Color.valueOf(Color.BLUE), null);
|
Color.valueOf(Color.BLUE), null);
|
||||||
|
|
||||||
String jsonString =
|
String jsonString =
|
||||||
"{\"android.theme.customization.system_palette\":\"override.package.name\","
|
"{\"android.theme.customization.color_source\":\"home_wallpaper\","
|
||||||
+ "\"android.theme.customization.color_source\":\"home_wallpaper\","
|
+ "\"android.theme.customization.system_palette\":\"A16B00\","
|
||||||
|
+ "\"android.theme.customization.accent_color\":\"A16B00\","
|
||||||
+ "\"android.theme.customization.color_index\":\"2\"}";
|
+ "\"android.theme.customization.color_index\":\"2\"}";
|
||||||
|
|
||||||
when(mSecureSettings.getStringForUser(
|
when(mSecureSettings.getStringForUser(
|
||||||
@@ -339,8 +342,9 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
|
|||||||
WallpaperColors mainColors = new WallpaperColors(Color.valueOf(Color.RED),
|
WallpaperColors mainColors = new WallpaperColors(Color.valueOf(Color.RED),
|
||||||
Color.valueOf(Color.BLUE), null);
|
Color.valueOf(Color.BLUE), null);
|
||||||
String jsonString =
|
String jsonString =
|
||||||
"{\"android.theme.customization.system_palette\":\"override.package.name\","
|
"{\"android.theme.customization.color_source\":\"home_wallpaper\","
|
||||||
+ "\"android.theme.customization.color_source\":\"home_wallpaper\","
|
+ "\"android.theme.customization.system_palette\":\"A16B00\","
|
||||||
|
+ "\"android.theme.customization.accent_color\":\"A16B00\","
|
||||||
+ "\"android.theme.customization.color_index\":\"2\"}";
|
+ "\"android.theme.customization.color_index\":\"2\"}";
|
||||||
when(mSecureSettings.getStringForUser(
|
when(mSecureSettings.getStringForUser(
|
||||||
eq(Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES), anyInt()))
|
eq(Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES), anyInt()))
|
||||||
@@ -366,8 +370,9 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
|
|||||||
WallpaperColors mainColors = new WallpaperColors(Color.valueOf(Color.RED),
|
WallpaperColors mainColors = new WallpaperColors(Color.valueOf(Color.RED),
|
||||||
Color.valueOf(Color.BLUE), null);
|
Color.valueOf(Color.BLUE), null);
|
||||||
String jsonString =
|
String jsonString =
|
||||||
"{\"android.theme.customization.system_palette\":\"override.package.name\","
|
"{\"android.theme.customization.color_source\":\"lock_wallpaper\","
|
||||||
+ "\"android.theme.customization.color_source\":\"lock_wallpaper\","
|
+ "\"android.theme.customization.system_palette\":\"A16B00\","
|
||||||
|
+ "\"android.theme.customization.accent_color\":\"A16B00\","
|
||||||
+ "\"android.theme.customization.color_index\":\"2\"}";
|
+ "\"android.theme.customization.color_index\":\"2\"}";
|
||||||
when(mSecureSettings.getStringForUser(
|
when(mSecureSettings.getStringForUser(
|
||||||
eq(Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES), anyInt()))
|
eq(Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES), anyInt()))
|
||||||
@@ -394,8 +399,9 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
|
|||||||
Color.valueOf(Color.BLUE), null);
|
Color.valueOf(Color.BLUE), null);
|
||||||
|
|
||||||
String jsonString =
|
String jsonString =
|
||||||
"{\"android.theme.customization.system_palette\":\"override.package.name\","
|
"{\"android.theme.customization.color_source\":\"home_wallpaper\","
|
||||||
+ "\"android.theme.customization.color_source\":\"home_wallpaper\","
|
+ "\"android.theme.customization.system_palette\":\"A16B00\","
|
||||||
|
+ "\"android.theme.customization.accent_color\":\"A16B00\","
|
||||||
+ "\"android.theme.customization.color_index\":\"2\"}";
|
+ "\"android.theme.customization.color_index\":\"2\"}";
|
||||||
|
|
||||||
when(mSecureSettings.getStringForUser(
|
when(mSecureSettings.getStringForUser(
|
||||||
@@ -415,6 +421,36 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
|
|||||||
.applyCurrentUserOverlays(any(), any(), anyInt(), any());
|
.applyCurrentUserOverlays(any(), any(), anyInt(), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onWallpaperColorsChanged_keepThemeWhenFromLatestWallpaperAndSpecifiedColor() {
|
||||||
|
// Shouldn't ask for a new theme when the colors of the last applied wallpaper change
|
||||||
|
// with the same specified system palette one.
|
||||||
|
WallpaperColors mainColors = new WallpaperColors(Color.valueOf(Color.RED),
|
||||||
|
Color.valueOf(0xffa16b00), null);
|
||||||
|
|
||||||
|
String jsonString =
|
||||||
|
"{\"android.theme.customization.color_source\":\"home_wallpaper\","
|
||||||
|
+ "\"android.theme.customization.system_palette\":\"A16B00\","
|
||||||
|
+ "\"android.theme.customization.accent_color\":\"A16B00\","
|
||||||
|
+ "\"android.theme.customization.color_index\":\"2\"}";
|
||||||
|
|
||||||
|
when(mSecureSettings.getStringForUser(
|
||||||
|
eq(Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES), anyInt()))
|
||||||
|
.thenReturn(jsonString);
|
||||||
|
when(mWallpaperManager.getWallpaperId(WallpaperManager.FLAG_LOCK)).thenReturn(1);
|
||||||
|
// SYSTEM wallpaper is the last applied one
|
||||||
|
when(mWallpaperManager.getWallpaperId(WallpaperManager.FLAG_SYSTEM)).thenReturn(2);
|
||||||
|
|
||||||
|
mColorsListener.getValue().onColorsChanged(mainColors, WallpaperManager.FLAG_SYSTEM);
|
||||||
|
|
||||||
|
ArgumentCaptor<String> updatedSetting = ArgumentCaptor.forClass(String.class);
|
||||||
|
verify(mSecureSettings, never()).putString(
|
||||||
|
eq(Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES), updatedSetting.capture());
|
||||||
|
|
||||||
|
// Apply overlay by existing theme from secure setting
|
||||||
|
verify(mThemeOverlayApplier).applyCurrentUserOverlays(any(), any(), anyInt(), any());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onWallpaperColorsChanged_keepThemeIfNotLatestWallpaper() {
|
public void onWallpaperColorsChanged_keepThemeIfNotLatestWallpaper() {
|
||||||
// Shouldn't ask for a new theme when the colors of the wallpaper that is not the last
|
// Shouldn't ask for a new theme when the colors of the wallpaper that is not the last
|
||||||
@@ -423,8 +459,9 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
|
|||||||
Color.valueOf(Color.BLUE), null);
|
Color.valueOf(Color.BLUE), null);
|
||||||
|
|
||||||
String jsonString =
|
String jsonString =
|
||||||
"{\"android.theme.customization.system_palette\":\"override.package.name\","
|
"{\"android.theme.customization.color_source\":\"home_wallpaper\","
|
||||||
+ "\"android.theme.customization.color_source\":\"home_wallpaper\","
|
+ "\"android.theme.customization.system_palette\":\"A16B00\","
|
||||||
|
+ "\"android.theme.customization.accent_color\":\"A16B00\","
|
||||||
+ "\"android.theme.customization.color_index\":\"2\"}";
|
+ "\"android.theme.customization.color_index\":\"2\"}";
|
||||||
|
|
||||||
when(mSecureSettings.getStringForUser(
|
when(mSecureSettings.getStringForUser(
|
||||||
|
|||||||
Reference in New Issue
Block a user