Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ebadfb17 authored by Christopher Tate's avatar Christopher Tate
Browse files

Fix wallpaper restore from pre-N devices

The previous path "worked" but left the wallpaper bookkeeping with
incorrect SELinux labeling, which led to cascade failures later on
when apps tried to set new system wallpaper imagery or read the
current image for the picker UI.

We now (a) explicitly label wallpaper files in all change cases,
(b) let the restored imagery flow through the full crop path, as
should have been done in the first place, and as a result (c) lift
the size restrictions on the source image, because now we are doing
a device-appropriate scaling operation on the image.

The "when to crop/scale" test has been slightly relaxed such that
a restored image of exactly the right size now longer triggers a
superfluous factor-1.0 scaling operation.

Bug 30361282

Change-Id: I9a305eea2227952493f64ab78862648cafb816ff
parent dd756c26
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ public class WallpaperBackupHelper extends FileBackupHelperBase implements Backu
    // If 'true', then apply an acceptable-size heuristic at restore time, dropping back
    // to the factory default wallpaper if the restored one differs "too much" from the
    // device's preferred wallpaper image dimensions.
    private static final boolean REJECT_OUTSIZED_RESTORE = true;
    private static final boolean REJECT_OUTSIZED_RESTORE = false;

    // When outsized restore rejection is enabled, this is the maximum ratio between the
    // source and target image heights that will be permitted.  The ratio is checked both
@@ -60,6 +60,9 @@ public class WallpaperBackupHelper extends FileBackupHelperBase implements Backu
    public static final String WALLPAPER_IMAGE =
            new File(Environment.getUserSystemDirectory(UserHandle.USER_SYSTEM),
                    "wallpaper").getAbsolutePath();
    public static final String WALLPAPER_ORIG_IMAGE =
            new File(Environment.getUserSystemDirectory(UserHandle.USER_SYSTEM),
                    "wallpaper_orig").getAbsolutePath();
    public static final String WALLPAPER_INFO =
            new File(Environment.getUserSystemDirectory(UserHandle.USER_SYSTEM),
                    "wallpaper_info.xml").getAbsolutePath();
@@ -199,7 +202,7 @@ public class WallpaperBackupHelper extends FileBackupHelperBase implements Backu
            // since it does not exist anywhere other than the private wallpaper
            // file.
            Slog.d(TAG, "Applying restored wallpaper image.");
            f.renameTo(new File(WALLPAPER_IMAGE));
            f.renameTo(new File(WALLPAPER_ORIG_IMAGE));
        }
    }
}
+3 −3
Original line number Diff line number Diff line
@@ -252,6 +252,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub {
                            if (DEBUG) {
                                Slog.v(TAG, "Wallpaper written; generating crop");
                            }
                            SELinux.restorecon(changedFile);
                            if (moved) {
                                // This is a restore, so generate the crop using any just-restored new
                                // crop guidelines, making sure to preserve our local dimension hints.
@@ -259,7 +260,6 @@ public class WallpaperManagerService extends IWallpaperManager.Stub {
                                if (DEBUG) {
                                    Slog.v(TAG, "moved-to, therefore restore; reloading metadata");
                                }
                                SELinux.restorecon(changedFile);
                                loadSettingsLocked(wallpaper.userId, true);
                            }
                            generateCrop(wallpaper);
@@ -353,8 +353,8 @@ public class WallpaperManagerService extends IWallpaperManager.Stub {
                        (cropHint.bottom > options.outHeight ? options.outHeight - cropHint.bottom : 0));

                // Don't bother cropping if what we're left with is identity
                needCrop = (options.outHeight >= cropHint.height()
                        && options.outWidth >= cropHint.width());
                needCrop = (options.outHeight > cropHint.height()
                        && options.outWidth > cropHint.width());
            }

            // scale if the crop height winds up not matching the recommended metrics