Merge changes I8cd9af52,I86a9f18a into udc-qpr-dev am: 7229d8b76f

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23636757

Change-Id: I6ad159940634006209d41bcf210c588be27a1803
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Aurélien Pomini
2023-06-12 16:46:19 +00:00
committed by Automerger Merge Worker
2 changed files with 116 additions and 15 deletions

View File

@@ -2475,19 +2475,38 @@ public class WallpaperManager {
} }
/** /**
* Reset all wallpaper to the factory default. * Reset all wallpaper to the factory default. As opposed to {@link #clear()}, if the device
* is configured to have a live wallpaper by default, apply it.
* *
* <p>This method requires the caller to hold the permission * <p>This method requires the caller to hold the permission
* {@link android.Manifest.permission#SET_WALLPAPER}. * {@link android.Manifest.permission#SET_WALLPAPER}.
*/ */
@RequiresPermission(android.Manifest.permission.SET_WALLPAPER) @RequiresPermission(android.Manifest.permission.SET_WALLPAPER)
public void clearWallpaper() { public void clearWallpaper() {
if (isLockscreenLiveWallpaperEnabled()) {
clearWallpaper(FLAG_LOCK | FLAG_SYSTEM, mContext.getUserId());
return;
}
clearWallpaper(FLAG_LOCK, mContext.getUserId()); clearWallpaper(FLAG_LOCK, mContext.getUserId());
clearWallpaper(FLAG_SYSTEM, mContext.getUserId()); clearWallpaper(FLAG_SYSTEM, mContext.getUserId());
} }
/** /**
* Clear the wallpaper for a specific user. The caller must hold the * Clear the wallpaper for a specific user.
* <ul>
* <li> When called with {@code which=}{@link #FLAG_LOCK}, clear the lockscreen wallpaper.
* The home screen wallpaper will become visible on the lock screen. </li>
*
* <li> When called with {@code which=}{@link #FLAG_SYSTEM}, revert the home screen
* wallpaper to default. The lockscreen wallpaper will be unchanged: if the previous
* wallpaper was shared between home and lock screen, it will become lock screen only. </li>
*
* <li> When called with {@code which=}({@link #FLAG_LOCK} | {@link #FLAG_SYSTEM}), put the
* default wallpaper on both home and lock screen, removing any user defined wallpaper.</li>
* </ul>
* </p>
*
* The caller must hold the
* INTERACT_ACROSS_USERS_FULL permission to clear another user's * INTERACT_ACROSS_USERS_FULL permission to clear another user's
* wallpaper, and must hold the SET_WALLPAPER permission in all * wallpaper, and must hold the SET_WALLPAPER permission in all
* circumstances. * circumstances.
@@ -2792,8 +2811,9 @@ public class WallpaperManager {
/** /**
* Remove any currently set system wallpaper, reverting to the system's built-in * Remove any currently set system wallpaper, reverting to the system's built-in
* wallpaper. On success, the intent {@link Intent#ACTION_WALLPAPER_CHANGED} * wallpaper. As opposed to {@link #clearWallpaper()}, this method always set a static wallpaper
* is broadcast. * with the default image, even if the device is configured to have a live wallpaper by default.
* On success, the intent {@link Intent#ACTION_WALLPAPER_CHANGED} is broadcast.
* *
* <p>This method requires the caller to hold the permission * <p>This method requires the caller to hold the permission
* {@link android.Manifest.permission#SET_WALLPAPER}. * {@link android.Manifest.permission#SET_WALLPAPER}.
@@ -2808,9 +2828,14 @@ public class WallpaperManager {
/** /**
* Remove one or more currently set wallpapers, reverting to the system default * Remove one or more currently set wallpapers, reverting to the system default
* display for each one. If {@link #FLAG_SYSTEM} is set in the {@code which} * display for each one. On success, the intent {@link Intent#ACTION_WALLPAPER_CHANGED}
* parameter, the intent {@link Intent#ACTION_WALLPAPER_CHANGED} will be broadcast * is broadcast.
* upon success. * <ul>
* <li> If {@link #FLAG_SYSTEM} is set in the {@code which} parameter, put the default
* wallpaper on both home and lock screen, removing any user defined wallpaper. </li>
* <li> When called with {@code which=}{@link #FLAG_LOCK}, clear the lockscreen wallpaper.
* The home screen wallpaper will become visible on the lock screen. </li>
* </ul>
* *
* @param which A bitwise combination of {@link #FLAG_SYSTEM} or * @param which A bitwise combination of {@link #FLAG_SYSTEM} or
* {@link #FLAG_LOCK} * {@link #FLAG_LOCK}
@@ -2820,6 +2845,7 @@ public class WallpaperManager {
public void clear(@SetWallpaperFlags int which) throws IOException { public void clear(@SetWallpaperFlags int which) throws IOException {
if ((which & FLAG_SYSTEM) != 0) { if ((which & FLAG_SYSTEM) != 0) {
clear(); clear();
if (isLockscreenLiveWallpaperEnabled()) return;
} }
if ((which & FLAG_LOCK) != 0) { if ((which & FLAG_LOCK) != 0) {
clearWallpaper(FLAG_LOCK, mContext.getUserId()); clearWallpaper(FLAG_LOCK, mContext.getUserId());

View File

@@ -371,6 +371,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
if (lockedWallpaper != null) { if (lockedWallpaper != null) {
detachWallpaperLocked(lockedWallpaper); detachWallpaperLocked(lockedWallpaper);
} }
clearWallpaperBitmaps(mWallpaper.userId, FLAG_LOCK);
mLockWallpaperMap.remove(wallpaper.userId); mLockWallpaperMap.remove(wallpaper.userId);
notifyColorsWhich |= FLAG_LOCK; notifyColorsWhich |= FLAG_LOCK;
} }
@@ -2036,7 +2037,11 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
WallpaperData data = null; WallpaperData data = null;
synchronized (mLock) { synchronized (mLock) {
if (mIsLockscreenLiveWallpaperEnabled) {
clearWallpaperLocked(callingPackage, false, which, userId);
} else {
clearWallpaperLocked(false, which, userId, null); clearWallpaperLocked(false, which, userId, null);
}
if (which == FLAG_LOCK) { if (which == FLAG_LOCK) {
data = mLockWallpaperMap.get(userId); data = mLockWallpaperMap.get(userId);
@@ -2053,7 +2058,64 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
} }
} }
void clearWallpaperLocked(boolean defaultFailed, int which, int userId, IRemoteCallback reply) { private void clearWallpaperLocked(String callingPackage, boolean defaultFailed,
int which, int userId) {
// Might need to bring it in the first time to establish our rewrite
if (!mWallpaperMap.contains(userId)) {
loadSettingsLocked(userId, false, FLAG_LOCK | FLAG_SYSTEM);
}
final WallpaperData wallpaper = mWallpaperMap.get(userId);
final WallpaperData lockWallpaper = mLockWallpaperMap.get(userId);
if (which == FLAG_LOCK && lockWallpaper == null) {
// It's already gone; we're done.
if (DEBUG) {
Slog.i(TAG, "Lock wallpaper already cleared");
}
return;
}
RuntimeException e = null;
try {
if (userId != mCurrentUserId && !hasCrossUserPermission()) return;
final ComponentName component;
final int finalWhich;
if ((which & FLAG_LOCK) > 0 && lockWallpaper != null) {
clearWallpaperBitmaps(lockWallpaper);
}
if ((which & FLAG_SYSTEM) > 0) {
clearWallpaperBitmaps(wallpaper);
}
// lock only case: set the system wallpaper component to both screens
if (which == FLAG_LOCK) {
component = wallpaper.wallpaperComponent;
finalWhich = FLAG_LOCK | FLAG_SYSTEM;
} else {
component = defaultFailed ? mImageWallpaper : null;
finalWhich = which;
}
boolean success = withCleanCallingIdentity(() -> setWallpaperComponent(
component, callingPackage, finalWhich, userId));
if (success) return;
} catch (IllegalArgumentException e1) {
e = e1;
}
// This can happen if the default wallpaper component doesn't
// exist. This should be a system configuration problem, but
// let's not let it crash the system and just live with no
// wallpaper.
Slog.e(TAG, "Default wallpaper component not found!", e);
withCleanCallingIdentity(() -> clearWallpaperComponentLocked(wallpaper));
}
// TODO(b/266818039) remove this version of the method
private void clearWallpaperLocked(boolean defaultFailed, int which, int userId,
IRemoteCallback reply) {
if (which != FLAG_SYSTEM && which != FLAG_LOCK) { if (which != FLAG_SYSTEM && which != FLAG_LOCK) {
throw new IllegalArgumentException("Must specify exactly one kind of wallpaper to clear"); throw new IllegalArgumentException("Must specify exactly one kind of wallpaper to clear");
} }
@@ -3144,8 +3206,13 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
// Migrate the bitmap files outright; no need to copy // Migrate the bitmap files outright; no need to copy
try { try {
Os.rename(sysWP.wallpaperFile.getAbsolutePath(), lockWP.wallpaperFile.getAbsolutePath()); if (!mIsLockscreenLiveWallpaperEnabled || sysWP.wallpaperFile.exists()) {
Os.rename(sysWP.wallpaperFile.getAbsolutePath(),
lockWP.wallpaperFile.getAbsolutePath());
}
if (!mIsLockscreenLiveWallpaperEnabled || sysWP.cropFile.exists()) {
Os.rename(sysWP.cropFile.getAbsolutePath(), lockWP.cropFile.getAbsolutePath()); Os.rename(sysWP.cropFile.getAbsolutePath(), lockWP.cropFile.getAbsolutePath());
}
mLockWallpaperMap.put(userId, lockWP); mLockWallpaperMap.put(userId, lockWP);
if (mIsLockscreenLiveWallpaperEnabled) { if (mIsLockscreenLiveWallpaperEnabled) {
SELinux.restorecon(lockWP.wallpaperFile); SELinux.restorecon(lockWP.wallpaperFile);
@@ -3208,16 +3275,17 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
} }
@VisibleForTesting @VisibleForTesting
void setWallpaperComponent(ComponentName name, String callingPackage, boolean setWallpaperComponent(ComponentName name, String callingPackage,
@SetWallpaperFlags int which, int userId) { @SetWallpaperFlags int which, int userId) {
if (mIsLockscreenLiveWallpaperEnabled) { if (mIsLockscreenLiveWallpaperEnabled) {
setWallpaperComponentInternal(name, callingPackage, which, userId); return setWallpaperComponentInternal(name, callingPackage, which, userId);
} else { } else {
setWallpaperComponentInternalLegacy(name, callingPackage, which, userId); setWallpaperComponentInternalLegacy(name, callingPackage, which, userId);
return true;
} }
} }
private void setWallpaperComponentInternal(ComponentName name, String callingPackage, private boolean setWallpaperComponentInternal(ComponentName name, String callingPackage,
@SetWallpaperFlags int which, int userIdIn) { @SetWallpaperFlags int which, int userIdIn) {
if (DEBUG) { if (DEBUG) {
Slog.v(TAG, "Setting new live wallpaper: which=" + which + ", component: " + name); Slog.v(TAG, "Setting new live wallpaper: which=" + which + ", component: " + name);
@@ -3228,6 +3296,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
checkPermission(android.Manifest.permission.SET_WALLPAPER_COMPONENT); checkPermission(android.Manifest.permission.SET_WALLPAPER_COMPONENT);
boolean shouldNotifyColors = false; boolean shouldNotifyColors = false;
boolean bindSuccess;
final WallpaperData newWallpaper; final WallpaperData newWallpaper;
synchronized (mLock) { synchronized (mLock) {
@@ -3276,7 +3345,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
*/ */
boolean forceRebind = same && systemIsBoth && which == FLAG_SYSTEM; boolean forceRebind = same && systemIsBoth && which == FLAG_SYSTEM;
boolean bindSuccess = bindWallpaperComponentLocked(name, /* force */ bindSuccess = bindWallpaperComponentLocked(name, /* force */
forceRebind, /* fromUser */ true, newWallpaper, callback); forceRebind, /* fromUser */ true, newWallpaper, callback);
if (bindSuccess) { if (bindSuccess) {
if (!same) { if (!same) {
@@ -3295,8 +3364,10 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
}); });
} }
} }
boolean lockBitmapCleared = false;
if (!mImageWallpaper.equals(newWallpaper.wallpaperComponent)) { if (!mImageWallpaper.equals(newWallpaper.wallpaperComponent)) {
clearWallpaperBitmaps(newWallpaper); clearWallpaperBitmaps(newWallpaper);
lockBitmapCleared = newWallpaper.mWhich == FLAG_LOCK;
} }
newWallpaper.wallpaperId = makeWallpaperIdLocked(); newWallpaper.wallpaperId = makeWallpaperIdLocked();
notifyCallbacksLocked(newWallpaper); notifyCallbacksLocked(newWallpaper);
@@ -3314,6 +3385,9 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
updateEngineFlags(newWallpaper); updateEngineFlags(newWallpaper);
} }
} }
if (!lockBitmapCleared) {
clearWallpaperBitmaps(newWallpaper.userId, FLAG_LOCK);
}
mLockWallpaperMap.remove(newWallpaper.userId); mLockWallpaperMap.remove(newWallpaper.userId);
} }
} }
@@ -3326,6 +3400,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
notifyWallpaperColorsChanged(newWallpaper, which); notifyWallpaperColorsChanged(newWallpaper, which);
notifyWallpaperColorsChanged(mFallbackWallpaper, FLAG_SYSTEM); notifyWallpaperColorsChanged(mFallbackWallpaper, FLAG_SYSTEM);
} }
return bindSuccess;
} }
// TODO(b/266818039) Remove this method // TODO(b/266818039) Remove this method