Skip to content

Commit 004c166

Browse files
author
Christopher Tate
committed
Tweak wallpaper restore acceptance heuristics
We now accept for restore any image that is at least wide enough to fit the screen, and has a height within a comfortable margin of the previously stated target. Bug 17677006 Change-Id: I5937a82ddfbfa0bbb30d568621eb48e4b3533fac
1 parent 5c6756f commit 004c166

1 file changed

Lines changed: 20 additions & 20 deletions

File tree

core/java/android/app/backup/WallpaperBackupHelper.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,17 @@ public WallpaperBackupHelper(Context context, String[] files, String[] keys) {
8080
mFiles = files;
8181
mKeys = keys;
8282

83-
WallpaperManager wpm;
84-
wpm = (WallpaperManager) context.getSystemService(Context.WALLPAPER_SERVICE);
85-
mDesiredMinWidth = (double) wpm.getDesiredMinimumWidth();
83+
final WindowManager wm =
84+
(WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
85+
final WallpaperManager wpm =
86+
(WallpaperManager) context.getSystemService(Context.WALLPAPER_SERVICE);
87+
final Display d = wm.getDefaultDisplay();
88+
final Point size = new Point();
89+
d.getSize(size);
90+
mDesiredMinWidth = size.x;
8691
mDesiredMinHeight = (double) wpm.getDesiredMinimumHeight();
8792

88-
if (mDesiredMinWidth <= 0 || mDesiredMinHeight <= 0) {
89-
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
90-
Display d = wm.getDefaultDisplay();
91-
Point size = new Point();
92-
d.getSize(size);
93-
mDesiredMinWidth = size.x;
93+
if (mDesiredMinHeight <= 0) {
9494
mDesiredMinHeight = size.y;
9595
}
9696

@@ -130,15 +130,12 @@ public void restoreEntity(BackupDataInputStream data) {
130130
if (DEBUG) Slog.d(TAG, "Restoring wallpaper image w=" + options.outWidth
131131
+ " h=" + options.outHeight);
132132

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

0 commit comments

Comments
 (0)