Fixes theme choice on boot when scheme is not from latest wallpaper.

Color theme was getting reset on reboot if the theme was based on a
wallpaper that was not the most recently set (e.g., based on lock screen
wallpaper when the home screen wallpaper had been set later on). This
applied to both static and live wallpapers.

Fixes: 229406616
Fixes: 234603929
Test: TreeHugger passes
Change-Id: I325e3fae9be8f56b13393320171e78ccffeea249
This commit is contained in:
Chris Poultney
2022-08-08 18:57:35 +00:00
parent 2701e8074c
commit 312cbbd921
2 changed files with 70 additions and 9 deletions

View File

@@ -244,7 +244,8 @@ public class ThemeOverlayController extends CoreStartable implements Dumpable {
final int currentUser = mUserTracker.getUserId();
final boolean hadWallpaperColors = mCurrentColors.get(userId) != null;
int latestWallpaperType = getLatestWallpaperType(userId);
if ((flags & latestWallpaperType) != 0) {
boolean eventForLatestWallpaper = (flags & latestWallpaperType) != 0;
if (eventForLatestWallpaper) {
mCurrentColors.put(userId, wallpaperColors);
if (DEBUG) Log.d(TAG, "got new colors: " + wallpaperColors + " where: " + flags);
}
@@ -280,14 +281,19 @@ public class ThemeOverlayController extends CoreStartable implements Dumpable {
currentUser);
boolean isDestinationBoth = (flags == (WallpaperManager.FLAG_SYSTEM
| WallpaperManager.FLAG_LOCK));
boolean isDestinationHomeOnly = (flags == WallpaperManager.FLAG_SYSTEM);
try {
JSONObject jsonObject = (overlayPackageJson == null) ? new JSONObject()
: 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))
&& ((flags & latestWallpaperType) != 0 && !isSeedColorSet(jsonObject,
wallpaperColors))) {
String wallpaperPickerColorSource = jsonObject.optString(OVERLAY_COLOR_SOURCE);
boolean userChosePresetColor = COLOR_SOURCE_PRESET.equals(wallpaperPickerColorSource);
boolean userChoseLockScreenColor = COLOR_SOURCE_LOCK.equals(wallpaperPickerColorSource);
boolean preserveLockScreenColor = isDestinationHomeOnly && userChoseLockScreenColor;
if (!userChosePresetColor && !preserveLockScreenColor && eventForLatestWallpaper
&& !isSeedColorSet(jsonObject, wallpaperColors)) {
mSkipSettingChange = true;
if (jsonObject.has(OVERLAY_CATEGORY_ACCENT_COLOR) || jsonObject.has(
OVERLAY_CATEGORY_SYSTEM_PALETTE)) {
@@ -642,7 +648,7 @@ public class ThemeOverlayController extends CoreStartable implements Dumpable {
}
if (mNeedsOverlayCreation) {
mNeedsOverlayCreation = false;
mThemeManager.applyCurrentUserOverlays(categoryToPackage, new FabricatedOverlay[] {
mThemeManager.applyCurrentUserOverlays(categoryToPackage, new FabricatedOverlay[]{
mSecondaryOverlay, mNeutralOverlay
}, currentUser, managedProfiles);
} else {

View File

@@ -310,7 +310,7 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
}
@Test
public void onWallpaperColorsChanged_ResetThemeWithNewHomeWallpapers() {
public void onWallpaperColorsChanged_resetThemeWithNewHomeWallpapers() {
// Should ask for a new theme when wallpaper colors change
WallpaperColors mainColors = new WallpaperColors(Color.valueOf(Color.RED),
Color.valueOf(Color.BLUE), null);
@@ -344,6 +344,61 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
.applyCurrentUserOverlays(any(), any(), anyInt(), any());
}
@Test
public void onWallpaperColorsChanged_keepsThemeWhenSetFromLockScreen() {
// Should ask for a new theme when wallpaper colors change
WallpaperColors mainColors = new WallpaperColors(Color.valueOf(Color.RED),
Color.valueOf(Color.BLUE), null);
String jsonString =
"{\"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\"}";
when(mSecureSettings.getStringForUser(
eq(Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES), anyInt()))
.thenReturn(jsonString);
when(mWallpaperManager.getWallpaperIdForUser(WallpaperManager.FLAG_LOCK, USER_SYSTEM))
.thenReturn(20);
when(mWallpaperManager.getWallpaperIdForUser(WallpaperManager.FLAG_SYSTEM, USER_SYSTEM))
.thenReturn(21);
mColorsListener.getValue().onColorsChanged(mainColors, WallpaperManager.FLAG_SYSTEM,
USER_SYSTEM);
verify(mSecureSettings, never()).putStringForUser(
eq(Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES), any(), anyInt());
}
@Test
public void onWallpaperColorsChanged_resetLockScreenThemeWhenBothSet() {
// Should ask for a new theme when wallpaper colors change
WallpaperColors mainColors = new WallpaperColors(Color.valueOf(Color.RED),
Color.valueOf(Color.BLUE), null);
String jsonString =
"{\"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\"}";
when(mSecureSettings.getStringForUser(
eq(Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES), anyInt()))
.thenReturn(jsonString);
when(mWallpaperManager.getWallpaperIdForUser(WallpaperManager.FLAG_LOCK, USER_SYSTEM))
.thenReturn(20);
when(mWallpaperManager.getWallpaperIdForUser(WallpaperManager.FLAG_SYSTEM, USER_SYSTEM))
.thenReturn(21);
mColorsListener.getValue().onColorsChanged(mainColors,
WallpaperManager.FLAG_SYSTEM | WallpaperManager.FLAG_LOCK,
USER_SYSTEM);
ArgumentCaptor<String> updatedSetting = ArgumentCaptor.forClass(String.class);
verify(mSecureSettings).putStringForUser(
eq(Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES), updatedSetting.capture(),
anyInt());
assertThat(updatedSetting.getValue().contains(
"android.theme.customization.color_both\":\"1")).isTrue();
verify(mThemeOverlayApplier)
.applyCurrentUserOverlays(any(), any(), anyInt(), any());
}
@Test
public void onSettingChanged_honorThemeStyle() {
when(mDeviceProvisionedController.isUserSetup(anyInt())).thenReturn(true);
@@ -381,7 +436,7 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
}
@Test
public void onWallpaperColorsChanged_ResetThemeWithNewHomeAndLockWallpaper() {
public void onWallpaperColorsChanged_resetThemeWithNewHomeAndLockWallpaper() {
// Should ask for a new theme when wallpaper colors change
WallpaperColors mainColors = new WallpaperColors(Color.valueOf(Color.RED),
Color.valueOf(Color.BLUE), null);
@@ -450,7 +505,7 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
WallpaperColors mainColors = new WallpaperColors(Color.valueOf(Color.RED),
Color.valueOf(Color.BLUE), null);
String jsonString =
"{\"android.theme.customization.color_source\":\"lock_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\"}";
@@ -476,7 +531,7 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
}
@Test
public void onWallpaperColorsChanged_ResetThemeWhenFromLatestWallpaper() {
public void onWallpaperColorsChanged_resetThemeWhenFromLatestWallpaper() {
// Should ask for a new theme when the colors of the last applied wallpaper change
WallpaperColors mainColors = new WallpaperColors(Color.valueOf(Color.RED),
Color.valueOf(Color.BLUE), null);