summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/app/WallpaperManager.java40
-rw-r--r--services/core/java/com/android/server/wallpaper/WallpaperManagerService.java85
2 files changed, 110 insertions, 15 deletions
diff --git a/core/java/android/app/WallpaperManager.java b/core/java/android/app/WallpaperManager.java
index 235e90dd96df..39d146b9c8d0 100644
--- a/core/java/android/app/WallpaperManager.java
+++ b/core/java/android/app/WallpaperManager.java
@@ -2476,19 +2476,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
* {@link android.Manifest.permission#SET_WALLPAPER}.
*/
@RequiresPermission(android.Manifest.permission.SET_WALLPAPER)
public void clearWallpaper() {
+ if (isLockscreenLiveWallpaperEnabled()) {
+ clearWallpaper(FLAG_LOCK | FLAG_SYSTEM, mContext.getUserId());
+ return;
+ }
clearWallpaper(FLAG_LOCK, 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
* wallpaper, and must hold the SET_WALLPAPER permission in all
* circumstances.
@@ -2793,8 +2812,9 @@ public class WallpaperManager {
/**
* Remove any currently set system wallpaper, reverting to the system's built-in
- * wallpaper. On success, the intent {@link Intent#ACTION_WALLPAPER_CHANGED}
- * is broadcast.
+ * wallpaper. As opposed to {@link #clearWallpaper()}, this method always set a static wallpaper
+ * 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
* {@link android.Manifest.permission#SET_WALLPAPER}.
@@ -2809,9 +2829,14 @@ public class WallpaperManager {
/**
* 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}
- * parameter, the intent {@link Intent#ACTION_WALLPAPER_CHANGED} will be broadcast
- * upon success.
+ * display for each one. On success, the intent {@link Intent#ACTION_WALLPAPER_CHANGED}
+ * is broadcast.
+ * <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
* {@link #FLAG_LOCK}
@@ -2821,6 +2846,7 @@ public class WallpaperManager {
public void clear(@SetWallpaperFlags int which) throws IOException {
if ((which & FLAG_SYSTEM) != 0) {
clear();
+ if (isLockscreenLiveWallpaperEnabled()) return;
}
if ((which & FLAG_LOCK) != 0) {
clearWallpaper(FLAG_LOCK, mContext.getUserId());
diff --git a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
index c329d6bf2578..1769f060807a 100644
--- a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
+++ b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
@@ -1991,7 +1991,11 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
WallpaperData data = null;
synchronized (mLock) {
- clearWallpaperLocked(false, which, userId, null);
+ if (mIsLockscreenLiveWallpaperEnabled) {
+ clearWallpaperLocked(callingPackage, false, which, userId);
+ } else {
+ clearWallpaperLocked(false, which, userId, null);
+ }
if (which == FLAG_LOCK) {
data = mLockWallpaperMap.get(userId);
@@ -2008,7 +2012,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) {
throw new IllegalArgumentException("Must specify exactly one kind of wallpaper to clear");
}
@@ -3099,8 +3160,13 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
// Migrate the bitmap files outright; no need to copy
try {
- Os.rename(sysWP.wallpaperFile.getAbsolutePath(), lockWP.wallpaperFile.getAbsolutePath());
- Os.rename(sysWP.cropFile.getAbsolutePath(), lockWP.cropFile.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());
+ }
mLockWallpaperMap.put(userId, lockWP);
if (mIsLockscreenLiveWallpaperEnabled) {
SELinux.restorecon(lockWP.wallpaperFile);
@@ -3163,16 +3229,17 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
}
@VisibleForTesting
- void setWallpaperComponent(ComponentName name, String callingPackage,
+ boolean setWallpaperComponent(ComponentName name, String callingPackage,
@SetWallpaperFlags int which, int userId) {
if (mIsLockscreenLiveWallpaperEnabled) {
- setWallpaperComponentInternal(name, callingPackage, which, userId);
+ return setWallpaperComponentInternal(name, callingPackage, which, userId);
} else {
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) {
if (DEBUG) {
Slog.v(TAG, "Setting new live wallpaper: which=" + which + ", component: " + name);
@@ -3183,6 +3250,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
checkPermission(android.Manifest.permission.SET_WALLPAPER_COMPONENT);
boolean shouldNotifyColors = false;
+ boolean bindSuccess;
final WallpaperData newWallpaper;
synchronized (mLock) {
@@ -3231,7 +3299,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
*/
boolean forceRebind = same && systemIsBoth && which == FLAG_SYSTEM;
- boolean bindSuccess = bindWallpaperComponentLocked(name, /* force */
+ bindSuccess = bindWallpaperComponentLocked(name, /* force */
forceRebind, /* fromUser */ true, newWallpaper, callback);
if (bindSuccess) {
if (!same) {
@@ -3281,6 +3349,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
notifyWallpaperColorsChanged(newWallpaper, which);
notifyWallpaperColorsChanged(mFallbackWallpaper, FLAG_SYSTEM);
}
+ return bindSuccess;
}
// TODO(b/266818039) Remove this method