• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.IBackupCallback;
20 import android.app.backup.IBackupManager;
21 import android.os.ParcelFileDescriptor;
22 
23 /**
24  * Interface presented by applications being asked to participate in the
25  * backup & restore mechanism.  End user code will not typically implement
26  * this interface directly; they subclass BackupAgent instead.
27  *
28  * {@hide}
29  */
30 oneway interface IBackupAgent {
31     /**
32      * Request that the app perform an incremental backup.
33      *
34      * @param oldState Read-only file containing the description blob of the
35      *        app's data state as of the last backup operation's completion.
36      *        This file is empty or invalid when a full backup is being
37      *        requested.
38      *
39      * @param data Read-write file, empty when onBackup() is called, that
40      *        is the data destination for this backup pass's incrementals.
41      *
42      * @param newState Read-write file, empty when onBackup() is called,
43      *        where the new state blob is to be recorded.
44      *
45      * @param quotaBytes Quota reported by the transport for this backup operation (in bytes).
46      *
47      * @param callbackBinder Binder on which to indicate operation completion.
48      *
49      * @param transportFlags Flags with additional information about the transport.
50      */
doBackup(in ParcelFileDescriptor oldState, in ParcelFileDescriptor data, in ParcelFileDescriptor newState, long quotaBytes, IBackupCallback callbackBinder, int transportFlags)51     void doBackup(in ParcelFileDescriptor oldState,
52             in ParcelFileDescriptor data,
53             in ParcelFileDescriptor newState,
54             long quotaBytes, IBackupCallback callbackBinder, int transportFlags);
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, long appVersionCode, in ParcelFileDescriptor newState, int token, IBackupManager callbackBinder)79     void doRestore(in ParcelFileDescriptor data,
80             long appVersionCode, in ParcelFileDescriptor newState,
81             int token, IBackupManager callbackBinder);
82 
83      /**
84      * Restore an entire data snapshot to the application and pass the list of excluded keys to the
85      * backup agent.
86      *
87      * @param excludedKeys List of keys to be excluded from the restore. It will be passed to the
88      *        backup agent to make it aware of what data has been removed (in case it has any
89      *        application-level implications) as well as the data that should be removed by the
90      *        agent itself.
91      */
doRestoreWithExcludedKeys(in ParcelFileDescriptor data, long appVersionCode, in ParcelFileDescriptor newState, int token, IBackupManager callbackBinder, in List<String> excludedKeys)92     void doRestoreWithExcludedKeys(in ParcelFileDescriptor data,
93             long appVersionCode, in ParcelFileDescriptor newState,
94             int token, IBackupManager callbackBinder, in List<String> excludedKeys);
95 
96     /**
97      * Perform a "full" backup to the given file descriptor.  The output file is presumed
98      * to be a socket or other non-seekable, write-only data sink.  When this method is
99      * called, the app should write all of its files to the output.
100      *
101      * @param data Write-only file to receive the backed-up file content stream.
102      *        The data must be formatted correctly for the resulting archive to be
103      *        legitimate, so that will be tightly controlled by the available API.
104      *
105      * @param quotaBytes Quota reported by the transport for this backup operation (in bytes).
106      *
107      * @param token Opaque token identifying this transaction.  This must
108      *        be echoed back to the backup service binder once the agent is
109      *        finished restoring the application based on the restore data
110      *        contents.
111      *
112      * @param callbackBinder Binder on which to indicate operation completion,
113      *        passed here as a convenience to the agent.
114      *
115      * @param transportFlags Flags with additional information about transport.
116      */
doFullBackup(in ParcelFileDescriptor data, long quotaBytes, int token, IBackupManager callbackBinder, int transportFlags)117     void doFullBackup(in ParcelFileDescriptor data, long quotaBytes, int token,
118             IBackupManager callbackBinder, int transportFlags);
119 
120     /**
121      * Estimate how much data a full backup will deliver
122      */
doMeasureFullBackup(long quotaBytes, int token, IBackupManager callbackBinder, int transportFlags)123     void doMeasureFullBackup(long quotaBytes, int token, IBackupManager callbackBinder,
124             int transportFlags);
125 
126     /**
127      * Tells the application agent that the backup data size exceeded current transport quota.
128      * Later calls to {@link #onBackup(ParcelFileDescriptor, BackupDataOutput, ParcelFileDescriptor)}
129      * and {@link #onFullBackup(FullBackupDataOutput)} could use this information
130      * to reduce backup size under the limit.
131      * However, the quota can change, so do not assume that the value passed in here is absolute,
132      * similarly all subsequent backups should not be restricted to this size.
133      * This callback will be invoked before data has been put onto the wire in a preflight check,
134      * so it is relatively inexpensive to hit your quota.
135      * Apps that hit quota repeatedly without dealing with it can be subject to having their backup
136      * schedule reduced.
137      * The {@code quotaBytes} is a loose guideline b/c of metadata added by the backupmanager
138      * so apps should be more aggressive in trimming their backup set.
139      *
140      * @param backupDataBytes Expected or already processed amount of data.
141      *                        Could be less than total backup size if backup process was interrupted
142      *                        before finish of processing all backup data.
143      * @param quotaBytes Current amount of backup data that is allowed for the app.
144      * @param callbackBinder Binder on which to indicate operation completion.
145      */
doQuotaExceeded(long backupDataBytes, long quotaBytes, IBackupCallback callbackBinder)146     void doQuotaExceeded(long backupDataBytes, long quotaBytes, IBackupCallback callbackBinder);
147 
148     /**
149      * Restore a single "file" to the application.  The file was typically obtained from
150      * a full-backup dataset.  The agent reads 'size' bytes of file content
151      * from the provided file descriptor.
152      *
153      * @param data Read-only pipe delivering the file content itself.
154      *
155      * @param size Size of the file being restored.
156      * @param type Type of file system entity, e.g. FullBackup.TYPE_DIRECTORY.
157      * @param domain Name of the file's semantic domain to which the 'path' argument is a
158      *        relative path.  e.g. FullBackup.DATABASE_TREE_TOKEN.
159      * @param path Relative path of the file within its semantic domain.
160      * @param mode Access mode of the file system entity, e.g. 0660.
161      * @param mtime Last modification time of the file system entity.
162      * @param token Opaque token identifying this transaction.  This must
163      *        be echoed back to the backup service binder once the agent is
164      *        finished restoring the application based on the restore data
165      *        contents.
166      * @param callbackBinder Binder on which to indicate operation completion,
167      *        passed here as a convenience to the agent.
168      */
doRestoreFile(in ParcelFileDescriptor data, long size, int type, String domain, String path, long mode, long mtime, int token, IBackupManager callbackBinder)169     void doRestoreFile(in ParcelFileDescriptor data, long size,
170             int type, String domain, String path, long mode, long mtime,
171             int token, IBackupManager callbackBinder);
172 
173     /**
174      * Provide the app with a canonical "all data has been delivered" end-of-restore
175      * callback so that it can do any postprocessing of the restored data that might
176      * be appropriate.  This is issued after both key/value and full data restore
177      * operations have completed.
178      *
179      * @param token Opaque token identifying this transaction.  This must
180      *        be echoed back to the backup service binder once the agent is
181      *        finished restoring the application based on the restore data
182      *        contents.
183      * @param callbackBinder Binder on which to indicate operation completion,
184      *        passed here as a convenience to the agent.
185      */
doRestoreFinished(int token, IBackupManager callbackBinder)186     void doRestoreFinished(int token, IBackupManager callbackBinder);
187 
188     /**
189      * Out of band: instruct the agent to crash within the client process.  This is used
190      * when the backup infrastructure detects a semantic error post-hoc and needs to
191      * pass the problem back to the app.
192      *
193      * @param message The message to be passed to the agent's application in an exception.
194      */
fail(String message)195     void fail(String message);
196 }
197