Fixes lives wallpaper preview and colors not updating after setting

Fixes: b/279576915
Test: manually verified correct behavior on Pixel 7
Change-Id: I2200f73aae9015a3eb532f9cd786a85faca6c9d0
This commit is contained in:
Chris Poultney
2023-05-12 20:11:23 +00:00
parent 28ce92a21f
commit 0185d65791
2 changed files with 23 additions and 15 deletions

View File

@@ -3031,9 +3031,6 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
}
}
final boolean fromForegroundApp = Binder.withCleanCallingIdentity(() ->
mActivityManager.getPackageImportance(callingPackage) == IMPORTANCE_FOREGROUND);
synchronized (mLock) {
if (DEBUG) Slog.v(TAG, "setWallpaper which=0x" + Integer.toHexString(which));
WallpaperData wallpaper;
@@ -3066,7 +3063,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
wallpaper.mSystemWasBoth = systemIsBoth;
wallpaper.mWhich = which;
wallpaper.setComplete = completion;
wallpaper.fromForegroundApp = fromForegroundApp;
wallpaper.fromForegroundApp = isFromForegroundApp(callingPackage);
wallpaper.cropHint.set(cropHint);
wallpaper.allowBackup = allowBackup;
wallpaper.mWallpaperDimAmount = getWallpaperDimAmount();
@@ -3153,27 +3150,28 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
@SetWallpaperFlags int which, int userId) {
if (isWallpaperSupported(callingPackage) && isSetWallpaperAllowed(callingPackage)) {
setWallpaperComponent(name, which, userId);
setWallpaperComponent(name, callingPackage, which, userId);
}
}
// ToDo: Remove this version of the function
@Override
public void setWallpaperComponent(ComponentName name) {
setWallpaperComponent(name, UserHandle.getCallingUserId(), FLAG_SYSTEM);
setWallpaperComponent(name, "", UserHandle.getCallingUserId(), FLAG_SYSTEM);
}
@VisibleForTesting
void setWallpaperComponent(ComponentName name, @SetWallpaperFlags int which, int userId) {
void setWallpaperComponent(ComponentName name, String callingPackage,
@SetWallpaperFlags int which, int userId) {
if (mIsLockscreenLiveWallpaperEnabled) {
setWallpaperComponentInternal(name, which, userId);
setWallpaperComponentInternal(name, callingPackage, which, userId);
} else {
setWallpaperComponentInternalLegacy(name, which, userId);
setWallpaperComponentInternalLegacy(name, callingPackage, which, userId);
}
}
private void setWallpaperComponentInternal(ComponentName name, @SetWallpaperFlags int which,
int userIdIn) {
private void setWallpaperComponentInternal(ComponentName name, String callingPackage,
@SetWallpaperFlags int which, int userIdIn) {
if (DEBUG) {
Slog.v(TAG, "Setting new live wallpaper: which=" + which + ", component: " + name);
}
@@ -3209,6 +3207,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
newWallpaper.imageWallpaperPending = false;
newWallpaper.mWhich = which;
newWallpaper.mSystemWasBoth = systemIsBoth;
newWallpaper.fromForegroundApp = isFromForegroundApp(callingPackage);
final WallpaperDestinationChangeHandler
liveSync = new WallpaperDestinationChangeHandler(
newWallpaper);
@@ -3280,7 +3279,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
}
// TODO(b/266818039) Remove this method
private void setWallpaperComponentInternalLegacy(ComponentName name,
private void setWallpaperComponentInternalLegacy(ComponentName name, String callingPackage,
@SetWallpaperFlags int which, int userId) {
userId = ActivityManager.handleIncomingUser(getCallingPid(), getCallingUid(), userId,
false /* all */, true /* full */, "changing live wallpaper", null /* pkg */);
@@ -3320,6 +3319,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
try {
wallpaper.imageWallpaperPending = false;
wallpaper.mWhich = which;
wallpaper.fromForegroundApp = isFromForegroundApp(callingPackage);
boolean same = changingToSame(name, wallpaper);
if (bindWallpaperComponentLocked(name, false, true, wallpaper, null)) {
if (!same) {
@@ -3679,6 +3679,11 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
}
}
private boolean isFromForegroundApp(String callingPackage) {
return Binder.withCleanCallingIdentity(() ->
mActivityManager.getPackageImportance(callingPackage) == IMPORTANCE_FOREGROUND);
}
/**
* Certain user types do not support wallpapers (e.g. managed profiles). The check is
* implemented through through the OP_WRITE_WALLPAPER AppOp.

View File

@@ -292,7 +292,8 @@ public class WallpaperManagerServiceTests {
verifyLastWallpaperData(testUserId, sDefaultWallpaperComponent);
verifyCurrentSystemData(testUserId);
mService.setWallpaperComponent(sImageWallpaperComponentName, FLAG_SYSTEM, testUserId);
mService.setWallpaperComponent(sImageWallpaperComponentName, sContext.getOpPackageName(),
FLAG_SYSTEM, testUserId);
verifyLastWallpaperData(testUserId, sImageWallpaperComponentName);
verifyCurrentSystemData(testUserId);
@@ -321,7 +322,8 @@ public class WallpaperManagerServiceTests {
WallpaperManagerService.DisplayConnector connector =
mService.mLastWallpaper.connection.getDisplayConnectorOrCreate(DEFAULT_DISPLAY);
mService.setWallpaperComponent(sDefaultWallpaperComponent, FLAG_SYSTEM, testUserId);
mService.setWallpaperComponent(sDefaultWallpaperComponent, sContext.getOpPackageName(),
FLAG_SYSTEM, testUserId);
verify(connector.mEngine).dispatchWallpaperCommand(
eq(COMMAND_REAPPLY), anyInt(), anyInt(), anyInt(), any());
@@ -465,7 +467,8 @@ public class WallpaperManagerServiceTests {
public void testGetAdjustedWallpaperColorsOnDimming() throws RemoteException {
final int testUserId = USER_SYSTEM;
mService.switchUser(testUserId, null);
mService.setWallpaperComponent(sDefaultWallpaperComponent, FLAG_SYSTEM, testUserId);
mService.setWallpaperComponent(sDefaultWallpaperComponent, sContext.getOpPackageName(),
FLAG_SYSTEM, testUserId);
WallpaperData wallpaper = mService.getCurrentWallpaperData(FLAG_SYSTEM, testUserId);
// Mock a wallpaper data with color hints that support dark text and dark theme