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

Commit 5d650722 authored by Ruslan Tkhakokhov's avatar Ruslan Tkhakokhov Committed by Android (Google) Code Review
Browse files

Merge "[FSD2D] Add BackupManager API to start restore"

parents 016f6e7b 9bdd2f67
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.commands.bmgr;
import android.annotation.IntDef;
import android.annotation.UserIdInt;
import android.app.backup.BackupManager;
import android.app.backup.BackupManager.OperationType;
import android.app.backup.BackupManagerMonitor;
import android.app.backup.BackupProgress;
import android.app.backup.BackupTransport;
@@ -666,7 +667,7 @@ public class Bmgr {

        // The rest of the 'list' options work with a restore session on the current transport
        try {
            mRestore = mBmgr.beginRestoreSessionForUser(userId, null, null);
            mRestore = mBmgr.beginRestoreSessionForUser(userId, null, null, OperationType.BACKUP);
            if (mRestore == null) {
                System.err.println(BMGR_ERR_NO_RESTORESESSION_FOR_USER + userId);
                return;
@@ -821,7 +822,7 @@ public class Bmgr {

        try {
            boolean didRestore = false;
            mRestore = mBmgr.beginRestoreSessionForUser(userId, null, null);
            mRestore = mBmgr.beginRestoreSessionForUser(userId, null, null, OperationType.BACKUP);
            if (mRestore == null) {
                System.err.println(BMGR_ERR_NO_RESTORESESSION_FOR_USER + userId);
                return;
+30 −1
Original line number Diff line number Diff line
@@ -355,7 +355,36 @@ public class BackupManager {
            try {
                // All packages, current transport
                IRestoreSession binder =
                        sService.beginRestoreSessionForUser(mContext.getUserId(), null, null);
                        sService.beginRestoreSessionForUser(mContext.getUserId(), null, null,
                                OperationType.BACKUP);
                if (binder != null) {
                    session = new RestoreSession(mContext, binder);
                }
            } catch (RemoteException e) {
                Log.e(TAG, "beginRestoreSession() couldn't connect");
            }
        }
        return session;
    }

    /**
     * Begin the process of restoring data from backup.  See the
     * {@link android.app.backup.RestoreSession} class for documentation on that process.
     *
     * @param operationType Type of the operation, see {@link OperationType}
     *
     * @hide
     */
    @RequiresPermission(android.Manifest.permission.BACKUP)
    public RestoreSession beginRestoreSession(@OperationType int operationType) {
        RestoreSession session = null;
        checkServiceBinder();
        if (sService != null) {
            try {
                // All packages, current transport
                IRestoreSession binder =
                        sService.beginRestoreSessionForUser(mContext.getUserId(), null, null,
                                operationType);
                if (binder != null) {
                    session = new RestoreSession(mContext, binder);
                }
+3 −1
Original line number Diff line number Diff line
@@ -547,9 +547,11 @@ interface IBackupManager {
     *        set can be restored.
     * @param transportID The name of the transport to use for the restore operation.
     *        May be null, in which case the current active transport is used.
     * @param operationType Type of the operation, see {@link BackupManager#OperationType}
     * @return An interface to the restore session, or null on error.
     */
    IRestoreSession beginRestoreSessionForUser(int userId, String packageName, String transportID);
    IRestoreSession beginRestoreSessionForUser(int userId, String packageName, String transportID,
            int operationType);

    /**
     * Notify the backup manager that a BackupAgent has completed the operation
+7 −4
Original line number Diff line number Diff line
@@ -1239,9 +1239,10 @@ public class BackupManagerService extends IBackupManager.Stub {

    @Override
    public IRestoreSession beginRestoreSessionForUser(
            int userId, String packageName, String transportID) throws RemoteException {
            int userId, String packageName, String transportID,
            @OperationType int operationType) throws RemoteException {
        return isUserReadyForBackup(userId)
                ? beginRestoreSession(userId, packageName, transportID) : null;
                ? beginRestoreSession(userId, packageName, transportID, operationType) : null;
    }

    /**
@@ -1250,13 +1251,15 @@ public class BackupManagerService extends IBackupManager.Stub {
     */
    @Nullable
    public IRestoreSession beginRestoreSession(
            @UserIdInt int userId, String packageName, String transportName) {
            @UserIdInt int userId, String packageName, String transportName,
            @OperationType int operationType) {
        UserBackupManagerService userBackupManagerService =
                getServiceForUserIfCallerHasPermission(userId, "beginRestoreSession()");

        return userBackupManagerService == null
                ? null
                : userBackupManagerService.beginRestoreSession(packageName, transportName);
                : userBackupManagerService.beginRestoreSession(packageName, transportName,
                        operationType);
    }

    @Override
+8 −4
Original line number Diff line number Diff line
@@ -3973,7 +3973,8 @@ public class UserBackupManagerService {
                                restoreSet,
                                packageName,
                                token,
                                listener);
                                listener,
                                mScheduledBackupEligibility);
                mBackupHandler.sendMessage(msg);
            } catch (Exception e) {
                // Calling into the transport broke; back off and proceed with the installation.
@@ -4002,13 +4003,15 @@ public class UserBackupManagerService {
    }

    /** Hand off a restore session. */
    public IRestoreSession beginRestoreSession(String packageName, String transport) {
    public IRestoreSession beginRestoreSession(String packageName, String transport,
            @OperationType int operationType) {
        if (DEBUG) {
            Slog.v(
                    TAG,
                    addUserIdToLogMessage(
                            mUserId,
                            "beginRestoreSession: pkg=" + packageName + " transport=" + transport));
                            "beginRestoreSession: pkg=" + packageName + " transport=" + transport
                                + "operationType=" + operationType));
        }

        boolean needPermission = true;
@@ -4065,7 +4068,8 @@ public class UserBackupManagerService {
                                "Restore session requested but currently running backups"));
                return null;
            }
            mActiveRestoreSession = new ActiveRestoreSession(this, packageName, transport);
            mActiveRestoreSession = new ActiveRestoreSession(this, packageName, transport,
                    getEligibilityRulesForOperation(operationType));
            mBackupHandler.sendEmptyMessageDelayed(MSG_RESTORE_SESSION_TIMEOUT,
                    mAgentTimeoutParameters.getRestoreAgentTimeoutMillis());
        }
Loading