diff --git a/api/system-current.txt b/api/system-current.txt index e00507ee884cb..3b8db0baf3bb1 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -6940,26 +6940,64 @@ package android.app.backup { public class BackupManagerMonitor { ctor public BackupManagerMonitor(); method public void onEvent(android.os.Bundle); + field public static final java.lang.String EXTRA_LOG_CANCEL_ALL = "android.app.backup.extra.LOG_CANCEL_ALL"; field public static final java.lang.String EXTRA_LOG_EVENT_CATEGORY = "android.app.backup.extra.LOG_EVENT_CATEGORY"; field public static final java.lang.String EXTRA_LOG_EVENT_ID = "android.app.backup.extra.LOG_EVENT_ID"; field public static final java.lang.String EXTRA_LOG_EVENT_PACKAGE_NAME = "android.app.backup.extra.LOG_EVENT_PACKAGE_NAME"; field public static final java.lang.String EXTRA_LOG_EVENT_PACKAGE_VERSION = "android.app.backup.extra.LOG_EVENT_PACKAGE_VERSION"; + field public static final java.lang.String EXTRA_LOG_EXCEPTION_FULL_BACKUP = "android.app.backup.extra.LOG_EXCEPTION_FULL_BACKUP"; + field public static final java.lang.String EXTRA_LOG_ILLEGAL_KEY = "android.app.backup.extra.LOG_ILLEGAL_KEY"; + field public static final java.lang.String EXTRA_LOG_MANIFEST_PACKAGE_NAME = "android.app.backup.extra.LOG_MANIFEST_PACKAGE_NAME"; field public static final java.lang.String EXTRA_LOG_OLD_VERSION = "android.app.backup.extra.LOG_OLD_VERSION"; + field public static final java.lang.String EXTRA_LOG_POLICY_ALLOW_APKS = "android.app.backup.extra.LOG_POLICY_ALLOW_APKS"; + field public static final java.lang.String EXTRA_LOG_PREFLIGHT_ERROR = "android.app.backup.extra.LOG_PREFLIGHT_ERROR"; + field public static final java.lang.String EXTRA_LOG_RESTORE_ANYWAY = "android.app.backup.extra.LOG_RESTORE_ANYWAY"; + field public static final java.lang.String EXTRA_LOG_RESTORE_VERSION = "android.app.backup.extra.LOG_RESTORE_VERSION"; + field public static final java.lang.String EXTRA_LOG_WIDGET_PACKAGE_NAME = "android.app.backup.extra.LOG_WIDGET_PACKAGE_NAME"; field public static final int LOG_EVENT_CATEGORY_AGENT = 2; // 0x2 field public static final int LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY = 3; // 0x3 field public static final int LOG_EVENT_CATEGORY_TRANSPORT = 1; // 0x1 + field public static final int LOG_EVENT_ID_APK_NOT_INSTALLED = 40; // 0x28 field public static final int LOG_EVENT_ID_APP_HAS_NO_AGENT = 28; // 0x1c + field public static final int LOG_EVENT_ID_BACKUP_DISABLED = 13; // 0xd + field public static final int LOG_EVENT_ID_CANNOT_RESTORE_WITHOUT_APK = 41; // 0x29 field public static final int LOG_EVENT_ID_CANT_FIND_AGENT = 30; // 0x1e - field public static final int LOG_EVENT_ID_FULL_BACKUP_TIMEOUT = 4; // 0x4 + field public static final int LOG_EVENT_ID_CORRUPT_MANIFEST = 46; // 0x2e + field public static final int LOG_EVENT_ID_DEVICE_NOT_PROVISIONED = 14; // 0xe + field public static final int LOG_EVENT_ID_ERROR_PREFLIGHT = 16; // 0x10 + field public static final int LOG_EVENT_ID_EXCEPTION_FULL_BACKUP = 19; // 0x13 + field public static final int LOG_EVENT_ID_EXPECTED_DIFFERENT_PACKAGE = 43; // 0x2b + field public static final int LOG_EVENT_ID_FULL_BACKUP_CANCEL = 4; // 0x4 + field public static final int LOG_EVENT_ID_FULL_RESTORE_ALLOW_BACKUP_FALSE = 39; // 0x27 + field public static final int LOG_EVENT_ID_FULL_RESTORE_SIGNATURE_MISMATCH = 37; // 0x25 field public static final int LOG_EVENT_ID_FULL_RESTORE_TIMEOUT = 45; // 0x2d - field public static final int LOG_EVENT_ID_KEY_VALUE_BACKUP_TIMEOUT = 21; // 0x15 + field public static final int LOG_EVENT_ID_ILLEGAL_KEY = 5; // 0x5 + field public static final int LOG_EVENT_ID_KEY_VALUE_BACKUP_CANCEL = 21; // 0x15 field public static final int LOG_EVENT_ID_KEY_VALUE_RESTORE_TIMEOUT = 31; // 0x1f + field public static final int LOG_EVENT_ID_LOST_TRANSPORT = 25; // 0x19 + field public static final int LOG_EVENT_ID_MISSING_SIGNATURE = 42; // 0x2a + field public static final int LOG_EVENT_ID_NO_DATA_TO_SEND = 7; // 0x7 field public static final int LOG_EVENT_ID_NO_PACKAGES = 49; // 0x31 + field public static final int LOG_EVENT_ID_NO_PM_METADATA_RECEIVED = 23; // 0x17 field public static final int LOG_EVENT_ID_NO_RESTORE_METADATA_AVAILABLE = 22; // 0x16 + field public static final int LOG_EVENT_ID_PACKAGE_INELIGIBLE = 9; // 0x9 + field public static final int LOG_EVENT_ID_PACKAGE_KEY_VALUE_PARTICIPANT = 10; // 0xa field public static final int LOG_EVENT_ID_PACKAGE_NOT_FOUND = 12; // 0xc field public static final int LOG_EVENT_ID_PACKAGE_NOT_PRESENT = 26; // 0x1a + field public static final int LOG_EVENT_ID_PACKAGE_STOPPED = 11; // 0xb field public static final int LOG_EVENT_ID_PACKAGE_TRANSPORT_NOT_PRESENT = 15; // 0xf + field public static final int LOG_EVENT_ID_PM_AGENT_HAS_NO_METADATA = 24; // 0x18 + field public static final int LOG_EVENT_ID_QUOTA_HIT_PREFLIGHT = 18; // 0x12 + field public static final int LOG_EVENT_ID_RESTORE_ANY_VERSION = 34; // 0x22 + field public static final int LOG_EVENT_ID_RESTORE_VERSION_HIGHER = 27; // 0x1b + field public static final int LOG_EVENT_ID_SIGNATURE_MISMATCH = 29; // 0x1d + field public static final int LOG_EVENT_ID_SYSTEM_APP_NO_AGENT = 38; // 0x26 + field public static final int LOG_EVENT_ID_TRANSPORT_IS_NULL = 50; // 0x32 + field public static final int LOG_EVENT_ID_UNKNOWN_VERSION = 44; // 0x2c + field public static final int LOG_EVENT_ID_VERSIONS_MATCH = 35; // 0x23 field public static final int LOG_EVENT_ID_VERSION_OF_BACKUP_OLDER = 36; // 0x24 + field public static final int LOG_EVENT_ID_WIDGET_METADATA_MISMATCH = 47; // 0x2f + field public static final int LOG_EVENT_ID_WIDGET_UNKNOWN_VERSION = 48; // 0x30 } public abstract class BackupObserver { diff --git a/core/java/android/app/backup/BackupManagerMonitor.java b/core/java/android/app/backup/BackupManagerMonitor.java index d2a623e0b13ad..ebad16e0bc3d3 100644 --- a/core/java/android/app/backup/BackupManagerMonitor.java +++ b/core/java/android/app/backup/BackupManagerMonitor.java @@ -54,26 +54,118 @@ public class BackupManagerMonitor { public static final String EXTRA_LOG_EVENT_CATEGORY = "android.app.backup.extra.LOG_EVENT_CATEGORY"; + /** - * string: when we have event of id LOG_EVENT_ID_VERSION_OF_BACKUP_OLDER we send the version + * boolean: when we have an event with id LOG_EVENT_ID_KEY_VALUE_BACKUP_CANCEL we record if + * the call was to cancel backup of all packages + */ + public static final String EXTRA_LOG_CANCEL_ALL = "android.app.backup.extra.LOG_CANCEL_ALL"; + + /** + * string: when we have an event with id LOG_EVENT_ID_ILLEGAL_KEY we send the key that was used + * by the app + */ + public static final String EXTRA_LOG_ILLEGAL_KEY = "android.app.backup.extra.LOG_ILLEGAL_KEY"; + + /** + * long: when we have an event with id LOG_EVENT_ID_ERROR_PREFLIGHT we send the error code that + * was returned by the transport during preflight + */ + public static final String EXTRA_LOG_PREFLIGHT_ERROR = + "android.app.backup.extra.LOG_PREFLIGHT_ERROR"; + + /** + * string: when we have an event with id LOG_EVENT_ID_EXCEPTION_FULL_BACKUP we send the + * exception's stacktrace + */ + public static final String EXTRA_LOG_EXCEPTION_FULL_BACKUP = + "android.app.backup.extra.LOG_EXCEPTION_FULL_BACKUP"; + + /** + * int: when we have an event with id LOG_EVENT_ID_RESTORE_VERSION_HIGHER we send the + * restore package version + */ + public static final String EXTRA_LOG_RESTORE_VERSION = + "android.app.backup.extra.LOG_RESTORE_VERSION"; + + /** + * boolean: when we have an event with id LOG_EVENT_ID_RESTORE_VERSION_HIGHER we record if + * ApplicationInfo.FLAG_RESTORE_ANY_VERSION flag is set + */ + public static final String EXTRA_LOG_RESTORE_ANYWAY = + "android.app.backup.extra.LOG_RESTORE_ANYWAY"; + + + /** + * boolean: when we have an event with id LOG_EVENT_ID_APK_NOT_INSTALLED we record if + * the policy allows to install apks provided with the dataset + */ + public static final String EXTRA_LOG_POLICY_ALLOW_APKS = + "android.app.backup.extra.LOG_POLICY_ALLOW_APKS"; + + + /** + * string: when we have an event with id LOG_EVENT_ID_EXPECTED_DIFFERENT_PACKAGE we record the + * package name provided in the restore manifest + */ + public static final String EXTRA_LOG_MANIFEST_PACKAGE_NAME = + "android.app.backup.extra.LOG_MANIFEST_PACKAGE_NAME"; + + /** + * string: when we have an event with id LOG_EVENT_ID_WIDGET_METADATA_MISMATCH we record the + * package name provided in the widget metadata + */ + public static final String EXTRA_LOG_WIDGET_PACKAGE_NAME = + "android.app.backup.extra.LOG_WIDGET_PACKAGE_NAME"; + + /** + * int: when we have event of id LOG_EVENT_ID_VERSION_OF_BACKUP_OLDER we send the version * of the backup. */ - public static final String EXTRA_LOG_OLD_VERSION = - "android.app.backup.extra.LOG_OLD_VERSION"; + public static final String EXTRA_LOG_OLD_VERSION = "android.app.backup.extra.LOG_OLD_VERSION"; // TODO complete this list with all log messages. And document properly. - public static final int LOG_EVENT_ID_FULL_BACKUP_TIMEOUT = 4; + public static final int LOG_EVENT_ID_FULL_BACKUP_CANCEL = 4; + public static final int LOG_EVENT_ID_ILLEGAL_KEY = 5; + public static final int LOG_EVENT_ID_NO_DATA_TO_SEND = 7; + public static final int LOG_EVENT_ID_PACKAGE_INELIGIBLE = 9; + public static final int LOG_EVENT_ID_PACKAGE_KEY_VALUE_PARTICIPANT = 10; + public static final int LOG_EVENT_ID_PACKAGE_STOPPED = 11; public static final int LOG_EVENT_ID_PACKAGE_NOT_FOUND = 12; + public static final int LOG_EVENT_ID_BACKUP_DISABLED = 13; + public static final int LOG_EVENT_ID_DEVICE_NOT_PROVISIONED = 14; public static final int LOG_EVENT_ID_PACKAGE_TRANSPORT_NOT_PRESENT = 15; - public static final int LOG_EVENT_ID_KEY_VALUE_BACKUP_TIMEOUT = 21; + public static final int LOG_EVENT_ID_ERROR_PREFLIGHT = 16; + public static final int LOG_EVENT_ID_QUOTA_HIT_PREFLIGHT = 18; + public static final int LOG_EVENT_ID_EXCEPTION_FULL_BACKUP = 19; + public static final int LOG_EVENT_ID_KEY_VALUE_BACKUP_CANCEL = 21; public static final int LOG_EVENT_ID_NO_RESTORE_METADATA_AVAILABLE = 22; + public static final int LOG_EVENT_ID_NO_PM_METADATA_RECEIVED = 23; + public static final int LOG_EVENT_ID_PM_AGENT_HAS_NO_METADATA = 24; + public static final int LOG_EVENT_ID_LOST_TRANSPORT = 25; public static final int LOG_EVENT_ID_PACKAGE_NOT_PRESENT = 26; + public static final int LOG_EVENT_ID_RESTORE_VERSION_HIGHER = 27; public static final int LOG_EVENT_ID_APP_HAS_NO_AGENT = 28; + public static final int LOG_EVENT_ID_SIGNATURE_MISMATCH = 29; public static final int LOG_EVENT_ID_CANT_FIND_AGENT = 30; public static final int LOG_EVENT_ID_KEY_VALUE_RESTORE_TIMEOUT = 31; + public static final int LOG_EVENT_ID_RESTORE_ANY_VERSION = 34; + public static final int LOG_EVENT_ID_VERSIONS_MATCH = 35; public static final int LOG_EVENT_ID_VERSION_OF_BACKUP_OLDER = 36; + public static final int LOG_EVENT_ID_FULL_RESTORE_SIGNATURE_MISMATCH = 37; + public static final int LOG_EVENT_ID_SYSTEM_APP_NO_AGENT = 38; + public static final int LOG_EVENT_ID_FULL_RESTORE_ALLOW_BACKUP_FALSE = 39; + public static final int LOG_EVENT_ID_APK_NOT_INSTALLED = 40; + public static final int LOG_EVENT_ID_CANNOT_RESTORE_WITHOUT_APK = 41; + public static final int LOG_EVENT_ID_MISSING_SIGNATURE = 42; + public static final int LOG_EVENT_ID_EXPECTED_DIFFERENT_PACKAGE = 43; + public static final int LOG_EVENT_ID_UNKNOWN_VERSION = 44; public static final int LOG_EVENT_ID_FULL_RESTORE_TIMEOUT = 45; + public static final int LOG_EVENT_ID_CORRUPT_MANIFEST = 46; + public static final int LOG_EVENT_ID_WIDGET_METADATA_MISMATCH = 47; + public static final int LOG_EVENT_ID_WIDGET_UNKNOWN_VERSION = 48; public static final int LOG_EVENT_ID_NO_PACKAGES = 49; + public static final int LOG_EVENT_ID_TRANSPORT_IS_NULL = 50; diff --git a/services/backup/java/com/android/server/backup/BackupManagerService.java b/services/backup/java/com/android/server/backup/BackupManagerService.java index 4f8b8af495185..2d947a4dfca13 100644 --- a/services/backup/java/com/android/server/backup/BackupManagerService.java +++ b/services/backup/java/com/android/server/backup/BackupManagerService.java @@ -16,9 +16,23 @@ package com.android.server.backup; -import static android.app.backup.BackupManagerMonitor.LOG_EVENT_ID_VERSION_OF_BACKUP_OLDER; -import static android.app.backup.BackupManagerMonitor.LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY; +import static android.app.backup.BackupManagerMonitor.EXTRA_LOG_EVENT_PACKAGE_NAME; +import static android.app.backup.BackupManagerMonitor.EXTRA_LOG_EVENT_PACKAGE_VERSION; import static android.app.backup.BackupManagerMonitor.EXTRA_LOG_OLD_VERSION; +import static android.app.backup.BackupManagerMonitor.EXTRA_LOG_POLICY_ALLOW_APKS; +import static android.app.backup.BackupManagerMonitor.EXTRA_LOG_MANIFEST_PACKAGE_NAME; +import static android.app.backup.BackupManagerMonitor.LOG_EVENT_CATEGORY_AGENT; +import static android.app.backup.BackupManagerMonitor.LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY; +import static android.app.backup.BackupManagerMonitor.LOG_EVENT_ID_VERSION_OF_BACKUP_OLDER; +import static android.app.backup.BackupManagerMonitor.LOG_EVENT_ID_FULL_RESTORE_SIGNATURE_MISMATCH; +import static android.app.backup.BackupManagerMonitor.LOG_EVENT_ID_SYSTEM_APP_NO_AGENT; +import static android.app.backup.BackupManagerMonitor.LOG_EVENT_ID_FULL_RESTORE_ALLOW_BACKUP_FALSE; +import static android.app.backup.BackupManagerMonitor.LOG_EVENT_ID_APK_NOT_INSTALLED; +import static android.app.backup.BackupManagerMonitor.LOG_EVENT_ID_CANNOT_RESTORE_WITHOUT_APK; +import static android.app.backup.BackupManagerMonitor.LOG_EVENT_ID_MISSING_SIGNATURE; +import static android.app.backup.BackupManagerMonitor.LOG_EVENT_ID_EXPECTED_DIFFERENT_PACKAGE; +import static android.app.backup.BackupManagerMonitor.LOG_EVENT_ID_RESTORE_ANY_VERSION; +import static android.app.backup.BackupManagerMonitor.LOG_EVENT_ID_VERSIONS_MATCH; import static android.content.pm.ApplicationInfo.PRIVATE_FLAG_BACKUP_IN_FOREGROUND; import android.app.ActivityManager; @@ -2374,6 +2388,8 @@ public class BackupManagerService { IBackupTransport transport = mTransportManager.getCurrentTransportBinder(); if (transport == null) { sendBackupFinished(observer, BackupManager.ERROR_TRANSPORT_ABORTED); + monitor = monitorEvent(monitor, BackupManagerMonitor.LOG_EVENT_ID_TRANSPORT_IS_NULL, + null, BackupManagerMonitor.LOG_EVENT_CATEGORY_TRANSPORT, null); return BackupManager.ERROR_TRANSPORT_ABORTED; } @@ -3338,6 +3354,14 @@ public class BackupManagerService { addBackupTrace("illegal key " + key + " from " + pkgName); EventLog.writeEvent(EventLogTags.BACKUP_AGENT_FAILURE, pkgName, "bad key"); + mMonitor = monitorEvent(mMonitor, + BackupManagerMonitor.LOG_EVENT_ID_ILLEGAL_KEY, + mCurrentPackage, + BackupManagerMonitor + .LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY, + putMonitoringExtra(null, + BackupManagerMonitor.EXTRA_LOG_ILLEGAL_KEY, + key)); mBackupHandler.removeMessages(MSG_BACKUP_OPERATION_TIMEOUT); sendBackupOnPackageResult(mObserver, pkgName, BackupManager.ERROR_AGENT_FAILURE); @@ -3407,6 +3431,11 @@ public class BackupManagerService { if (MORE_DEBUG) Slog.i(TAG, "no backup data written; not calling transport"); addBackupTrace("no data to send"); + mMonitor = monitorEvent(mMonitor, + BackupManagerMonitor.LOG_EVENT_ID_NO_DATA_TO_SEND, + mCurrentPackage, + BackupManagerMonitor.LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY, + null); } if (mStatus == BackupTransport.TRANSPORT_OK) { @@ -3502,8 +3531,10 @@ public class BackupManagerService { Slog.e(TAG, "Cancel backing up " + mCurrentPackage.packageName); EventLog.writeEvent(EventLogTags.BACKUP_AGENT_FAILURE, mCurrentPackage.packageName); mMonitor = monitorEvent(mMonitor, - BackupManagerMonitor.LOG_EVENT_ID_KEY_VALUE_BACKUP_TIMEOUT, - mCurrentPackage, BackupManagerMonitor.LOG_EVENT_CATEGORY_AGENT, null); + BackupManagerMonitor.LOG_EVENT_ID_KEY_VALUE_BACKUP_CANCEL, + mCurrentPackage, BackupManagerMonitor.LOG_EVENT_CATEGORY_AGENT, + putMonitoringExtra(null, BackupManagerMonitor.EXTRA_LOG_CANCEL_ALL, + mCancelAll)); addBackupTrace( "cancel of " + mCurrentPackage.packageName + ", cancelAll=" + cancelAll); errorCleanup(); @@ -4593,6 +4624,11 @@ public class BackupManagerService { if (MORE_DEBUG) { Slog.d(TAG, "Ignoring ineligible package " + pkg); } + mMonitor = monitorEvent(mMonitor, + BackupManagerMonitor.LOG_EVENT_ID_PACKAGE_INELIGIBLE, + mCurrentPackage, + BackupManagerMonitor.LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY, + null); sendBackupOnPackageResult(mBackupObserver, pkg, BackupManager.ERROR_BACKUP_NOT_ALLOWED); continue; @@ -4603,6 +4639,11 @@ public class BackupManagerService { Slog.d(TAG, "Ignoring full-data backup of key/value participant " + pkg); } + mMonitor = monitorEvent(mMonitor, + BackupManagerMonitor.LOG_EVENT_ID_PACKAGE_KEY_VALUE_PARTICIPANT, + mCurrentPackage, + BackupManagerMonitor.LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY, + null); sendBackupOnPackageResult(mBackupObserver, pkg, BackupManager.ERROR_BACKUP_NOT_ALLOWED); continue; @@ -4613,6 +4654,11 @@ public class BackupManagerService { if (MORE_DEBUG) { Slog.d(TAG, "Ignoring stopped package " + pkg); } + mMonitor = monitorEvent(mMonitor, + BackupManagerMonitor.LOG_EVENT_ID_PACKAGE_STOPPED, + mCurrentPackage, + BackupManagerMonitor.LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY, + null); sendBackupOnPackageResult(mBackupObserver, pkg, BackupManager.ERROR_BACKUP_NOT_ALLOWED); continue; @@ -4620,7 +4666,7 @@ public class BackupManagerService { mPackages.add(info); } catch (NameNotFoundException e) { Slog.i(TAG, "Requested package " + pkg + " not found; ignoring"); - monitor = monitorEvent(monitor, + mMonitor = monitorEvent(mMonitor, BackupManagerMonitor.LOG_EVENT_ID_PACKAGE_NOT_FOUND, mCurrentPackage, BackupManagerMonitor.LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY, @@ -4696,9 +4742,17 @@ public class BackupManagerService { if (!mEnabled || !mProvisioned) { // Backups are globally disabled, so don't proceed. if (DEBUG) { - Slog.i(TAG, "full backup requested but e=" + mEnabled - + " p=" + mProvisioned + "; ignoring"); + Slog.i(TAG, "full backup requested but enabled=" + mEnabled + + " provisioned=" + mProvisioned + "; ignoring"); } + int monitoringEvent; + if (!mEnabled) { + monitoringEvent = BackupManagerMonitor.LOG_EVENT_ID_BACKUP_DISABLED; + } else { + monitoringEvent = BackupManagerMonitor.LOG_EVENT_ID_DEVICE_NOT_PROVISIONED; + } + mMonitor = monitorEvent(mMonitor, monitoringEvent, null, + BackupManagerMonitor.LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY, null); mUpdateSchedule = false; backupRunStatus = BackupManager.ERROR_BACKUP_NOT_ALLOWED; return; @@ -4722,7 +4776,8 @@ public class BackupManagerService { PackageInfo currentPackage = mPackages.get(i); String packageName = currentPackage.packageName; if (DEBUG) { - Slog.i(TAG, "Initiating full-data transport backup of " + packageName); + Slog.i(TAG, "Initiating full-data transport backup of " + packageName + + " token: " + mCurrentOpToken); } EventLog.writeEvent(EventLogTags.FULL_BACKUP_PACKAGE, packageName); @@ -4781,6 +4836,13 @@ public class BackupManagerService { + packageName + ": " + preflightResult + ", not running backup."); } + mMonitor = monitorEvent(mMonitor, + BackupManagerMonitor.LOG_EVENT_ID_ERROR_PREFLIGHT, + mCurrentPackage, + BackupManagerMonitor.LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY, + putMonitoringExtra(null, + BackupManagerMonitor.EXTRA_LOG_PREFLIGHT_ERROR, + preflightResult)); backupPackageStatus = (int) preflightResult; } else { int nRead = 0; @@ -4808,6 +4870,11 @@ public class BackupManagerService { if (backupPackageStatus == BackupTransport.TRANSPORT_QUOTA_EXCEEDED) { Slog.w(TAG, "Package hit quota limit in-flight " + packageName + ": " + totalRead + " of " + quota); + mMonitor = monitorEvent(mMonitor, + BackupManagerMonitor.LOG_EVENT_ID_QUOTA_HIT_PREFLIGHT, + mCurrentPackage, + BackupManagerMonitor.LOG_EVENT_CATEGORY_TRANSPORT, + null); mBackupRunner.sendQuotaExceeded(totalRead, quota); } } @@ -4942,6 +5009,14 @@ public class BackupManagerService { } catch (Exception e) { backupRunStatus = BackupManager.ERROR_TRANSPORT_ABORTED; Slog.w(TAG, "Exception trying full transport backup", e); + mMonitor = monitorEvent(mMonitor, + BackupManagerMonitor.LOG_EVENT_ID_EXCEPTION_FULL_BACKUP, + mCurrentPackage, + BackupManagerMonitor.LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY, + putMonitoringExtra(null, + BackupManagerMonitor.EXTRA_LOG_EXCEPTION_FULL_BACKUP, + Log.getStackTraceString(e))); + } finally { if (mCancelAll) { @@ -5221,7 +5296,7 @@ public class BackupManagerService { } mMonitor = monitorEvent(mMonitor, - BackupManagerMonitor.LOG_EVENT_ID_FULL_BACKUP_TIMEOUT, + BackupManagerMonitor.LOG_EVENT_ID_FULL_BACKUP_CANCEL, mCurrentPackage, BackupManagerMonitor.LOG_EVENT_CATEGORY_AGENT, null); mIsCancelled = true; // Cancel tasks spun off by this task. @@ -6309,9 +6384,29 @@ public class BackupManagerService { } else { Slog.w(TAG, "Metadata mismatch: package " + info.packageName + " but widget data for " + pkg); + + Bundle monitoringExtras = putMonitoringExtra(null, + EXTRA_LOG_EVENT_PACKAGE_NAME, info.packageName); + monitoringExtras = putMonitoringExtra(monitoringExtras, + BackupManagerMonitor.EXTRA_LOG_WIDGET_PACKAGE_NAME, pkg); + mMonitor = monitorEvent(mMonitor, + BackupManagerMonitor.LOG_EVENT_ID_WIDGET_METADATA_MISMATCH, + null, + LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY, + monitoringExtras); } } else { Slog.w(TAG, "Unsupported metadata version " + version); + + Bundle monitoringExtras = putMonitoringExtra(null, EXTRA_LOG_EVENT_PACKAGE_NAME, + info.packageName); + monitoringExtras = putMonitoringExtra(monitoringExtras, + EXTRA_LOG_EVENT_PACKAGE_VERSION, version); + mMonitor = monitorEvent(mMonitor, + BackupManagerMonitor.LOG_EVENT_ID_WIDGET_UNKNOWN_VERSION, + null, + LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY, + monitoringExtras); } } @@ -6386,10 +6481,20 @@ public class BackupManagerService { if ((pkgInfo.applicationInfo.flags & ApplicationInfo.FLAG_RESTORE_ANY_VERSION) != 0) { Slog.i(TAG, "Package has restoreAnyVersion; taking data"); + mMonitor = monitorEvent(mMonitor, + LOG_EVENT_ID_RESTORE_ANY_VERSION, + pkgInfo, + LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY, + null); policy = RestorePolicy.ACCEPT; } else if (pkgInfo.versionCode >= version) { Slog.i(TAG, "Sig + version match; taking data"); policy = RestorePolicy.ACCEPT; + mMonitor = monitorEvent(mMonitor, + LOG_EVENT_ID_VERSIONS_MATCH, + pkgInfo, + LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY, + null); } else { // The data is from a newer version of the app than // is presently installed. That means we can only @@ -6403,30 +6508,43 @@ public class BackupManagerService { } else { Slog.i(TAG, "Data requires newer version " + version + "; ignoring"); - ArrayList> list = - new ArrayList<>(); - list.add(new Pair( - EXTRA_LOG_OLD_VERSION, - Integer.toString(version))); mMonitor = monitorEvent(mMonitor, LOG_EVENT_ID_VERSION_OF_BACKUP_OLDER, pkgInfo, LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY, - list); + putMonitoringExtra(null, + EXTRA_LOG_OLD_VERSION, + version)); + policy = RestorePolicy.IGNORE; } } } else { Slog.w(TAG, "Restore manifest signatures do not match " + "installed application for " + info.packageName); + mMonitor = monitorEvent(mMonitor, + LOG_EVENT_ID_FULL_RESTORE_SIGNATURE_MISMATCH, + pkgInfo, + LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY, + null); } } else { Slog.w(TAG, "Package " + info.packageName + " is system level with no agent"); + mMonitor = monitorEvent(mMonitor, + LOG_EVENT_ID_SYSTEM_APP_NO_AGENT, + pkgInfo, + LOG_EVENT_CATEGORY_AGENT, + null); } } else { if (DEBUG) Slog.i(TAG, "Restore manifest from " + info.packageName + " but allowBackup=false"); + mMonitor = monitorEvent(mMonitor, + LOG_EVENT_ID_FULL_RESTORE_ALLOW_BACKUP_FALSE, + pkgInfo, + LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY, + null); } } catch (NameNotFoundException e) { // Okay, the target app isn't installed. We can process @@ -6439,26 +6557,71 @@ public class BackupManagerService { } else { policy = RestorePolicy.IGNORE; } + Bundle monitoringExtras = putMonitoringExtra(null, + EXTRA_LOG_EVENT_PACKAGE_NAME, info.packageName); + monitoringExtras = putMonitoringExtra(monitoringExtras, + EXTRA_LOG_POLICY_ALLOW_APKS, mAllowApks); + mMonitor = monitorEvent(mMonitor, + LOG_EVENT_ID_APK_NOT_INSTALLED, + null, + LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY, + monitoringExtras); } if (policy == RestorePolicy.ACCEPT_IF_APK && !hasApk) { Slog.i(TAG, "Cannot restore package " + info.packageName + " without the matching .apk"); + mMonitor = monitorEvent(mMonitor, + LOG_EVENT_ID_CANNOT_RESTORE_WITHOUT_APK, + null, + LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY, + putMonitoringExtra(null, + EXTRA_LOG_EVENT_PACKAGE_NAME, info.packageName)); } } else { Slog.i(TAG, "Missing signature on backed-up package " + info.packageName); + mMonitor = monitorEvent(mMonitor, + LOG_EVENT_ID_MISSING_SIGNATURE, + null, + LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY, + putMonitoringExtra(null, + EXTRA_LOG_EVENT_PACKAGE_NAME, info.packageName)); } } else { Slog.i(TAG, "Expected package " + info.packageName + " but restore manifest claims " + manifestPackage); + Bundle monitoringExtras = putMonitoringExtra(null, + EXTRA_LOG_EVENT_PACKAGE_NAME, info.packageName); + monitoringExtras = putMonitoringExtra(monitoringExtras, + EXTRA_LOG_MANIFEST_PACKAGE_NAME, manifestPackage); + mMonitor = monitorEvent(mMonitor, + LOG_EVENT_ID_EXPECTED_DIFFERENT_PACKAGE, + null, + LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY, + monitoringExtras); } } else { Slog.i(TAG, "Unknown restore manifest version " + version + " for package " + info.packageName); + Bundle monitoringExtras = putMonitoringExtra(null, + EXTRA_LOG_EVENT_PACKAGE_NAME, info.packageName); + monitoringExtras = putMonitoringExtra(monitoringExtras, + EXTRA_LOG_EVENT_PACKAGE_VERSION, version); + mMonitor = monitorEvent(mMonitor, + BackupManagerMonitor.LOG_EVENT_ID_UNKNOWN_VERSION, + null, + LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY, + monitoringExtras); + } } catch (NumberFormatException e) { Slog.w(TAG, "Corrupt restore manifest for package " + info.packageName); + mMonitor = monitorEvent(mMonitor, + BackupManagerMonitor.LOG_EVENT_ID_CORRUPT_MANIFEST, + null, + LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY, + putMonitoringExtra(null, EXTRA_LOG_EVENT_PACKAGE_NAME, info.packageName)); } catch (IllegalArgumentException e) { Slog.w(TAG, e.getMessage()); } @@ -8557,7 +8720,12 @@ if (MORE_DEBUG) Slog.v(TAG, " + got " + nRead + "; now wanting " + (size - soF return; } if (!PACKAGE_MANAGER_SENTINEL.equals(desc.getPackageName())) { - Slog.e(TAG, "Required metadata but got " + desc.getPackageName()); + Slog.e(TAG, "Required package metadata but got " + + desc.getPackageName()); + mMonitor = monitorEvent(mMonitor, + BackupManagerMonitor.LOG_EVENT_ID_NO_PM_METADATA_RECEIVED, + mCurrentPackage, + BackupManagerMonitor.LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY, null); mStatus = BackupTransport.TRANSPORT_ERROR; executeNextState(UnifiedRestoreState.FINAL); return; @@ -8585,7 +8753,11 @@ if (MORE_DEBUG) Slog.v(TAG, " + got " + nRead + "; now wanting " + (size - soF // signature/version verification etc, so we simply do not proceed with // the restore operation. if (!mPmAgent.hasMetadata()) { - Slog.e(TAG, "No restore metadata available, so not restoring"); + Slog.e(TAG, "PM agent has no metadata, so not restoring"); + mMonitor = monitorEvent(mMonitor, + BackupManagerMonitor.LOG_EVENT_ID_PM_AGENT_HAS_NO_METADATA, + mCurrentPackage, + BackupManagerMonitor.LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY, null); EventLog.writeEvent(EventLogTags.RESTORE_AGENT_FAILURE, PACKAGE_MANAGER_SENTINEL, "Package manager restore metadata missing"); @@ -8601,6 +8773,10 @@ if (MORE_DEBUG) Slog.v(TAG, " + got " + nRead + "; now wanting " + (size - soF } catch (Exception e) { // If we lost the transport at any time, halt Slog.e(TAG, "Unable to contact transport for restore: " + e.getMessage()); + mMonitor = monitorEvent(mMonitor, + BackupManagerMonitor.LOG_EVENT_ID_LOST_TRANSPORT, + null, + BackupManagerMonitor.LOG_EVENT_CATEGORY_TRANSPORT, null); mStatus = BackupTransport.TRANSPORT_ERROR; mBackupHandler.removeMessages(MSG_BACKUP_RESTORE_STEP, this); executeNextState(UnifiedRestoreState.FINAL); @@ -8670,17 +8846,37 @@ if (MORE_DEBUG) Slog.v(TAG, " + got " + nRead + "; now wanting " + (size - soF // handle this case, we do not attempt the restore. if ((mCurrentPackage.applicationInfo.flags & ApplicationInfo.FLAG_RESTORE_ANY_VERSION) == 0) { - String message = "Version " + metaInfo.versionCode + String message = "Source version " + metaInfo.versionCode + " > installed version " + mCurrentPackage.versionCode; Slog.w(TAG, "Package " + pkgName + ": " + message); + Bundle monitoringExtras = putMonitoringExtra(null, + BackupManagerMonitor.EXTRA_LOG_RESTORE_VERSION, + metaInfo.versionCode); + monitoringExtras = putMonitoringExtra(monitoringExtras, + BackupManagerMonitor.EXTRA_LOG_RESTORE_ANYWAY, false); + mMonitor = monitorEvent(mMonitor, + BackupManagerMonitor.LOG_EVENT_ID_RESTORE_VERSION_HIGHER, + mCurrentPackage, + BackupManagerMonitor.LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY, + monitoringExtras); EventLog.writeEvent(EventLogTags.RESTORE_AGENT_FAILURE, pkgName, message); nextState = UnifiedRestoreState.RUNNING_QUEUE; return; } else { - if (DEBUG) Slog.v(TAG, "Version " + metaInfo.versionCode - + " > installed " + mCurrentPackage.versionCode + if (DEBUG) Slog.v(TAG, "Source version " + metaInfo.versionCode + + " > installed version " + mCurrentPackage.versionCode + " but restoreAnyVersion"); + Bundle monitoringExtras = putMonitoringExtra(null, + BackupManagerMonitor.EXTRA_LOG_RESTORE_VERSION, + metaInfo.versionCode); + monitoringExtras = putMonitoringExtra(monitoringExtras, + BackupManagerMonitor.EXTRA_LOG_RESTORE_ANYWAY, true); + mMonitor = monitorEvent(mMonitor, + BackupManagerMonitor.LOG_EVENT_ID_RESTORE_VERSION_HIGHER, + mCurrentPackage, + BackupManagerMonitor.LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY, + monitoringExtras); } } @@ -8739,6 +8935,9 @@ if (MORE_DEBUG) Slog.v(TAG, " + got " + nRead + "; now wanting " + (size - soF Metadata metaInfo = mPmAgent.getRestoredMetadata(packageName); if (!BackupUtils.signaturesMatch(metaInfo.sigHashes, mCurrentPackage)) { Slog.w(TAG, "Signature mismatch restoring " + packageName); + mMonitor = monitorEvent(mMonitor, + BackupManagerMonitor.LOG_EVENT_ID_SIGNATURE_MISMATCH, mCurrentPackage, + BackupManagerMonitor.LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY, null); EventLog.writeEvent(EventLogTags.RESTORE_AGENT_FAILURE, packageName, "Signature mismatch"); executeNextState(UnifiedRestoreState.RUNNING_QUEUE); @@ -11035,23 +11234,54 @@ if (MORE_DEBUG) Slog.v(TAG, " + got " + nRead + "; now wanting " + (size - soF } } + private Bundle putMonitoringExtra(Bundle extras, String key, String value) { + if (extras == null) { + extras = new Bundle(); + } + extras.putString(key, value); + return extras; + } + + private Bundle putMonitoringExtra(Bundle extras, String key, int value) { + if (extras == null) { + extras = new Bundle(); + } + extras.putInt(key, value); + return extras; + } + + private Bundle putMonitoringExtra(Bundle extras, String key, long value) { + if (extras == null) { + extras = new Bundle(); + } + extras.putLong(key, value); + return extras; + } + + + private Bundle putMonitoringExtra(Bundle extras, String key, boolean value) { + if (extras == null) { + extras = new Bundle(); + } + extras.putBoolean(key, value); + return extras; + } + private static IBackupManagerMonitor monitorEvent(IBackupManagerMonitor monitor, int id, - PackageInfo pkg, int category, ArrayList> extras) { + PackageInfo pkg, int category, Bundle extras) { if (monitor != null) { try { Bundle bundle = new Bundle(); bundle.putInt(BackupManagerMonitor.EXTRA_LOG_EVENT_ID, id); bundle.putInt(BackupManagerMonitor.EXTRA_LOG_EVENT_CATEGORY, category); if (pkg != null) { - bundle.putString(BackupManagerMonitor.EXTRA_LOG_EVENT_PACKAGE_NAME, + bundle.putString(EXTRA_LOG_EVENT_PACKAGE_NAME, pkg.packageName); bundle.putInt(BackupManagerMonitor.EXTRA_LOG_EVENT_PACKAGE_VERSION, pkg.versionCode); } if (extras != null) { - for (Pair pair : extras) { - bundle.putString(pair.first, pair.second); - } + bundle.putAll(extras); } monitor.onEvent(bundle); return monitor;