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 | |
Christopher Tate | 4528186 | 2010-03-05 15:46:30 -0800 | [diff] [blame] | 19 | import android.app.backup.IBackupManager; |
Christopher Tate | 22b8787 | 2009-05-04 16:41:53 -0700 | [diff] [blame] | 20 | import android.os.ParcelFileDescriptor; |
| 21 | |
Christopher Tate | 487529a | 2009-04-29 14:03:25 -0700 | [diff] [blame] | 22 | /** |
| 23 | * Interface presented by applications being asked to participate in the |
Christopher Tate | 4528186 | 2010-03-05 15:46:30 -0800 | [diff] [blame] | 24 | * backup & restore mechanism. End user code will not typically implement |
| 25 | * this interface directly; they subclass BackupAgent instead. |
Christopher Tate | 487529a | 2009-04-29 14:03:25 -0700 | [diff] [blame] | 26 | * |
| 27 | * {@hide} |
Christopher Tate | 22b8787 | 2009-05-04 16:41:53 -0700 | [diff] [blame] | 28 | */ |
Christopher Tate | 44a2790 | 2010-01-27 17:15:49 -0800 | [diff] [blame] | 29 | oneway interface IBackupAgent { |
Christopher Tate | 487529a | 2009-04-29 14:03:25 -0700 | [diff] [blame] | 30 | /** |
| 31 | * Request that the app perform an incremental backup. |
| 32 | * |
Christopher Tate | 22b8787 | 2009-05-04 16:41:53 -0700 | [diff] [blame] | 33 | * @param oldState Read-only file containing the description blob of the |
Christopher Tate | 487529a | 2009-04-29 14:03:25 -0700 | [diff] [blame] | 34 | * app's data state as of the last backup operation's completion. |
Christopher Tate | 22b8787 | 2009-05-04 16:41:53 -0700 | [diff] [blame] | 35 | * This file is empty or invalid when a full backup is being |
| 36 | * requested. |
Christopher Tate | 487529a | 2009-04-29 14:03:25 -0700 | [diff] [blame] | 37 | * |
Christopher Tate | 22b8787 | 2009-05-04 16:41:53 -0700 | [diff] [blame] | 38 | * @param data Read-write file, empty when onBackup() is called, that |
Christopher Tate | 487529a | 2009-04-29 14:03:25 -0700 | [diff] [blame] | 39 | * is the data destination for this backup pass's incrementals. |
| 40 | * |
Christopher Tate | 22b8787 | 2009-05-04 16:41:53 -0700 | [diff] [blame] | 41 | * @param newState Read-write file, empty when onBackup() is called, |
Christopher Tate | 487529a | 2009-04-29 14:03:25 -0700 | [diff] [blame] | 42 | * where the new state blob is to be recorded. |
Christopher Tate | 44a2790 | 2010-01-27 17:15:49 -0800 | [diff] [blame] | 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. |
Christopher Tate | 487529a | 2009-04-29 14:03:25 -0700 | [diff] [blame] | 50 | */ |
Christopher Tate | 22b8787 | 2009-05-04 16:41:53 -0700 | [diff] [blame] | 51 | void doBackup(in ParcelFileDescriptor oldState, |
| 52 | in ParcelFileDescriptor data, |
Christopher Tate | 44a2790 | 2010-01-27 17:15:49 -0800 | [diff] [blame] | 53 | in ParcelFileDescriptor newState, |
| 54 | int token, IBackupManager callbackBinder); |
Christopher Tate | 487529a | 2009-04-29 14:03:25 -0700 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * Restore an entire data snapshot to the application. |
| 58 | * |
Christopher Tate | 22b8787 | 2009-05-04 16:41:53 -0700 | [diff] [blame] | 59 | * @param data Read-only file containing the full data snapshot of the |
Christopher Tate | 487529a | 2009-04-29 14:03:25 -0700 | [diff] [blame] | 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 | * |
Christopher Tate | 5cbbf56 | 2009-06-22 16:44:51 -0700 | [diff] [blame] | 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 | * |
Christopher Tate | 22b8787 | 2009-05-04 16:41:53 -0700 | [diff] [blame] | 67 | * @param newState Read-write file, empty when onRestore() is called, |
Christopher Tate | 487529a | 2009-04-29 14:03:25 -0700 | [diff] [blame] | 68 | * that is to be written with the state description that holds after |
| 69 | * the restore has been completed. |
Christopher Tate | 44a2790 | 2010-01-27 17:15:49 -0800 | [diff] [blame] | 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. |
Christopher Tate | 487529a | 2009-04-29 14:03:25 -0700 | [diff] [blame] | 78 | */ |
Christopher Tate | adfe8b8 | 2014-02-04 16:23:32 -0800 | [diff] [blame] | 79 | void doRestore(in ParcelFileDescriptor data, |
| 80 | int appVersionCode, in ParcelFileDescriptor newState, |
| 81 | int token, IBackupManager callbackBinder); |
Christopher Tate | 75a9970 | 2011-05-18 16:28:19 -0700 | [diff] [blame] | 82 | |
| 83 | /** |
Christopher Tate | 79ec80d | 2011-06-24 14:58:49 -0700 | [diff] [blame] | 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 | */ |
| 100 | void doFullBackup(in ParcelFileDescriptor data, int token, IBackupManager callbackBinder); |
| 101 | |
| 102 | /** |
Christopher Tate | 11ae768 | 2015-03-24 18:48:10 -0700 | [diff] [blame] | 103 | * Estimate how much data a full backup will deliver |
| 104 | */ |
| 105 | void doMeasureFullBackup(int token, IBackupManager callbackBinder); |
| 106 | |
| 107 | /** |
Sergey Poromov | 872d3b6 | 2016-01-12 15:48:08 +0100 | [diff] [blame] | 108 | * Tells the application agent that the backup data size exceeded current transport quota. |
| 109 | * Later calls to {@link #onBackup(ParcelFileDescriptor, BackupDataOutput, ParcelFileDescriptor)} |
| 110 | * and {@link #onFullBackup(FullBackupDataOutput)} could use this information |
| 111 | * to reduce backup size under the limit. |
| 112 | * However, the quota can change, so do not assume that the value passed in here is absolute, |
| 113 | * similarly all subsequent backups should not be restricted to this size. |
| 114 | * This callback will be invoked before data has been put onto the wire in a preflight check, |
| 115 | * so it is relatively inexpensive to hit your quota. |
| 116 | * Apps that hit quota repeatedly without dealing with it can be subject to having their backup |
| 117 | * schedule reduced. |
| 118 | * The {@code quotaBytes} is a loose guideline b/c of metadata added by the backupmanager |
| 119 | * so apps should be more aggressive in trimming their backup set. |
| 120 | * |
| 121 | * @param backupDataBytes Expected or already processed amount of data. |
| 122 | * Could be less than total backup size if backup process was interrupted |
| 123 | * before finish of processing all backup data. |
| 124 | * @param quotaBytes Current amount of backup data that is allowed for the app. |
| 125 | */ |
| 126 | void doQuotaExceeded(long backupDataBytes, long quotaBytes); |
| 127 | |
| 128 | /** |
Christopher Tate | 75a9970 | 2011-05-18 16:28:19 -0700 | [diff] [blame] | 129 | * Restore a single "file" to the application. The file was typically obtained from |
| 130 | * a full-backup dataset. The agent reads 'size' bytes of file content |
| 131 | * from the provided file descriptor. |
| 132 | * |
| 133 | * @param data Read-only pipe delivering the file content itself. |
| 134 | * |
| 135 | * @param size Size of the file being restored. |
| 136 | * @param type Type of file system entity, e.g. FullBackup.TYPE_DIRECTORY. |
| 137 | * @param domain Name of the file's semantic domain to which the 'path' argument is a |
| 138 | * relative path. e.g. FullBackup.DATABASE_TREE_TOKEN. |
| 139 | * @param path Relative path of the file within its semantic domain. |
| 140 | * @param mode Access mode of the file system entity, e.g. 0660. |
| 141 | * @param mtime Last modification time of the file system entity. |
Christopher Tate | adfe8b8 | 2014-02-04 16:23:32 -0800 | [diff] [blame] | 142 | * @param token Opaque token identifying this transaction. This must |
| 143 | * be echoed back to the backup service binder once the agent is |
| 144 | * finished restoring the application based on the restore data |
| 145 | * contents. |
| 146 | * @param callbackBinder Binder on which to indicate operation completion, |
| 147 | * passed here as a convenience to the agent. |
Christopher Tate | 75a9970 | 2011-05-18 16:28:19 -0700 | [diff] [blame] | 148 | */ |
| 149 | void doRestoreFile(in ParcelFileDescriptor data, long size, |
| 150 | int type, String domain, String path, long mode, long mtime, |
| 151 | int token, IBackupManager callbackBinder); |
Christopher Tate | adfe8b8 | 2014-02-04 16:23:32 -0800 | [diff] [blame] | 152 | |
Christopher Tate | cba5941 | 2014-04-01 10:38:29 -0700 | [diff] [blame] | 153 | /** |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 154 | * Provide the app with a canonical "all data has been delivered" end-of-restore |
| 155 | * callback so that it can do any postprocessing of the restored data that might |
| 156 | * be appropriate. This is issued after both key/value and full data restore |
| 157 | * operations have completed. |
| 158 | * |
| 159 | * @param token Opaque token identifying this transaction. This must |
| 160 | * be echoed back to the backup service binder once the agent is |
| 161 | * finished restoring the application based on the restore data |
| 162 | * contents. |
| 163 | * @param callbackBinder Binder on which to indicate operation completion, |
| 164 | * passed here as a convenience to the agent. |
| 165 | */ |
| 166 | void doRestoreFinished(int token, IBackupManager callbackBinder); |
| 167 | |
| 168 | /** |
Christopher Tate | cba5941 | 2014-04-01 10:38:29 -0700 | [diff] [blame] | 169 | * Out of band: instruct the agent to crash within the client process. This is used |
| 170 | * when the backup infrastructure detects a semantic error post-hoc and needs to |
| 171 | * pass the problem back to the app. |
| 172 | * |
| 173 | * @param message The message to be passed to the agent's application in an exception. |
| 174 | */ |
| 175 | void fail(String message); |
Christopher Tate | 487529a | 2009-04-29 14:03:25 -0700 | [diff] [blame] | 176 | } |