blob: e3f0d54bc1a1a4033005b49605611102ef6e210a [file] [log] [blame]
Joe Onorato1cf58742009-06-12 11:06:24 -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
Christopher Tate45281862010-03-05 15:46:30 -080017package android.app.backup;
Joe Onorato1cf58742009-06-12 11:06:24 -070018
Joe Onoratod2d9ceb2009-06-18 13:11:18 -070019import android.os.ParcelFileDescriptor;
20
Christopher Tatee28290e2010-02-16 15:22:26 -080021/**
Scott Maind17da432010-04-29 21:42:58 -070022 * Defines the calling interface that {@link BackupAgentHelper} uses
Christopher Tate7cc08822010-04-12 18:24:05 -070023 * when dispatching backup and restore operations to the installed helpers.
24 * Applications can define and install their own helpers as well as using those
25 * provided as part of the Android framework.
Kenny Root5a20ea12010-02-23 18:49:11 -080026 * <p>
Christopher Tate7cc08822010-04-12 18:24:05 -070027 * Although multiple helper objects may be installed simultaneously, each helper
28 * is responsible only for handling its own data, and will not see entities
29 * created by other components within the backup system. Invocations of multiple
30 * helpers are performed sequentially by the {@link BackupAgentHelper}, with each
31 * helper given a chance to access its own saved state from within the state record
32 * produced during the previous backup operation.
33 *
34 * @see BackupAgentHelper
35 * @see FileBackupHelper
36 * @see SharedPreferencesBackupHelper
Christopher Tatee28290e2010-02-16 15:22:26 -080037 */
Joe Onorato06290a42009-06-18 20:10:37 -070038public interface BackupHelper {
Joe Onorato5f15d152009-06-16 16:31:35 -040039 /**
Kenny Root5a20ea12010-02-23 18:49:11 -080040 * Based on <code>oldState</code>, determine which of the files from the
41 * application's data directory need to be backed up, write them to
42 * <code>data</code>, and fill in <code>newState</code> with the state as it
43 * exists now.
Christopher Tate7cc08822010-04-12 18:24:05 -070044 * <p>
45 * Implementing this method is much like implementing
Scott Maind17da432010-04-29 21:42:58 -070046 * {@link BackupAgent#onBackup(ParcelFileDescriptor, BackupDataOutput, ParcelFileDescriptor)
47 * onBackup()} &mdash; the method parameters are the same. When this method is invoked the
Christopher Tate7cc08822010-04-12 18:24:05 -070048 * {@code oldState} descriptor points to the beginning of the state data
49 * written during this helper's previous backup operation, and the {@code newState}
50 * descriptor points to the file location at which the helper should write its
51 * new state after performing the backup operation.
52 * <p class="note">
Scott Maind17da432010-04-29 21:42:58 -070053 * <strong>Note:</strong> The helper should not close or seek either the {@code oldState} or
Christopher Tate7cc08822010-04-12 18:24:05 -070054 * the {@code newState} file descriptors.</p>
Scott Maind17da432010-04-29 21:42:58 -070055 *
56 * @param oldState An open, read-only {@link android.os.ParcelFileDescriptor} pointing to the
57 * last backup state provided by the application. May be
58 * <code>null</code>, in which case no prior state is being
59 * provided and the application should perform a full backup.
60 * @param data An open, read/write {@link BackupDataOutput}
61 * pointing to the backup data destination.
62 * Typically the application will use backup helper classes to
63 * write to this file.
64 * @param newState An open, read/write {@link android.os.ParcelFileDescriptor} pointing to an
65 * empty file. The application should record the final backup
66 * state here after writing the requested data to the <code>data</code>
67 * output stream.
Joe Onorato06290a42009-06-18 20:10:37 -070068 */
69 public void performBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
70 ParcelFileDescriptor newState);
71
72 /**
Christopher Tatecc84c692010-03-29 14:54:02 -070073 * Called by {@link android.app.backup.BackupAgentHelper BackupAgentHelper}
Christopher Tate7cc08822010-04-12 18:24:05 -070074 * to restore a single entity from the restore data set. This method will be
75 * called for each entity in the data set that belongs to this handler.
76 * <p class="note">
Scott Maind17da432010-04-29 21:42:58 -070077 * <strong>Note:</strong> Do not close the <code>data</code> stream. Do not read more than
78 * {@link android.app.backup.BackupDataInputStream#size() size()} bytes from
79 * <code>data</code>.</p>
80 *
81 * @param data An open {@link BackupDataInputStream} from which the backup data can be read.
Joe Onorato5f15d152009-06-16 16:31:35 -040082 */
Joe Onoratoefd0fab2009-06-17 16:20:55 -070083 public void restoreEntity(BackupDataInputStream data);
Joe Onorato06290a42009-06-18 20:10:37 -070084
85 /**
Christopher Tatecc84c692010-03-29 14:54:02 -070086 * Called by {@link android.app.backup.BackupAgentHelper BackupAgentHelper}
Christopher Tate4e14a822010-04-08 12:54:23 -070087 * after a restore operation to write the backup state file corresponding to
Christopher Tate7cc08822010-04-12 18:24:05 -070088 * the data as processed by the helper. The data written here will be
89 * available to the helper during the next call to its
Scott Maind17da432010-04-29 21:42:58 -070090 * {@link #performBackup(ParcelFileDescriptor, BackupDataOutput, ParcelFileDescriptor)
91 * performBackup()} method.
Christopher Tate7cc08822010-04-12 18:24:05 -070092 * <p>
Scott Maind17da432010-04-29 21:42:58 -070093 * This method will be called even if the handler's
94 * {@link #restoreEntity(BackupDataInputStream) restoreEntity()} method was never invoked during
Christopher Tate7cc08822010-04-12 18:24:05 -070095 * the restore operation.
96 * <p class="note">
Scott Maind17da432010-04-29 21:42:58 -070097 * <strong>Note:</strong> The helper should not close or seek the {@code newState}
Christopher Tate7cc08822010-04-12 18:24:05 -070098 * file descriptor.</p>
Scott Maind17da432010-04-29 21:42:58 -070099 *
100 * @param newState A {@link android.os.ParcelFileDescriptor} to which the new state will be
101 * written.
Joe Onorato06290a42009-06-18 20:10:37 -0700102 */
Christopher Tate7cc08822010-04-12 18:24:05 -0700103 public void writeNewStateDescription(ParcelFileDescriptor newState);
Joe Onorato1cf58742009-06-12 11:06:24 -0700104}
105