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

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

Merge "Determine restore operation type through RestoreSet" into sc-dev

parents ef1688ac 5c3913d9
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -66,6 +66,8 @@ public class LocalTransport extends BackupTransport {

    private static final String INCREMENTAL_DIR = "_delta";
    private static final String FULL_DATA_DIR = "_full";
    private static final String DEVICE_NAME_FOR_D2D_RESTORE_SET = "D2D";
    private static final String DEFAULT_DEVICE_NAME_FOR_RESTORE_SET = "flash";

    // The currently-active restore set always has the same (nonzero!) token
    private static final long CURRENT_SET_TOKEN = 1;
@@ -603,8 +605,10 @@ public class LocalTransport extends BackupTransport {
        existing[num++] = CURRENT_SET_TOKEN;

        RestoreSet[] available = new RestoreSet[num];
        String deviceName = mParameters.isDeviceTransfer() ? DEVICE_NAME_FOR_D2D_RESTORE_SET
                : DEFAULT_DEVICE_NAME_FOR_RESTORE_SET;
        for (int i = 0; i < available.length; i++) {
            available[i] = new RestoreSet("Local disk image", "flash", existing[i]);
            available[i] = new RestoreSet("Local disk image", deviceName, existing[i]);
        }
        return available;
    }
+16 −2
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server.backup.restore;

import static android.app.backup.BackupManager.OperationType;

import static com.android.server.backup.BackupManagerService.DEBUG;
import static com.android.server.backup.BackupManagerService.MORE_DEBUG;
import static com.android.server.backup.internal.BackupHandler.MSG_RESTORE_SESSION_TIMEOUT;
@@ -24,6 +26,7 @@ import static com.android.server.backup.internal.BackupHandler.MSG_RUN_RESTORE;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.backup.BackupManager;
import android.app.backup.IBackupManagerMonitor;
import android.app.backup.IRestoreObserver;
import android.app.backup.IRestoreSession;
@@ -51,6 +54,7 @@ import java.util.function.BiFunction;
 */
public class ActiveRestoreSession extends IRestoreSession.Stub {
    private static final String TAG = "RestoreSession";
    private static final String DEVICE_NAME_FOR_D2D_SET = "D2D";

    private final TransportManager mTransportManager;
    private final String mTransportName;
@@ -174,6 +178,7 @@ public class ActiveRestoreSession extends IRestoreSession.Stub {
            for (int i = 0; i < mRestoreSets.length; i++) {
                if (token == mRestoreSets[i].token) {
                    final long oldId = Binder.clearCallingIdentity();
                    RestoreSet restoreSet = mRestoreSets[i];
                    try {
                        return sendRestoreToHandlerLocked(
                                (transportClient, listener) ->
@@ -183,7 +188,7 @@ public class ActiveRestoreSession extends IRestoreSession.Stub {
                                                monitor,
                                                token,
                                                listener,
                                                mBackupEligibilityRules),
                                                getBackupEligibilityRules(restoreSet)),
                                "RestoreSession.restoreAll()");
                    } finally {
                        Binder.restoreCallingIdentity(oldId);
@@ -266,6 +271,7 @@ public class ActiveRestoreSession extends IRestoreSession.Stub {
            for (int i = 0; i < mRestoreSets.length; i++) {
                if (token == mRestoreSets[i].token) {
                    final long oldId = Binder.clearCallingIdentity();
                    RestoreSet restoreSet = mRestoreSets[i];
                    try {
                        return sendRestoreToHandlerLocked(
                                (transportClient, listener) ->
@@ -277,7 +283,7 @@ public class ActiveRestoreSession extends IRestoreSession.Stub {
                                                packages,
                                                /* isSystemRestore */ packages.length > 1,
                                                listener,
                                                mBackupEligibilityRules),
                                                getBackupEligibilityRules(restoreSet)),
                                "RestoreSession.restorePackages(" + packages.length + " packages)");
                    } finally {
                        Binder.restoreCallingIdentity(oldId);
@@ -290,6 +296,14 @@ public class ActiveRestoreSession extends IRestoreSession.Stub {
        return -1;
    }

    private BackupEligibilityRules getBackupEligibilityRules(RestoreSet restoreSet) {
        // TODO(b/182986784): Remove device name comparison once a designated field for operation
        //  type is added to RestoreSet object.
        int operationType = DEVICE_NAME_FOR_D2D_SET.equals(restoreSet.device)
                ? OperationType.MIGRATION : OperationType.BACKUP;
        return mBackupManagerService.getEligibilityRulesForOperation(operationType);
    }

    public synchronized int restorePackage(String packageName, IRestoreObserver observer,
            IBackupManagerMonitor monitor) {
        if (DEBUG) {