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

Commit cdf7961f authored by Christopher Tate's avatar Christopher Tate Committed by Android (Google) Code Review
Browse files

Merge "Tweak wallpaper restore acceptance heuristics" into lmp-dev

parents 81e3e472 004c1665
Loading
Loading
Loading
Loading
+20 −20
Original line number Original line Diff line number Diff line
@@ -80,17 +80,17 @@ public class WallpaperBackupHelper extends FileBackupHelperBase implements Backu
        mFiles = files;
        mFiles = files;
        mKeys = keys;
        mKeys = keys;


        WallpaperManager wpm;
        final WindowManager wm =
        wpm = (WallpaperManager) context.getSystemService(Context.WALLPAPER_SERVICE);
                (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        mDesiredMinWidth = (double) wpm.getDesiredMinimumWidth();
        final WallpaperManager wpm =
        mDesiredMinHeight = (double) wpm.getDesiredMinimumHeight();
                (WallpaperManager) context.getSystemService(Context.WALLPAPER_SERVICE);

        final Display d = wm.getDefaultDisplay();
        if (mDesiredMinWidth <= 0 || mDesiredMinHeight <= 0) {
        final Point size = new Point();
            WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
            Display d = wm.getDefaultDisplay();
            Point size = new Point();
        d.getSize(size);
        d.getSize(size);
        mDesiredMinWidth = size.x;
        mDesiredMinWidth = size.x;
        mDesiredMinHeight = (double) wpm.getDesiredMinimumHeight();

        if (mDesiredMinHeight <= 0) {
            mDesiredMinHeight = size.y;
            mDesiredMinHeight = size.y;
        }
        }


@@ -130,15 +130,12 @@ public class WallpaperBackupHelper extends FileBackupHelperBase implements Backu
                    if (DEBUG) Slog.d(TAG, "Restoring wallpaper image w=" + options.outWidth
                    if (DEBUG) Slog.d(TAG, "Restoring wallpaper image w=" + options.outWidth
                            + " h=" + options.outHeight);
                            + " h=" + options.outHeight);


                    // How much does the image differ from our preference?  The threshold
                    // We accept any wallpaper that is at least as wide as our preference
                    // here is set to accept any image larger than our target, because
                    // (i.e. wide enough to fill the screen), and is within a comfortable
                    // scaling down is acceptable; but to reject images that are deemed
                    // factor of the target height, to avoid significant clipping/scaling/
                    // "too small" to scale up attractively.  The value 1.33 is just barely
                    // letterboxing.
                    // too low to pass Nexus 1 or Droid wallpapers for use on a Xoom, but
                    final double heightRatio = mDesiredMinHeight / options.outHeight;
                    // will pass anything relatively larger.
                    if (options.outWidth >= mDesiredMinWidth
                    double widthRatio = mDesiredMinWidth / options.outWidth;
                    double heightRatio = mDesiredMinHeight / options.outHeight;
                    if (widthRatio > 0 && widthRatio < 1.33
                            && heightRatio > 0 && heightRatio < 1.33) {
                            && heightRatio > 0 && heightRatio < 1.33) {
                        // sufficiently close to our resolution; go ahead and use it
                        // sufficiently close to our resolution; go ahead and use it
                        Slog.d(TAG, "Applying restored wallpaper image.");
                        Slog.d(TAG, "Applying restored wallpaper image.");
@@ -147,8 +144,11 @@ public class WallpaperBackupHelper extends FileBackupHelperBase implements Backu
                        // since it does not exist anywhere other than the private wallpaper
                        // since it does not exist anywhere other than the private wallpaper
                        // file.
                        // file.
                    } else {
                    } else {
                        Slog.i(TAG, "Dimensions too far off; using default wallpaper. wr=" + widthRatio
                        Slog.i(TAG, "Restored image dimensions (w="
                                + " hr=" + heightRatio);
                                + options.outWidth + ", h=" + options.outHeight
                                + ") too far off target (tw="
                                + mDesiredMinWidth + ", th=" + mDesiredMinHeight
                                + "); falling back to default wallpaper.");
                        f.delete();
                        f.delete();
                    }
                    }
                }
                }