Don't restore wildly wrong sized wallpapers

If the dimensions of the original are sufficiently different from the
device's preferred dimensions, just don't restore the image.  This
avoids bad letterboxing / clipping on e.g. phone <-> tablet data
migration.

The expansion/shrinkage ratios used here allow restores of saved
wallpaper images among HVGA devices, among WVGA variants, and
among tablets; but skip restoring wallpapers across those
categories (where severe clipping or letterboxing would occur).

Bug 3261863

Change-Id: I75e75d6401d18f1df10d75796ee04e21d2302cfa
diff --git a/services/java/com/android/server/SystemBackupAgent.java b/services/java/com/android/server/SystemBackupAgent.java
index fff1874..a1f43b4 100644
--- a/services/java/com/android/server/SystemBackupAgent.java
+++ b/services/java/com/android/server/SystemBackupAgent.java
@@ -16,18 +16,16 @@
 
 package com.android.server;
 
-import android.app.backup.AbsoluteFileBackupHelper;
 import android.app.backup.BackupDataInput;
-import android.app.backup.BackupDataInputStream;
 import android.app.backup.BackupDataOutput;
-import android.app.backup.BackupHelper;
 import android.app.backup.BackupAgentHelper;
+import android.app.backup.WallpaperBackupHelper;
 import android.content.Context;
 import android.os.ParcelFileDescriptor;
 import android.os.ServiceManager;
-import android.os.SystemService;
 import android.util.Slog;
 
+
 import java.io.File;
 import java.io.IOException;
 
@@ -54,7 +52,7 @@
             // TODO: Send a delete for any stored wallpaper image in this case?
             files = new String[] { WALLPAPER_INFO };
         }
-        addHelper("wallpaper", new AbsoluteFileBackupHelper(SystemBackupAgent.this, files));
+        addHelper("wallpaper", new WallpaperBackupHelper(SystemBackupAgent.this, files));
         super.onBackup(oldState, data, newState);
     }
 
@@ -62,12 +60,11 @@
     public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
             throws IOException {
         // On restore, we also support a previous data schema "system_files"
-        addHelper("wallpaper", new AbsoluteFileBackupHelper(SystemBackupAgent.this,
+        addHelper("wallpaper", new WallpaperBackupHelper(SystemBackupAgent.this,
                 new String[] { WALLPAPER_IMAGE, WALLPAPER_INFO }));
-        addHelper("system_files", new AbsoluteFileBackupHelper(SystemBackupAgent.this,
+        addHelper("system_files", new WallpaperBackupHelper(SystemBackupAgent.this,
                 new String[] { WALLPAPER_IMAGE }));
 
-        boolean success = false;
         try {
             super.onRestore(data, appVersionCode, newState);
 
@@ -75,7 +72,7 @@
                     Context.WALLPAPER_SERVICE);
             wallpaper.settingsRestored();
         } catch (IOException ex) {
-            // If there was a failure, delete everything for the wallpaper, this is too aggresive,
+            // If there was a failure, delete everything for the wallpaper, this is too aggressive,
             // but this is hopefully a rare failure.
             Slog.d(TAG, "restore failed", ex);
             (new File(WALLPAPER_IMAGE)).delete();