Loading packages/SystemUI/multivalentTests/src/com/android/systemui/theme/ThemeOverlayControllerTest.java +111 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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), Loading Loading @@ -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. Loading Loading @@ -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 Loading packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java +15 −9 Original line number Diff line number Diff line Loading @@ -242,11 +242,17 @@ public class ThemeOverlayController implements CoreStartable, Dumpable { } }; private int getLatestWallpaperType(int userId) { 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) { if (newWallpaperColors == null) { Loading Loading @@ -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); } Loading Loading @@ -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( Loading Loading @@ -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); Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/theme/ThemeOverlayControllerTest.java +111 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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), Loading Loading @@ -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. Loading Loading @@ -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 Loading
packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java +15 −9 Original line number Diff line number Diff line Loading @@ -242,11 +242,17 @@ public class ThemeOverlayController implements CoreStartable, Dumpable { } }; private int getLatestWallpaperType(int userId) { 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) { if (newWallpaperColors == null) { Loading Loading @@ -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); } Loading Loading @@ -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( Loading Loading @@ -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); Loading