• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android.backup;
18 
19 import android.content.Context;
20 import android.os.ParcelFileDescriptor;
21 import android.util.Log;
22 
23 import java.io.File;
24 import 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  */
32 public class AbsoluteFileBackupHelper extends FileBackupHelperBase implements BackupHelper {
33     private static final String TAG = "AbsoluteFileBackupHelper";
34     private static final boolean DEBUG = false;
35 
36     Context mContext;
37     String[] mFiles;
38 
AbsoluteFileBackupHelper(Context context, String... files)39     public AbsoluteFileBackupHelper(Context context, String... files) {
40         super(context);
41 
42         mContext = context;
43         mFiles = files;
44     }
45 
46     /**
47      * Based on oldState, determine which of the files from the application's data directory
48      * need to be backed up, write them to the data stream, and fill in newState with the
49      * state as it exists now.
50      */
performBackup(ParcelFileDescriptor oldState, BackupDataOutput data, ParcelFileDescriptor newState)51     public void performBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
52             ParcelFileDescriptor newState) {
53         // use the file paths as the keys, too
54         performBackup_checked(oldState, data, newState, mFiles, mFiles);
55     }
56 
restoreEntity(BackupDataInputStream data)57     public void restoreEntity(BackupDataInputStream data) {
58         if (DEBUG) 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 
67