Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c126e4fd authored by Sarp Misoglu's avatar Sarp Misoglu
Browse files

Log cancellation reason for full backups to BMM

Currently it's not possible to know from these logs if the backup was
cancelled due to timeout or the app crashing or due to backups being
explicitly cancelled by an external caller. This CL fixes that issue.

Flag: EXEMPT log only update
Test: manual // PFTBT is notoriously impossible to write unit tests for.
Bug: 399645990
Change-Id: Ia18fdec1d9547130926bf62666ac055e320fb0b6
parent 7aec8c1a
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -1138,6 +1138,10 @@ public class Bmgr {
                }
                out.append("]");
            }
            if (event.containsKey(BackupManagerMonitor.EXTRA_LOG_CANCELLATION_REASON)) {
                out.append(" cancellationReason: ");
                out.append(event.getInt(BackupManagerMonitor.EXTRA_LOG_CANCELLATION_REASON));
            }
            if (mVerbose) {
                Set<String> remainingKeys = new ArraySet<>(event.keySet());
                remainingKeys.remove(BackupManagerMonitor.EXTRA_LOG_EVENT_ID);
+9 −0
Original line number Diff line number Diff line
@@ -164,6 +164,15 @@ public class BackupManagerMonitor {
  public static final String EXTRA_LOG_V_TO_U_ALLOWLIST =
          "android.app.backup.extra.V_TO_U_ALLOWLIST";

  /**
   * An int indicating why a backup was cancelled. One of {@link
   * com.android.server.backup.BackupRestoreTask.CancellationReason}.
   *
   * @hide
   */
  public static final String EXTRA_LOG_CANCELLATION_REASON =
          "android.app.backup.extra.CANCELLATION_REASON";

  // TODO complete this list with all log messages. And document properly.
  public static final int LOG_EVENT_ID_FULL_BACKUP_CANCEL = 4;
  public static final int LOG_EVENT_ID_ILLEGAL_KEY = 5;
+7 −2
Original line number Diff line number Diff line
@@ -973,13 +973,18 @@ public class PerformFullTransportBackupTask extends FullBackupTask implements Ba

        @Override
        public void handleCancel(@CancellationReason int cancellationReason) {
            Slog.w(TAG, "Full backup cancel of " + mTarget.packageName);
            Slog.w(
                    TAG,
                    "Cancelled backup: " + mTarget.packageName + " reason:" + cancellationReason);

            mBackupManagerMonitorEventSender.monitorEvent(
                    BackupManagerMonitor.LOG_EVENT_ID_FULL_BACKUP_CANCEL,
                    mTarget,
                    BackupManagerMonitor.LOG_EVENT_CATEGORY_AGENT,
                    /* extras= */ null);
                    BackupManagerMonitorEventSender.putMonitoringExtra(
                            /* extras= */ null,
                            BackupManagerMonitor.EXTRA_LOG_CANCELLATION_REASON,
                            cancellationReason));
            mIsCancelled = true;
            // Cancel tasks spun off by this task.
            mUserBackupManagerService.handleCancel(mEphemeralToken, cancellationReason);