blob: 80b0174b22c3c107ddbaf0d655e949d0acbe3314 [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
Dianne Hackborna924dc0d2011-02-17 14:22:17 -080019
Christopher Tate45281862010-03-05 15:46:30 -080020import android.app.backup.BackupDataInput;
Christopher Tate45281862010-03-05 15:46:30 -080021import android.app.backup.BackupDataOutput;
Christopher Tatecc84c692010-03-29 14:54:02 -070022import android.app.backup.BackupAgentHelper;
Christopher Tate3f64f8d2010-12-10 17:12:19 -080023import android.app.backup.WallpaperBackupHelper;
Joe Onorato9bb8fd72009-07-28 18:24:51 -070024import android.content.Context;
25import android.os.ParcelFileDescriptor;
26import android.os.ServiceManager;
Joe Onorato8a9b2202010-02-26 18:56:32 -080027import android.util.Slog;
Joe Onorato9bb8fd72009-07-28 18:24:51 -070028
Christopher Tate3f64f8d2010-12-10 17:12:19 -080029
Joe Onorato9bb8fd72009-07-28 18:24:51 -070030import java.io.File;
31import java.io.IOException;
32
33/**
Christopher Tate7c2bb662009-09-20 19:47:46 -070034 * Backup agent for various system-managed data, currently just the system wallpaper
Joe Onorato9bb8fd72009-07-28 18:24:51 -070035 */
Christopher Tatecc84c692010-03-29 14:54:02 -070036public class SystemBackupAgent extends BackupAgentHelper {
Joe Onorato9bb8fd72009-07-28 18:24:51 -070037 private static final String TAG = "SystemBackupAgent";
38
Christopher Tate7c2bb662009-09-20 19:47:46 -070039 // These paths must match what the WallpaperManagerService uses
Joe Onorato9bb8fd72009-07-28 18:24:51 -070040 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
Christopher Tate7c2bb662009-09-20 19:47:46 -070044 public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
45 ParcelFileDescriptor newState) throws IOException {
46 // We only back up the data under the current "wallpaper" schema with metadata
Dan Egnor541fa512009-11-11 17:00:06 -080047 WallpaperManagerService wallpaper = (WallpaperManagerService)ServiceManager.getService(
48 Context.WALLPAPER_SERVICE);
49 String[] files = new String[] { WALLPAPER_IMAGE, WALLPAPER_INFO };
50 if (wallpaper != null && wallpaper.mName != null && wallpaper.mName.length() > 0) {
51 // When the wallpaper has a name, back up the info by itself.
52 // TODO: Don't rely on the innards of the service object like this!
53 // TODO: Send a delete for any stored wallpaper image in this case?
54 files = new String[] { WALLPAPER_INFO };
55 }
Christopher Tate3f64f8d2010-12-10 17:12:19 -080056 addHelper("wallpaper", new WallpaperBackupHelper(SystemBackupAgent.this, files));
Christopher Tate7c2bb662009-09-20 19:47:46 -070057 super.onBackup(oldState, data, newState);
Joe Onorato9bb8fd72009-07-28 18:24:51 -070058 }
59
60 @Override
61 public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
62 throws IOException {
Christopher Tate7c2bb662009-09-20 19:47:46 -070063 // On restore, we also support a previous data schema "system_files"
Christopher Tate3f64f8d2010-12-10 17:12:19 -080064 addHelper("wallpaper", new WallpaperBackupHelper(SystemBackupAgent.this,
Christopher Tate7c2bb662009-09-20 19:47:46 -070065 new String[] { WALLPAPER_IMAGE, WALLPAPER_INFO }));
Christopher Tate3f64f8d2010-12-10 17:12:19 -080066 addHelper("system_files", new WallpaperBackupHelper(SystemBackupAgent.this,
Christopher Tate7c2bb662009-09-20 19:47:46 -070067 new String[] { WALLPAPER_IMAGE }));
68
Joe Onorato9bb8fd72009-07-28 18:24:51 -070069 try {
70 super.onRestore(data, appVersionCode, newState);
71
Dianne Hackborn8cc6a502009-08-05 21:29:42 -070072 WallpaperManagerService wallpaper = (WallpaperManagerService)ServiceManager.getService(
Joe Onorato9bb8fd72009-07-28 18:24:51 -070073 Context.WALLPAPER_SERVICE);
74 wallpaper.settingsRestored();
75 } catch (IOException ex) {
Christopher Tate3f64f8d2010-12-10 17:12:19 -080076 // If there was a failure, delete everything for the wallpaper, this is too aggressive,
Joe Onorato9bb8fd72009-07-28 18:24:51 -070077 // but this is hopefully a rare failure.
Joe Onorato8a9b2202010-02-26 18:56:32 -080078 Slog.d(TAG, "restore failed", ex);
Joe Onorato9bb8fd72009-07-28 18:24:51 -070079 (new File(WALLPAPER_IMAGE)).delete();
80 (new File(WALLPAPER_INFO)).delete();
81 }
82 }
83}