Merge "Keep attributes when wallpaper changes" into sc-dev am: 7a474b19f4

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14842873

Change-Id: Ia9fb764b0bbbe281a1dceebe249b24c4d39843e9
This commit is contained in:
Kunhung Li
2021-06-09 02:04:36 +00:00
committed by Automerger Merge Worker
3 changed files with 93 additions and 31 deletions

View File

@@ -75,6 +75,10 @@ public class ThemeOverlayApplier implements Dumpable {
static final String COLOR_SOURCE_PRESET = "preset"; static final String COLOR_SOURCE_PRESET = "preset";
static final String COLOR_SOURCE_HOME = "home_wallpaper";
static final String COLOR_SOURCE_LOCK = "lock_wallpaper";
static final String TIMESTAMP_FIELD = "_applied_timestamp"; static final String TIMESTAMP_FIELD = "_applied_timestamp";
@VisibleForTesting @VisibleForTesting

View File

@@ -16,6 +16,8 @@
package com.android.systemui.theme; package com.android.systemui.theme;
import static com.android.systemui.keyguard.WakefulnessLifecycle.WAKEFULNESS_ASLEEP; import static com.android.systemui.keyguard.WakefulnessLifecycle.WAKEFULNESS_ASLEEP;
import static com.android.systemui.theme.ThemeOverlayApplier.COLOR_SOURCE_HOME;
import static com.android.systemui.theme.ThemeOverlayApplier.COLOR_SOURCE_LOCK;
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;
@@ -200,11 +202,11 @@ 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( boolean isDestinationBoth = (flags == (WallpaperManager.FLAG_SYSTEM
WallpaperManager.FLAG_LOCK) < 0; | WallpaperManager.FLAG_LOCK));
if (!TextUtils.isEmpty(overlayPackageJson)) {
try { try {
JSONObject jsonObject = new JSONObject(overlayPackageJson); JSONObject jsonObject = (overlayPackageJson == null) ? new JSONObject()
: new JSONObject(overlayPackageJson);
if (!COLOR_SOURCE_PRESET.equals(jsonObject.optString(OVERLAY_COLOR_SOURCE)) if (!COLOR_SOURCE_PRESET.equals(jsonObject.optString(OVERLAY_COLOR_SOURCE))
&& ((flags & latestWallpaperType) != 0)) { && ((flags & latestWallpaperType) != 0)) {
mSkipSettingChange = true; mSkipSettingChange = true;
@@ -212,13 +214,15 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
OVERLAY_CATEGORY_SYSTEM_PALETTE)) { 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_INDEX); jsonObject.remove(OVERLAY_COLOR_INDEX);
} }
// Keep color_both value because users can change either or both home and // Keep color_both value because users can change either or both home and
// lock screen wallpapers. // lock screen wallpapers.
jsonObject.put(OVERLAY_COLOR_BOTH, isDestinationBoth ? "1" : "0"); jsonObject.put(OVERLAY_COLOR_BOTH, isDestinationBoth ? "1" : "0");
jsonObject.put(OVERLAY_COLOR_SOURCE,
(flags == WallpaperManager.FLAG_LOCK) ? COLOR_SOURCE_LOCK
: COLOR_SOURCE_HOME);
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 "
@@ -230,7 +234,6 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
} catch (JSONException e) { } catch (JSONException e) {
Log.i(TAG, "Failed to parse THEME_CUSTOMIZATION_OVERLAY_PACKAGES.", e); Log.i(TAG, "Failed to parse THEME_CUSTOMIZATION_OVERLAY_PACKAGES.", e);
} }
}
reevaluateSystemTheme(false /* forceReload */); reevaluateSystemTheme(false /* forceReload */);
} }

View File

@@ -232,9 +232,9 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
verify(mSecureSettings).putString( verify(mSecureSettings).putString(
eq(Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES), updatedSetting.capture()); eq(Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES), updatedSetting.capture());
assertThat(updatedSetting.getValue().contains("android.theme.customization.system_palette")) assertThat(updatedSetting.getValue().contains("android.theme.customization.accent_color"))
.isFalse(); .isFalse();
assertThat(updatedSetting.getValue().contains("android.theme.customization.color_source")) assertThat(updatedSetting.getValue().contains("android.theme.customization.system_palette"))
.isFalse(); .isFalse();
assertThat(updatedSetting.getValue().contains("android.theme.customization.color_index")) assertThat(updatedSetting.getValue().contains("android.theme.customization.color_index"))
.isFalse(); .isFalse();
@@ -289,7 +289,8 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
.thenReturn(jsonString); .thenReturn(jsonString);
when(mWallpaperManager.getWallpaperId(WallpaperManager.FLAG_LOCK)).thenReturn(-1); when(mWallpaperManager.getWallpaperId(WallpaperManager.FLAG_LOCK)).thenReturn(-1);
mColorsListener.getValue().onColorsChanged(mainColors, WallpaperManager.FLAG_SYSTEM); mColorsListener.getValue().onColorsChanged(mainColors,
WallpaperManager.FLAG_SYSTEM | WallpaperManager.FLAG_LOCK);
ArgumentCaptor<String> updatedSetting = ArgumentCaptor.forClass(String.class); ArgumentCaptor<String> updatedSetting = ArgumentCaptor.forClass(String.class);
verify(mSecureSettings).putString( verify(mSecureSettings).putString(
@@ -302,6 +303,60 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
.applyCurrentUserOverlays(any(), any(), anyInt(), any()); .applyCurrentUserOverlays(any(), any(), anyInt(), any());
} }
@Test
public void onWallpaperColorsChanged_changeLockWallpaper() {
// 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_LOCK);
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_source\":\"lock_wallpaper")).isTrue();
assertThat(updatedSetting.getValue().contains("android.theme.customization.color_index"))
.isFalse();
verify(mThemeOverlayApplier)
.applyCurrentUserOverlays(any(), any(), anyInt(), any());
}
@Test
public void onWallpaperColorsChanged_changeHomeWallpaper() {
// 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\":\"lock_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_source\":\"home_wallpaper")).isTrue();
assertThat(updatedSetting.getValue().contains("android.theme.customization.color_index"))
.isFalse();
verify(mThemeOverlayApplier)
.applyCurrentUserOverlays(any(), any(), anyInt(), any());
}
@Test @Test
public void onWallpaperColorsChanged_ResetThemeWhenFromLatestWallpaper() { public void onWallpaperColorsChanged_ResetThemeWhenFromLatestWallpaper() {
// Should ask for a new theme when the colors of the last applied wallpaper change // Should ask for a new theme when the colors of the last applied wallpaper change