blob: acd20bd8a4a24cea874e1849fd8b758310756b33 [file] [log] [blame]
Kenny Root15a4d2f2010-03-11 18:20:12 -08001/*
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 Tate93e7e222009-06-01 16:49:50 -070017package android.app;
18
Christopher Tate45281862010-03-05 15:46:30 -080019import android.app.backup.BackupAgent;
20import android.app.backup.BackupDataInput;
21import android.app.backup.BackupDataOutput;
22import android.app.backup.FileBackupHelper;
Christopher Tate93e7e222009-06-01 16:49:50 -070023import android.os.ParcelFileDescriptor;
24import android.util.Log;
25
26import java.io.File;
27import java.util.ArrayList;
28import 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
38public 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 Roota3639da2010-02-17 11:06:26 -080068 FileBackupHelper helper = new FileBackupHelper(this,
69 allFiles.toArray(new String[allFiles.size()]));
Joe Onorato06290a42009-06-18 20:10:37 -070070 helper.performBackup(oldState, data, newState);
Christopher Tate93e7e222009-06-01 16:49:50 -070071 }
72
73 @Override
Christopher Tate5cbbf562009-06-22 16:44:51 -070074 public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) {
Christopher Tate93e7e222009-06-01 16:49:50 -070075 }
Christopher Tate93e7e222009-06-01 16:49:50 -070076}