diff options
| -rw-r--r-- | api/system-current.txt | 6 | ||||
| -rw-r--r-- | core/java/android/app/backup/RestoreSession.java | 72 |
2 files changed, 71 insertions, 7 deletions
diff --git a/api/system-current.txt b/api/system-current.txt index 61a7f587dc42..954e195d8434 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -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 { diff --git a/core/java/android/app/backup/RestoreSession.java b/core/java/android/app/backup/RestoreSession.java index 79925ec2d47a..122e87e7d8ac 100644 --- a/core/java/android/app/backup/RestoreSession.java +++ b/core/java/android/app/backup/RestoreSession.java @@ -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); } |