blob: b6819615db222cc1a45dfdf1dc77d3fbc52a4076 [file] [log] [blame]
Joe Onorato9bb8fd72009-07-28 18:24:51 -07001/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
19import android.backup.AbsoluteFileBackupHelper;
20import android.backup.BackupDataInput;
21import android.backup.BackupDataInputStream;
22import android.backup.BackupDataOutput;
23import android.backup.BackupHelper;
24import android.backup.BackupHelperAgent;
25import android.content.Context;
26import android.os.ParcelFileDescriptor;
27import android.os.ServiceManager;
28import android.os.SystemService;
29import android.util.Log;
30
31import java.io.File;
32import java.io.IOException;
33
34/**
35 * Backup agent for various system-managed data
36 */
37public class SystemBackupAgent extends BackupHelperAgent {
38 private static final String TAG = "SystemBackupAgent";
39
40 private static final String WALLPAPER_IMAGE = "/data/data/com.android.settings/files/wallpaper";
41 private static final String WALLPAPER_INFO = "/data/system/wallpaper_info.xml";
42
43 @Override
44 public void onCreate() {
45 addHelper("wallpaper", new AbsoluteFileBackupHelper(SystemBackupAgent.this,
46 new String[] { WALLPAPER_IMAGE, WALLPAPER_INFO }));
47 }
48
49 @Override
50 public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
51 throws IOException {
52 boolean success = false;
53 try {
54 super.onRestore(data, appVersionCode, newState);
55
56 WallpaperService wallpaper = (WallpaperService)ServiceManager.getService(
57 Context.WALLPAPER_SERVICE);
58 wallpaper.settingsRestored();
59 } catch (IOException ex) {
60 // If there was a failure, delete everything for the wallpaper, this is too aggresive,
61 // but this is hopefully a rare failure.
62 Log.d(TAG, "restore failed", ex);
63 (new File(WALLPAPER_IMAGE)).delete();
64 (new File(WALLPAPER_INFO)).delete();
65 }
66 }
67}