1 /*
2  * Copyright 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.app;
18 
19 import android.app.backup.IBackupManager;
20 import android.os.ParcelFileDescriptor;
21 
22 /**
23  * Interface presented by applications being asked to participate in the
24  * backup & restore mechanism.  End user code will not typically implement
25  * this interface directly; they subclass BackupAgent instead.
26  *
27  * {@hide}
28  */
29 oneway interface IBackupAgent {
30     /**
31      * Request that the app perform an incremental backup.
32      *
33      * @param oldState Read-only file containing the description blob of the
34      *        app's data state as of the last backup operation's completion.
35      *        This file is empty or invalid when a full backup is being
36      *        requested.
37      *
38      * @param data Read-write file, empty when onBackup() is called, that
39      *        is the data destination for this backup pass's incrementals.
40      *
41      * @param newState Read-write file, empty when onBackup() is called,
42      *        where the new state blob is to be recorded.
43      *
44      * @param token Opaque token identifying this transaction.  This must
45      *        be echoed back to the backup service binder once the new
46      *        data has been written to the data and newState files.
47      *
48      * @param callbackBinder Binder on which to indicate operation completion,
49      *        passed here as a convenience to the agent.
50      */
doBackup(in ParcelFileDescriptor oldState, in ParcelFileDescriptor data, in ParcelFileDescriptor newState, int token, IBackupManager callbackBinder)51     void doBackup(in ParcelFileDescriptor oldState,
52             in ParcelFileDescriptor data,
53             in ParcelFileDescriptor newState,
54             int token, IBackupManager callbackBinder);
55 
56     /**
57      * Restore an entire data snapshot to the application.
58      *
59      * @param data Read-only file containing the full data snapshot of the
60      *        app's backup.  This is to be a <i>replacement</i> of the app's
61      *        current data, not to be merged into it.
62      *
63      * @param appVersionCode The android:versionCode attribute of the application
64      *        that created this data set.  This can help the agent distinguish among
65      *        various historical backup content possibilities.
66      *
67      * @param newState Read-write file, empty when onRestore() is called,
68      *        that is to be written with the state description that holds after
69      *        the restore has been completed.
70      *
71      * @param token Opaque token identifying this transaction.  This must
72      *        be echoed back to the backup service binder once the agent is
73      *        finished restoring the application based on the restore data
74      *        contents.
75      *
76      * @param callbackBinder Binder on which to indicate operation completion,
77      *        passed here as a convenience to the agent.
78      */
doRestore(in ParcelFileDescriptor data, int appVersionCode, in ParcelFileDescriptor newState, int token, IBackupManager callbackBinder)79     void doRestore(in ParcelFileDescriptor data,
80             int appVersionCode, in ParcelFileDescriptor newState,
81             int token, IBackupManager callbackBinder);
82 
83     /**
84      * Perform a "full" backup to the given file descriptor.  The output file is presumed
85      * to be a socket or other non-seekable, write-only data sink.  When this method is
86      * called, the app should write all of its files to the output.
87      *
88      * @param data Write-only file to receive the backed-up file content stream.
89      *        The data must be formatted correctly for the resulting archive to be
90      *        legitimate, so that will be tightly controlled by the available API.
91      *
92      * @param token Opaque token identifying this transaction.  This must
93      *        be echoed back to the backup service binder once the agent is
94      *        finished restoring the application based on the restore data
95      *        contents.
96      *
97      * @param callbackBinder Binder on which to indicate operation completion,
98      *        passed here as a convenience to the agent.
99      */
doFullBackup(in ParcelFileDescriptor data, int token, IBackupManager callbackBinder)100     void doFullBackup(in ParcelFileDescriptor data, int token, IBackupManager callbackBinder);
101 
102     /**
103      * Estimate how much data a full backup will deliver
104      */
doMeasureFullBackup(int token, IBackupManager callbackBinder)105     void doMeasureFullBackup(int token, IBackupManager callbackBinder);
106 
107     /**
108      * Restore a single "file" to the application.  The file was typically obtained from
109      * a full-backup dataset.  The agent reads 'size' bytes of file content
110      * from the provided file descriptor.
111      *
112      * @param data Read-only pipe delivering the file content itself.
113      *
114      * @param size Size of the file being restored.
115      * @param type Type of file system entity, e.g. FullBackup.TYPE_DIRECTORY.
116      * @param domain Name of the file's semantic domain to which the 'path' argument is a
117      *        relative path.  e.g. FullBackup.DATABASE_TREE_TOKEN.
118      * @param path Relative path of the file within its semantic domain.
119      * @param mode Access mode of the file system entity, e.g. 0660.
120      * @param mtime Last modification time of the file system entity.
121      * @param token Opaque token identifying this transaction.  This must
122      *        be echoed back to the backup service binder once the agent is
123      *        finished restoring the application based on the restore data
124      *        contents.
125      * @param callbackBinder Binder on which to indicate operation completion,
126      *        passed here as a convenience to the agent.
127      */
doRestoreFile(in ParcelFileDescriptor data, long size, int type, String domain, String path, long mode, long mtime, int token, IBackupManager callbackBinder)128     void doRestoreFile(in ParcelFileDescriptor data, long size,
129             int type, String domain, String path, long mode, long mtime,
130             int token, IBackupManager callbackBinder);
131 
132     /**
133      * Provide the app with a canonical "all data has been delivered" end-of-restore
134      * callback so that it can do any postprocessing of the restored data that might
135      * be appropriate.  This is issued after both key/value and full data restore
136      * operations have completed.
137      *
138      * @param token Opaque token identifying this transaction.  This must
139      *        be echoed back to the backup service binder once the agent is
140      *        finished restoring the application based on the restore data
141      *        contents.
142      * @param callbackBinder Binder on which to indicate operation completion,
143      *        passed here as a convenience to the agent.
144      */
doRestoreFinished(int token, IBackupManager callbackBinder)145     void doRestoreFinished(int token, IBackupManager callbackBinder);
146 
147     /**
148      * Out of band: instruct the agent to crash within the client process.  This is used
149      * when the backup infrastructure detects a semantic error post-hoc and needs to
150      * pass the problem back to the app.
151      *
152      * @param message The message to be passed to the agent's application in an exception.
153      */
fail(String message)154     void fail(String message);
155 }
156