BackupTestAgent.java revision d2d9ceb7305d593c1b767bbb05de0082a9af4109
1/*
2 * Copyright (C) 2007 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 com.android.backuptest;
18
19import android.app.BackupAgent;
20import android.backup.BackupDataInput;
21import android.backup.BackupDataOutput;
22import android.backup.FileBackupHelper;
23import android.backup.FileRestoreHelper;
24import android.backup.RestoreHelperDispatcher;
25import android.os.ParcelFileDescriptor;
26import android.util.Log;
27
28import java.io.IOException;
29
30public class BackupTestAgent extends BackupAgent
31{
32    static final String TAG = "BackupTestAgent";
33
34    static final String SHARED_PREFS = "shared_prefs";
35    static final String DATA_FILES = "data_files";
36    static final String[] FILES = new String[] {
37                    BackupTestActivity.FILE_NAME
38                };
39
40    @Override
41    public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
42             ParcelFileDescriptor newState) {
43        Log.d(TAG, "onBackup");
44
45        (new FileBackupHelper(this, DATA_FILES)).performBackup(oldState, data, newState, FILES);
46    }
47
48    @Override
49    public void onRestore(BackupDataInput data, ParcelFileDescriptor newState)
50            throws IOException {
51        Log.d(TAG, "onRestore");
52
53        RestoreHelperDispatcher dispatch = new RestoreHelperDispatcher();
54
55        // dispatch.addHelper(SHARED_PREFS, new SharedPrefsRestoreHelper(this));
56        dispatch.addHelper(DATA_FILES, new FileRestoreHelper(this));
57
58        dispatch.dispatch(data, newState);
59    }
60}
61
62