diff options
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java | 16 | ||||
| -rw-r--r-- | packages/SystemUI/tests/src/com/android/systemui/theme/ThemeOverlayControllerTest.java | 63 |
2 files changed, 70 insertions, 9 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java b/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java index 094490ba7adc..adef1823d491 100644 --- a/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java +++ b/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java @@ -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 { 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 b7f38f1433ff..50259b5246f5 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/theme/ThemeOverlayControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/theme/ThemeOverlayControllerTest.java @@ -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); @@ -345,6 +345,61 @@ public class ThemeOverlayControllerTest extends SysuiTestCase { } @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); List<Style> validStyles = Arrays.asList(Style.EXPRESSIVE, Style.SPRITZ, Style.TONAL_SPOT, @@ -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); |