1 /* 2 * Copyright (C) 2017 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.backup; 18 19 import android.annotation.SystemApi; 20 import android.app.backup.BackupAnnotations.OperationType; 21 import android.content.pm.PackageInfo; 22 import android.os.Bundle; 23 24 /** 25 * Callback class for receiving important events during backup/restore operations. 26 * Events consist mostly of errors and exceptions, giving detailed reason on why a restore/backup 27 * failed or any time BackupManager makes an important decision. 28 * On the other hand {@link BackupObserver} will give a failure/success view without 29 * getting into details why. This callback runs on the thread it was called on because it can get 30 * a bit spammy. 31 * These callbacks will run on the binder thread. 32 * 33 * @hide 34 */ 35 @SystemApi 36 public class BackupManagerMonitor { 37 38 // Logging constants for BackupManagerMonitor 39 public static final int LOG_EVENT_CATEGORY_TRANSPORT = 1; 40 public static final int LOG_EVENT_CATEGORY_AGENT = 2; 41 public static final int LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY = 3; 42 /** string : the package name */ 43 public static final String EXTRA_LOG_EVENT_PACKAGE_NAME = 44 "android.app.backup.extra.LOG_EVENT_PACKAGE_NAME"; 45 /** int : the versionCode of the package named by EXTRA_LOG_EVENT_PACKAGE_NAME 46 * @deprecated Use {@link #EXTRA_LOG_EVENT_PACKAGE_LONG_VERSION} */ 47 @Deprecated 48 public static final String EXTRA_LOG_EVENT_PACKAGE_VERSION = 49 "android.app.backup.extra.LOG_EVENT_PACKAGE_VERSION"; 50 /** long : the full versionCode of the package named by EXTRA_LOG_EVENT_PACKAGE_NAME */ 51 public static final String EXTRA_LOG_EVENT_PACKAGE_LONG_VERSION = 52 "android.app.backup.extra.LOG_EVENT_PACKAGE_FULL_VERSION"; 53 /** int : the id of the log message, will be a unique identifier */ 54 public static final String EXTRA_LOG_EVENT_ID = "android.app.backup.extra.LOG_EVENT_ID"; 55 /** 56 * int : category will be one of 57 * { LOG_EVENT_CATEGORY_TRANSPORT, 58 * LOG_EVENT_CATEGORY_AGENT, 59 * LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY}. 60 */ 61 public static final String EXTRA_LOG_EVENT_CATEGORY = 62 "android.app.backup.extra.LOG_EVENT_CATEGORY"; 63 64 65 /** 66 * boolean: when we have an event with id LOG_EVENT_ID_KEY_VALUE_BACKUP_CANCEL we record if 67 * the call was to cancel backup of all packages 68 */ 69 public static final String EXTRA_LOG_CANCEL_ALL = "android.app.backup.extra.LOG_CANCEL_ALL"; 70 71 /** 72 * string: when we have an event with id LOG_EVENT_ID_ILLEGAL_KEY we send the key that was used 73 * by the app 74 */ 75 public static final String EXTRA_LOG_ILLEGAL_KEY = "android.app.backup.extra.LOG_ILLEGAL_KEY"; 76 77 /** 78 * long: when we have an event with id LOG_EVENT_ID_ERROR_PREFLIGHT we send the error code that 79 * was returned by the transport during preflight 80 */ 81 public static final String EXTRA_LOG_PREFLIGHT_ERROR = 82 "android.app.backup.extra.LOG_PREFLIGHT_ERROR"; 83 84 /** 85 * string: when we have an event with id LOG_EVENT_ID_EXCEPTION_FULL_BACKUP we send the 86 * exception's stacktrace 87 */ 88 public static final String EXTRA_LOG_EXCEPTION_FULL_BACKUP = 89 "android.app.backup.extra.LOG_EXCEPTION_FULL_BACKUP"; 90 91 /** 92 * int: when we have an event with id LOG_EVENT_ID_RESTORE_VERSION_HIGHER we send the 93 * restore package version 94 */ 95 public static final String EXTRA_LOG_RESTORE_VERSION = 96 "android.app.backup.extra.LOG_RESTORE_VERSION"; 97 98 /** 99 * boolean: when we have an event with id LOG_EVENT_ID_RESTORE_VERSION_HIGHER we record if 100 * ApplicationInfo.FLAG_RESTORE_ANY_VERSION flag is set 101 */ 102 public static final String EXTRA_LOG_RESTORE_ANYWAY = 103 "android.app.backup.extra.LOG_RESTORE_ANYWAY"; 104 105 106 /** 107 * boolean: when we have an event with id LOG_EVENT_ID_APK_NOT_INSTALLED we record if 108 * the policy allows to install apks provided with the dataset 109 */ 110 public static final String EXTRA_LOG_POLICY_ALLOW_APKS = 111 "android.app.backup.extra.LOG_POLICY_ALLOW_APKS"; 112 113 114 /** 115 * string: when we have an event with id LOG_EVENT_ID_EXPECTED_DIFFERENT_PACKAGE we record the 116 * package name provided in the restore manifest 117 */ 118 public static final String EXTRA_LOG_MANIFEST_PACKAGE_NAME = 119 "android.app.backup.extra.LOG_MANIFEST_PACKAGE_NAME"; 120 121 /** 122 * string: when we have an event with id LOG_EVENT_ID_WIDGET_METADATA_MISMATCH we record the 123 * package name provided in the widget metadata 124 */ 125 public static final String EXTRA_LOG_WIDGET_PACKAGE_NAME = 126 "android.app.backup.extra.LOG_WIDGET_PACKAGE_NAME"; 127 128 /** 129 * int: when we have event of id LOG_EVENT_ID_VERSION_OF_BACKUP_OLDER we send the version 130 * of the backup. 131 */ 132 public static final String EXTRA_LOG_OLD_VERSION = "android.app.backup.extra.LOG_OLD_VERSION"; 133 134 /** 135 * ParcelableList: when we have an event of id LOG_EVENT_ID_AGENT_LOGGING_RESULTS we send a list 136 * of {@link android.app.backup.BackupRestoreEventLogger.DataTypeResult}. 137 */ 138 public static final String EXTRA_LOG_AGENT_LOGGING_RESULTS = 139 "android.app.backup.extra.LOG_AGENT_LOGGING_RESULTS"; 140 141 /** 142 * The operation type this log is associated with. See {@link OperationType}. 143 * 144 * @hide 145 */ 146 public static final String EXTRA_LOG_OPERATION_TYPE = "android.app.backup.extra.OPERATION_TYPE"; 147 148 /** 149 * List of system components that do not support restore in a V-> U OS downgrade, even if 150 * restoreAnyVersion is set to true. 151 * Read from Settings.Secure.V_TO_U_RESTORE_DENYLIST 152 * 153 * @hide 154 */ 155 public static final String EXTRA_LOG_V_TO_U_DENYLIST = "android.app.backup.extra.V_TO_U_DENYLIST"; 156 157 /** 158 * List of system components that support restore in a V-> U OS downgrade, even if 159 * restoreAnyVersion is set to false. 160 * Read from Settings.Secure.V_TO_U_RESTORE_ALLOWLIST 161 * 162 * @hide 163 */ 164 public static final String EXTRA_LOG_V_TO_U_ALLOWLIST = 165 "android.app.backup.extra.V_TO_U_ALLOWLIST"; 166 167 // TODO complete this list with all log messages. And document properly. 168 public static final int LOG_EVENT_ID_FULL_BACKUP_CANCEL = 4; 169 public static final int LOG_EVENT_ID_ILLEGAL_KEY = 5; 170 public static final int LOG_EVENT_ID_NO_DATA_TO_SEND = 7; 171 public static final int LOG_EVENT_ID_PACKAGE_INELIGIBLE = 9; 172 public static final int LOG_EVENT_ID_PACKAGE_KEY_VALUE_PARTICIPANT = 10; 173 public static final int LOG_EVENT_ID_PACKAGE_STOPPED = 11; 174 public static final int LOG_EVENT_ID_PACKAGE_NOT_FOUND = 12; 175 public static final int LOG_EVENT_ID_BACKUP_DISABLED = 13; 176 public static final int LOG_EVENT_ID_DEVICE_NOT_PROVISIONED = 14; 177 public static final int LOG_EVENT_ID_PACKAGE_TRANSPORT_NOT_PRESENT = 15; 178 public static final int LOG_EVENT_ID_ERROR_PREFLIGHT = 16; 179 public static final int LOG_EVENT_ID_QUOTA_HIT_PREFLIGHT = 18; 180 public static final int LOG_EVENT_ID_EXCEPTION_FULL_BACKUP = 19; 181 public static final int LOG_EVENT_ID_KEY_VALUE_BACKUP_CANCEL = 21; 182 public static final int LOG_EVENT_ID_NO_RESTORE_METADATA_AVAILABLE = 22; 183 public static final int LOG_EVENT_ID_NO_PM_METADATA_RECEIVED = 23; 184 public static final int LOG_EVENT_ID_PM_AGENT_HAS_NO_METADATA = 24; 185 public static final int LOG_EVENT_ID_LOST_TRANSPORT = 25; 186 public static final int LOG_EVENT_ID_PACKAGE_NOT_PRESENT = 26; 187 public static final int LOG_EVENT_ID_RESTORE_VERSION_HIGHER = 27; 188 public static final int LOG_EVENT_ID_APP_HAS_NO_AGENT = 28; 189 public static final int LOG_EVENT_ID_SIGNATURE_MISMATCH = 29; 190 public static final int LOG_EVENT_ID_CANT_FIND_AGENT = 30; 191 public static final int LOG_EVENT_ID_KEY_VALUE_RESTORE_TIMEOUT = 31; 192 public static final int LOG_EVENT_ID_RESTORE_ANY_VERSION = 34; 193 public static final int LOG_EVENT_ID_VERSIONS_MATCH = 35; 194 public static final int LOG_EVENT_ID_VERSION_OF_BACKUP_OLDER = 36; 195 public static final int LOG_EVENT_ID_FULL_RESTORE_SIGNATURE_MISMATCH = 37; 196 public static final int LOG_EVENT_ID_SYSTEM_APP_NO_AGENT = 38; 197 public static final int LOG_EVENT_ID_FULL_RESTORE_ALLOW_BACKUP_FALSE = 39; 198 public static final int LOG_EVENT_ID_APK_NOT_INSTALLED = 40; 199 public static final int LOG_EVENT_ID_CANNOT_RESTORE_WITHOUT_APK = 41; 200 public static final int LOG_EVENT_ID_MISSING_SIGNATURE = 42; 201 public static final int LOG_EVENT_ID_EXPECTED_DIFFERENT_PACKAGE = 43; 202 public static final int LOG_EVENT_ID_UNKNOWN_VERSION = 44; 203 public static final int LOG_EVENT_ID_FULL_RESTORE_TIMEOUT = 45; 204 public static final int LOG_EVENT_ID_CORRUPT_MANIFEST = 46; 205 public static final int LOG_EVENT_ID_WIDGET_METADATA_MISMATCH = 47; 206 public static final int LOG_EVENT_ID_WIDGET_UNKNOWN_VERSION = 48; 207 public static final int LOG_EVENT_ID_NO_PACKAGES = 49; 208 public static final int LOG_EVENT_ID_TRANSPORT_IS_NULL = 50; 209 /** The transport returned {@link BackupTransport#TRANSPORT_NON_INCREMENTAL_BACKUP_REQUIRED}. */ 210 public static final int LOG_EVENT_ID_TRANSPORT_NON_INCREMENTAL_BACKUP_REQUIRED = 51; 211 212 public static final int LOG_EVENT_ID_AGENT_LOGGING_RESULTS = 52; 213 /** @hide */ 214 public static final int LOG_EVENT_ID_START_SYSTEM_RESTORE = 53; 215 /** @hide */ 216 public static final int LOG_EVENT_ID_START_RESTORE_AT_INSTALL = 54; 217 /** A transport error happened during {@link PerformUnifiedRestoreTask#startRestore()} 218 @hide */ 219 public static final int LOG_EVENT_ID_TRANSPORT_ERROR_DURING_START_RESTORE = 55; 220 /** Unable to get the name of the next package in the queue during a restore operation 221 @hide */ 222 public static final int LOG_EVENT_ID_CANNOT_GET_NEXT_PKG_NAME = 56; 223 /** Attempting a restore operation that is neither KV nor full 224 @hide */ 225 public static final int LOG_EVENT_ID_UNKNOWN_RESTORE_TYPE = 57; 226 /** The package is part of KeyValue restore 227 @hide */ 228 public static final int LOG_EVENT_ID_KV_RESTORE = 58; 229 /** The package is part of Full restore 230 @hide */ 231 public static final int LOG_EVENT_ID_FULL_RESTORE = 59; 232 /** Unable to fetch the nest restore target in the queue 233 @hide */ 234 public static final int LOG_EVENT_ID_NO_NEXT_RESTORE_TARGET = 60; 235 /** An error occurred while attempting KeyValueRestore 236 @hide */ 237 public static final int LOG_EVENT_ID_KV_AGENT_ERROR = 61; 238 /** Restore operation finished for the given package 239 @hide */ 240 public static final int LOG_EVENT_ID_PACKAGE_RESTORE_FINISHED= 62; 241 /** A transport error happened during 242 * {@link PerformUnifiedRestoreTask#initiateOneRestore(PackageInfo, long)} 243 @hide */ 244 public static final int LOG_EVENT_ID_TRANSPORT_ERROR_KV_RESTORE = 63; 245 /** Unable to instantiate the feeder thread in full restore 246 @hide */ 247 public static final int LOG_EVENT_ID_NO_FEEDER_THREAD = 64; 248 /** An error occurred while attempting Full restore 249 @hide */ 250 public static final int LOG_EVENT_ID_FULL_AGENT_ERROR = 65; 251 /** A transport error happened during a full restore 252 @hide */ 253 public static final int LOG_EVENT_ID_TRANSPORT_ERROR_FULL_RESTORE = 66; 254 /** Start restore operation for a given package 255 @hide */ 256 public static final int LOG_EVENT_ID_START_PACKAGE_RESTORE = 67; 257 /** Whole restore operation is complete 258 @hide */ 259 public static final int LOG_EVENT_ID_RESTORE_COMPLETE = 68; 260 /** Agent error during {@link PerformUnifiedRestoreTask#restoreFinished()} 261 @hide */ 262 public static final int LOG_EVENT_ID_AGENT_FAILURE = 69; 263 /** V to U restore attempt, pkg is eligible 264 @hide */ 265 public static final int LOG_EVENT_ID_V_TO_U_RESTORE_PKG_ELIGIBLE = 70; 266 /** V to U restore attempt, pkg is not eligible 267 @hide */ 268 public static final int LOG_EVENT_ID_V_TO_U_RESTORE_PKG_NOT_ELIGIBLE = 71; 269 /** V to U restore attempt, allowlist and denlist are set 270 @hide */ 271 public static final int LOG_EVENT_ID_V_TO_U_RESTORE_SET_LIST = 72; 272 /** As part of package install, {@link PackageManager} invoked restore. 273 @hide */ 274 public static final int LOG_EVENT_ID_RESTORE_AT_INSTALL_INVOKED = 73; 275 /** Skipping restore at package install 276 @hide */ 277 public static final int LOG_EVENT_ID_SKIP_RESTORE_AT_INSTALL = 74; 278 /** Package is eligible and is accepted for restore 279 @hide */ 280 public static final int LOG_EVENT_ID_PACKAGE_ACCEPTED_FOR_RESTORE = 75; 281 /** Restore data doesn't belong to the package for which restore is started 282 @hide */ 283 public static final int LOG_EVENT_ID_RESTORE_DATA_DOES_NOT_BELONG_TO_PACKAGE = 76; 284 /** Unable to create BackupAgent for package for restore 285 @hide */ 286 public static final int LOG_EVENT_ID_UNABLE_TO_CREATE_AGENT_FOR_RESTORE = 77; 287 /** BackupAgent crashed after creation but before accepting any data 288 @hide */ 289 public static final int LOG_EVENT_ID_AGENT_CRASHED_BEFORE_RESTORE_DATA_IS_SENT = 78; 290 /** Failure in streaming restore data to BackupAgent 291 @hide */ 292 public static final int LOG_EVENT_ID_FAILED_TO_SEND_DATA_TO_AGENT_DURING_RESTORE = 79; 293 /** BackupAgent related failure during restore 294 @hide */ 295 public static final int LOG_EVENT_ID_AGENT_FAILURE_DURING_RESTORE = 80; 296 /** Failure in reading data from TransportPackage during restore 297 @hide */ 298 public static final int LOG_EVENT_ID_FAILED_TO_READ_DATA_FROM_TRANSPORT = 81; 299 300 /** 301 * This method will be called each time something important happens on BackupManager. 302 * 303 * @param event bundle will contain data about event: 304 * - event id, not optional, a unique identifier for each event. 305 * - package name, optional, the current package we're backing up/restoring if applicable. 306 * - package version, optional, the current package version we're backing up/restoring 307 * if applicable. 308 * - category of event, not optional, one of 309 * { LOG_EVENT_CATEGORY_TRANSPORT, 310 * LOG_EVENT_CATEGORY_AGENT, 311 * LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY} 312 * 313 */ onEvent(Bundle event)314 public void onEvent(Bundle event) { 315 } 316 } 317