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