| Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server; |
| 18 | |
| 19 | import android.backup.AbsoluteFileBackupHelper; |
| 20 | import android.backup.BackupDataInput; |
| 21 | import android.backup.BackupDataInputStream; |
| 22 | import android.backup.BackupDataOutput; |
| 23 | import android.backup.BackupHelper; |
| 24 | import android.backup.BackupHelperAgent; |
| 25 | import android.content.Context; |
| 26 | import android.os.ParcelFileDescriptor; |
| 27 | import android.os.ServiceManager; |
| 28 | import android.os.SystemService; |
| 29 | import android.util.Log; |
| 30 | |
| 31 | import java.io.File; |
| 32 | import java.io.IOException; |
| 33 | |
| 34 | /** |
| Christopher Tate | 7c2bb66 | 2009-09-20 19:47:46 -0700 | [diff] [blame] | 35 | * Backup agent for various system-managed data, currently just the system wallpaper |
| Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 36 | */ |
| 37 | public class SystemBackupAgent extends BackupHelperAgent { |
| 38 | private static final String TAG = "SystemBackupAgent"; |
| 39 | |
| Christopher Tate | 7c2bb66 | 2009-09-20 19:47:46 -0700 | [diff] [blame] | 40 | // These paths must match what the WallpaperManagerService uses |
| Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 41 | private static final String WALLPAPER_IMAGE = "/data/data/com.android.settings/files/wallpaper"; |
| 42 | private static final String WALLPAPER_INFO = "/data/system/wallpaper_info.xml"; |
| 43 | |
| 44 | @Override |
| Christopher Tate | 7c2bb66 | 2009-09-20 19:47:46 -0700 | [diff] [blame] | 45 | public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data, |
| 46 | ParcelFileDescriptor newState) throws IOException { |
| 47 | // We only back up the data under the current "wallpaper" schema with metadata |
| Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 48 | addHelper("wallpaper", new AbsoluteFileBackupHelper(SystemBackupAgent.this, |
| 49 | new String[] { WALLPAPER_IMAGE, WALLPAPER_INFO })); |
| Christopher Tate | 7c2bb66 | 2009-09-20 19:47:46 -0700 | [diff] [blame] | 50 | super.onBackup(oldState, data, newState); |
| Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) |
| 55 | throws IOException { |
| Christopher Tate | 7c2bb66 | 2009-09-20 19:47:46 -0700 | [diff] [blame] | 56 | // On restore, we also support a previous data schema "system_files" |
| 57 | addHelper("wallpaper", new AbsoluteFileBackupHelper(SystemBackupAgent.this, |
| 58 | new String[] { WALLPAPER_IMAGE, WALLPAPER_INFO })); |
| 59 | addHelper("system_files", new AbsoluteFileBackupHelper(SystemBackupAgent.this, |
| 60 | new String[] { WALLPAPER_IMAGE })); |
| 61 | |
| Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 62 | boolean success = false; |
| 63 | try { |
| 64 | super.onRestore(data, appVersionCode, newState); |
| 65 | |
| Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 66 | WallpaperManagerService wallpaper = (WallpaperManagerService)ServiceManager.getService( |
| Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 67 | Context.WALLPAPER_SERVICE); |
| 68 | wallpaper.settingsRestored(); |
| 69 | } catch (IOException ex) { |
| 70 | // If there was a failure, delete everything for the wallpaper, this is too aggresive, |
| 71 | // but this is hopefully a rare failure. |
| 72 | Log.d(TAG, "restore failed", ex); |
| 73 | (new File(WALLPAPER_IMAGE)).delete(); |
| 74 | (new File(WALLPAPER_INFO)).delete(); |
| 75 | } |
| 76 | } |
| 77 | } |