diff options
| author | 2024-11-04 14:59:31 +0000 | |
|---|---|---|
| committer | 2024-11-04 14:59:31 +0000 | |
| commit | 3f72bb5dc06cf16bc1b6af82ffe98c050e88ee02 (patch) | |
| tree | 2d6d840ead793b69c92581b81cbe783ffc3ae7e2 | |
| parent | c36dad8239a558604eca02c29a67222acc95df75 (diff) | |
| parent | 187ed18b8ca10b761e589ef55f7dc1e682671980 (diff) | |
Merge "Adjust color logic to be based only on home wallpaper" into main
| -rw-r--r-- | packages/SystemUI/multivalentTests/src/com/android/systemui/theme/ThemeOverlayControllerTest.java | 111 | ||||
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java | 24 |
2 files changed, 126 insertions, 9 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/theme/ThemeOverlayControllerTest.java b/packages/SystemUI/multivalentTests/src/com/android/systemui/theme/ThemeOverlayControllerTest.java index 53e033ef7c93..e7ca1dd3e4b7 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/theme/ThemeOverlayControllerTest.java +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/theme/ThemeOverlayControllerTest.java @@ -51,6 +51,8 @@ import android.graphics.Color; import android.os.Handler; import android.os.UserHandle; import android.os.UserManager; +import android.platform.test.annotations.DisableFlags; +import android.platform.test.annotations.EnableFlags; import android.provider.Settings; import androidx.annotation.VisibleForTesting; @@ -561,6 +563,113 @@ public class ThemeOverlayControllerTest extends SysuiTestCase { } @Test + @EnableFlags(com.android.systemui.shared.Flags.FLAG_NEW_CUSTOMIZATION_PICKER_UI) + public void onWallpaperColorsChanged_homeWallpaper_shouldUpdateTheme() { + // 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); + + 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.getWallpaperIdForUser(WallpaperManager.FLAG_SYSTEM, USER_SYSTEM)) + .thenReturn(1); + // Set LOCK wallpaper as the last applied one to verify that theme is no longer based on + // latest wallpaper + when(mWallpaperManager.getWallpaperIdForUser(WallpaperManager.FLAG_LOCK, USER_SYSTEM)) + .thenReturn(2); + + mColorsListener.getValue().onColorsChanged(mainColors, WallpaperManager.FLAG_SYSTEM, + USER_SYSTEM); + + ArgumentCaptor<String> updatedSetting = ArgumentCaptor.forClass(String.class); + verify(mSecureSettings).putStringForUser( + eq(Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES), updatedSetting.capture(), + anyInt()); + + verify(mThemeOverlayApplier) + .applyCurrentUserOverlays(any(), any(), anyInt(), any(), any()); + } + + + + @Test + @EnableFlags(com.android.systemui.shared.Flags.FLAG_NEW_CUSTOMIZATION_PICKER_UI) + public void onWallpaperColorsChanged_homeWallpaperWithSameColor_shouldKeepThemeAndReapply() { + // 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.getWallpaperIdForUser(WallpaperManager.FLAG_SYSTEM, USER_SYSTEM)) + .thenReturn(1); + // Set LOCK wallpaper as the last applied one to verify that theme is no longer based on + // latest wallpaper + when(mWallpaperManager.getWallpaperIdForUser(WallpaperManager.FLAG_LOCK, USER_SYSTEM)) + .thenReturn(2); + + mColorsListener.getValue().onColorsChanged(mainColors, WallpaperManager.FLAG_SYSTEM, + USER_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(), any()); + } + + @Test + @EnableFlags(com.android.systemui.shared.Flags.FLAG_NEW_CUSTOMIZATION_PICKER_UI) + public void onWallpaperColorsChanged_lockWallpaper_shouldKeepTheme() { + // 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); + + 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.getWallpaperIdForUser(WallpaperManager.FLAG_SYSTEM, USER_SYSTEM)) + .thenReturn(1); + // Set LOCK wallpaper as the last applied one to verify that theme is no longer based on + // latest wallpaper + when(mWallpaperManager.getWallpaperIdForUser(WallpaperManager.FLAG_LOCK, USER_SYSTEM)) + .thenReturn(2); + + mColorsListener.getValue().onColorsChanged(mainColors, WallpaperManager.FLAG_LOCK, + USER_SYSTEM); + + ArgumentCaptor<String> updatedSetting = ArgumentCaptor.forClass(String.class); + verify(mSecureSettings, never()).putString( + eq(Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES), updatedSetting.capture()); + + verify(mThemeOverlayApplier, never()) + .applyCurrentUserOverlays(any(), any(), anyInt(), any(), any()); + } + + @Test + @DisableFlags(com.android.systemui.shared.Flags.FLAG_NEW_CUSTOMIZATION_PICKER_UI) 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), @@ -594,6 +703,7 @@ public class ThemeOverlayControllerTest extends SysuiTestCase { } @Test + @DisableFlags(com.android.systemui.shared.Flags.FLAG_NEW_CUSTOMIZATION_PICKER_UI) 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. @@ -627,6 +737,7 @@ public class ThemeOverlayControllerTest extends SysuiTestCase { } @Test + @DisableFlags(com.android.systemui.shared.Flags.FLAG_NEW_CUSTOMIZATION_PICKER_UI) public void onWallpaperColorsChanged_keepThemeIfNotLatestWallpaper() { // Shouldn't ask for a new theme when the colors of the wallpaper that is not the last // applied one change diff --git a/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java b/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java index 9c8ef0421888..1c3fece1beb1 100644 --- a/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java +++ b/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java @@ -242,10 +242,16 @@ public class ThemeOverlayController implements CoreStartable, Dumpable { } }; - private int getLatestWallpaperType(int userId) { - return mWallpaperManager.getWallpaperIdForUser(WallpaperManager.FLAG_LOCK, userId) - > mWallpaperManager.getWallpaperIdForUser(WallpaperManager.FLAG_SYSTEM, userId) - ? WallpaperManager.FLAG_LOCK : WallpaperManager.FLAG_SYSTEM; + private int getDefaultWallpaperColorsSource(int userId) { + if (com.android.systemui.shared.Flags.newCustomizationPickerUi()) { + // The wallpaper colors source is always the home wallpaper. + return WallpaperManager.FLAG_SYSTEM; + } else { + // The wallpaper colors source is based on the last set wallpaper. + return mWallpaperManager.getWallpaperIdForUser(WallpaperManager.FLAG_LOCK, userId) + > mWallpaperManager.getWallpaperIdForUser(WallpaperManager.FLAG_SYSTEM, userId) + ? WallpaperManager.FLAG_LOCK : WallpaperManager.FLAG_SYSTEM; + } } private boolean isSeedColorSet(JSONObject jsonObject, WallpaperColors newWallpaperColors) { @@ -279,9 +285,9 @@ public class ThemeOverlayController implements CoreStartable, Dumpable { private void handleWallpaperColors(WallpaperColors wallpaperColors, int flags, int userId) { final int currentUser = mUserTracker.getUserId(); final boolean hadWallpaperColors = mCurrentColors.get(userId) != null; - int latestWallpaperType = getLatestWallpaperType(userId); - boolean eventForLatestWallpaper = (flags & latestWallpaperType) != 0; - if (eventForLatestWallpaper) { + int wallpaperColorsSource = getDefaultWallpaperColorsSource(userId); + boolean wallpaperColorsNeedUpdate = (flags & wallpaperColorsSource) != 0; + if (wallpaperColorsNeedUpdate) { mCurrentColors.put(userId, wallpaperColors); if (DEBUG) Log.d(TAG, "got new colors: " + wallpaperColors + " where: " + flags); } @@ -328,7 +334,7 @@ public class ThemeOverlayController implements CoreStartable, Dumpable { boolean userChoseLockScreenColor = COLOR_SOURCE_LOCK.equals(wallpaperPickerColorSource); boolean preserveLockScreenColor = isDestinationHomeOnly && userChoseLockScreenColor; - if (!userChosePresetColor && !preserveLockScreenColor && eventForLatestWallpaper + if (!userChosePresetColor && !preserveLockScreenColor && wallpaperColorsNeedUpdate && !isSeedColorSet(jsonObject, wallpaperColors)) { mSkipSettingChange = true; if (jsonObject.has(OVERLAY_CATEGORY_ACCENT_COLOR) || jsonObject.has( @@ -494,7 +500,7 @@ public class ThemeOverlayController implements CoreStartable, Dumpable { // Upon boot, make sure we have the most up to date colors Runnable updateColors = () -> { WallpaperColors systemColor = mWallpaperManager.getWallpaperColors( - getLatestWallpaperType(mUserTracker.getUserId())); + getDefaultWallpaperColorsSource(mUserTracker.getUserId())); Runnable applyColors = () -> { if (DEBUG) Log.d(TAG, "Boot colors: " + systemColor); mCurrentColors.put(mUserTracker.getUserId(), systemColor); |