diff options
author | Ruslan Tkhakokhov <rthakohov@google.com> | 2019-03-11 16:26:17 +0000 |
---|---|---|
committer | Ruslan Tkhakokhov <rthakohov@google.com> | 2019-03-18 12:26:02 +0000 |
commit | 507e6f834daa7021c3c1afc752972a079cf96fb3 (patch) | |
tree | 12e447e1a50a873eaa57d78c3e5cee8eb052c841 | |
parent | 25f0e8167185b53a41328d9181799f61c61d0950 (diff) |
API Review: Internal RestoreSession#restorePackages
Bug: 120843781
Test: 1) atest RunBackupFrameworksServicesRoboTests
2) atest CtsBackupTestCases
3) atest CtsBackupHostTestCases
4) atest GtsBackupTestCases
5) atest GtsBackupHostTestCases
Change-Id: Ice42aedd702e1c16b074d7a00d7b15d8f4aaf733
6 files changed, 40 insertions, 36 deletions
diff --git a/cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java b/cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java index 062ba655640e..98ab6665958c 100644 --- a/cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java +++ b/cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java @@ -803,8 +803,8 @@ public class Bmgr { } else { String[] names = new String[filter.size()]; filter.toArray(names); - didRestore = (mRestore.restoreSome(token, observer, - null, names) == 0); + didRestore = (mRestore.restorePackages(token, observer, names, + null) == 0); } break; } diff --git a/core/java/android/app/backup/IRestoreSession.aidl b/core/java/android/app/backup/IRestoreSession.aidl index b9e94856b69e..c3a298bd8ee5 100644 --- a/core/java/android/app/backup/IRestoreSession.aidl +++ b/core/java/android/app/backup/IRestoreSession.aidl @@ -71,8 +71,8 @@ interface IRestoreSession { * applications mentioned in this list will have their data restored. * @param monitor If non null the binder will send important events to this monitor. */ - int restoreSome(long token, IRestoreObserver observer, IBackupManagerMonitor monitor, - in String[] packages); + int restorePackages(long token, IRestoreObserver observer, in String[] packages, + IBackupManagerMonitor monitor); /** * Restore a single application from backup. The data will be restored from the diff --git a/core/java/android/app/backup/RestoreSession.java b/core/java/android/app/backup/RestoreSession.java index 122e87e7d8ac..084b13b61617 100644 --- a/core/java/android/app/backup/RestoreSession.java +++ b/core/java/android/app/backup/RestoreSession.java @@ -163,8 +163,8 @@ public class RestoreSession { ? null : new BackupManagerMonitorWrapper(monitor); try { - err = mBinder.restoreSome(token, mObserver, monitorWrapper, - packages.toArray(new String[] {})); + err = mBinder.restorePackages(token, mObserver, packages.toArray(new String[] {}), + monitorWrapper); } catch (RemoteException e) { Log.d(TAG, "Can't contact server to restore packages"); } diff --git a/services/backup/java/com/android/server/backup/params/RestoreParams.java b/services/backup/java/com/android/server/backup/params/RestoreParams.java index 5125b0d5234e..c9a6b6038a93 100644 --- a/services/backup/java/com/android/server/backup/params/RestoreParams.java +++ b/services/backup/java/com/android/server/backup/params/RestoreParams.java @@ -105,7 +105,7 @@ public class RestoreParams { /** * Caller specifies whether is considered a system-level restore. */ - public static RestoreParams createForRestoreSome( + public static RestoreParams createForRestorePackages( TransportClient transportClient, IRestoreObserver observer, IBackupManagerMonitor monitor, diff --git a/services/backup/java/com/android/server/backup/restore/ActiveRestoreSession.java b/services/backup/java/com/android/server/backup/restore/ActiveRestoreSession.java index 0fa0f89e329e..10304c39f021 100644 --- a/services/backup/java/com/android/server/backup/restore/ActiveRestoreSession.java +++ b/services/backup/java/com/android/server/backup/restore/ActiveRestoreSession.java @@ -22,6 +22,7 @@ import static com.android.server.backup.internal.BackupHandler.MSG_RESTORE_SESSI import static com.android.server.backup.internal.BackupHandler.MSG_RUN_GET_RESTORE_SETS; import static com.android.server.backup.internal.BackupHandler.MSG_RUN_RESTORE; +import android.annotation.NonNull; import android.annotation.Nullable; import android.app.backup.IBackupManagerMonitor; import android.app.backup.IRestoreObserver; @@ -192,18 +193,22 @@ public class ActiveRestoreSession extends IRestoreSession.Stub { } // Restores of more than a single package are treated as 'system' restores - public synchronized int restoreSome(long token, IRestoreObserver observer, - IBackupManagerMonitor monitor, String[] packages) { + public synchronized int restorePackages(long token, @Nullable IRestoreObserver observer, + @NonNull String[] packages, @Nullable IBackupManagerMonitor monitor) { mBackupManagerService.getContext().enforceCallingOrSelfPermission( android.Manifest.permission.BACKUP, "performRestore"); if (DEBUG) { StringBuilder b = new StringBuilder(128); - b.append("restoreSome token="); + b.append("restorePackages token="); b.append(Long.toHexString(token)); b.append(" observer="); - b.append(observer.toString()); + if (observer == null) { + b.append("null"); + } else { + b.append(observer.toString()); + } b.append(" monitor="); if (monitor == null) { b.append("null"); @@ -260,7 +265,7 @@ public class ActiveRestoreSession extends IRestoreSession.Stub { try { return sendRestoreToHandlerLocked( (transportClient, listener) -> - RestoreParams.createForRestoreSome( + RestoreParams.createForRestorePackages( transportClient, observer, monitor, @@ -268,7 +273,7 @@ public class ActiveRestoreSession extends IRestoreSession.Stub { packages, /* isSystemRestore */ packages.length > 1, listener), - "RestoreSession.restoreSome(" + packages.length + " packages)"); + "RestoreSession.restorePackages(" + packages.length + " packages)"); } finally { Binder.restoreCallingIdentity(oldId); } diff --git a/services/robotests/backup/src/com/android/server/backup/restore/ActiveRestoreSessionTest.java b/services/robotests/backup/src/com/android/server/backup/restore/ActiveRestoreSessionTest.java index f17a9fe48c61..f4cea7ae86a6 100644 --- a/services/robotests/backup/src/com/android/server/backup/restore/ActiveRestoreSessionTest.java +++ b/services/robotests/backup/src/com/android/server/backup/restore/ActiveRestoreSessionTest.java @@ -326,15 +326,14 @@ public class ActiveRestoreSessionTest { } @Test - public void testRestoreSome_for2Packages() throws Exception { + public void testRestorePackages_for2Packages() throws Exception { mShadowApplication.grantPermissions(android.Manifest.permission.BACKUP); TransportMock transportMock = setUpTransport(mTransport); IRestoreSession restoreSession = createActiveRestoreSessionWithRestoreSets(null, mTransport, mRestoreSet1); - int result = - restoreSession.restoreSome( - TOKEN_1, mObserver, mMonitor, new String[] {PACKAGE_1, PACKAGE_2}); + int result = restoreSession.restorePackages(TOKEN_1, mObserver, + new String[] {PACKAGE_1, PACKAGE_2}, mMonitor); mShadowBackupLooper.runToEndOfTasks(); assertThat(result).isEqualTo(0); @@ -349,27 +348,27 @@ public class ActiveRestoreSessionTest { } @Test - public void testRestoreSome_for2Packages_createsSystemRestoreTask() throws Exception { + public void testRestorePackages_for2Packages_createsSystemRestoreTask() throws Exception { mShadowApplication.grantPermissions(android.Manifest.permission.BACKUP); setUpTransport(mTransport); IRestoreSession restoreSession = createActiveRestoreSessionWithRestoreSets(null, mTransport, mRestoreSet1); - restoreSession.restoreSome( - TOKEN_1, mObserver, mMonitor, new String[] {PACKAGE_1, PACKAGE_2}); + restoreSession.restorePackages(TOKEN_1, mObserver, new String[] {PACKAGE_1, PACKAGE_2}, + mMonitor); mShadowBackupLooper.runToEndOfTasks(); assertThat(ShadowPerformUnifiedRestoreTask.getLastCreated().isFullSystemRestore()).isTrue(); } @Test - public void testRestoreSome_for1Package() throws Exception { + public void testRestorePackages_for1Package() throws Exception { mShadowApplication.grantPermissions(android.Manifest.permission.BACKUP); setUpTransport(mTransport); IRestoreSession restoreSession = createActiveRestoreSessionWithRestoreSets(null, mTransport, mRestoreSet1); - restoreSession.restoreSome(TOKEN_1, mObserver, mMonitor, new String[] {PACKAGE_1}); + restoreSession.restorePackages(TOKEN_1, mObserver, new String[] {PACKAGE_1}, mMonitor); mShadowBackupLooper.runToEndOfTasks(); ShadowPerformUnifiedRestoreTask shadowTask = @@ -379,13 +378,13 @@ public class ActiveRestoreSessionTest { } @Test - public void testRestoreSome_for1Package_createsNonSystemRestoreTask() throws Exception { + public void testRestorePackages_for1Package_createsNonSystemRestoreTask() throws Exception { mShadowApplication.grantPermissions(android.Manifest.permission.BACKUP); setUpTransport(mTransport); IRestoreSession restoreSession = createActiveRestoreSessionWithRestoreSets(null, mTransport, mRestoreSet1); - restoreSession.restoreSome(TOKEN_1, mObserver, mMonitor, new String[] {PACKAGE_1}); + restoreSession.restorePackages(TOKEN_1, mObserver, new String[] {PACKAGE_1}, mMonitor); mShadowBackupLooper.runToEndOfTasks(); assertThat(ShadowPerformUnifiedRestoreTask.getLastCreated().isFullSystemRestore()) @@ -393,32 +392,32 @@ public class ActiveRestoreSessionTest { } @Test - public void testRestoreSome_whenNoRestoreSets() throws Exception { + public void testRestorePackages_whenNoRestoreSets() throws Exception { mShadowApplication.grantPermissions(android.Manifest.permission.BACKUP); setUpTransport(mTransport); IRestoreSession restoreSession = createActiveRestoreSession(null, mTransport); - int result = - restoreSession.restoreSome(TOKEN_1, mObserver, mMonitor, new String[] {PACKAGE_1}); + int result = restoreSession.restorePackages(TOKEN_1, mObserver, new String[] {PACKAGE_1}, + mMonitor); assertThat(result).isEqualTo(-1); } @Test - public void testRestoreSome_whenSinglePackageSession() throws Exception { + public void testRestorePackages_whenSinglePackageSession() throws Exception { mShadowApplication.grantPermissions(android.Manifest.permission.BACKUP); setUpTransport(mTransport); IRestoreSession restoreSession = createActiveRestoreSessionWithRestoreSets(PACKAGE_1, mTransport, mRestoreSet1); - int result = - restoreSession.restoreSome(TOKEN_1, mObserver, mMonitor, new String[] {PACKAGE_2}); + int result = restoreSession.restorePackages(TOKEN_1, mObserver, new String[] {PACKAGE_2}, + mMonitor); assertThat(result).isEqualTo(-1); } @Test - public void testRestoreSome_whenSessionEnded() throws Exception { + public void testRestorePackages_whenSessionEnded() throws Exception { mShadowApplication.grantPermissions(android.Manifest.permission.BACKUP); setUpTransport(mTransport); IRestoreSession restoreSession = @@ -429,19 +428,19 @@ public class ActiveRestoreSessionTest { expectThrows( IllegalStateException.class, () -> - restoreSession.restoreSome( - TOKEN_1, mObserver, mMonitor, new String[] {PACKAGE_1})); + restoreSession.restorePackages(TOKEN_1, mObserver, new String[] {PACKAGE_1}, + mMonitor)); } @Test - public void testRestoreSome_whenTransportNotRegistered() throws Exception { + public void testRestorePackages_whenTransportNotRegistered() throws Exception { mShadowApplication.grantPermissions(android.Manifest.permission.BACKUP); setUpTransport(mTransport.unregistered()); IRestoreSession restoreSession = createActiveRestoreSessionWithRestoreSets(null, mTransport, mRestoreSet1); - int result = - restoreSession.restoreSome(TOKEN_1, mObserver, mMonitor, new String[] {PACKAGE_1}); + int result = restoreSession.restorePackages(TOKEN_1, mObserver, new String[] {PACKAGE_1}, + mMonitor); assertThat(result).isEqualTo(-1); } |