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_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 COLOR_SOURCE_PRESET = "preset";
|
||||||
|
|
||||||
static final String TIMESTAMP_FIELD = "_applied_timestamp";
|
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.COLOR_SOURCE_PRESET;
|
||||||
import static com.android.systemui.theme.ThemeOverlayApplier.OVERLAY_CATEGORY_ACCENT_COLOR;
|
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_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.OVERLAY_COLOR_SOURCE;
|
||||||
import static com.android.systemui.theme.ThemeOverlayApplier.TIMESTAMP_FIELD;
|
import static com.android.systemui.theme.ThemeOverlayApplier.TIMESTAMP_FIELD;
|
||||||
|
|
||||||
@@ -96,11 +98,11 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
|
|||||||
private SecureSettings mSecureSettings;
|
private SecureSettings mSecureSettings;
|
||||||
private final Executor mMainExecutor;
|
private final Executor mMainExecutor;
|
||||||
private final Handler mBgHandler;
|
private final Handler mBgHandler;
|
||||||
private final WallpaperManager mWallpaperManager;
|
|
||||||
private final boolean mIsMonetEnabled;
|
private final boolean mIsMonetEnabled;
|
||||||
private UserTracker mUserTracker;
|
private UserTracker mUserTracker;
|
||||||
private DeviceProvisionedController mDeviceProvisionedController;
|
private DeviceProvisionedController mDeviceProvisionedController;
|
||||||
private WallpaperColors mSystemColors;
|
private WallpaperColors mSystemColors;
|
||||||
|
private WallpaperManager mWallpaperManager;
|
||||||
// If fabricated overlays were already created for the current theme.
|
// If fabricated overlays were already created for the current theme.
|
||||||
private boolean mNeedsOverlayCreation;
|
private boolean mNeedsOverlayCreation;
|
||||||
// Dominant olor extracted from wallpaper, NOT the color used on the overlay
|
// 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(
|
String overlayPackageJson = mSecureSettings.getStringForUser(
|
||||||
Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES,
|
Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES,
|
||||||
currentUser);
|
currentUser);
|
||||||
|
boolean isDestinationBoth = mWallpaperManager.getWallpaperId(
|
||||||
|
WallpaperManager.FLAG_LOCK) < 0;
|
||||||
if (!TextUtils.isEmpty(overlayPackageJson)) {
|
if (!TextUtils.isEmpty(overlayPackageJson)) {
|
||||||
try {
|
try {
|
||||||
JSONObject jsonObject = new JSONObject(overlayPackageJson);
|
JSONObject jsonObject = new JSONObject(overlayPackageJson);
|
||||||
if ((jsonObject.has(OVERLAY_CATEGORY_ACCENT_COLOR)
|
if (!COLOR_SOURCE_PRESET.equals(jsonObject.optString(OVERLAY_COLOR_SOURCE))) {
|
||||||
|| jsonObject.has(OVERLAY_CATEGORY_SYSTEM_PALETTE))
|
|
||||||
&& !COLOR_SOURCE_PRESET.equals(
|
|
||||||
jsonObject.optString(OVERLAY_COLOR_SOURCE))) {
|
|
||||||
mSkipSettingChange = true;
|
mSkipSettingChange = true;
|
||||||
|
if (jsonObject.has(OVERLAY_CATEGORY_ACCENT_COLOR) || jsonObject.has(
|
||||||
|
OVERLAY_CATEGORY_SYSTEM_PALETTE)) {
|
||||||
jsonObject.remove(OVERLAY_CATEGORY_ACCENT_COLOR);
|
jsonObject.remove(OVERLAY_CATEGORY_ACCENT_COLOR);
|
||||||
jsonObject.remove(OVERLAY_CATEGORY_SYSTEM_PALETTE);
|
jsonObject.remove(OVERLAY_CATEGORY_SYSTEM_PALETTE);
|
||||||
jsonObject.remove(OVERLAY_COLOR_SOURCE);
|
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());
|
jsonObject.put(TIMESTAMP_FIELD, System.currentTimeMillis());
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "Updating theme setting from "
|
Log.d(TAG, "Updating theme setting from "
|
||||||
|
|||||||
@@ -211,7 +211,9 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
|
|||||||
|
|
||||||
String jsonString =
|
String jsonString =
|
||||||
"{\"android.theme.customization.system_palette\":\"override.package.name\","
|
"{\"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(
|
when(mSecureSettings.getStringForUser(
|
||||||
eq(Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES), anyInt()))
|
eq(Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES), anyInt()))
|
||||||
.thenReturn(jsonString);
|
.thenReturn(jsonString);
|
||||||
@@ -224,6 +226,68 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
|
|||||||
|
|
||||||
assertThat(updatedSetting.getValue().contains("android.theme.customization.system_palette"))
|
assertThat(updatedSetting.getValue().contains("android.theme.customization.system_palette"))
|
||||||
.isFalse();
|
.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)
|
verify(mThemeOverlayApplier)
|
||||||
.applyCurrentUserOverlays(any(), any(), anyInt(), any());
|
.applyCurrentUserOverlays(any(), any(), anyInt(), any());
|
||||||
|
|||||||
Reference in New Issue
Block a user