diff --git a/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayApplier.java b/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayApplier.java index 865aa23f69e6d..d61848c95a09d 100644 --- a/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayApplier.java +++ b/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayApplier.java @@ -69,6 +69,10 @@ public class ThemeOverlayApplier implements Dumpable { static final String OVERLAY_COLOR_SOURCE = "android.theme.customization.color_source"; + static final String OVERLAY_COLOR_INDEX = "android.theme.customization.color_index"; + + static final String OVERLAY_COLOR_BOTH = "android.theme.customization.color_both"; + static final String COLOR_SOURCE_PRESET = "preset"; static final String TIMESTAMP_FIELD = "_applied_timestamp"; diff --git a/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java b/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java index d97e9d538f6af..795e72caf641e 100644 --- a/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java +++ b/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java @@ -18,6 +18,8 @@ package com.android.systemui.theme; import static com.android.systemui.theme.ThemeOverlayApplier.COLOR_SOURCE_PRESET; import static com.android.systemui.theme.ThemeOverlayApplier.OVERLAY_CATEGORY_ACCENT_COLOR; import static com.android.systemui.theme.ThemeOverlayApplier.OVERLAY_CATEGORY_SYSTEM_PALETTE; +import static com.android.systemui.theme.ThemeOverlayApplier.OVERLAY_COLOR_BOTH; +import static com.android.systemui.theme.ThemeOverlayApplier.OVERLAY_COLOR_INDEX; import static com.android.systemui.theme.ThemeOverlayApplier.OVERLAY_COLOR_SOURCE; import static com.android.systemui.theme.ThemeOverlayApplier.TIMESTAMP_FIELD; @@ -96,11 +98,11 @@ public class ThemeOverlayController extends SystemUI implements Dumpable { private SecureSettings mSecureSettings; private final Executor mMainExecutor; private final Handler mBgHandler; - private final WallpaperManager mWallpaperManager; private final boolean mIsMonetEnabled; private UserTracker mUserTracker; private DeviceProvisionedController mDeviceProvisionedController; private WallpaperColors mSystemColors; + private WallpaperManager mWallpaperManager; // If fabricated overlays were already created for the current theme. private boolean mNeedsOverlayCreation; // Dominant olor extracted from wallpaper, NOT the color used on the overlay @@ -173,17 +175,24 @@ public class ThemeOverlayController extends SystemUI implements Dumpable { String overlayPackageJson = mSecureSettings.getStringForUser( Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES, currentUser); + boolean isDestinationBoth = mWallpaperManager.getWallpaperId( + WallpaperManager.FLAG_LOCK) < 0; if (!TextUtils.isEmpty(overlayPackageJson)) { try { JSONObject jsonObject = new JSONObject(overlayPackageJson); - if ((jsonObject.has(OVERLAY_CATEGORY_ACCENT_COLOR) - || jsonObject.has(OVERLAY_CATEGORY_SYSTEM_PALETTE)) - && !COLOR_SOURCE_PRESET.equals( - jsonObject.optString(OVERLAY_COLOR_SOURCE))) { + if (!COLOR_SOURCE_PRESET.equals(jsonObject.optString(OVERLAY_COLOR_SOURCE))) { mSkipSettingChange = true; - jsonObject.remove(OVERLAY_CATEGORY_ACCENT_COLOR); - jsonObject.remove(OVERLAY_CATEGORY_SYSTEM_PALETTE); - jsonObject.remove(OVERLAY_COLOR_SOURCE); + if (jsonObject.has(OVERLAY_CATEGORY_ACCENT_COLOR) || jsonObject.has( + OVERLAY_CATEGORY_SYSTEM_PALETTE)) { + jsonObject.remove(OVERLAY_CATEGORY_ACCENT_COLOR); + jsonObject.remove(OVERLAY_CATEGORY_SYSTEM_PALETTE); + jsonObject.remove(OVERLAY_COLOR_SOURCE); + jsonObject.remove(OVERLAY_COLOR_INDEX); + } + // Keep color_both value because users can change either or both home and + // lock screen wallpapers. + jsonObject.put(OVERLAY_COLOR_BOTH, isDestinationBoth ? "1" : "0"); + jsonObject.put(TIMESTAMP_FIELD, System.currentTimeMillis()); if (DEBUG) { Log.d(TAG, "Updating theme setting from " diff --git a/packages/SystemUI/tests/src/com/android/systemui/theme/ThemeOverlayControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/theme/ThemeOverlayControllerTest.java index 9f1dad84b6ce9..75c0cb315e8d6 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/theme/ThemeOverlayControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/theme/ThemeOverlayControllerTest.java @@ -211,7 +211,9 @@ public class ThemeOverlayControllerTest extends SysuiTestCase { 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.color_index\":\"2\"}"; + when(mSecureSettings.getStringForUser( eq(Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES), anyInt())) .thenReturn(jsonString); @@ -224,6 +226,68 @@ public class ThemeOverlayControllerTest extends SysuiTestCase { assertThat(updatedSetting.getValue().contains("android.theme.customization.system_palette")) .isFalse(); + assertThat(updatedSetting.getValue().contains("android.theme.customization.color_source")) + .isFalse(); + assertThat(updatedSetting.getValue().contains("android.theme.customization.color_index")) + .isFalse(); + + verify(mThemeOverlayApplier) + .applyCurrentUserOverlays(any(), any(), anyInt(), any()); + } + + @Test + public void onWallpaperColorsChanged_ResetThemeWithDifferentWallpapers() { + // 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.system_palette\":\"override.package.name\"," + + "\"android.theme.customization.color_source\":\"home_wallpaper\"," + + "\"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(20); + + mColorsListener.getValue().onColorsChanged(mainColors, WallpaperManager.FLAG_SYSTEM); + + ArgumentCaptor updatedSetting = ArgumentCaptor.forClass(String.class); + verify(mSecureSettings).putString( + eq(Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES), updatedSetting.capture()); + + assertThat(updatedSetting.getValue().contains( + "android.theme.customization.color_both\":\"0")).isTrue(); + + verify(mThemeOverlayApplier) + .applyCurrentUserOverlays(any(), any(), anyInt(), any()); + } + + @Test + public void onWallpaperColorsChanged_ResetThemeWithSameWallpaper() { + // 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.system_palette\":\"override.package.name\"," + + "\"android.theme.customization.color_source\":\"home_wallpaper\"," + + "\"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); + + mColorsListener.getValue().onColorsChanged(mainColors, WallpaperManager.FLAG_SYSTEM); + + ArgumentCaptor updatedSetting = ArgumentCaptor.forClass(String.class); + verify(mSecureSettings).putString( + eq(Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES), updatedSetting.capture()); + + assertThat(updatedSetting.getValue().contains( + "android.theme.customization.color_both\":\"1")).isTrue(); verify(mThemeOverlayApplier) .applyCurrentUserOverlays(any(), any(), anyInt(), any());