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

Commit 25f0e816 authored by Ruslan Tkhakokhov's avatar Ruslan Tkhakokhov
Browse files

API Review: RestoreSession#restoreSomePackages

1. Rename restoreSome to restorePackages
2. Add @Nullable annotation for BackupObserver, BackupManagerMonitor and @NonNull for 'packages' params
3. Update javadoc to reflect the difference between BackupObserver and BackupManagerMonitor
4. Change 'packages' param from String[] to Set

Bug: 120843781
Test: 1) atest RunBackupFrameworksServicesRoboTests
      2) atest CtsBackupTestCases
      3) atest CtsBackupHostTestCases
      4) atest GtsBackupTestCases
      5) atest GtsBackupHostTestCases

Change-Id: I433739c0b1e62059b10593c233dfb2f461a8630e
parent e3cbf906
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -924,8 +924,10 @@ package android.app.backup {
    method public int restoreAll(long, android.app.backup.RestoreObserver);
    method public int restorePackage(String, android.app.backup.RestoreObserver, android.app.backup.BackupManagerMonitor);
    method public int restorePackage(String, android.app.backup.RestoreObserver);
    method public int restoreSome(long, android.app.backup.RestoreObserver, android.app.backup.BackupManagerMonitor, String[]);
    method public int restoreSome(long, android.app.backup.RestoreObserver, String[]);
    method public int restorePackages(long, @Nullable android.app.backup.RestoreObserver, @NonNull java.util.Set<java.lang.String>, @Nullable android.app.backup.BackupManagerMonitor);
    method public int restorePackages(long, @Nullable android.app.backup.RestoreObserver, @NonNull java.util.Set<java.lang.String>);
    method @Deprecated public int restoreSome(long, android.app.backup.RestoreObserver, android.app.backup.BackupManagerMonitor, String[]);
    method @Deprecated public int restoreSome(long, android.app.backup.RestoreObserver, String[]);
  }
  public class RestoreSet implements android.os.Parcelable {
+67 −5
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.app.backup;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.content.Context;
import android.os.Bundle;
@@ -24,6 +26,10 @@ import android.os.Message;
import android.os.RemoteException;
import android.util.Log;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * Interface for managing a restore session.
 * @hide
@@ -138,14 +144,15 @@ public class RestoreSession {
     *   the restore set that should be used.
     * @param observer If non-null, this binder points to an object that will receive
     *   progress callbacks during the restore operation.
     * @param monitor If non-null, this binder points to an object that will receive
     *   progress callbacks during the restore operation.
     * @param packages The set of packages for which to attempt a restore.  Regardless of
     *   the contents of the actual back-end dataset named by {@code token}, only
     *   applications mentioned in this list will have their data restored.
     * @param monitor If non-null, this binder points to an object that will receive
     *   progress callbacks during the restore operation containing detailed information on any
     *   failures or important decisions made by {@link BackupManager}.
     */
    public int restoreSome(long token, RestoreObserver observer, BackupManagerMonitor monitor,
            String[] packages) {
    public int restorePackages(long token, @Nullable RestoreObserver observer,
            @NonNull Set<String> packages, @Nullable BackupManagerMonitor monitor) {
        int err = -1;
        if (mObserver != null) {
            Log.d(TAG, "restoreAll() called during active restore");
@@ -156,7 +163,8 @@ public class RestoreSession {
                ? null
                : new BackupManagerMonitorWrapper(monitor);
        try {
            err = mBinder.restoreSome(token, mObserver, monitorWrapper, packages);
            err = mBinder.restoreSome(token, mObserver, monitorWrapper,
                    packages.toArray(new String[] {}));
        } catch (RemoteException e) {
            Log.d(TAG, "Can't contact server to restore packages");
        }
@@ -180,6 +188,60 @@ public class RestoreSession {
     *   the contents of the actual back-end dataset named by {@code token}, only
     *   applications mentioned in this list will have their data restored.
     */
    public int restorePackages(long token, @Nullable RestoreObserver observer,
            @NonNull Set<String> packages) {
        return restorePackages(token, observer, packages, null);
    }

    /**
     * Restore select packages from the given set onto the device, replacing the
     * current data of any app contained in the set with the data previously
     * backed up.
     *
     * <p>Callers must hold the android.permission.BACKUP permission to use this method.
     *
     * @return Zero on success, nonzero on error. The observer will only receive
     *   progress callbacks if this method returned zero.
     * @param token The token from {@link getAvailableRestoreSets()} corresponding to
     *   the restore set that should be used.
     * @param observer If non-null, this binder points to an object that will receive
     *   progress callbacks during the restore operation.
     * @param monitor If non-null, this binder points to an object that will receive
     *   progress callbacks during the restore operation.
     * @param packages The set of packages for which to attempt a restore.  Regardless of
     *   the contents of the actual back-end dataset named by {@code token}, only
     *   applications mentioned in this list will have their data restored.
     *
     * @deprecated use {@link RestoreSession#restorePackages(long, RestoreObserver,
     *   BackupManagerMonitor, Set)} instead.
     */
    @Deprecated
    public int restoreSome(long token, RestoreObserver observer, BackupManagerMonitor monitor,
            String[] packages) {
        return restorePackages(token, observer, new HashSet<>(Arrays.asList(packages)), monitor);
    }

    /**
     * Restore select packages from the given set onto the device, replacing the
     * current data of any app contained in the set with the data previously
     * backed up.
     *
     * <p>Callers must hold the android.permission.BACKUP permission to use this method.
     *
     * @return Zero on success, nonzero on error. The observer will only receive
     *   progress callbacks if this method returned zero.
     * @param token The token from {@link getAvailableRestoreSets()} corresponding to
     *   the restore set that should be used.
     * @param observer If non-null, this binder points to an object that will receive
     *   progress callbacks during the restore operation.
     * @param packages The set of packages for which to attempt a restore.  Regardless of
     *   the contents of the actual back-end dataset named by {@code token}, only
     *   applications mentioned in this list will have their data restored.
     *
     * @deprecated use {@link RestoreSession#restorePackages(long, RestoreObserver, Set)}
     *   instead.
     */
    @Deprecated
    public int restoreSome(long token, RestoreObserver observer, String[] packages) {
        return restoreSome(token, observer, null, packages);
    }