Loading packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java +19 −11 Original line number Diff line number Diff line Loading @@ -103,11 +103,11 @@ public class ThemeOverlayController extends SystemUI implements Dumpable { private final boolean mIsMonetEnabled; private UserTracker mUserTracker; private DeviceProvisionedController mDeviceProvisionedController; private WallpaperColors mSystemColors; private WallpaperColors mCurrentColors; 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 // Dominant color extracted from wallpaper, NOT the color used on the overlay protected int mMainWallpaperColor = Color.TRANSPARENT; // Accent color extracted from wallpaper, NOT the color used on the overlay protected int mWallpaperAccentColor = Color.TRANSPARENT; Loading Loading @@ -162,10 +162,17 @@ public class ThemeOverlayController extends SystemUI implements Dumpable { handleWallpaperColors(wallpaperColors, which); }; private int getLatestWallpaperType() { return mWallpaperManager.getWallpaperId(WallpaperManager.FLAG_LOCK) > mWallpaperManager.getWallpaperId(WallpaperManager.FLAG_SYSTEM) ? WallpaperManager.FLAG_LOCK : WallpaperManager.FLAG_SYSTEM; } private void handleWallpaperColors(WallpaperColors wallpaperColors, int flags) { final boolean hadWallpaperColors = mSystemColors != null; if ((flags & WallpaperManager.FLAG_SYSTEM) != 0) { mSystemColors = wallpaperColors; final boolean hadWallpaperColors = mCurrentColors != null; int latestWallpaperType = getLatestWallpaperType(); if ((flags & latestWallpaperType) != 0) { mCurrentColors = wallpaperColors; if (DEBUG) Log.d(TAG, "got new colors: " + wallpaperColors + " where: " + flags); } Loading @@ -183,7 +190,7 @@ public class ThemeOverlayController extends SystemUI implements Dumpable { } else { if (DEBUG) { Log.i(TAG, "During user setup, but allowing first color event: had? " + hadWallpaperColors + " has? " + (mSystemColors != null)); + hadWallpaperColors + " has? " + (mCurrentColors != null)); } } } Loading @@ -198,7 +205,8 @@ public class ThemeOverlayController extends SystemUI implements Dumpable { if (!TextUtils.isEmpty(overlayPackageJson)) { try { JSONObject 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)) { mSkipSettingChange = true; if (jsonObject.has(OVERLAY_CATEGORY_ACCENT_COLOR) || jsonObject.has( OVERLAY_CATEGORY_SYSTEM_PALETTE)) { Loading Loading @@ -314,10 +322,10 @@ 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( WallpaperManager.FLAG_SYSTEM); getLatestWallpaperType()); mMainExecutor.execute(() -> { if (DEBUG) Log.d(TAG, "Boot colors: " + systemColor); mSystemColors = systemColor; mCurrentColors = systemColor; reevaluateSystemTheme(false /* forceReload */); }); }; Loading Loading @@ -348,7 +356,7 @@ public class ThemeOverlayController extends SystemUI implements Dumpable { } private void reevaluateSystemTheme(boolean forceReload) { final WallpaperColors currentColors = mSystemColors; final WallpaperColors currentColors = mCurrentColors; final int mainColor; final int accentCandidate; if (currentColors == null) { Loading Loading @@ -506,7 +514,7 @@ public class ThemeOverlayController extends SystemUI implements Dumpable { @Override public void dump(@NonNull FileDescriptor fd, @NonNull PrintWriter pw, @NonNull String[] args) { pw.println("mSystemColors=" + mSystemColors); pw.println("mSystemColors=" + mCurrentColors); pw.println("mMainWallpaperColor=" + Integer.toHexString(mMainWallpaperColor)); pw.println("mWallpaperAccentColor=" + Integer.toHexString(mWallpaperAccentColor)); pw.println("mSecondaryOverlay=" + mSecondaryOverlay); Loading packages/SystemUI/tests/src/com/android/systemui/theme/ThemeOverlayControllerTest.java +58 −0 Original line number Diff line number Diff line Loading @@ -258,6 +258,7 @@ public class ThemeOverlayControllerTest extends SysuiTestCase { eq(Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES), anyInt())) .thenReturn(jsonString); when(mWallpaperManager.getWallpaperId(WallpaperManager.FLAG_LOCK)).thenReturn(20); when(mWallpaperManager.getWallpaperId(WallpaperManager.FLAG_SYSTEM)).thenReturn(21); mColorsListener.getValue().onColorsChanged(mainColors, WallpaperManager.FLAG_SYSTEM); Loading Loading @@ -301,6 +302,63 @@ public class ThemeOverlayControllerTest extends SysuiTestCase { .applyCurrentUserOverlays(any(), any(), anyInt(), any()); } @Test public void onWallpaperColorsChanged_ResetThemeWhenFromLatestWallpaper() { // Should ask for a new theme when the colors of the last applied wallpaper 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); // SYSTEM wallpaper is the last applied one when(mWallpaperManager.getWallpaperId(WallpaperManager.FLAG_SYSTEM)).thenReturn(2); 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()); verify(mThemeOverlayApplier) .applyCurrentUserOverlays(any(), any(), anyInt(), any()); } @Test public void onWallpaperColorsChanged_keepThemeIfNotLatestWallpaper() { // Shouldn't ask for a new theme when the colors of the wallpaper that is not the last // applied one 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); // SYSTEM wallpaper is the last applied one when(mWallpaperManager.getWallpaperId(WallpaperManager.FLAG_SYSTEM)).thenReturn(2); mColorsListener.getValue().onColorsChanged(mainColors, WallpaperManager.FLAG_LOCK); verify(mSecureSettings, never()).putString( eq(Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES), any()); verify(mThemeOverlayApplier, never()) .applyCurrentUserOverlays(any(), any(), anyInt(), any()); } @Test public void onProfileAdded_setsTheme() { mBroadcastReceiver.getValue().onReceive(null, Loading Loading
packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java +19 −11 Original line number Diff line number Diff line Loading @@ -103,11 +103,11 @@ public class ThemeOverlayController extends SystemUI implements Dumpable { private final boolean mIsMonetEnabled; private UserTracker mUserTracker; private DeviceProvisionedController mDeviceProvisionedController; private WallpaperColors mSystemColors; private WallpaperColors mCurrentColors; 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 // Dominant color extracted from wallpaper, NOT the color used on the overlay protected int mMainWallpaperColor = Color.TRANSPARENT; // Accent color extracted from wallpaper, NOT the color used on the overlay protected int mWallpaperAccentColor = Color.TRANSPARENT; Loading Loading @@ -162,10 +162,17 @@ public class ThemeOverlayController extends SystemUI implements Dumpable { handleWallpaperColors(wallpaperColors, which); }; private int getLatestWallpaperType() { return mWallpaperManager.getWallpaperId(WallpaperManager.FLAG_LOCK) > mWallpaperManager.getWallpaperId(WallpaperManager.FLAG_SYSTEM) ? WallpaperManager.FLAG_LOCK : WallpaperManager.FLAG_SYSTEM; } private void handleWallpaperColors(WallpaperColors wallpaperColors, int flags) { final boolean hadWallpaperColors = mSystemColors != null; if ((flags & WallpaperManager.FLAG_SYSTEM) != 0) { mSystemColors = wallpaperColors; final boolean hadWallpaperColors = mCurrentColors != null; int latestWallpaperType = getLatestWallpaperType(); if ((flags & latestWallpaperType) != 0) { mCurrentColors = wallpaperColors; if (DEBUG) Log.d(TAG, "got new colors: " + wallpaperColors + " where: " + flags); } Loading @@ -183,7 +190,7 @@ public class ThemeOverlayController extends SystemUI implements Dumpable { } else { if (DEBUG) { Log.i(TAG, "During user setup, but allowing first color event: had? " + hadWallpaperColors + " has? " + (mSystemColors != null)); + hadWallpaperColors + " has? " + (mCurrentColors != null)); } } } Loading @@ -198,7 +205,8 @@ public class ThemeOverlayController extends SystemUI implements Dumpable { if (!TextUtils.isEmpty(overlayPackageJson)) { try { JSONObject 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)) { mSkipSettingChange = true; if (jsonObject.has(OVERLAY_CATEGORY_ACCENT_COLOR) || jsonObject.has( OVERLAY_CATEGORY_SYSTEM_PALETTE)) { Loading Loading @@ -314,10 +322,10 @@ 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( WallpaperManager.FLAG_SYSTEM); getLatestWallpaperType()); mMainExecutor.execute(() -> { if (DEBUG) Log.d(TAG, "Boot colors: " + systemColor); mSystemColors = systemColor; mCurrentColors = systemColor; reevaluateSystemTheme(false /* forceReload */); }); }; Loading Loading @@ -348,7 +356,7 @@ public class ThemeOverlayController extends SystemUI implements Dumpable { } private void reevaluateSystemTheme(boolean forceReload) { final WallpaperColors currentColors = mSystemColors; final WallpaperColors currentColors = mCurrentColors; final int mainColor; final int accentCandidate; if (currentColors == null) { Loading Loading @@ -506,7 +514,7 @@ public class ThemeOverlayController extends SystemUI implements Dumpable { @Override public void dump(@NonNull FileDescriptor fd, @NonNull PrintWriter pw, @NonNull String[] args) { pw.println("mSystemColors=" + mSystemColors); pw.println("mSystemColors=" + mCurrentColors); pw.println("mMainWallpaperColor=" + Integer.toHexString(mMainWallpaperColor)); pw.println("mWallpaperAccentColor=" + Integer.toHexString(mWallpaperAccentColor)); pw.println("mSecondaryOverlay=" + mSecondaryOverlay); Loading
packages/SystemUI/tests/src/com/android/systemui/theme/ThemeOverlayControllerTest.java +58 −0 Original line number Diff line number Diff line Loading @@ -258,6 +258,7 @@ public class ThemeOverlayControllerTest extends SysuiTestCase { eq(Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES), anyInt())) .thenReturn(jsonString); when(mWallpaperManager.getWallpaperId(WallpaperManager.FLAG_LOCK)).thenReturn(20); when(mWallpaperManager.getWallpaperId(WallpaperManager.FLAG_SYSTEM)).thenReturn(21); mColorsListener.getValue().onColorsChanged(mainColors, WallpaperManager.FLAG_SYSTEM); Loading Loading @@ -301,6 +302,63 @@ public class ThemeOverlayControllerTest extends SysuiTestCase { .applyCurrentUserOverlays(any(), any(), anyInt(), any()); } @Test public void onWallpaperColorsChanged_ResetThemeWhenFromLatestWallpaper() { // Should ask for a new theme when the colors of the last applied wallpaper 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); // SYSTEM wallpaper is the last applied one when(mWallpaperManager.getWallpaperId(WallpaperManager.FLAG_SYSTEM)).thenReturn(2); 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()); verify(mThemeOverlayApplier) .applyCurrentUserOverlays(any(), any(), anyInt(), any()); } @Test public void onWallpaperColorsChanged_keepThemeIfNotLatestWallpaper() { // Shouldn't ask for a new theme when the colors of the wallpaper that is not the last // applied one 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); // SYSTEM wallpaper is the last applied one when(mWallpaperManager.getWallpaperId(WallpaperManager.FLAG_SYSTEM)).thenReturn(2); mColorsListener.getValue().onColorsChanged(mainColors, WallpaperManager.FLAG_LOCK); verify(mSecureSettings, never()).putString( eq(Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES), any()); verify(mThemeOverlayApplier, never()) .applyCurrentUserOverlays(any(), any(), anyInt(), any()); } @Test public void onProfileAdded_setsTheme() { mBroadcastReceiver.getValue().onReceive(null, Loading