Merge "Fix WallpaperPicker not being able to assign colors" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
db5a7a4ce0
@@ -450,19 +450,23 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
|
||||
OverlayIdentifier systemPalette = categoryToPackage.get(OVERLAY_CATEGORY_SYSTEM_PALETTE);
|
||||
if (mIsMonetEnabled && systemPalette != null && systemPalette.getPackageName() != null) {
|
||||
try {
|
||||
int color = Integer.parseInt(systemPalette.getPackageName().toLowerCase(), 16);
|
||||
String colorString = systemPalette.getPackageName().toLowerCase();
|
||||
if (!colorString.startsWith("#")) {
|
||||
colorString = "#" + colorString;
|
||||
}
|
||||
int color = Color.parseColor(colorString);
|
||||
mNeutralOverlay = getOverlay(color, NEUTRAL);
|
||||
mNeedsOverlayCreation = true;
|
||||
categoryToPackage.remove(OVERLAY_CATEGORY_SYSTEM_PALETTE);
|
||||
} catch (NumberFormatException e) {
|
||||
Log.w(TAG, "Invalid color definition: " + systemPalette.getPackageName());
|
||||
} catch (Exception e) {
|
||||
// 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.
|
||||
Integer.parseInt(systemPalette.getPackageName().toLowerCase(), 16);
|
||||
categoryToPackage.remove(OVERLAY_CATEGORY_SYSTEM_PALETTE);
|
||||
} catch (NumberFormatException e) {
|
||||
// This is a package name. All good, let's continue
|
||||
@@ -473,12 +477,17 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
|
||||
OverlayIdentifier accentPalette = categoryToPackage.get(OVERLAY_CATEGORY_ACCENT_COLOR);
|
||||
if (mIsMonetEnabled && accentPalette != null && accentPalette.getPackageName() != null) {
|
||||
try {
|
||||
int color = Integer.parseInt(accentPalette.getPackageName().toLowerCase(), 16);
|
||||
String colorString = accentPalette.getPackageName().toLowerCase();
|
||||
if (!colorString.startsWith("#")) {
|
||||
colorString = "#" + colorString;
|
||||
}
|
||||
int color = Color.parseColor(colorString);
|
||||
mSecondaryOverlay = getOverlay(color, ACCENT);
|
||||
mNeedsOverlayCreation = true;
|
||||
categoryToPackage.remove(OVERLAY_CATEGORY_ACCENT_COLOR);
|
||||
} catch (NumberFormatException e) {
|
||||
Log.w(TAG, "Invalid color definition: " + accentPalette.getPackageName());
|
||||
} catch (Exception e) {
|
||||
// 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) {
|
||||
try {
|
||||
|
||||
@@ -465,6 +465,44 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
|
||||
any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void catchException_whenPackageNameIsOverlayName() {
|
||||
mDeviceProvisionedController = mock(DeviceProvisionedController.class);
|
||||
mThemeOverlayApplier = mock(ThemeOverlayApplier.class);
|
||||
mWallpaperManager = mock(WallpaperManager.class);
|
||||
|
||||
// Assume we have some wallpaper colors at boot.
|
||||
when(mWallpaperManager.getWallpaperColors(anyInt()))
|
||||
.thenReturn(new WallpaperColors(Color.valueOf(Color.GRAY), null, null));
|
||||
|
||||
Executor executor = MoreExecutors.directExecutor();
|
||||
|
||||
mThemeOverlayController = new ThemeOverlayController(null /* context */,
|
||||
mBroadcastDispatcher, mBgHandler, executor, executor, mThemeOverlayApplier,
|
||||
mSecureSettings, mWallpaperManager, mUserManager, mDeviceProvisionedController,
|
||||
mUserTracker, mDumpManager, mFeatureFlags, mWakefulnessLifecycle) {
|
||||
@Nullable
|
||||
@Override
|
||||
protected FabricatedOverlay getOverlay(int color, int type) {
|
||||
FabricatedOverlay overlay = mock(FabricatedOverlay.class);
|
||||
when(overlay.getIdentifier())
|
||||
.thenReturn(new OverlayIdentifier("com.thebest.livewallpaperapp.ever"));
|
||||
|
||||
return overlay;
|
||||
}
|
||||
|
||||
};
|
||||
mThemeOverlayController.start();
|
||||
|
||||
verify(mWallpaperManager).addOnColorsChangedListener(mColorsListener.capture(), eq(null),
|
||||
eq(UserHandle.USER_ALL));
|
||||
verify(mDeviceProvisionedController).addCallback(mDeviceProvisionedListener.capture());
|
||||
|
||||
// Colors were applied during controller initialization.
|
||||
verify(mThemeOverlayApplier).applyCurrentUserOverlays(any(), any(), anyInt(), any());
|
||||
clearInvocations(mThemeOverlayApplier);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onWallpaperColorsChanged_defersUntilSetupIsCompleted_ifHasColors() {
|
||||
mDeviceProvisionedController = mock(DeviceProvisionedController.class);
|
||||
|
||||
Reference in New Issue
Block a user