• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.os.Bundle;
21 
22 /**
23  * Callback class for receiving important events during backup/restore operations.
24  * Events consist mostly of errors and exceptions, giving detailed reason on why a restore/backup
25  * failed or any time BackupManager makes an important decision.
26  * On the other hand {@link BackupObserver} will give a failure/success view without
27  * getting into details why. This callback runs on the thread it was called on because it can get
28  * a bit spammy.
29  * These callbacks will run on the binder thread.
30  *
31  * @hide
32  */
33 @SystemApi
34 public class BackupManagerMonitor {
35 
36   // Logging constants for BackupManagerMonitor
37   public static final int LOG_EVENT_CATEGORY_TRANSPORT = 1;
38   public static final int LOG_EVENT_CATEGORY_AGENT = 2;
39   public static final int LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY = 3;
40   /** string : the package name */
41   public static final String EXTRA_LOG_EVENT_PACKAGE_NAME =
42           "android.app.backup.extra.LOG_EVENT_PACKAGE_NAME";
43   /** int : the versionCode of the package named by EXTRA_LOG_EVENT_PACKAGE_NAME
44    * @deprecated Use {@link #EXTRA_LOG_EVENT_PACKAGE_LONG_VERSION} */
45   @Deprecated
46   public static final String EXTRA_LOG_EVENT_PACKAGE_VERSION =
47           "android.app.backup.extra.LOG_EVENT_PACKAGE_VERSION";
48   /** long : the full versionCode of the package named by EXTRA_LOG_EVENT_PACKAGE_NAME */
49   public static final String EXTRA_LOG_EVENT_PACKAGE_LONG_VERSION =
50           "android.app.backup.extra.LOG_EVENT_PACKAGE_FULL_VERSION";
51   /** int : the id of the log message, will be a unique identifier */
52   public static final String EXTRA_LOG_EVENT_ID = "android.app.backup.extra.LOG_EVENT_ID";
53   /**
54    *  int : category will be one of
55    *  { LOG_EVENT_CATEGORY_TRANSPORT,
56    *    LOG_EVENT_CATEGORY_AGENT,
57    *    LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY}.
58    */
59   public static final String EXTRA_LOG_EVENT_CATEGORY =
60           "android.app.backup.extra.LOG_EVENT_CATEGORY";
61 
62 
63   /**
64    * boolean: when we have an event with id LOG_EVENT_ID_KEY_VALUE_BACKUP_CANCEL we record if
65    * the call was to cancel backup of all packages
66    */
67   public static final String EXTRA_LOG_CANCEL_ALL = "android.app.backup.extra.LOG_CANCEL_ALL";
68 
69   /**
70    * string: when we have an event with id LOG_EVENT_ID_ILLEGAL_KEY we send the key that was used
71    * by the app
72    */
73   public static final String EXTRA_LOG_ILLEGAL_KEY = "android.app.backup.extra.LOG_ILLEGAL_KEY";
74 
75   /**
76    * long: when we have an event with id LOG_EVENT_ID_ERROR_PREFLIGHT we send the error code that
77    * was returned by the transport during preflight
78    */
79   public static final String EXTRA_LOG_PREFLIGHT_ERROR =
80           "android.app.backup.extra.LOG_PREFLIGHT_ERROR";
81 
82   /**
83    * string: when we have an event with id LOG_EVENT_ID_EXCEPTION_FULL_BACKUP we send the
84    * exception's stacktrace
85    */
86   public static final String EXTRA_LOG_EXCEPTION_FULL_BACKUP =
87           "android.app.backup.extra.LOG_EXCEPTION_FULL_BACKUP";
88 
89   /**
90    * int: when we have an event with id LOG_EVENT_ID_RESTORE_VERSION_HIGHER we send the
91    * restore package version
92    */
93   public static final String EXTRA_LOG_RESTORE_VERSION =
94           "android.app.backup.extra.LOG_RESTORE_VERSION";
95 
96   /**
97    * boolean: when we have an event with id LOG_EVENT_ID_RESTORE_VERSION_HIGHER we record if
98    * ApplicationInfo.FLAG_RESTORE_ANY_VERSION flag is set
99    */
100   public static final String EXTRA_LOG_RESTORE_ANYWAY =
101           "android.app.backup.extra.LOG_RESTORE_ANYWAY";
102 
103 
104   /**
105    * boolean: when we have an event with id LOG_EVENT_ID_APK_NOT_INSTALLED we record if
106    * the policy allows to install apks provided with the dataset
107    */
108   public static final String EXTRA_LOG_POLICY_ALLOW_APKS =
109           "android.app.backup.extra.LOG_POLICY_ALLOW_APKS";
110 
111 
112   /**
113    * string: when we have an event with id LOG_EVENT_ID_EXPECTED_DIFFERENT_PACKAGE we record the
114    * package name provided in the restore manifest
115    */
116   public static final String EXTRA_LOG_MANIFEST_PACKAGE_NAME =
117           "android.app.backup.extra.LOG_MANIFEST_PACKAGE_NAME";
118 
119   /**
120    * string: when we have an event with id LOG_EVENT_ID_WIDGET_METADATA_MISMATCH we record the
121    * package name provided in the widget metadata
122    */
123   public static final String EXTRA_LOG_WIDGET_PACKAGE_NAME =
124           "android.app.backup.extra.LOG_WIDGET_PACKAGE_NAME";
125 
126   /**
127    * int: when we have event of id LOG_EVENT_ID_VERSION_OF_BACKUP_OLDER we send the version
128    * of the backup.
129    */
130   public static final String EXTRA_LOG_OLD_VERSION = "android.app.backup.extra.LOG_OLD_VERSION";
131 
132   // TODO complete this list with all log messages. And document properly.
133   public static final int LOG_EVENT_ID_FULL_BACKUP_CANCEL = 4;
134   public static final int LOG_EVENT_ID_ILLEGAL_KEY = 5;
135   public static final int LOG_EVENT_ID_NO_DATA_TO_SEND = 7;
136   public static final int LOG_EVENT_ID_PACKAGE_INELIGIBLE = 9;
137   public static final int LOG_EVENT_ID_PACKAGE_KEY_VALUE_PARTICIPANT = 10;
138   public static final int LOG_EVENT_ID_PACKAGE_STOPPED = 11;
139   public static final int LOG_EVENT_ID_PACKAGE_NOT_FOUND = 12;
140   public static final int LOG_EVENT_ID_BACKUP_DISABLED = 13;
141   public static final int LOG_EVENT_ID_DEVICE_NOT_PROVISIONED = 14;
142   public static final int LOG_EVENT_ID_PACKAGE_TRANSPORT_NOT_PRESENT = 15;
143   public static final int LOG_EVENT_ID_ERROR_PREFLIGHT = 16;
144   public static final int LOG_EVENT_ID_QUOTA_HIT_PREFLIGHT = 18;
145   public static final int LOG_EVENT_ID_EXCEPTION_FULL_BACKUP = 19;
146   public static final int LOG_EVENT_ID_KEY_VALUE_BACKUP_CANCEL = 21;
147   public static final int LOG_EVENT_ID_NO_RESTORE_METADATA_AVAILABLE = 22;
148   public static final int LOG_EVENT_ID_NO_PM_METADATA_RECEIVED = 23;
149   public static final int LOG_EVENT_ID_PM_AGENT_HAS_NO_METADATA = 24;
150   public static final int LOG_EVENT_ID_LOST_TRANSPORT = 25;
151   public static final int LOG_EVENT_ID_PACKAGE_NOT_PRESENT = 26;
152   public static final int LOG_EVENT_ID_RESTORE_VERSION_HIGHER = 27;
153   public static final int LOG_EVENT_ID_APP_HAS_NO_AGENT = 28;
154   public static final int LOG_EVENT_ID_SIGNATURE_MISMATCH = 29;
155   public static final int LOG_EVENT_ID_CANT_FIND_AGENT = 30;
156   public static final int LOG_EVENT_ID_KEY_VALUE_RESTORE_TIMEOUT = 31;
157   public static final int LOG_EVENT_ID_RESTORE_ANY_VERSION = 34;
158   public static final int LOG_EVENT_ID_VERSIONS_MATCH = 35;
159   public static final int LOG_EVENT_ID_VERSION_OF_BACKUP_OLDER = 36;
160   public static final int LOG_EVENT_ID_FULL_RESTORE_SIGNATURE_MISMATCH = 37;
161   public static final int LOG_EVENT_ID_SYSTEM_APP_NO_AGENT = 38;
162   public static final int LOG_EVENT_ID_FULL_RESTORE_ALLOW_BACKUP_FALSE = 39;
163   public static final int LOG_EVENT_ID_APK_NOT_INSTALLED = 40;
164   public static final int LOG_EVENT_ID_CANNOT_RESTORE_WITHOUT_APK = 41;
165   public static final int LOG_EVENT_ID_MISSING_SIGNATURE = 42;
166   public static final int LOG_EVENT_ID_EXPECTED_DIFFERENT_PACKAGE = 43;
167   public static final int LOG_EVENT_ID_UNKNOWN_VERSION = 44;
168   public static final int LOG_EVENT_ID_FULL_RESTORE_TIMEOUT = 45;
169   public static final int LOG_EVENT_ID_CORRUPT_MANIFEST = 46;
170   public static final int LOG_EVENT_ID_WIDGET_METADATA_MISMATCH = 47;
171   public static final int LOG_EVENT_ID_WIDGET_UNKNOWN_VERSION = 48;
172   public static final int LOG_EVENT_ID_NO_PACKAGES = 49;
173   public static final int LOG_EVENT_ID_TRANSPORT_IS_NULL = 50;
174 
175     /**
176      * The transport returned {@link BackupTransport#TRANSPORT_NON_INCREMENTAL_BACKUP_REQUIRED}.
177      */
178     public static final int LOG_EVENT_ID_TRANSPORT_NON_INCREMENTAL_BACKUP_REQUIRED = 51;
179 
180 
181 
182 
183 
184   /**
185    * This method will be called each time something important happens on BackupManager.
186    *
187    * @param event bundle will contain data about event:
188    *    - event id, not optional, a unique identifier for each event.
189    *    - package name, optional, the current package we're backing up/restoring if applicable.
190    *    - package version, optional, the current package version  we're backing up/restoring
191    *          if applicable.
192    *    - category of event, not optional, one of
193    *          { LOG_EVENT_CATEGORY_TRANSPORT,
194    *            LOG_EVENT_CATEGORY_AGENT,
195    *            LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY}
196    *
197    */
onEvent(Bundle event)198   public void onEvent(Bundle event) {
199   }
200 }
201