Merge "Refine color overlay attributes" into sc-dev am: f76ad95208 am: 4cd28ad801
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14609911 Change-Id: Ibdf470f27ca6b8627da1072e9ff2346ee09a0c64
This commit is contained in:
@@ -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";
|
||||
|
||||
@@ -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 "
|
||||
|
||||
@@ -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<String> 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<String> 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());
|
||||
|
||||
Reference in New Issue
Block a user