Lines Matching defs:wallpaper

17 package com.android.server.wallpaper;
80 import android.service.wallpaper.IWallpaperConnection;
81 import android.service.wallpaper.IWallpaperEngine;
82 import android.service.wallpaper.IWallpaperService;
83 import android.service.wallpaper.WallpaperService;
172 * Minimum time between crashes of a wallpaper service for us to consider
173 * restarting it vs. just reverting to the static wallpaper.
178 static final String WALLPAPER_CROP = "wallpaper";
191 * Observes the wallpaper for changes and notifies all IWallpaperServiceCallbacks
192 * that the wallpaper has changed. The CREATE is triggered when there is no
193 * wallpaper set and is created for the first time. The CLOSE_WRITE is triggered
194 * every time the wallpaper is changed.
204 public WallpaperObserver(WallpaperData wallpaper) {
205 super(getWallpaperDir(wallpaper.userId).getAbsolutePath(),
207 mUserId = wallpaper.userId;
208 mWallpaperDir = getWallpaperDir(wallpaper.userId);
209 mWallpaper = wallpaper;
215 WallpaperData wallpaper = null;
218 wallpaper = mLockWallpaperMap.get(mUserId);
220 if (wallpaper == null) {
221 // no lock-specific wallpaper exists, or sys case, handled together
222 wallpaper = mWallpaperMap.get(mUserId);
225 return (wallpaper != null) ? wallpaper : mWallpaper;
237 // System and system+lock changes happen on the system wallpaper input file;
238 // lock-only changes happen on the dedicated lock wallpaper input file
242 WallpaperData wallpaper = dataForEvent(sysWallpaperChanged, lockWallpaperChanged);
249 + " imagePending=" + wallpaper.imageWallpaperPending
250 + " whichPending=0x" + Integer.toHexString(wallpaper.whichPending)
256 // new system-only wallpaper. Tell keyguard about it and make sure it
263 notifyWallpaperColorsChanged(wallpaper, FLAG_LOCK);
269 notifyCallbacksLocked(wallpaper);
270 if (wallpaper.wallpaperComponent == null
272 || wallpaper.imageWallpaperPending) {
289 loadSettingsLocked(wallpaper.userId, true);
291 generateCrop(wallpaper);
295 wallpaper.imageWallpaperPending = false;
297 // If this was the system wallpaper, rebind...
299 false, wallpaper, null);
303 || (wallpaper.whichPending & FLAG_LOCK) != 0) {
305 Slog.i(TAG, "Lock-relevant wallpaper changed");
307 // either a lock-only wallpaper commit or a system+lock event.
309 // we're falling back to displaying the system wallpaper there.
311 mLockWallpaperMap.remove(wallpaper.userId);
318 saveSettingsLocked(wallpaper.userId);
321 if (wallpaper.setComplete != null) {
323 wallpaper.setComplete.onWallpaperChanged();
336 notifyWallpaperColorsChanged(wallpaper, notifyColorsWhich);
373 * was wallpaper theme mode and dark wallpaper was set, therefoe, the theme was dark.
416 WallpaperData wallpaper;
418 wallpaper = mWallpaperMap.get(mCurrentUserId);
427 if (!needUpdateLocked(wallpaper.primaryColors, updatedThemeMode)) {
432 if (wallpaper != null) {
433 notifyWallpaperColorsChanged(wallpaper, FLAG_SYSTEM);
448 private void notifyWallpaperColorsChanged(@NonNull WallpaperData wallpaper, int which) {
452 mColorsChangedListeners.get(wallpaper.userId);
465 needsExtraction = wallpaper.primaryColors == null;
470 notifyColorListeners(wallpaper.primaryColors, which, wallpaper.userId);
473 extractColors(wallpaper);
476 if (wallpaper.primaryColors == null) {
480 notifyColorListeners(wallpaper.primaryColors, which, wallpaper.userId);
540 * @param wallpaper a wallpaper representation
542 private void extractColors(WallpaperData wallpaper) {
547 // Not having a wallpaperComponent means it's a lock screen wallpaper.
548 final boolean imageWallpaper = mImageWallpaper.equals(wallpaper.wallpaperComponent)
549 || wallpaper.wallpaperComponent == null;
550 if (imageWallpaper && wallpaper.cropFile != null && wallpaper.cropFile.exists()) {
551 cropFile = wallpaper.cropFile.getAbsolutePath();
553 wallpaperId = wallpaper.wallpaperId;
566 Slog.w(TAG, "Cannot extract colors because wallpaper could not be read.");
571 if (wallpaper.wallpaperId == wallpaperId) {
572 wallpaper.primaryColors = colors;
575 saveSettingsLocked(wallpaper.userId);
577 Slog.w(TAG, "Not setting primary colors since wallpaper changed");
588 * @param colors a wallpaper primary colors representation
617 * Once a new wallpaper has been written via setWallpaper(...), it needs to be cropped
620 private void generateCrop(WallpaperData wallpaper) {
623 Rect cropHint = new Rect(wallpaper.cropHint);
626 Slog.v(TAG, "Generating crop for new wallpaper(s): 0x"
627 + Integer.toHexString(wallpaper.whichPending)
628 + " to " + wallpaper.cropFile.getName()
630 + ") dim=(" + wallpaper.width + 'x' + wallpaper.height + ')');
636 BitmapFactory.decodeFile(wallpaper.wallpaperFile.getAbsolutePath(), options);
638 Slog.w(TAG, "Invalid wallpaper data");
669 needScale = (wallpaper.height != cropHint.height());
673 Slog.v(TAG, "dims: w=" + wallpaper.width + " h=" + wallpaper.height);
682 Slog.v(TAG, "Null crop of new wallpaper; copying");
684 success = FileUtils.copyFile(wallpaper.wallpaperFile, wallpaper.cropFile);
686 wallpaper.cropFile.delete();
687 // TODO: fall back to default wallpaper in this case
695 wallpaper.wallpaperFile.getAbsolutePath(), false);
703 final int actualScale = cropHint.height() / wallpaper.height;
721 Slog.e(TAG, "Could not decode new wallpaper");
729 final float heightR = ((float)wallpaper.height) / ((float)cropHint.height());
735 destWidth, wallpaper.height, true);
738 Slog.v(TAG, " dims: w=" + wallpaper.width
739 + " h=" + wallpaper.height);
744 f = new FileOutputStream(wallpaper.cropFile);
762 Slog.e(TAG, "Unable to apply new wallpaper");
763 wallpaper.cropFile.delete();
766 if (wallpaper.cropFile.exists()) {
767 boolean didRestorecon = SELinux.restorecon(wallpaper.cropFile.getAbsoluteFile());
790 * ID of the current wallpaper, changed every time anything sets a wallpaper.
791 * This is used for external detection of wallpaper update activity.
802 * Name of the default wallpaper component; might be different from mImageWallpaper
822 * True while the client is writing a new wallpaper
838 * Is the OS allowed to back up this wallpaper imagery?
843 * Resource name if using a picture from the wallpaper gallery
848 * The component name of the currently set live wallpaper.
853 * The component name of the wallpaper that should be set next.
858 * The ID of this wallpaper
874 * List of callbacks registered they should each be notified when the wallpaper is changed.
896 // Called during initialization of a given user's wallpaper bookkeeping
916 /** Time in milliseconds until we expect the wallpaper to reconnect (unless we're in the
917 * middle of an update). If exceeded, the wallpaper gets reset to the system default. */
933 // Don't expect wallpaper services to relaunch during shutdown
943 + ", reverting to built-in wallpaper!");
950 public WallpaperConnection(WallpaperInfo info, WallpaperData wallpaper) {
952 mWallpaper = wallpaper;
976 Slog.e(TAG, "Does not match expected wallpaper component "
986 // wallpaper outage, we do our "wait for reset" work as a continuation,
999 // it for an extended amount of time to avoid having a black wallpaper.
1004 Slog.i(TAG, "Started wallpaper reconnect timeout for " + mWallpaper.wallpaperComponent);
1010 // The wallpaper disappeared. If this isn't a system-default one, track
1022 // wallpaper if its service was shut down twice
1027 Slog.w(TAG, "Reverting to built-in wallpaper!");
1037 Slog.w(TAG, "Reverting to built-in wallpaper!");
1055 * Called by a live wallpaper if its colors have changed.
1056 * @param primaryColors representation of wallpaper primary colors
1072 // It's also the lock screen wallpaper when we don't have a bitmap in there
1091 Slog.w(TAG, "Failed to set wallpaper dimensions", e);
1099 Slog.w(TAG, "Failed to set wallpaper padding", e);
1111 // This will trigger onComputeColors in the wallpaper engine.
1115 Slog.w(TAG, "Failed to request wallpaper colors", e);
1153 WallpaperData wallpaper = mWallpaperMap.get(mCurrentUserId);
1154 if (wallpaper != null) {
1155 final ComponentName wpService = wallpaper.wallpaperComponent;
1160 wallpaper.wallpaperUpdating = false;
1161 clearWallpaperComponentLocked(wallpaper);
1163 wallpaper, null)) {
1166 clearWallpaperLocked(false, FLAG_SYSTEM, wallpaper.userId, null);
1179 WallpaperData wallpaper = mWallpaperMap.get(mCurrentUserId);
1180 if (wallpaper != null) {
1181 if (wallpaper.wallpaperComponent == null
1182 || !wallpaper.wallpaperComponent.getPackageName().equals(packageName)) {
1185 doPackagesChangedLocked(true, wallpaper);
1196 WallpaperData wallpaper = mWallpaperMap.get(mCurrentUserId);
1197 if (wallpaper != null) {
1198 if (wallpaper.wallpaperComponent != null
1199 && wallpaper.wallpaperComponent.getPackageName().equals(packageName)) {
1201 Slog.i(TAG, "Wallpaper service " + wallpaper.wallpaperComponent
1204 wallpaper.wallpaperUpdating = true;
1205 if (wallpaper.connection != null) {
1207 wallpaper.connection.mResetRunnable);
1221 WallpaperData wallpaper = mWallpaperMap.get(mCurrentUserId);
1222 if (wallpaper != null) {
1223 boolean res = doPackagesChangedLocked(doit, wallpaper);
1236 WallpaperData wallpaper = mWallpaperMap.get(mCurrentUserId);
1237 if (wallpaper != null) {
1238 doPackagesChangedLocked(true, wallpaper);
1243 boolean doPackagesChangedLocked(boolean doit, WallpaperData wallpaper) {
1245 if (wallpaper.wallpaperComponent != null) {
1246 int change = isPackageDisappearing(wallpaper.wallpaperComponent
1253 + wallpaper.wallpaperComponent);
1254 clearWallpaperLocked(false, FLAG_SYSTEM, wallpaper.userId, null);
1258 if (wallpaper.nextWallpaperComponent != null) {
1259 int change = isPackageDisappearing(wallpaper.nextWallpaperComponent
1263 wallpaper.nextWallpaperComponent = null;
1266 if (wallpaper.wallpaperComponent != null
1267 && isPackageModified(wallpaper.wallpaperComponent.getPackageName())) {
1269 mContext.getPackageManager().getServiceInfo(wallpaper.wallpaperComponent,
1274 + wallpaper.wallpaperComponent);
1275 clearWallpaperLocked(false, FLAG_SYSTEM, wallpaper.userId, null);
1278 if (wallpaper.nextWallpaperComponent != null
1279 && isPackageModified(wallpaper.nextWallpaperComponent.getPackageName())) {
1281 mContext.getPackageManager().getServiceInfo(wallpaper.nextWallpaperComponent,
1285 wallpaper.nextWallpaperComponent = null;
1326 WallpaperData wallpaper = mWallpaperMap.valueAt(i);
1327 wallpaper.wallpaperObserver.stopWatching();
1335 WallpaperData wallpaper = mWallpaperMap.get(UserHandle.USER_SYSTEM);
1336 // If we think we're going to be using the system image wallpaper imagery, make
1338 if (mImageWallpaper.equals(wallpaper.nextWallpaperComponent)) {
1340 if (!wallpaper.cropExists()) {
1344 generateCrop(wallpaper);
1347 if (!wallpaper.cropExists()) {
1355 Slog.i(TAG, "Nondefault wallpaper component; gracefully ignoring");
1411 void stopObserver(WallpaperData wallpaper) {
1412 if (wallpaper != null) {
1413 if (wallpaper.wallpaperObserver != null) {
1414 wallpaper.wallpaperObserver.stopWatching();
1415 wallpaper.wallpaperObserver = null;
1417 if (wallpaper.themeSettingsObserver != null) {
1418 wallpaper.themeSettingsObserver.stopObserving(mContext);
1419 wallpaper.themeSettingsObserver = null;
1445 // the desired wallpaper is not direct-boot aware, load it now
1453 // operations involving the wallpaper files. This isn't timing-critical,
1499 // Not started watching yet, in case wallpaper data was loaded for other reasons.
1522 void switchWallpaper(WallpaperData wallpaper, IRemoteCallback reply) {
1525 final ComponentName cname = wallpaper.wallpaperComponent != null ?
1526 wallpaper.wallpaperComponent : wallpaper.nextWallpaperComponent;
1527 if (!bindWallpaperComponentLocked(cname, true, false, wallpaper, reply)) {
1528 // We failed to bind the desired wallpaper, but that might
1529 // happen if the wallpaper isn't direct-boot aware
1533 PackageManager.MATCH_DIRECT_BOOT_UNAWARE, wallpaper.userId);
1538 Slog.w(TAG, "Failure starting previous wallpaper; clearing");
1539 clearWallpaperLocked(false, FLAG_SYSTEM, wallpaper.userId, reply);
1542 // We might end up persisting the current wallpaper data
1545 wallpaper.wallpaperComponent = wallpaper.nextWallpaperComponent;
1546 final WallpaperData fallback = new WallpaperData(wallpaper.userId,
1578 // When clearing a wallpaper, broadcast new valid colors
1586 throw new IllegalArgumentException("Must specify exactly one kind of wallpaper to clear");
1589 WallpaperData wallpaper = null;
1591 wallpaper = mLockWallpaperMap.get(userId);
1592 if (wallpaper == null) {
1595 Slog.i(TAG, "Lock wallpaper already cleared");
1600 wallpaper = mWallpaperMap.get(userId);
1601 if (wallpaper == null) {
1604 wallpaper = mWallpaperMap.get(userId);
1607 if (wallpaper == null) {
1613 if (wallpaper.wallpaperFile.exists()) {
1614 wallpaper.wallpaperFile.delete();
1615 wallpaper.cropFile.delete();
1621 Slog.i(TAG, "Notifying keyguard of lock wallpaper clear");
1636 wallpaper.primaryColors = null;
1637 wallpaper.imageWallpaperPending = false;
1641 : null, true, false, wallpaper, reply)) {
1648 // This can happen if the default wallpaper component doesn't
1651 // wallpaper.
1652 Slog.e(TAG, "Default wallpaper component not found!", e);
1653 clearWallpaperComponentLocked(wallpaper);
1681 // User hasn't started yet, so load her settings to peek at the wallpaper
1709 WallpaperData wallpaper = getWallpaperSafeLocked(userId, FLAG_SYSTEM);
1718 if (width != wallpaper.width || height != wallpaper.height) {
1719 wallpaper.width = width;
1720 wallpaper.height = height;
1723 if (wallpaper.connection != null) {
1724 if (wallpaper.connection.mEngine != null) {
1726 wallpaper.connection.mEngine.setDesiredSize(
1730 notifyCallbacksLocked(wallpaper);
1731 } else if (wallpaper.connection.mService != null) {
1735 wallpaper.connection.mDimensionsChanged = true;
1744 WallpaperData wallpaper = mWallpaperMap.get(UserHandle.getCallingUserId());
1745 if (wallpaper != null) {
1746 return wallpaper.width;
1755 WallpaperData wallpaper = mWallpaperMap.get(UserHandle.getCallingUserId());
1756 if (wallpaper != null) {
1757 return wallpaper.height;
1771 WallpaperData wallpaper = getWallpaperSafeLocked(userId, FLAG_SYSTEM);
1776 if (!padding.equals(wallpaper.padding)) {
1777 wallpaper.padding.set(padding);
1780 if (wallpaper.connection != null) {
1781 if (wallpaper.connection.mEngine != null) {
1783 wallpaper.connection.mEngine.setDisplayPadding(padding);
1786 notifyCallbacksLocked(wallpaper);
1787 } else if (wallpaper.connection.mService != null) {
1791 wallpaper.connection.mPaddingChanged = true;
1819 callingPkg, Binder.getCallingUid(), "read wallpaper");
1826 throw new IllegalArgumentException("Must specify exactly one kind of wallpaper to read");
1832 WallpaperData wallpaper = whichSet.get(wallpaperUserId);
1833 if (wallpaper == null) {
1834 // There is no established wallpaper imagery of this type (expected
1841 outParams.putInt("width", wallpaper.width);
1842 outParams.putInt("height", wallpaper.height);
1845 wallpaper.callbacks.register(cb);
1847 if (!wallpaper.cropFile.exists()) {
1850 return ParcelFileDescriptor.open(wallpaper.cropFile, MODE_READ_ONLY);
1853 Slog.w(TAG, "Error getting wallpaper", e);
1864 WallpaperData wallpaper = mWallpaperMap.get(userId);
1865 if (wallpaper != null && wallpaper.connection != null) {
1866 return wallpaper.connection.mInfo;
1878 throw new IllegalArgumentException("Must specify exactly one kind of wallpaper");
1884 WallpaperData wallpaper = map.get(userId);
1885 if (wallpaper != null) {
1886 return wallpaper.wallpaperId;
1937 // Cannot talk to wallpaper engine.
1967 // Try to get the system wallpaper anyway since it might
1968 // also be the lock screen wallpaper
1993 false /* all */, true /* full */, "changing wallpaper", null /* pkg */);
1997 final String msg = "Must specify a valid wallpaper category to set";
2019 WallpaperData wallpaper;
2022 * wallpaper, we need to migrate that image over to being lock-only before
2032 wallpaper = getWallpaperSafeLocked(userId, which);
2035 ParcelFileDescriptor pfd = updateWallpaperBitmapLocked(name, wallpaper, extras);
2037 wallpaper.imageWallpaperPending = true;
2038 wallpaper.whichPending = which;
2039 wallpaper.setComplete = completion;
2040 wallpaper.cropHint.set(cropHint);
2041 wallpaper.allowBackup = allowBackup;
2054 Slog.i(TAG, "No system wallpaper? Not tracking for lock-only");
2059 // We know a-priori that there is no lock-only wallpaper currently
2074 Slog.e(TAG, "Can't migrate system wallpaper: " + e.getMessage());
2083 ParcelFileDescriptor updateWallpaperBitmapLocked(String name, WallpaperData wallpaper,
2087 File dir = getWallpaperDir(wallpaper.userId);
2095 ParcelFileDescriptor fd = ParcelFileDescriptor.open(wallpaper.wallpaperFile,
2097 if (!SELinux.restorecon(wallpaper.wallpaperFile)) {
2100 wallpaper.name = name;
2101 wallpaper.wallpaperId = makeWallpaperIdLocked();
2103 extras.putInt(WallpaperManager.EXTRA_NEW_WALLPAPER_ID, wallpaper.wallpaperId);
2106 wallpaper.primaryColors = null;
2108 Slog.v(TAG, "updateWallpaperBitmapLocked() : id=" + wallpaper.wallpaperId
2109 + " name=" + name + " file=" + wallpaper.wallpaperFile.getName());
2113 Slog.w(TAG, "Error setting wallpaper", e);
2135 false /* all */, true /* full */, "changing live wallpaper", null /* pkg */);
2140 WallpaperData wallpaper;
2144 wallpaper = mWallpaperMap.get(userId);
2145 if (wallpaper == null) {
2151 // system+lock image currently, migrate the system wallpaper to be a lock-only
2153 // wallpaper.
2154 if (mImageWallpaper.equals(wallpaper.wallpaperComponent)) {
2162 // New live wallpaper is also a lock wallpaper if nothing is set
2168 wallpaper.imageWallpaperPending = false;
2169 boolean same = changingToSame(name, wallpaper);
2170 if (bindWallpaperComponentLocked(name, false, true, wallpaper, null)) {
2172 wallpaper.primaryColors = null;
2174 wallpaper.wallpaperId = makeWallpaperIdLocked();
2175 notifyCallbacksLocked(wallpaper);
2184 notifyWallpaperColorsChanged(wallpaper, which);
2188 private boolean changingToSame(ComponentName componentName, WallpaperData wallpaper) {
2189 if (wallpaper.connection != null) {
2190 if (wallpaper.wallpaperComponent == null) {
2193 // Still using default wallpaper.
2196 } else if (wallpaper.wallpaperComponent.equals(componentName)) {
2197 // Changing to same wallpaper.
2198 if (DEBUG) Slog.v(TAG, "same wallpaper");
2206 boolean fromUser, WallpaperData wallpaper, IRemoteCallback reply) {
2211 if (!force && changingToSame(componentName, wallpaper)) {
2219 // Fall back to static image wallpaper
2223 if (DEBUG_LIVE) Slog.v(TAG, "No default component; using image wallpaper");
2226 int serviceUserId = wallpaper.userId;
2230 // The wallpaper component we're trying to use doesn't exist
2231 Slog.w(TAG, "Attempted wallpaper " + componentName + " is unavailable");
2249 // Make sure the selected service is actually a wallpaper service.
2277 String msg = "Selected service is not a wallpaper: "
2289 WallpaperConnection newConn = new WallpaperConnection(wi, wallpaper);
2310 if (wallpaper.userId == mCurrentUserId && mLastWallpaper != null) {
2313 wallpaper.wallpaperComponent = componentName;
2314 wallpaper.connection = newConn;
2317 if (wallpaper.userId == mCurrentUserId) {
2321 mLastWallpaper = wallpaper;
2336 void detachWallpaperLocked(WallpaperData wallpaper) {
2337 if (wallpaper.connection != null) {
2338 if (wallpaper.connection.mReply != null) {
2340 wallpaper.connection.mReply.sendResult(null);
2343 wallpaper.connection.mReply = null;
2345 if (wallpaper.connection.mEngine != null) {
2347 wallpaper.connection.mEngine.destroy();
2351 mContext.unbindService(wallpaper.connection);
2354 Slog.v(TAG, "Removing window token: " + wallpaper.connection.mToken);
2355 mIWindowManager.removeWindowToken(wallpaper.connection.mToken, DEFAULT_DISPLAY);
2358 wallpaper.connection.mService = null;
2359 wallpaper.connection.mEngine = null;
2360 wallpaper.connection = null;
2364 void clearWallpaperComponentLocked(WallpaperData wallpaper) {
2365 wallpaper.wallpaperComponent = null;
2366 detachWallpaperLocked(wallpaper);
2369 void attachServiceLocked(WallpaperConnection conn, WallpaperData wallpaper) {
2373 wallpaper.width, wallpaper.height, wallpaper.padding);
2375 Slog.w(TAG, "Failed attaching wallpaper; clearing", e);
2376 if (!wallpaper.wallpaperUpdating) {
2377 bindWallpaperComponentLocked(null, false, false, wallpaper, null);
2382 private void notifyCallbacksLocked(WallpaperData wallpaper) {
2383 final int n = wallpaper.callbacks.beginBroadcast();
2386 wallpaper.callbacks.getBroadcastItem(i).onWallpaperChanged();
2393 wallpaper.callbacks.finishBroadcast();
2438 WallpaperData wallpaper = (which == FLAG_LOCK)
2441 return (wallpaper != null) ? wallpaper.allowBackup : false;
2460 WallpaperData wallpaper;
2462 wallpaper = mWallpaperMap.get(userId);
2463 if (wallpaper != null) {
2464 writeWallpaperAttributes(out, "wp", wallpaper);
2466 wallpaper = mLockWallpaperMap.get(userId);
2467 if (wallpaper != null) {
2468 writeWallpaperAttributes(out, "kwp", wallpaper);
2483 private void writeWallpaperAttributes(XmlSerializer out, String tag, WallpaperData wallpaper)
2486 Slog.v(TAG, "writeWallpaperAttributes id=" + wallpaper.wallpaperId);
2489 out.attribute(null, "id", Integer.toString(wallpaper.wallpaperId));
2490 out.attribute(null, "width", Integer.toString(wallpaper.width));
2491 out.attribute(null, "height", Integer.toString(wallpaper.height));
2493 out.attribute(null, "cropLeft", Integer.toString(wallpaper.cropHint.left));
2494 out.attribute(null, "cropTop", Integer.toString(wallpaper.cropHint.top));
2495 out.attribute(null, "cropRight", Integer.toString(wallpaper.cropHint.right));
2496 out.attribute(null, "cropBottom", Integer.toString(wallpaper.cropHint.bottom));
2498 if (wallpaper.padding.left != 0) {
2499 out.attribute(null, "paddingLeft", Integer.toString(wallpaper.padding.left));
2501 if (wallpaper.padding.top != 0) {
2502 out.attribute(null, "paddingTop", Integer.toString(wallpaper.padding.top));
2504 if (wallpaper.padding.right != 0) {
2505 out.attribute(null, "paddingRight", Integer.toString(wallpaper.padding.right));
2507 if (wallpaper.padding.bottom != 0) {
2508 out.attribute(null, "paddingBottom", Integer.toString(wallpaper.padding.bottom));
2511 if (wallpaper.primaryColors != null) {
2512 int colorsCount = wallpaper.primaryColors.getMainColors().size();
2516 final Color wc = wallpaper.primaryColors.getMainColors().get(i);
2521 Integer.toString(wallpaper.primaryColors.getColorHints()));
2524 out.attribute(null, "name", wallpaper.name);
2525 if (wallpaper.wallpaperComponent != null
2526 && !wallpaper.wallpaperComponent.equals(mImageWallpaper)) {
2528 wallpaper.wallpaperComponent.flattenToShortString());
2531 if (wallpaper.allowBackup) {
2545 // Migrations from earlier wallpaper image storage schemas
2548 // we've got the 'wallpaper' crop file but not the nominal source image,
2551 Slog.i(TAG, "Migrating wallpaper schema");
2558 Slog.i(TAG, "Migrating antique wallpaper schema");
2580 * Sometimes it is expected the wallpaper map may not have a user's data. E.g. This could
2586 * Important: this method loads settings to initialize the given user's wallpaper data if
2590 // We're setting either just system (work with the system wallpaper),
2591 // both (also work with the system wallpaper), or just the lock
2592 // wallpaper (update against the existing lock wallpaper if any).
2597 WallpaperData wallpaper = whichSet.get(userId);
2598 if (wallpaper == null) {
2602 wallpaper = whichSet.get(userId);
2604 // yet a lock-only wallpaper set for this user, so we need to establish
2606 if (wallpaper == null) {
2608 wallpaper = new WallpaperData(userId,
2610 mLockWallpaperMap.put(userId, wallpaper);
2611 ensureSaneWallpaperData(wallpaper);
2615 Slog.wtf(TAG, "Didn't find wallpaper in non-lock case!");
2616 wallpaper = new WallpaperData(userId, WALLPAPER, WALLPAPER_CROP);
2617 mWallpaperMap.put(userId, wallpaper);
2618 ensureSaneWallpaperData(wallpaper);
2622 return wallpaper;
2630 WallpaperData wallpaper = mWallpaperMap.get(userId);
2631 if (wallpaper == null) {
2635 wallpaper = new WallpaperData(userId, WALLPAPER, WALLPAPER_CROP);
2636 wallpaper.allowBackup = true;
2637 mWallpaperMap.put(userId, wallpaper);
2638 if (!wallpaper.cropExists()) {
2639 if (wallpaper.sourceExists()) {
2640 generateCrop(wallpaper);
2642 Slog.i(TAG, "No static wallpaper imagery; defaults will be shown");
2659 parseWallpaperAttributes(parser, wallpaper, keepDimensionHints);
2661 // A system wallpaper might also be a live wallpaper
2663 wallpaper.nextWallpaperComponent = comp != null
2666 if (wallpaper.nextWallpaperComponent == null
2667 || "android".equals(wallpaper.nextWallpaperComponent
2669 wallpaper.nextWallpaperComponent = mImageWallpaper;
2673 Slog.v(TAG, "mWidth:" + wallpaper.width);
2674 Slog.v(TAG, "mHeight:" + wallpaper.height);
2675 Slog.v(TAG, "cropRect:" + wallpaper.cropHint);
2676 Slog.v(TAG, "primaryColors:" + wallpaper.primaryColors);
2677 Slog.v(TAG, "mName:" + wallpaper.name);
2679 + wallpaper.nextWallpaperComponent);
2682 // keyguard-specific wallpaper for this user
2695 Slog.w(TAG, "no current wallpaper -- first boot?");
2710 wallpaper.width = -1;
2711 wallpaper.height = -1;
2712 wallpaper.cropHint.set(0, 0, 0, 0);
2713 wallpaper.padding.set(0, 0, 0, 0);
2714 wallpaper.name = "";
2718 if (wallpaper.wallpaperId <= 0) {
2719 wallpaper.wallpaperId = makeWallpaperIdLocked();
2721 Slog.w(TAG, "Didn't set wallpaper id in loadSettingsLocked(" + userId
2722 + "); now " + wallpaper.wallpaperId);
2727 ensureSaneWallpaperData(wallpaper);
2734 private void ensureSaneWallpaperData(WallpaperData wallpaper) {
2737 if (wallpaper.width < baseSize) {
2738 wallpaper.width = baseSize;
2740 if (wallpaper.height < baseSize) {
2741 wallpaper.height = baseSize;
2744 if (wallpaper.cropHint.width() <= 0
2745 || wallpaper.cropHint.height() <= 0) {
2746 wallpaper.cropHint.set(0, 0, wallpaper.width, wallpaper.height);
2750 private void parseWallpaperAttributes(XmlPullParser parser, WallpaperData wallpaper,
2754 final int id = wallpaper.wallpaperId = Integer.parseInt(idString);
2759 wallpaper.wallpaperId = makeWallpaperIdLocked();
2763 wallpaper.width = Integer.parseInt(parser.getAttributeValue(null, "width"));
2764 wallpaper.height = Integer.parseInt(parser
2767 wallpaper.cropHint.left = getAttributeInt(parser, "cropLeft", 0);
2768 wallpaper.cropHint.top = getAttributeInt(parser, "cropTop", 0);
2769 wallpaper.cropHint.right = getAttributeInt(parser, "cropRight", 0);
2770 wallpaper.cropHint.bottom = getAttributeInt(parser, "cropBottom", 0);
2771 wallpaper.padding.left = getAttributeInt(parser, "paddingLeft", 0);
2772 wallpaper.padding.top = getAttributeInt(parser, "paddingTop", 0);
2773 wallpaper.padding.right = getAttributeInt(parser, "paddingRight", 0);
2774 wallpaper.padding.bottom = getAttributeInt(parser, "paddingBottom", 0);
2791 wallpaper.primaryColors = new WallpaperColors(primary, secondary, tertiary, colorHints);
2793 wallpaper.name = parser.getAttributeValue(null, "name");
2794 wallpaper.allowBackup = "true".equals(parser.getAttributeValue(null, "backup"));
2812 WallpaperData wallpaper = null;
2816 wallpaper = mWallpaperMap.get(UserHandle.USER_SYSTEM);
2817 wallpaper.wallpaperId = makeWallpaperIdLocked(); // always bump id at restore
2818 wallpaper.allowBackup = true; // by definition if it was restored
2819 if (wallpaper.nextWallpaperComponent != null
2820 && !wallpaper.nextWallpaperComponent.equals(mImageWallpaper)) {
2821 if (!bindWallpaperComponentLocked(wallpaper.nextWallpaperComponent, false, false,
2822 wallpaper, null)) {
2823 // No such live wallpaper or other failure; fall back to the default
2824 // live wallpaper (since the profile being restored indicated that the
2826 bindWallpaperComponentLocked(null, false, false, wallpaper, null);
2830 // If there's a wallpaper name, we use that. If that can't be loaded, then we
2832 if ("".equals(wallpaper.name)) {
2837 success = restoreNamedResourceLocked(wallpaper);
2840 + " id=" + wallpaper.wallpaperId);
2842 generateCrop(wallpaper); // based on the new image + metadata
2843 bindWallpaperComponentLocked(wallpaper.nextWallpaperComponent, true, false,
2844 wallpaper, null);
2850 Slog.e(TAG, "Failed to restore wallpaper: '" + wallpaper.name + "'");
2851 wallpaper.name = "";
2861 boolean restoreNamedResourceLocked(WallpaperData wallpaper) {
2862 if (wallpaper.name.length() > 4 && "res:".equals(wallpaper.name.substring(0, 4))) {
2863 String resName = wallpaper.name.substring(4);
2898 if (wallpaper.wallpaperFile.exists()) {
2899 wallpaper.wallpaperFile.delete();
2900 wallpaper.cropFile.delete();
2902 fos = new FileOutputStream(wallpaper.wallpaperFile);
2903 cos = new FileOutputStream(wallpaper.cropFile);
2913 Slog.v(TAG, "Restored wallpaper: " + resName);
2920 Slog.e(TAG, "IOException while restoring wallpaper ", e);
2942 pw.println("System wallpaper state:");
2944 WallpaperData wallpaper = mWallpaperMap.valueAt(i);
2945 pw.print(" User "); pw.print(wallpaper.userId);
2946 pw.print(": id="); pw.println(wallpaper.wallpaperId);
2948 pw.print(wallpaper.width);
2950 pw.println(wallpaper.height);
2951 pw.print(" mCropHint="); pw.println(wallpaper.cropHint);
2952 pw.print(" mPadding="); pw.println(wallpaper.padding);
2953 pw.print(" mName="); pw.println(wallpaper.name);
2954 pw.print(" mAllowBackup="); pw.println(wallpaper.allowBackup);
2955 pw.print(" mWallpaperComponent="); pw.println(wallpaper.wallpaperComponent);
2956 if (wallpaper.connection != null) {
2957 WallpaperConnection conn = wallpaper.connection;
2972 pw.println(wallpaper.lastDiedTime - SystemClock.uptimeMillis());
2975 pw.println("Lock wallpaper state:");
2977 WallpaperData wallpaper = mLockWallpaperMap.valueAt(i);
2978 pw.print(" User "); pw.print(wallpaper.userId);
2979 pw.print(": id="); pw.println(wallpaper.wallpaperId);
2980 pw.print(" mWidth="); pw.print(wallpaper.width);
2981 pw.print(" mHeight="); pw.println(wallpaper.height);
2982 pw.print(" mCropHint="); pw.println(wallpaper.cropHint);
2983 pw.print(" mPadding="); pw.println(wallpaper.padding);
2984 pw.print(" mName="); pw.println(wallpaper.name);
2985 pw.print(" mAllowBackup="); pw.println(wallpaper.allowBackup);