Christopher Tate | 487529a | 2009-04-29 14:03:25 -0700 | [diff] [blame] | 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 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 17 | package android.app; |
Christopher Tate | 487529a | 2009-04-29 14:03:25 -0700 | [diff] [blame] | 18 | |
Bernardo Rufino | 2d87f45 | 2018-06-22 11:47:49 +0100 | [diff] [blame] | 19 | import android.app.backup.IBackupCallback; |
Christopher Tate | 4528186 | 2010-03-05 15:46:30 -0800 | [diff] [blame] | 20 | import android.app.backup.IBackupManager; |
Christopher Tate | 22b8787 | 2009-05-04 16:41:53 -0700 | [diff] [blame] | 21 | import android.os.ParcelFileDescriptor; |
| 22 | |
Christopher Tate | 487529a | 2009-04-29 14:03:25 -0700 | [diff] [blame] | 23 | /** |
| 24 | * Interface presented by applications being asked to participate in the |
Christopher Tate | 4528186 | 2010-03-05 15:46:30 -0800 | [diff] [blame] | 25 | * backup & restore mechanism. End user code will not typically implement |
| 26 | * this interface directly; they subclass BackupAgent instead. |
Christopher Tate | 487529a | 2009-04-29 14:03:25 -0700 | [diff] [blame] | 27 | * |
| 28 | * {@hide} |
Christopher Tate | 22b8787 | 2009-05-04 16:41:53 -0700 | [diff] [blame] | 29 | */ |
Christopher Tate | 44a2790 | 2010-01-27 17:15:49 -0800 | [diff] [blame] | 30 | oneway interface IBackupAgent { |
Christopher Tate | 487529a | 2009-04-29 14:03:25 -0700 | [diff] [blame] | 31 | /** |
| 32 | * Request that the app perform an incremental backup. |
| 33 | * |
Christopher Tate | 22b8787 | 2009-05-04 16:41:53 -0700 | [diff] [blame] | 34 | * @param oldState Read-only file containing the description blob of the |
Christopher Tate | 487529a | 2009-04-29 14:03:25 -0700 | [diff] [blame] | 35 | * app's data state as of the last backup operation's completion. |
Christopher Tate | 22b8787 | 2009-05-04 16:41:53 -0700 | [diff] [blame] | 36 | * This file is empty or invalid when a full backup is being |
| 37 | * requested. |
Christopher Tate | 487529a | 2009-04-29 14:03:25 -0700 | [diff] [blame] | 38 | * |
Christopher Tate | 22b8787 | 2009-05-04 16:41:53 -0700 | [diff] [blame] | 39 | * @param data Read-write file, empty when onBackup() is called, that |
Christopher Tate | 487529a | 2009-04-29 14:03:25 -0700 | [diff] [blame] | 40 | * is the data destination for this backup pass's incrementals. |
| 41 | * |
Christopher Tate | 22b8787 | 2009-05-04 16:41:53 -0700 | [diff] [blame] | 42 | * @param newState Read-write file, empty when onBackup() is called, |
Christopher Tate | 487529a | 2009-04-29 14:03:25 -0700 | [diff] [blame] | 43 | * where the new state blob is to be recorded. |
Christopher Tate | 44a2790 | 2010-01-27 17:15:49 -0800 | [diff] [blame] | 44 | * |
Shreyas Basarge | b6e73c9 | 2017-01-31 20:13:43 +0000 | [diff] [blame] | 45 | * @param quota Quota reported by the transport for this backup operation (in bytes). |
| 46 | * |
Christopher Tate | 44a2790 | 2010-01-27 17:15:49 -0800 | [diff] [blame] | 47 | * @param token Opaque token identifying this transaction. This must |
| 48 | * be echoed back to the backup service binder once the new |
| 49 | * data has been written to the data and newState files. |
| 50 | * |
Bernardo Rufino | 74eee10 | 2018-08-29 16:01:49 +0100 | [diff] [blame] | 51 | * @param callbackBinder Binder on which to indicate operation completion. |
Robert Berry | 39194c0 | 2018-01-11 13:50:56 +0000 | [diff] [blame] | 52 | * |
| 53 | * @param transportFlags Flags with additional information about the transport. |
Christopher Tate | 487529a | 2009-04-29 14:03:25 -0700 | [diff] [blame] | 54 | */ |
Christopher Tate | 22b8787 | 2009-05-04 16:41:53 -0700 | [diff] [blame] | 55 | void doBackup(in ParcelFileDescriptor oldState, |
| 56 | in ParcelFileDescriptor data, |
Christopher Tate | 44a2790 | 2010-01-27 17:15:49 -0800 | [diff] [blame] | 57 | in ParcelFileDescriptor newState, |
Bernardo Rufino | 2d87f45 | 2018-06-22 11:47:49 +0100 | [diff] [blame] | 58 | long quotaBytes, IBackupCallback callbackBinder, int transportFlags); |
Christopher Tate | 487529a | 2009-04-29 14:03:25 -0700 | [diff] [blame] | 59 | |
| 60 | /** |
| 61 | * Restore an entire data snapshot to the application. |
| 62 | * |
Christopher Tate | 22b8787 | 2009-05-04 16:41:53 -0700 | [diff] [blame] | 63 | * @param data Read-only file containing the full data snapshot of the |
Christopher Tate | 487529a | 2009-04-29 14:03:25 -0700 | [diff] [blame] | 64 | * app's backup. This is to be a <i>replacement</i> of the app's |
| 65 | * current data, not to be merged into it. |
| 66 | * |
Christopher Tate | 5cbbf56 | 2009-06-22 16:44:51 -0700 | [diff] [blame] | 67 | * @param appVersionCode The android:versionCode attribute of the application |
| 68 | * that created this data set. This can help the agent distinguish among |
| 69 | * various historical backup content possibilities. |
| 70 | * |
Christopher Tate | 22b8787 | 2009-05-04 16:41:53 -0700 | [diff] [blame] | 71 | * @param newState Read-write file, empty when onRestore() is called, |
Christopher Tate | 487529a | 2009-04-29 14:03:25 -0700 | [diff] [blame] | 72 | * that is to be written with the state description that holds after |
| 73 | * the restore has been completed. |
Christopher Tate | 44a2790 | 2010-01-27 17:15:49 -0800 | [diff] [blame] | 74 | * |
| 75 | * @param token Opaque token identifying this transaction. This must |
| 76 | * be echoed back to the backup service binder once the agent is |
| 77 | * finished restoring the application based on the restore data |
| 78 | * contents. |
| 79 | * |
| 80 | * @param callbackBinder Binder on which to indicate operation completion, |
| 81 | * passed here as a convenience to the agent. |
Christopher Tate | 487529a | 2009-04-29 14:03:25 -0700 | [diff] [blame] | 82 | */ |
Christopher Tate | adfe8b8 | 2014-02-04 16:23:32 -0800 | [diff] [blame] | 83 | void doRestore(in ParcelFileDescriptor data, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 84 | long appVersionCode, in ParcelFileDescriptor newState, |
Christopher Tate | adfe8b8 | 2014-02-04 16:23:32 -0800 | [diff] [blame] | 85 | int token, IBackupManager callbackBinder); |
Christopher Tate | 75a9970 | 2011-05-18 16:28:19 -0700 | [diff] [blame] | 86 | |
Ruslan Tkhakokhov | d7f5fdb4 | 2019-12-10 11:15:45 +0000 | [diff] [blame] | 87 | /** |
| 88 | * Restore an entire data snapshot to the application and pass the list of excluded keys to the |
| 89 | * backup agent. |
| 90 | * |
| 91 | * @param excludedKeys List of keys to be excluded from the restore. It will be passed to the |
| 92 | * backup agent to make it aware of what data has been removed (in case it has any |
| 93 | * application-level implications) as well as the data that should be removed by the |
| 94 | * agent itself. |
| 95 | */ |
| 96 | void doRestoreWithExcludedKeys(in ParcelFileDescriptor data, |
| 97 | long appVersionCode, in ParcelFileDescriptor newState, |
| 98 | int token, IBackupManager callbackBinder, in List<String> excludedKeys); |
| 99 | |
Christopher Tate | 75a9970 | 2011-05-18 16:28:19 -0700 | [diff] [blame] | 100 | /** |
Christopher Tate | 79ec80d | 2011-06-24 14:58:49 -0700 | [diff] [blame] | 101 | * Perform a "full" backup to the given file descriptor. The output file is presumed |
| 102 | * to be a socket or other non-seekable, write-only data sink. When this method is |
| 103 | * called, the app should write all of its files to the output. |
| 104 | * |
| 105 | * @param data Write-only file to receive the backed-up file content stream. |
| 106 | * The data must be formatted correctly for the resulting archive to be |
| 107 | * legitimate, so that will be tightly controlled by the available API. |
| 108 | * |
Shreyas Basarge | b6e73c9 | 2017-01-31 20:13:43 +0000 | [diff] [blame] | 109 | * @param quota Quota reported by the transport for this backup operation (in bytes). |
| 110 | * |
Christopher Tate | 79ec80d | 2011-06-24 14:58:49 -0700 | [diff] [blame] | 111 | * @param token Opaque token identifying this transaction. This must |
| 112 | * be echoed back to the backup service binder once the agent is |
| 113 | * finished restoring the application based on the restore data |
| 114 | * contents. |
| 115 | * |
| 116 | * @param callbackBinder Binder on which to indicate operation completion, |
| 117 | * passed here as a convenience to the agent. |
Robert Berry | 39194c0 | 2018-01-11 13:50:56 +0000 | [diff] [blame] | 118 | * |
| 119 | * @param transportFlags Flags with additional information about transport. |
Christopher Tate | 79ec80d | 2011-06-24 14:58:49 -0700 | [diff] [blame] | 120 | */ |
Robert Berry | 39194c0 | 2018-01-11 13:50:56 +0000 | [diff] [blame] | 121 | void doFullBackup(in ParcelFileDescriptor data, long quotaBytes, int token, |
| 122 | IBackupManager callbackBinder, int transportFlags); |
Christopher Tate | 79ec80d | 2011-06-24 14:58:49 -0700 | [diff] [blame] | 123 | |
| 124 | /** |
Christopher Tate | 11ae768 | 2015-03-24 18:48:10 -0700 | [diff] [blame] | 125 | * Estimate how much data a full backup will deliver |
| 126 | */ |
Robert Berry | 39194c0 | 2018-01-11 13:50:56 +0000 | [diff] [blame] | 127 | void doMeasureFullBackup(long quotaBytes, int token, IBackupManager callbackBinder, |
| 128 | int transportFlags); |
Christopher Tate | 11ae768 | 2015-03-24 18:48:10 -0700 | [diff] [blame] | 129 | |
| 130 | /** |
Sergey Poromov | 872d3b6 | 2016-01-12 15:48:08 +0100 | [diff] [blame] | 131 | * Tells the application agent that the backup data size exceeded current transport quota. |
| 132 | * Later calls to {@link #onBackup(ParcelFileDescriptor, BackupDataOutput, ParcelFileDescriptor)} |
| 133 | * and {@link #onFullBackup(FullBackupDataOutput)} could use this information |
| 134 | * to reduce backup size under the limit. |
| 135 | * However, the quota can change, so do not assume that the value passed in here is absolute, |
| 136 | * similarly all subsequent backups should not be restricted to this size. |
| 137 | * This callback will be invoked before data has been put onto the wire in a preflight check, |
| 138 | * so it is relatively inexpensive to hit your quota. |
| 139 | * Apps that hit quota repeatedly without dealing with it can be subject to having their backup |
| 140 | * schedule reduced. |
| 141 | * The {@code quotaBytes} is a loose guideline b/c of metadata added by the backupmanager |
| 142 | * so apps should be more aggressive in trimming their backup set. |
| 143 | * |
| 144 | * @param backupDataBytes Expected or already processed amount of data. |
| 145 | * Could be less than total backup size if backup process was interrupted |
| 146 | * before finish of processing all backup data. |
| 147 | * @param quotaBytes Current amount of backup data that is allowed for the app. |
Bernardo Rufino | 74eee10 | 2018-08-29 16:01:49 +0100 | [diff] [blame] | 148 | * @param callbackBinder Binder on which to indicate operation completion. |
Sergey Poromov | 872d3b6 | 2016-01-12 15:48:08 +0100 | [diff] [blame] | 149 | */ |
Bernardo Rufino | 74eee10 | 2018-08-29 16:01:49 +0100 | [diff] [blame] | 150 | void doQuotaExceeded(long backupDataBytes, long quotaBytes, IBackupCallback callbackBinder); |
Sergey Poromov | 872d3b6 | 2016-01-12 15:48:08 +0100 | [diff] [blame] | 151 | |
| 152 | /** |
Christopher Tate | 75a9970 | 2011-05-18 16:28:19 -0700 | [diff] [blame] | 153 | * Restore a single "file" to the application. The file was typically obtained from |
| 154 | * a full-backup dataset. The agent reads 'size' bytes of file content |
| 155 | * from the provided file descriptor. |
| 156 | * |
| 157 | * @param data Read-only pipe delivering the file content itself. |
| 158 | * |
| 159 | * @param size Size of the file being restored. |
| 160 | * @param type Type of file system entity, e.g. FullBackup.TYPE_DIRECTORY. |
| 161 | * @param domain Name of the file's semantic domain to which the 'path' argument is a |
| 162 | * relative path. e.g. FullBackup.DATABASE_TREE_TOKEN. |
| 163 | * @param path Relative path of the file within its semantic domain. |
| 164 | * @param mode Access mode of the file system entity, e.g. 0660. |
| 165 | * @param mtime Last modification time of the file system entity. |
Christopher Tate | adfe8b8 | 2014-02-04 16:23:32 -0800 | [diff] [blame] | 166 | * @param token Opaque token identifying this transaction. This must |
| 167 | * be echoed back to the backup service binder once the agent is |
| 168 | * finished restoring the application based on the restore data |
| 169 | * contents. |
| 170 | * @param callbackBinder Binder on which to indicate operation completion, |
| 171 | * passed here as a convenience to the agent. |
Christopher Tate | 75a9970 | 2011-05-18 16:28:19 -0700 | [diff] [blame] | 172 | */ |
| 173 | void doRestoreFile(in ParcelFileDescriptor data, long size, |
| 174 | int type, String domain, String path, long mode, long mtime, |
| 175 | int token, IBackupManager callbackBinder); |
Christopher Tate | adfe8b8 | 2014-02-04 16:23:32 -0800 | [diff] [blame] | 176 | |
Christopher Tate | cba5941 | 2014-04-01 10:38:29 -0700 | [diff] [blame] | 177 | /** |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 178 | * Provide the app with a canonical "all data has been delivered" end-of-restore |
| 179 | * callback so that it can do any postprocessing of the restored data that might |
| 180 | * be appropriate. This is issued after both key/value and full data restore |
| 181 | * operations have completed. |
| 182 | * |
| 183 | * @param token Opaque token identifying this transaction. This must |
| 184 | * be echoed back to the backup service binder once the agent is |
| 185 | * finished restoring the application based on the restore data |
| 186 | * contents. |
| 187 | * @param callbackBinder Binder on which to indicate operation completion, |
| 188 | * passed here as a convenience to the agent. |
| 189 | */ |
| 190 | void doRestoreFinished(int token, IBackupManager callbackBinder); |
| 191 | |
| 192 | /** |
Christopher Tate | cba5941 | 2014-04-01 10:38:29 -0700 | [diff] [blame] | 193 | * Out of band: instruct the agent to crash within the client process. This is used |
| 194 | * when the backup infrastructure detects a semantic error post-hoc and needs to |
| 195 | * pass the problem back to the app. |
| 196 | * |
| 197 | * @param message The message to be passed to the agent's application in an exception. |
| 198 | */ |
| 199 | void fail(String message); |
Christopher Tate | 487529a | 2009-04-29 14:03:25 -0700 | [diff] [blame] | 200 | } |