summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayApplier.java7
-rw-r--r--packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java43
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/theme/ThemeOverlayControllerTest.java29
3 files changed, 76 insertions, 3 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayApplier.java b/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayApplier.java
index 3c1e12327d8f..865aa23f69e6 100644
--- a/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayApplier.java
+++ b/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayApplier.java
@@ -66,6 +66,13 @@ public class ThemeOverlayApplier implements Dumpable {
"android.theme.customization.accent_color";
static final String OVERLAY_CATEGORY_SYSTEM_PALETTE =
"android.theme.customization.system_palette";
+
+ static final String OVERLAY_COLOR_SOURCE = "android.theme.customization.color_source";
+
+ static final String COLOR_SOURCE_PRESET = "preset";
+
+ static final String TIMESTAMP_FIELD = "_applied_timestamp";
+
@VisibleForTesting
static final String OVERLAY_CATEGORY_FONT = "android.theme.customization.font";
@VisibleForTesting
diff --git a/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java b/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java
index 9bdd8c009531..195114f0f19f 100644
--- a/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java
+++ b/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java
@@ -15,8 +15,11 @@
*/
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_SOURCE;
+import static com.android.systemui.theme.ThemeOverlayApplier.TIMESTAMP_FIELD;
import android.annotation.Nullable;
import android.app.WallpaperColors;
@@ -90,12 +93,12 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
private final UserManager mUserManager;
private final BroadcastDispatcher mBroadcastDispatcher;
private final Executor mBgExecutor;
- private final SecureSettings mSecureSettings;
+ private SecureSettings mSecureSettings;
private final Executor mMainExecutor;
private final Handler mBgHandler;
private final WallpaperManager mWallpaperManager;
private final boolean mIsMonetEnabled;
- private final UserTracker mUserTracker;
+ private UserTracker mUserTracker;
private DeviceProvisionedController mDeviceProvisionedController;
private WallpaperColors mSystemColors;
// If fabricated overlays were already created for the current theme.
@@ -112,6 +115,8 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
private boolean mAcceptColorEvents = true;
// Defers changing themes until Setup Wizard is done.
private boolean mDeferredThemeEvaluation;
+ // Determines if we should ignore THEME_CUSTOMIZATION_OVERLAY_PACKAGES setting changes.
+ private boolean mSkipSettingChange;
private final DeviceProvisionedListener mDeviceProvisionedListener =
new DeviceProvisionedListener() {
@@ -162,6 +167,35 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
}
}
}
+ // Check if we need to reset to default colors (if a color override was set that is sourced
+ // from the wallpaper)
+ int currentUser = mUserTracker.getUserId();
+ String overlayPackageJson = mSecureSettings.getStringForUser(
+ Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES,
+ currentUser);
+ 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))) {
+ mSkipSettingChange = true;
+ jsonObject.remove(OVERLAY_CATEGORY_ACCENT_COLOR);
+ jsonObject.remove(OVERLAY_CATEGORY_SYSTEM_PALETTE);
+ jsonObject.remove(OVERLAY_COLOR_SOURCE);
+ jsonObject.put(TIMESTAMP_FIELD, System.currentTimeMillis());
+ if (DEBUG) {
+ Log.d(TAG, "Updating theme setting from "
+ + overlayPackageJson + " to " + jsonObject.toString());
+ }
+ mSecureSettings.putString(Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES,
+ jsonObject.toString());
+ }
+ } catch (JSONException e) {
+ Log.i(TAG, "Failed to parse THEME_CUSTOMIZATION_OVERLAY_PACKAGES.", e);
+ }
+ }
reevaluateSystemTheme(false /* forceReload */);
};
@@ -232,6 +266,11 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
mDeferredThemeEvaluation = true;
return;
}
+ if (mSkipSettingChange) {
+ if (DEBUG) Log.d(TAG, "Skipping setting change");
+ mSkipSettingChange = false;
+ return;
+ }
reevaluateSystemTheme(true /* forceReload */);
}
},
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 2d9d7154d229..9f1dad84b6ce 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/theme/ThemeOverlayControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/theme/ThemeOverlayControllerTest.java
@@ -185,7 +185,8 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
Color.valueOf(Color.BLUE), null);
String jsonString =
- "{\"android.theme.customization.system_palette\":\"override.package.name\"}";
+ "{\"android.theme.customization.system_palette\":\"override.package.name\","
+ + "\"android.theme.customization.color_source\":\"preset\"}";
when(mSecureSettings.getStringForUser(
eq(Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES), anyInt()))
.thenReturn(jsonString);
@@ -203,6 +204,32 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
}
@Test
+ public void onWallpaperColorsChanged_resetThemeIfNotPreset() {
+ // 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\"}";
+ when(mSecureSettings.getStringForUser(
+ eq(Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES), anyInt()))
+ .thenReturn(jsonString);
+
+ 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.system_palette"))
+ .isFalse();
+
+ verify(mThemeOverlayApplier)
+ .applyCurrentUserOverlays(any(), any(), anyInt(), any());
+ }
+
+ @Test
public void onProfileAdded_setsTheme() {
mBroadcastReceiver.getValue().onReceive(null,
new Intent(Intent.ACTION_MANAGED_PROFILE_ADDED));