blob: ab246754b5afa8fd350b4fc745a3feb28a73ec70 [file] [log] [blame]
Christopher Tate111bd4a2009-06-24 17:29:38 -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 android.backup;
18
19import android.content.Context;
20import android.os.ParcelFileDescriptor;
21import android.util.Log;
22
23import java.io.File;
24import java.io.FileDescriptor;
25
26/**
27 * Like FileBackupHelper, but takes absolute paths for the files instead of
28 * subpaths of getFilesDir()
29 *
30 * @hide
31 */
32public class AbsoluteFileBackupHelper extends FileBackupHelperBase implements BackupHelper {
33 private static final String TAG = "AbsoluteFileBackupHelper";
34
35 Context mContext;
36 String[] mFiles;
37
38 public AbsoluteFileBackupHelper(Context context, String... files) {
39 super(context);
40
41 mContext = context;
42 mFiles = files;
43 }
44
45 /**
46 * Based on oldState, determine which of the files from the application's data directory
47 * need to be backed up, write them to the data stream, and fill in newState with the
48 * state as it exists now.
49 */
50 public void performBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
51 ParcelFileDescriptor newState) {
52 // use the file paths as the keys, too
53 performBackup_checked(oldState, data, newState, mFiles, mFiles);
54 }
55
56 public void restoreEntity(BackupDataInputStream data) {
57 // TODO: turn this off before ship
58 Log.d(TAG, "got entity '" + data.getKey() + "' size=" + data.size());
59 String key = data.getKey();
60 if (isKeyInList(key, mFiles)) {
61 File f = new File(key);
62 writeFile(f, data);
63 }
64 }
65}
66