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

Commit 39a5936f authored by Beatrice Marchegiani's avatar Beatrice Marchegiani Committed by Android (Google) Code Review
Browse files

Merge "Add BMM events to V to U restore" into main

parents b9f34c78 8c06fe37
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -145,6 +145,25 @@ public class BackupManagerMonitor {
   */
  public static final String EXTRA_LOG_OPERATION_TYPE = "android.app.backup.extra.OPERATION_TYPE";

  /**
   * List of system components that do not support restore in a  V-> U OS downgrade, even if
   * restoreAnyVersion is set to true.
   * Read from Settings.Secure.V_TO_U_RESTORE_DENYLIST
   *
   * @hide
   */
  public static final String EXTRA_LOG_V_TO_U_DENYLIST = "android.app.backup.extra.V_TO_U_DENYLIST";

  /**
   * List of system components that support restore in a  V-> U OS downgrade, even if
   * restoreAnyVersion is set to false.
   * Read from Settings.Secure.V_TO_U_RESTORE_ALLOWLIST
   *
   * @hide
   */
  public static final String EXTRA_LOG_V_TO_U_ALLOWLIST =
          "android.app.backup.extra.V_TO_U_ALLOWLIST";

  // 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;
@@ -241,6 +260,15 @@ public class BackupManagerMonitor {
  /** Agent error during {@link PerformUnifiedRestoreTask#restoreFinished()}
   @hide */
  public static final int LOG_EVENT_ID_AGENT_FAILURE = 69;
  /** V to U restore attempt, pkg is eligible
   @hide */
  public static final int LOG_EVENT_ID_V_TO_U_RESTORE_PKG_ELIGIBLE = 70;
  /** V to U restore attempt, pkg is not eligible
   @hide */
  public static final int LOG_EVENT_ID_V_TO_U_RESTORE_PKG_NOT_ELIGIBLE = 71;
  /** V to U restore attempt, allowlist and denlist are set
   @hide */
  public static final int LOG_EVENT_ID_V_TO_U_RESTORE_SET_LIST = 72;

  /**
   * This method will be called each time something important happens on BackupManager.
+49 −0
Original line number Diff line number Diff line
@@ -667,12 +667,23 @@ public class PerformUnifiedRestoreTask implements BackupRestoreTask {
                                            backupManagerService.getContext().getContentResolver(),
                                            Settings.Secure.V_TO_U_RESTORE_DENYLIST,
                                            mUserId));
                        logVToUListsToBMM();
                        mAreVToUListsSet = true;
                    }
                    if (isPackageEligibleForVToURestore(mCurrentPackage)) {
                        mBackupManagerMonitorEventSender.monitorEvent(
                                BackupManagerMonitor.LOG_EVENT_ID_V_TO_U_RESTORE_PKG_ELIGIBLE,
                                mCurrentPackage,
                                BackupManagerMonitor.LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY,
                                addRestoreOperationTypeToEvent(/* extras= */null));
                        Slog.i(TAG, "Package " + pkgName
                                + " is eligible for V to U downgrade scenario");
                    } else {
                        mBackupManagerMonitorEventSender.monitorEvent(
                                BackupManagerMonitor.LOG_EVENT_ID_V_TO_U_RESTORE_PKG_NOT_ELIGIBLE,
                                mCurrentPackage,
                                BackupManagerMonitor.LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY,
                                addRestoreOperationTypeToEvent(/* extras= */null));
                        String message = "Package not eligible for V to U downgrade scenario";
                        Slog.i(TAG, pkgName + " : " + message);
                        EventLog.writeEvent(EventLogTags.RESTORE_AGENT_FAILURE, pkgName, message);
@@ -1703,14 +1714,25 @@ public class PerformUnifiedRestoreTask implements BackupRestoreTask {
        //      (and not in the denylist)
        //    - The package has restoreAnyVersion set to true and is not part of the denylist
        if (mVToUDenylist.contains(mCurrentPackage.packageName)){
            if (DEBUG) {
                Slog.i(TAG, mCurrentPackage.packageName + " : Package is in V to U denylist");
            }
            return false;
        } else if ((mCurrentPackage.applicationInfo.flags
                & ApplicationInfo.FLAG_RESTORE_ANY_VERSION)
                == 0) {
            // package has restoreAnyVersion set to false
            if (DEBUG) {
                Slog.i(TAG, mCurrentPackage.packageName
                        + " : Package has restoreAnyVersion=false and is in V to U allowlist");
            }
            return mVToUAllowlist.contains(mCurrentPackage.packageName);
        } else {
            // package has restoreAnyVersion set to true and is nor in denylist
            if (DEBUG) {
                Slog.i(TAG, mCurrentPackage.packageName
                        + " : Package has restoreAnyVersion=true and is not in V to U denylist");
            }
            return true;
        }
    }
@@ -1755,4 +1777,31 @@ public class PerformUnifiedRestoreTask implements BackupRestoreTask {
                monitoringExtras);
    }

    private void logVToUListsToBMM() {
        // send a BMM event with the allowlist
        Bundle monitoringExtrasAllowlist =
                mBackupManagerMonitorEventSender.putMonitoringExtra(
                        null,
                        BackupManagerMonitor.EXTRA_LOG_V_TO_U_ALLOWLIST,
                        mVToUAllowlist.toString());
        monitoringExtrasAllowlist = addRestoreOperationTypeToEvent(monitoringExtrasAllowlist);
        mBackupManagerMonitorEventSender.monitorEvent(
                BackupManagerMonitor.LOG_EVENT_ID_V_TO_U_RESTORE_SET_LIST,
                null,
                BackupManagerMonitor.LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY,
                monitoringExtrasAllowlist);
        // send a BMM event with the denylist
        Bundle monitoringExtrasDenylist =
                mBackupManagerMonitorEventSender.putMonitoringExtra(
                        null,
                        BackupManagerMonitor.EXTRA_LOG_V_TO_U_DENYLIST,
                        mVToUDenylist.toString());
        monitoringExtrasDenylist = addRestoreOperationTypeToEvent(monitoringExtrasDenylist);
        mBackupManagerMonitorEventSender.monitorEvent(
                BackupManagerMonitor.LOG_EVENT_ID_V_TO_U_RESTORE_SET_LIST,
                null,
                BackupManagerMonitor.LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY,
                monitoringExtrasDenylist);
    }

}
+31 −6
Original line number Diff line number Diff line
@@ -146,7 +146,6 @@ public class BackupManagerMonitorDumpsysUtils {
                        + eventBundle.getString(BackupManagerMonitor.EXTRA_LOG_EVENT_PACKAGE_NAME));
            }

            // TODO(b/296818666): add extras to the events
            addAgentLogsIfAvailable(eventBundle, pw);
            addExtrasIfAvailable(eventBundle, pw);
        } catch (java.io.IOException e) {
@@ -203,6 +202,11 @@ public class BackupManagerMonitorDumpsysUtils {
     * EXTRA_LOG_RESTORE_VERSION [int]: the version of the package on the source
     * EXTRA_LOG_RESTORE_ANYWAY [bool]: if the package allows restore any version
     * EXTRA_LOG_RESTORE_VERSION_TARGET [int]: an extra to record the package version on the target
     *
     * When we are performing a V to U downgrade (event with id V_TO_U_RESTORE_SET_LIST) we record
     * the value of the V to U allowlist and denylist:
     * EXTRA_LOG_V_TO_U_ALLOWLIST[string]
     * EXTRA_LOG_V_TO_U_DENYLIST[string]
     */
    private void addExtrasIfAvailable(Bundle eventBundle, PrintWriter pw) {
        if (eventBundle.getInt(BackupManagerMonitor.EXTRA_LOG_EVENT_ID) ==
@@ -222,6 +226,23 @@ public class BackupManagerMonitorDumpsysUtils {
                        BackupManagerMonitor.EXTRA_LOG_EVENT_PACKAGE_LONG_VERSION));
            }
        }

        if (eventBundle.getInt(BackupManagerMonitor.EXTRA_LOG_EVENT_ID)
                == BackupManagerMonitor.LOG_EVENT_ID_V_TO_U_RESTORE_SET_LIST) {
            if (eventBundle.containsKey(
                    BackupManagerMonitor.EXTRA_LOG_V_TO_U_DENYLIST)) {
                pw.println("\t\tV to U Denylist : "
                        + eventBundle.getString(
                        BackupManagerMonitor.EXTRA_LOG_V_TO_U_DENYLIST));
            }

            if (eventBundle.containsKey(
                    BackupManagerMonitor.EXTRA_LOG_V_TO_U_ALLOWLIST)) {
                pw.println("\t\tV to U Allowllist : "
                        + eventBundle.getString(
                        BackupManagerMonitor.EXTRA_LOG_V_TO_U_ALLOWLIST));
            }
        }
    }

    /*
@@ -342,10 +363,14 @@ public class BackupManagerMonitorDumpsysUtils {
            case BackupManagerMonitor.LOG_EVENT_ID_TRANSPORT_ERROR_FULL_RESTORE ->
                    "Transport error full restore";
            case BackupManagerMonitor.LOG_EVENT_ID_RESTORE_COMPLETE -> "Restore complete";
            case BackupManagerMonitor.LOG_EVENT_ID_START_PACKAGE_RESTORE ->
                    "Start package restore";
            case BackupManagerMonitor.LOG_EVENT_ID_AGENT_FAILURE ->
                    "Agent failure";
            case BackupManagerMonitor.LOG_EVENT_ID_START_PACKAGE_RESTORE -> "Start package restore";
            case BackupManagerMonitor.LOG_EVENT_ID_AGENT_FAILURE -> "Agent failure";
            case BackupManagerMonitor.LOG_EVENT_ID_V_TO_U_RESTORE_PKG_ELIGIBLE ->
                    "V to U restore pkg eligible";
            case BackupManagerMonitor.LOG_EVENT_ID_V_TO_U_RESTORE_PKG_NOT_ELIGIBLE ->
                    "V to U restore pkg not eligible";
            case BackupManagerMonitor.LOG_EVENT_ID_V_TO_U_RESTORE_SET_LIST ->
                    "V to U restore lists";
            default -> "Unknown log event ID: " + code;
        };
        return id;