| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.app.backup; |
| 18 |
|
| 19 |
import android.app.WallpaperManager; |
| 20 |
import android.content.Context; |
| 21 |
import android.os.Environment; |
| 22 |
import android.os.ParcelFileDescriptor; |
| 23 |
import android.os.UserHandle; |
| 24 |
import android.util.Slog; |
| 25 |
|
| 26 |
import java.io.File; |
| 27 |
import java.io.FileInputStream; |
| 28 |
import java.io.IOException; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public class WallpaperBackupHelper extends FileBackupHelperBase implements BackupHelper { |
| 38 |
private static final String TAG = "WallpaperBackupHelper"; |
| 39 |
private static final boolean DEBUG = false; |
| 40 |
|
| 41 |
|
| 42 |
public static final String WALLPAPER_IMAGE_KEY = |
| 43 |
"/data/data/com.android.settings/files/wallpaper"; |
| 44 |
public static final String WALLPAPER_INFO_KEY = "/data/system/wallpaper_info.xml"; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
private static final String STAGE_FILE = |
| 49 |
new File(Environment.getUserSystemDirectory(UserHandle.USER_SYSTEM), |
| 50 |
"wallpaper-tmp").getAbsolutePath(); |
| 51 |
|
| 52 |
private final String[] mKeys; |
| 53 |
private final WallpaperManager mWpm; |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
public WallpaperBackupHelper(Context context, String[] keys) { |
| 63 |
super(context); |
| 64 |
|
| 65 |
mContext = context; |
| 66 |
mKeys = keys; |
| 67 |
|
| 68 |
mWpm = (WallpaperManager) context.getSystemService(Context.WALLPAPER_SERVICE); |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
@Override |
| 77 |
public void performBackup(ParcelFileDescriptor oldState, BackupDataOutput data, |
| 78 |
ParcelFileDescriptor newState) { |
| 79 |
|
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
@Override |
| 87 |
public void restoreEntity(BackupDataInputStream data) { |
| 88 |
if (mWpm == null) { |
| 89 |
Slog.w(TAG, "restoreEntity(): no wallpaper service"); |
| 90 |
return; |
| 91 |
} |
| 92 |
final String key = data.getKey(); |
| 93 |
if (isKeyInList(key, mKeys)) { |
| 94 |
if (key.equals(WALLPAPER_IMAGE_KEY)) { |
| 95 |
|
| 96 |
File stage = new File(STAGE_FILE); |
| 97 |
try { |
| 98 |
if (writeFile(stage, data)) { |
| 99 |
try (FileInputStream in = new FileInputStream(stage)) { |
| 100 |
mWpm.setStream(in); |
| 101 |
} catch (IOException e) { |
| 102 |
Slog.e(TAG, "Unable to set restored wallpaper: " + e.getMessage()); |
| 103 |
} |
| 104 |
} else { |
| 105 |
Slog.e(TAG, "Unable to save restored wallpaper"); |
| 106 |
} |
| 107 |
} finally { |
| 108 |
stage.delete(); |
| 109 |
} |
| 110 |
} |
| 111 |
} |
| 112 |
} |
| 113 |
} |