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

Commit fbefde0a authored by Piyush Mehrotra's avatar Piyush Mehrotra Committed by Automerger Merge Worker
Browse files

Merge "Increase BMM logging coverage for restore at install flow" into 24D1-dev am: 6afb3e75

parents 4e98b884 6afb3e75
Loading
Loading
Loading
Loading
+18 −0
Original line number Original line Diff line number Diff line
@@ -1280,6 +1280,24 @@ public class Bmgr {
                return "START_PACKAGE_RESTORE";
                return "START_PACKAGE_RESTORE";
            case BackupManagerMonitor.LOG_EVENT_ID_AGENT_FAILURE:
            case BackupManagerMonitor.LOG_EVENT_ID_AGENT_FAILURE:
                return "AGENT_FAILURE";
                return "AGENT_FAILURE";
            case BackupManagerMonitor.LOG_EVENT_ID_RESTORE_AT_INSTALL_INVOKED:
                return "RESTORE_AT_INSTALL_INVOKED";
            case BackupManagerMonitor.LOG_EVENT_ID_SKIP_RESTORE_AT_INSTALL:
                return "SKIP_RESTORE_AT_INSTALL";
            case BackupManagerMonitor.LOG_EVENT_ID_PACKAGE_ACCEPTED_FOR_RESTORE:
                return "PACKAGE_ACCEPTED_FOR_RESTORE";
            case BackupManagerMonitor.LOG_EVENT_ID_RESTORE_DATA_DOES_NOT_BELONG_TO_PACKAGE:
                return "RESTORE_DATA_DOES_NOT_BELONG_TO_PACKAGE";
            case BackupManagerMonitor.LOG_EVENT_ID_UNABLE_TO_CREATE_AGENT_FOR_RESTORE:
                return "UNABLE_TO_CREATE_AGENT_FOR_RESTORE";
            case BackupManagerMonitor.LOG_EVENT_ID_AGENT_CRASHED_BEFORE_RESTORE_DATA_IS_SENT:
                return "AGENT_CRASHED_BEFORE_RESTORE_DATA_IS_SEN";
            case BackupManagerMonitor.LOG_EVENT_ID_FAILED_TO_SEND_DATA_TO_AGENT_DURING_RESTORE:
                return "FAILED_TO_SEND_DATA_TO_AGENT_DURING_RESTORE";
            case BackupManagerMonitor.LOG_EVENT_ID_AGENT_FAILURE_DURING_RESTORE:
                return "AGENT_FAILURE_DURING_RESTORE";
            case BackupManagerMonitor.LOG_EVENT_ID_FAILED_TO_READ_DATA_FROM_TRANSPORT:
                return "FAILED_TO_READ_DATA_FROM_TRANSPORT";
            default:
            default:
                return "UNKNOWN_ID";
                return "UNKNOWN_ID";
        }
        }
+27 −0
Original line number Original line Diff line number Diff line
@@ -269,6 +269,33 @@ public class BackupManagerMonitor {
  /** V to U restore attempt, allowlist and denlist are set
  /** V to U restore attempt, allowlist and denlist are set
   @hide */
   @hide */
  public static final int LOG_EVENT_ID_V_TO_U_RESTORE_SET_LIST = 72;
  public static final int LOG_EVENT_ID_V_TO_U_RESTORE_SET_LIST = 72;
  /** As part of package install, {@link PackageManager} invoked restore.
   @hide */
  public static final int LOG_EVENT_ID_RESTORE_AT_INSTALL_INVOKED = 73;
  /** Skipping restore at package install
   @hide */
  public static final int LOG_EVENT_ID_SKIP_RESTORE_AT_INSTALL = 74;
  /** Package is eligible and is accepted for restore
   @hide */
  public static final int LOG_EVENT_ID_PACKAGE_ACCEPTED_FOR_RESTORE = 75;
  /** Restore data doesn't belong to the package for which restore is started
   @hide */
  public static final int LOG_EVENT_ID_RESTORE_DATA_DOES_NOT_BELONG_TO_PACKAGE = 76;
  /** Unable to create BackupAgent for package for restore
   @hide */
  public static final int LOG_EVENT_ID_UNABLE_TO_CREATE_AGENT_FOR_RESTORE = 77;
  /** BackupAgent crashed after creation but before accepting any data
   @hide */
  public static final int LOG_EVENT_ID_AGENT_CRASHED_BEFORE_RESTORE_DATA_IS_SENT = 78;
  /** Failure in streaming restore data to BackupAgent
   @hide */
  public static final int LOG_EVENT_ID_FAILED_TO_SEND_DATA_TO_AGENT_DURING_RESTORE = 79;
  /** BackupAgent related failure during restore
   @hide */
  public static final int LOG_EVENT_ID_AGENT_FAILURE_DURING_RESTORE = 80;
  /** Failure in reading data from TransportPackage during restore
   @hide */
  public static final int LOG_EVENT_ID_FAILED_TO_READ_DATA_FROM_TRANSPORT = 81;


  /**
  /**
   * This method will be called each time something important happens on BackupManager.
   * This method will be called each time something important happens on BackupManager.
+8 −0
Original line number Original line Diff line number Diff line
@@ -51,3 +51,11 @@ flag {
    bug: "296844513"
    bug: "296844513"
    is_fixed_read_only: true
    is_fixed_read_only: true
}
}

flag {
    name: "enable_increased_bmm_logging_for_restore_at_install"
    namespace: "onboarding"
    description: "Increase BMM logging coverage in restore at install flow."
    bug: "331749778"
    is_fixed_read_only: true
}
 No newline at end of file
+49 −1
Original line number Original line Diff line number Diff line
@@ -3903,11 +3903,33 @@ public class UserBackupManagerService {
            skip = true;
            skip = true;
        }
        }


        BackupManagerMonitorEventSender  mBMMEventSender =
                getBMMEventSender(/*monitor=*/ null);
        PackageInfo packageInfo = getPackageInfoForBMMLogging(packageName);
        TransportConnection transportConnection =
        TransportConnection transportConnection =
                mTransportManager.getCurrentTransportClient("BMS.restoreAtInstall()");
                mTransportManager.getCurrentTransportClient("BMS.restoreAtInstall()");
        if (transportConnection == null) {
        if (transportConnection == null) {
            if (DEBUG) Slog.w(TAG, addUserIdToLogMessage(mUserId, "No transport client"));
            if (DEBUG) Slog.w(TAG, addUserIdToLogMessage(mUserId, "No transport client"));
            skip = true;
            skip = true;
        } else if (Flags.enableIncreasedBmmLoggingForRestoreAtInstall()) {
            try {
                BackupTransportClient transportClient = transportConnection.connectOrThrow(
                        "BMS.restoreAtInstall");
                mBMMEventSender.setMonitor(transportClient.getBackupManagerMonitor());
            } catch (TransportNotAvailableException | RemoteException e) {
                mBMMEventSender.monitorEvent(
                        BackupManagerMonitor.LOG_EVENT_ID_TRANSPORT_IS_NULL, packageInfo,
                        BackupManagerMonitor.LOG_EVENT_CATEGORY_TRANSPORT, null);
            }
        }

        if (Flags.enableIncreasedBmmLoggingForRestoreAtInstall()) {
            mBMMEventSender.monitorEvent(
                    BackupManagerMonitor.LOG_EVENT_ID_RESTORE_AT_INSTALL_INVOKED, packageInfo,
                    BackupManagerMonitor.LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY,
                    mBMMEventSender.putMonitoringExtra(/*extras=*/null,
                            BackupManagerMonitor.EXTRA_LOG_OPERATION_TYPE,
                            BackupAnnotations.OperationType.RESTORE));
        }
        }


        if (!mAutoRestore) {
        if (!mAutoRestore) {
@@ -3943,7 +3965,7 @@ public class UserBackupManagerService {
                        RestoreParams.createForRestoreAtInstall(
                        RestoreParams.createForRestoreAtInstall(
                                transportConnection,
                                transportConnection,
                                /* observer */ null,
                                /* observer */ null,
                                /* monitor */ null,
                                mBMMEventSender.getMonitor(),
                                restoreSet,
                                restoreSet,
                                packageName,
                                packageName,
                                token,
                                token,
@@ -3963,6 +3985,15 @@ public class UserBackupManagerService {
        if (skip) {
        if (skip) {
            // Auto-restore disabled or no way to attempt a restore
            // Auto-restore disabled or no way to attempt a restore


            if (Flags.enableIncreasedBmmLoggingForRestoreAtInstall()) {
                mBMMEventSender.monitorEvent(
                        BackupManagerMonitor.LOG_EVENT_ID_SKIP_RESTORE_AT_INSTALL, packageInfo,
                        BackupManagerMonitor.LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY,
                        mBMMEventSender.putMonitoringExtra(/*extras=*/null,
                                BackupManagerMonitor.EXTRA_LOG_OPERATION_TYPE,
                                BackupAnnotations.OperationType.RESTORE));
            }

            if (transportConnection != null) {
            if (transportConnection != null) {
                mTransportManager.disposeOfTransportClient(
                mTransportManager.disposeOfTransportClient(
                        transportConnection, "BMS.restoreAtInstall()");
                        transportConnection, "BMS.restoreAtInstall()");
@@ -3976,6 +4007,23 @@ public class UserBackupManagerService {
        }
        }
    }
    }


    private PackageInfo getPackageInfoForBMMLogging(String packageName) {
        try {
            return mPackageManager.getPackageInfoAsUser(packageName, 0, mUserId);
        } catch (NameNotFoundException e) {
            Slog.w(
                    TAG,
                    addUserIdToLogMessage(
                            mUserId, "Asked to get PackageInfo for BMM logging of nonexistent pkg "
                                    + packageName));

            PackageInfo packageInfo = new PackageInfo();
            packageInfo.packageName = packageName;

            return packageInfo;
        }
    }

    /** Hand off a restore session. */
    /** Hand off a restore session. */
    public IRestoreSession beginRestoreSession(String packageName, String transport) {
    public IRestoreSession beginRestoreSession(String packageName, String transport) {
        if (DEBUG) {
        if (DEBUG) {
+31 −0
Original line number Original line Diff line number Diff line
@@ -29,6 +29,7 @@ import android.app.ApplicationThreadConstants;
import android.app.IBackupAgent;
import android.app.IBackupAgent;
import android.app.backup.BackupAgent;
import android.app.backup.BackupAgent;
import android.app.backup.BackupAnnotations;
import android.app.backup.BackupAnnotations;
import android.app.backup.BackupManagerMonitor;
import android.app.backup.FullBackup;
import android.app.backup.FullBackup;
import android.app.backup.IBackupManagerMonitor;
import android.app.backup.IBackupManagerMonitor;
import android.app.backup.IFullBackupRestoreObserver;
import android.app.backup.IFullBackupRestoreObserver;
@@ -57,6 +58,7 @@ import com.android.server.backup.OperationStorage.OpType;
import com.android.server.backup.UserBackupManagerService;
import com.android.server.backup.UserBackupManagerService;
import com.android.server.backup.fullbackup.FullBackupObbConnection;
import com.android.server.backup.fullbackup.FullBackupObbConnection;
import com.android.server.backup.utils.BackupEligibilityRules;
import com.android.server.backup.utils.BackupEligibilityRules;
import com.android.server.backup.utils.BackupManagerMonitorEventSender;
import com.android.server.backup.utils.BytesReadListener;
import com.android.server.backup.utils.BytesReadListener;
import com.android.server.backup.utils.FullBackupRestoreObserverUtils;
import com.android.server.backup.utils.FullBackupRestoreObserverUtils;
import com.android.server.backup.utils.RestoreUtils;
import com.android.server.backup.utils.RestoreUtils;
@@ -143,6 +145,8 @@ public class FullRestoreEngine extends RestoreEngine {


    private FileMetadata mReadOnlyParent = null;
    private FileMetadata mReadOnlyParent = null;


    private BackupManagerMonitorEventSender mBackupManagerMonitorEventSender;

    public FullRestoreEngine(
    public FullRestoreEngine(
            UserBackupManagerService backupManagerService, OperationStorage operationStorage,
            UserBackupManagerService backupManagerService, OperationStorage operationStorage,
            BackupRestoreTask monitorTask, IFullBackupRestoreObserver observer,
            BackupRestoreTask monitorTask, IFullBackupRestoreObserver observer,
@@ -155,6 +159,7 @@ public class FullRestoreEngine extends RestoreEngine {
        mMonitorTask = monitorTask;
        mMonitorTask = monitorTask;
        mObserver = observer;
        mObserver = observer;
        mMonitor = monitor;
        mMonitor = monitor;
        mBackupManagerMonitorEventSender = new BackupManagerMonitorEventSender(monitor);
        mOnlyPackage = onlyPackage;
        mOnlyPackage = onlyPackage;
        mAllowApks = allowApks;
        mAllowApks = allowApks;
        mAgentTimeoutParameters = Objects.requireNonNull(
        mAgentTimeoutParameters = Objects.requireNonNull(
@@ -225,6 +230,9 @@ public class FullRestoreEngine extends RestoreEngine {
                    // one app's data but see a different app's on the wire
                    // one app's data but see a different app's on the wire
                    if (onlyPackage != null) {
                    if (onlyPackage != null) {
                        if (!pkg.equals(onlyPackage.packageName)) {
                        if (!pkg.equals(onlyPackage.packageName)) {
                            logBMMEvent(
                                    BackupManagerMonitor.LOG_EVENT_ID_RESTORE_DATA_DOES_NOT_BELONG_TO_PACKAGE,
                                    onlyPackage);
                            Slog.w(TAG, "Expected data for " + onlyPackage + " but saw " + pkg);
                            Slog.w(TAG, "Expected data for " + onlyPackage + " but saw " + pkg);
                            setResult(RestoreEngine.TRANSPORT_FAILURE);
                            setResult(RestoreEngine.TRANSPORT_FAILURE);
                            setRunning(false);
                            setRunning(false);
@@ -412,6 +420,9 @@ public class FullRestoreEngine extends RestoreEngine {
                        }
                        }


                        if (mAgent == null) {
                        if (mAgent == null) {
                            logBMMEvent(
                                    BackupManagerMonitor.LOG_EVENT_ID_UNABLE_TO_CREATE_AGENT_FOR_RESTORE,
                                    onlyPackage);
                            Slog.e(TAG, "Unable to create agent for " + pkg);
                            Slog.e(TAG, "Unable to create agent for " + pkg);
                            okay = false;
                            okay = false;
                            tearDownPipes();
                            tearDownPipes();
@@ -501,6 +512,9 @@ public class FullRestoreEngine extends RestoreEngine {
                        } catch (RemoteException e) {
                        } catch (RemoteException e) {
                            // whoops, remote entity went away.  We'll eat the content
                            // whoops, remote entity went away.  We'll eat the content
                            // ourselves, then, and not copy it over.
                            // ourselves, then, and not copy it over.
                            logBMMEvent(
                                    BackupManagerMonitor.LOG_EVENT_ID_AGENT_CRASHED_BEFORE_RESTORE_DATA_IS_SENT,
                                    onlyPackage);
                            Slog.e(TAG, "Agent crashed during full restore");
                            Slog.e(TAG, "Agent crashed during full restore");
                            agentSuccess = false;
                            agentSuccess = false;
                            okay = false;
                            okay = false;
@@ -531,6 +545,9 @@ public class FullRestoreEngine extends RestoreEngine {
                                    } catch (IOException e) {
                                    } catch (IOException e) {
                                        Slog.e(TAG, "Failed to write to restore pipe: "
                                        Slog.e(TAG, "Failed to write to restore pipe: "
                                                + e.getMessage());
                                                + e.getMessage());
                                        logBMMEvent(
                                                BackupManagerMonitor.LOG_EVENT_ID_FAILED_TO_SEND_DATA_TO_AGENT_DURING_RESTORE,
                                                onlyPackage);
                                        pipeOkay = false;
                                        pipeOkay = false;
                                    }
                                    }
                                }
                                }
@@ -548,6 +565,8 @@ public class FullRestoreEngine extends RestoreEngine {
                        // okay, if the remote end failed at any point, deal with
                        // okay, if the remote end failed at any point, deal with
                        // it by ignoring the rest of the restore on it
                        // it by ignoring the rest of the restore on it
                        if (!agentSuccess) {
                        if (!agentSuccess) {
                            logBMMEvent(BackupManagerMonitor.LOG_EVENT_ID_AGENT_FAILURE_DURING_RESTORE,
                                    onlyPackage);
                            Slog.w(TAG, "Agent failure restoring " + pkg + "; ending restore");
                            Slog.w(TAG, "Agent failure restoring " + pkg + "; ending restore");
                            mBackupManagerService.getBackupHandler().removeMessages(
                            mBackupManagerService.getBackupHandler().removeMessages(
                                    MSG_RESTORE_OPERATION_TIMEOUT);
                                    MSG_RESTORE_OPERATION_TIMEOUT);
@@ -590,6 +609,8 @@ public class FullRestoreEngine extends RestoreEngine {
            if (DEBUG) {
            if (DEBUG) {
                Slog.w(TAG, "io exception on restore socket read: " + e.getMessage());
                Slog.w(TAG, "io exception on restore socket read: " + e.getMessage());
            }
            }
            logBMMEvent(BackupManagerMonitor.LOG_EVENT_ID_FAILED_TO_READ_DATA_FROM_TRANSPORT,
                    onlyPackage);
            setResult(RestoreEngine.TRANSPORT_FAILURE);
            setResult(RestoreEngine.TRANSPORT_FAILURE);
            info = null;
            info = null;
        }
        }
@@ -631,6 +652,16 @@ public class FullRestoreEngine extends RestoreEngine {
        return false;
        return false;
    }
    }


    private void logBMMEvent(int eventId, PackageInfo pkgInfo) {
        if (Flags.enableIncreasedBmmLoggingForRestoreAtInstall()) {
            mBackupManagerMonitorEventSender.monitorEvent(eventId, pkgInfo,
                    BackupManagerMonitor.LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY,
                    mBackupManagerMonitorEventSender.putMonitoringExtra(/*extras=*/
                            null, BackupManagerMonitor.EXTRA_LOG_OPERATION_TYPE,
                            BackupAnnotations.OperationType.RESTORE));
        }
    }

    private static boolean isValidParent(FileMetadata parentDir, @NonNull FileMetadata childDir) {
    private static boolean isValidParent(FileMetadata parentDir, @NonNull FileMetadata childDir) {
        return parentDir != null
        return parentDir != null
                && childDir.packageName.equals(parentDir.packageName)
                && childDir.packageName.equals(parentDir.packageName)
Loading