Kenny Root | 15a4d2f | 2010-03-11 18:20:12 -0800 | [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 | |
Christopher Tate | 93e7e22 | 2009-06-01 16:49:50 -0700 | [diff] [blame] | 17 | package android.app; |
| 18 | |
Christopher Tate | 4528186 | 2010-03-05 15:46:30 -0800 | [diff] [blame] | 19 | import android.app.backup.BackupAgent; |
| 20 | import android.app.backup.BackupDataInput; |
| 21 | import android.app.backup.BackupDataOutput; |
| 22 | import android.app.backup.FileBackupHelper; |
Christopher Tate | 93e7e22 | 2009-06-01 16:49:50 -0700 | [diff] [blame] | 23 | import android.os.ParcelFileDescriptor; |
| 24 | import android.util.Log; |
| 25 | |
| 26 | import java.io.File; |
| 27 | import java.util.ArrayList; |
| 28 | import java.util.LinkedList; |
| 29 | |
| 30 | /** |
| 31 | * Backs up an application's entire /data/data/<package>/... file system. This |
| 32 | * class is used by the desktop full backup mechanism and is not intended for direct |
| 33 | * use by applications. |
| 34 | * |
| 35 | * {@hide} |
| 36 | */ |
| 37 | |
| 38 | public class FullBackupAgent extends BackupAgent { |
| 39 | // !!! TODO: turn off debugging |
| 40 | private static final String TAG = "FullBackupAgent"; |
| 41 | private static final boolean DEBUG = true; |
| 42 | |
| 43 | @Override |
| 44 | public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data, |
| 45 | ParcelFileDescriptor newState) { |
| 46 | LinkedList<File> dirsToScan = new LinkedList<File>(); |
| 47 | ArrayList<String> allFiles = new ArrayList<String>(); |
| 48 | |
| 49 | // build the list of files in the app's /data/data tree |
| 50 | dirsToScan.add(getFilesDir()); |
| 51 | if (DEBUG) Log.v(TAG, "Backing up dir tree @ " + getFilesDir().getAbsolutePath() + " :"); |
| 52 | while (dirsToScan.size() > 0) { |
| 53 | File dir = dirsToScan.removeFirst(); |
| 54 | File[] contents = dir.listFiles(); |
| 55 | if (contents != null) { |
| 56 | for (File f : contents) { |
| 57 | if (f.isDirectory()) { |
| 58 | dirsToScan.add(f); |
| 59 | } else if (f.isFile()) { |
| 60 | if (DEBUG) Log.v(TAG, " " + f.getAbsolutePath()); |
| 61 | allFiles.add(f.getAbsolutePath()); |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | // That's the file set; now back it all up |
Kenny Root | a3639da | 2010-02-17 11:06:26 -0800 | [diff] [blame] | 68 | FileBackupHelper helper = new FileBackupHelper(this, |
| 69 | allFiles.toArray(new String[allFiles.size()])); |
Joe Onorato | 06290a4 | 2009-06-18 20:10:37 -0700 | [diff] [blame] | 70 | helper.performBackup(oldState, data, newState); |
Christopher Tate | 93e7e22 | 2009-06-01 16:49:50 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | @Override |
Christopher Tate | 5cbbf56 | 2009-06-22 16:44:51 -0700 | [diff] [blame] | 74 | public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) { |
Christopher Tate | 93e7e22 | 2009-06-01 16:49:50 -0700 | [diff] [blame] | 75 | } |
Christopher Tate | 93e7e22 | 2009-06-01 16:49:50 -0700 | [diff] [blame] | 76 | } |