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 // TODO complete this list with all log messages. And document properly. 149 public static final int LOG_EVENT_ID_FULL_BACKUP_CANCEL = 4; 150 public static final int LOG_EVENT_ID_ILLEGAL_KEY = 5; 151 public static final int LOG_EVENT_ID_NO_DATA_TO_SEND = 7; 152 public static final int LOG_EVENT_ID_PACKAGE_INELIGIBLE = 9; 153 public static final int LOG_EVENT_ID_PACKAGE_KEY_VALUE_PARTICIPANT = 10; 154 public static final int LOG_EVENT_ID_PACKAGE_STOPPED = 11; 155 public static final int LOG_EVENT_ID_PACKAGE_NOT_FOUND = 12; 156 public static final int LOG_EVENT_ID_BACKUP_DISABLED = 13; 157 public static final int LOG_EVENT_ID_DEVICE_NOT_PROVISIONED = 14; 158 public static final int LOG_EVENT_ID_PACKAGE_TRANSPORT_NOT_PRESENT = 15; 159 public static final int LOG_EVENT_ID_ERROR_PREFLIGHT = 16; 160 public static final int LOG_EVENT_ID_QUOTA_HIT_PREFLIGHT = 18; 161 public static final int LOG_EVENT_ID_EXCEPTION_FULL_BACKUP = 19; 162 public static final int LOG_EVENT_ID_KEY_VALUE_BACKUP_CANCEL = 21; 163 public static final int LOG_EVENT_ID_NO_RESTORE_METADATA_AVAILABLE = 22; 164 public static final int LOG_EVENT_ID_NO_PM_METADATA_RECEIVED = 23; 165 public static final int LOG_EVENT_ID_PM_AGENT_HAS_NO_METADATA = 24; 166 public static final int LOG_EVENT_ID_LOST_TRANSPORT = 25; 167 public static final int LOG_EVENT_ID_PACKAGE_NOT_PRESENT = 26; 168 public static final int LOG_EVENT_ID_RESTORE_VERSION_HIGHER = 27; 169 public static final int LOG_EVENT_ID_APP_HAS_NO_AGENT = 28; 170 public static final int LOG_EVENT_ID_SIGNATURE_MISMATCH = 29; 171 public static final int LOG_EVENT_ID_CANT_FIND_AGENT = 30; 172 public static final int LOG_EVENT_ID_KEY_VALUE_RESTORE_TIMEOUT = 31; 173 public static final int LOG_EVENT_ID_RESTORE_ANY_VERSION = 34; 174 public static final int LOG_EVENT_ID_VERSIONS_MATCH = 35; 175 public static final int LOG_EVENT_ID_VERSION_OF_BACKUP_OLDER = 36; 176 public static final int LOG_EVENT_ID_FULL_RESTORE_SIGNATURE_MISMATCH = 37; 177 public static final int LOG_EVENT_ID_SYSTEM_APP_NO_AGENT = 38; 178 public static final int LOG_EVENT_ID_FULL_RESTORE_ALLOW_BACKUP_FALSE = 39; 179 public static final int LOG_EVENT_ID_APK_NOT_INSTALLED = 40; 180 public static final int LOG_EVENT_ID_CANNOT_RESTORE_WITHOUT_APK = 41; 181 public static final int LOG_EVENT_ID_MISSING_SIGNATURE = 42; 182 public static final int LOG_EVENT_ID_EXPECTED_DIFFERENT_PACKAGE = 43; 183 public static final int LOG_EVENT_ID_UNKNOWN_VERSION = 44; 184 public static final int LOG_EVENT_ID_FULL_RESTORE_TIMEOUT = 45; 185 public static final int LOG_EVENT_ID_CORRUPT_MANIFEST = 46; 186 public static final int LOG_EVENT_ID_WIDGET_METADATA_MISMATCH = 47; 187 public static final int LOG_EVENT_ID_WIDGET_UNKNOWN_VERSION = 48; 188 public static final int LOG_EVENT_ID_NO_PACKAGES = 49; 189 public static final int LOG_EVENT_ID_TRANSPORT_IS_NULL = 50; 190 /** The transport returned {@link BackupTransport#TRANSPORT_NON_INCREMENTAL_BACKUP_REQUIRED}. */ 191 public static final int LOG_EVENT_ID_TRANSPORT_NON_INCREMENTAL_BACKUP_REQUIRED = 51; 192 193 public static final int LOG_EVENT_ID_AGENT_LOGGING_RESULTS = 52; 194 /** @hide */ 195 public static final int LOG_EVENT_ID_START_SYSTEM_RESTORE = 53; 196 /** @hide */ 197 public static final int LOG_EVENT_ID_START_RESTORE_AT_INSTALL = 54; 198 /** A transport error happened during {@link PerformUnifiedRestoreTask#startRestore()} 199 @hide */ 200 public static final int LOG_EVENT_ID_TRANSPORT_ERROR_DURING_START_RESTORE = 55; 201 /** Unable to get the name of the next package in the queue during a restore operation 202 @hide */ 203 public static final int LOG_EVENT_ID_CANNOT_GET_NEXT_PKG_NAME = 56; 204 /** Attempting a restore operation that is neither KV nor full 205 @hide */ 206 public static final int LOG_EVENT_ID_UNKNOWN_RESTORE_TYPE = 57; 207 /** The package is part of KeyValue restore 208 @hide */ 209 public static final int LOG_EVENT_ID_KV_RESTORE = 58; 210 /** The package is part of Full restore 211 @hide */ 212 public static final int LOG_EVENT_ID_FULL_RESTORE = 59; 213 /** Unable to fetch the nest restore target in the queue 214 @hide */ 215 public static final int LOG_EVENT_ID_NO_NEXT_RESTORE_TARGET = 60; 216 /** An error occurred while attempting KeyValueRestore 217 @hide */ 218 public static final int LOG_EVENT_ID_KV_AGENT_ERROR = 61; 219 /** Restore operation finished for the given package 220 @hide */ 221 public static final int LOG_EVENT_ID_PACKAGE_RESTORE_FINISHED= 62; 222 /** A transport error happened during 223 * {@link PerformUnifiedRestoreTask#initiateOneRestore(PackageInfo, long)} 224 @hide */ 225 public static final int LOG_EVENT_ID_TRANSPORT_ERROR_KV_RESTORE = 63; 226 /** Unable to instantiate the feeder thread in full restore 227 @hide */ 228 public static final int LOG_EVENT_ID_NO_FEEDER_THREAD = 64; 229 /** An error occurred while attempting Full restore 230 @hide */ 231 public static final int LOG_EVENT_ID_FULL_AGENT_ERROR = 65; 232 /** A transport error happened during a full restore 233 @hide */ 234 public static final int LOG_EVENT_ID_TRANSPORT_ERROR_FULL_RESTORE = 66; 235 /** Start restore operation for a given package 236 @hide */ 237 public static final int LOG_EVENT_ID_START_PACKAGE_RESTORE = 67; 238 /** Whole restore operation is complete 239 @hide */ 240 public static final int LOG_EVENT_ID_RESTORE_COMPLETE = 68; 241 /** Agent error during {@link PerformUnifiedRestoreTask#restoreFinished()} 242 @hide */ 243 public static final int LOG_EVENT_ID_AGENT_FAILURE = 69; 244 245 /** 246 * This method will be called each time something important happens on BackupManager. 247 * 248 * @param event bundle will contain data about event: 249 * - event id, not optional, a unique identifier for each event. 250 * - package name, optional, the current package we're backing up/restoring if applicable. 251 * - package version, optional, the current package version we're backing up/restoring 252 * if applicable. 253 * - category of event, not optional, one of 254 * { LOG_EVENT_CATEGORY_TRANSPORT, 255 * LOG_EVENT_CATEGORY_AGENT, 256 * LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY} 257 * 258 */ onEvent(Bundle event)259 public void onEvent(Bundle event) { 260 } 261 } 262