DivestOS/Patches/LineageOS-19.1/android_frameworks_base/0025-Monet_Toggle.patch
Tad c08ce75b03 Churn
Signed-off-by: Tad <tad@spotco.us>
2022-07-13 10:01:32 -04:00

221 lines
11 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: empratyush <codelab@pratyush.dev>
Date: Thu, 24 Mar 2022 11:55:21 +0530
Subject: [PATCH] make monet based theming user configurable
---
core/java/android/provider/Settings.java | 21 +++++
.../theme/ThemeOverlayController.java | 76 +++++++++++--------
2 files changed, 65 insertions(+), 32 deletions(-)
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index d7cc36ff4ae2..72e6362c0a96 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -6341,6 +6341,27 @@ public final class Settings {
return putStringForUser(cr, name, Float.toString(value), userHandle);
}
+ /**
+ * Control whether to enable dynamic monet based theming mode.
+ * @hide
+ */
+ @UnsupportedAppUsage
+ public static final String MONET_MODE = "monet_mode";
+
+ /**
+ * MONET_MODE value for enabled mode.
+ * @hide
+ */
+ @UnsupportedAppUsage
+ public static final int MONET_MODE_ENABLED = 1;
+
+ /**
+ * MONET_MODE value for disabled mode.
+ * @hide
+ */
+ @UnsupportedAppUsage
+ public static final int MONET_MODE_DISABLED = 0;
+
/**
* Control whether to enable adaptive sleep mode.
* @hide
diff --git a/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java b/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java
index 02632cb3fc17..ea97abd4c423 100644
--- a/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java
+++ b/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java
@@ -117,7 +117,6 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
private final SystemSettings mSystemSettings;
private final Executor mMainExecutor;
private final Handler mBgHandler;
- private final boolean mIsMonetEnabled;
private final UserTracker mUserTracker;
private final ConfigurationController mConfigurationController;
private final DeviceProvisionedController mDeviceProvisionedController;
@@ -261,7 +260,11 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
final boolean hadWallpaperColors = mCurrentColors.get(userId) != null;
int latestWallpaperType = getLatestWallpaperType(userId);
if ((flags & latestWallpaperType) != 0) {
- mCurrentColors.put(userId, wallpaperColors);
+ if (isMonetEnabled(userId)){
+ mCurrentColors.put(userId, wallpaperColors);
+ }else{
+ mCurrentColors.put(userId, null);
+ }
if (DEBUG) Log.d(TAG, "got new colors: " + wallpaperColors + " where: " + flags);
}
@@ -358,6 +361,15 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
}
};
+ private boolean isMonetEnabled(int user){
+ return Settings.Secure.getIntForUser(
+ mContext.getContentResolver(),
+ Settings.Secure.MONET_MODE,
+ Settings.Secure.MONET_MODE_ENABLED,
+ user
+ ) == Settings.Secure.MONET_MODE_ENABLED;
+ }
+
@Inject
public ThemeOverlayController(Context context, BroadcastDispatcher broadcastDispatcher,
@Background Handler bgHandler, @Main Executor mainExecutor,
@@ -369,7 +381,6 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
configurationController, SystemSettings systemSettings) {
super(context);
- mIsMonetEnabled = featureFlags.isMonetEnabled();
mConfigurationController = configurationController;
mDeviceProvisionedController = deviceProvisionedController;
mBroadcastDispatcher = broadcastDispatcher;
@@ -441,10 +452,6 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
},
UserHandle.USER_ALL);
- if (!mIsMonetEnabled) {
- return;
- }
-
mUserTracker.addCallback(mUserTrackerCallback, mMainExecutor);
mConfigurationController.addCallback(mConfigurationListener);
@@ -452,8 +459,8 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
// Upon boot, make sure we have the most up to date colors
Runnable updateColors = () -> {
- WallpaperColors systemColor = mWallpaperManager.getWallpaperColors(
- getLatestWallpaperType(mUserTracker.getUserId()));
+ WallpaperColors systemColor =isMonetEnabled(mUserTracker.getUserId())? mWallpaperManager.getWallpaperColors(
+ getLatestWallpaperType(mUserTracker.getUserId())) : null;
Runnable applyColors = () -> {
if (DEBUG) Log.d(TAG, "Boot colors: " + systemColor);
mCurrentColors.put(mUserTracker.getUserId(), systemColor);
@@ -479,7 +486,7 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
@Override
public void onFinishedGoingToSleep() {
final int userId = mUserTracker.getUserId();
- final WallpaperColors colors = mDeferredWallpaperColors.get(userId);
+ final WallpaperColors colors =isMonetEnabled(mUserTracker.getUserId())? mDeferredWallpaperColors.get(userId) : null;
if (colors != null) {
int flags = mDeferredWallpaperColorsFlags.get(userId);
@@ -490,10 +497,27 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
}
}
});
+
+ mSecureSettings.registerContentObserverForUser(
+ Settings.Secure.getUriFor(Settings.Secure.MONET_MODE),
+ false,
+ new ContentObserver(mBgHandler) {
+ @Override
+ public void onChange(boolean selfChange) {
+ super.onChange(selfChange);
+ WallpaperColors color = isMonetEnabled(mUserTracker.getUserId())?
+ mWallpaperManager.getWallpaperColors(WallpaperManager.FLAG_SYSTEM, mUserTracker.getUserId())
+ : null;
+ handleWallpaperColors(color, WallpaperManager.FLAG_SYSTEM, mUserTracker.getUserId());
+ reevaluateSystemTheme(true);
+ }
+ },
+ UserHandle.USER_ALL
+ );
}
private void reevaluateSystemTheme(boolean forceReload) {
- final WallpaperColors currentColors = mCurrentColors.get(mUserTracker.getUserId());
+ final WallpaperColors currentColors =isMonetEnabled(mUserTracker.getUserId())? mCurrentColors.get(mUserTracker.getUserId()) : null;
final int mainColor;
final int accentCandidate;
if (currentColors == null) {
@@ -512,14 +536,12 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
mMainWallpaperColor = mainColor;
mWallpaperAccentColor = accentCandidate;
- if (mIsMonetEnabled) {
- mSecondaryOverlay = getOverlay(mWallpaperAccentColor, ACCENT);
- mNeutralOverlay = getOverlay(mMainWallpaperColor, NEUTRAL);
- mNeedsOverlayCreation = true;
- if (DEBUG) {
- Log.d(TAG, "fetched overlays. accent: " + mSecondaryOverlay
- + " neutral: " + mNeutralOverlay);
- }
+ mSecondaryOverlay = getOverlay(mWallpaperAccentColor, ACCENT);
+ mNeutralOverlay = getOverlay(mMainWallpaperColor, NEUTRAL);
+ mNeedsOverlayCreation = true;
+ if (DEBUG) {
+ Log.d(TAG, "fetched overlays. accent: " + mSecondaryOverlay
+ + " neutral: " + mNeutralOverlay);
}
updateThemeOverlays();
@@ -593,7 +615,7 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
// Let's generate system overlay if the style picker decided to override it.
OverlayIdentifier systemPalette = categoryToPackage.get(OVERLAY_CATEGORY_SYSTEM_PALETTE);
- if (mIsMonetEnabled && systemPalette != null && systemPalette.getPackageName() != null) {
+ if (systemPalette != null && systemPalette.getPackageName() != null) {
try {
String colorString = systemPalette.getPackageName().toLowerCase();
if (!colorString.startsWith("#")) {
@@ -607,20 +629,11 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
// Color.parseColor doesn't catch any exceptions from the calls it makes
Log.w(TAG, "Invalid color definition: " + systemPalette.getPackageName(), e);
}
- } else if (!mIsMonetEnabled && systemPalette != null) {
- try {
- // It's possible that we flipped the flag off and still have a @ColorInt in the
- // setting. We need to sanitize the input, otherwise the overlay transaction will
- // fail.
- categoryToPackage.remove(OVERLAY_CATEGORY_SYSTEM_PALETTE);
- } catch (NumberFormatException e) {
- // This is a package name. All good, let's continue
- }
}
// Same for accent color.
OverlayIdentifier accentPalette = categoryToPackage.get(OVERLAY_CATEGORY_ACCENT_COLOR);
- if (mIsMonetEnabled && accentPalette != null && accentPalette.getPackageName() != null) {
+ if (accentPalette != null && accentPalette.getPackageName() != null) {
try {
String colorString = accentPalette.getPackageName().toLowerCase();
if (!colorString.startsWith("#")) {
@@ -634,7 +647,7 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
// Color.parseColor doesn't catch any exceptions from the calls it makes
Log.w(TAG, "Invalid color definition: " + accentPalette.getPackageName(), e);
}
- } else if (!mIsMonetEnabled && accentPalette != null) {
+ } else if (accentPalette != null) {
try {
Integer.parseInt(accentPalette.getPackageName().toLowerCase(), 16);
categoryToPackage.remove(OVERLAY_CATEGORY_ACCENT_COLOR);
@@ -692,7 +705,6 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
pw.println("mWallpaperAccentColor=" + Integer.toHexString(mWallpaperAccentColor));
pw.println("mSecondaryOverlay=" + mSecondaryOverlay);
pw.println("mNeutralOverlay=" + mNeutralOverlay);
- pw.println("mIsMonetEnabled=" + mIsMonetEnabled);
pw.println("mColorScheme=" + mColorScheme);
pw.println("mNeedsOverlayCreation=" + mNeedsOverlayCreation);
pw.println("mAcceptColorEvents=" + mAcceptColorEvents);