diff options
author | Bernardo Rufino <brufino@google.com> | 2019-08-14 15:51:14 +0100 |
---|---|---|
committer | Bernardo Rufino <brufino@google.com> | 2019-08-14 15:53:51 +0100 |
commit | b188863fcc626e23f1a5da3e870fbd3d1b8b31b0 (patch) | |
tree | ed7b5724000e8129d26756cf8874bb00a599a983 | |
parent | dd1fbf2b15fcfa905c1f701e7f4241e0708393fd (diff) |
Move more transport operations to Trampoline
From BMS. Namely:
* selectBackupTransport()
* selectBackupTransportAsync()
* getConfigurationIntent()
* getDestinationString()
* getDataManagementIntent()
* getDataManagementLabel()
Test: atest BackupManagerServiceTest TrampolineRoboTest TrampolineTest
Bug: 135661048
Change-Id: I9dbc0c4dfa73bd9738ae658ff24f986000ffc54b
5 files changed, 255 insertions, 367 deletions
diff --git a/services/backup/java/com/android/server/backup/BackupManagerService.java b/services/backup/java/com/android/server/backup/BackupManagerService.java index eae0158f0c18..7fbfb33091ab 100644 --- a/services/backup/java/com/android/server/backup/BackupManagerService.java +++ b/services/backup/java/com/android/server/backup/BackupManagerService.java @@ -25,7 +25,6 @@ import android.app.backup.IBackupManagerMonitor; import android.app.backup.IBackupObserver; import android.app.backup.IFullBackupRestoreObserver; import android.app.backup.IRestoreSession; -import android.app.backup.ISelectBackupTransportCallback; import android.app.job.JobParameters; import android.app.job.JobScheduler; import android.app.job.JobService; @@ -153,54 +152,6 @@ public class BackupManagerService { } /** - * Selects transport {@code transportName} and returns the previously selected transport. - * - * @deprecated Use {@link #selectBackupTransportAsync(ComponentName, - * ISelectBackupTransportCallback)} instead. - */ - @Deprecated - @Nullable - public String selectBackupTransport(@UserIdInt int userId, String transportName) { - UserBackupManagerService userBackupManagerService = - getServiceForUserIfCallerHasPermission(userId, "selectBackupTransport()"); - - return userBackupManagerService == null - ? null - : userBackupManagerService.selectBackupTransport(transportName); - } - - /** - * Selects transport {@code transportComponent} asynchronously and notifies {@code listener} - * with the result upon completion. - */ - public void selectBackupTransportAsync( - @UserIdInt int userId, - ComponentName transportComponent, - ISelectBackupTransportCallback listener) { - UserBackupManagerService userBackupManagerService = - getServiceForUserIfCallerHasPermission(userId, "selectBackupTransportAsync()"); - - if (userBackupManagerService != null) { - userBackupManagerService.selectBackupTransportAsync(transportComponent, listener); - } - } - - /** - * Supply the configuration intent for the given transport. If the name is not one of the - * available transports, or if the transport does not supply any configuration UI, the method - * returns {@code null}. - */ - @Nullable - public Intent getConfigurationIntent(@UserIdInt int userId, String transportName) { - UserBackupManagerService userBackupManagerService = - getServiceForUserIfCallerHasPermission(userId, "getConfigurationIntent()"); - - return userBackupManagerService == null - ? null - : userBackupManagerService.getConfigurationIntent(transportName); - } - - /** * Sets the ancestral work profile for the calling user. * * <p> The ancestral work profile corresponds to the profile that was used to restore to the @@ -251,50 +202,6 @@ public class BackupManagerService { return null; } - /** - * Supply the current destination string for the given transport. If the name is not one of the - * registered transports the method will return null. - * - * <p>This string is used VERBATIM as the summary text of the relevant Settings item. - * - * @param transportName The name of the registered transport. - * @return The current destination string or null if the transport is not registered. - */ - @Nullable - public String getDestinationString(@UserIdInt int userId, String transportName) { - UserBackupManagerService userBackupManagerService = - getServiceForUserIfCallerHasPermission(userId, "getDestinationString()"); - - return userBackupManagerService == null - ? null - : userBackupManagerService.getDestinationString(transportName); - } - - /** Supply the manage-data intent for the given transport. */ - @Nullable - public Intent getDataManagementIntent(@UserIdInt int userId, String transportName) { - UserBackupManagerService userBackupManagerService = - getServiceForUserIfCallerHasPermission(userId, "getDataManagementIntent()"); - - return userBackupManagerService == null - ? null - : userBackupManagerService.getDataManagementIntent(transportName); - } - - /** - * Supply the menu label for affordances that fire the manage-data intent for the given - * transport. - */ - @Nullable - public CharSequence getDataManagementLabel(@UserIdInt int userId, String transportName) { - UserBackupManagerService userBackupManagerService = - getServiceForUserIfCallerHasPermission(userId, "getDataManagementLabel()"); - - return userBackupManagerService == null - ? null - : userBackupManagerService.getDataManagementLabel(transportName); - } - // --------------------------------------------- // SETTINGS OPERATIONS // --------------------------------------------- diff --git a/services/backup/java/com/android/server/backup/Trampoline.java b/services/backup/java/com/android/server/backup/Trampoline.java index 55cac327d131..f32fa1785969 100644 --- a/services/backup/java/com/android/server/backup/Trampoline.java +++ b/services/backup/java/com/android/server/backup/Trampoline.java @@ -872,7 +872,7 @@ public class Trampoline extends IBackupManager.Stub { public String selectBackupTransportForUser(int userId, String transport) throws RemoteException { return (isUserReadyForBackup(userId)) - ? mService.selectBackupTransport(userId, transport) : null; + ? selectBackupTransport(userId, transport) : null; } @Override @@ -880,11 +880,28 @@ public class Trampoline extends IBackupManager.Stub { return selectBackupTransportForUser(binderGetCallingUserId(), transport); } + /** + * Selects transport {@code transportName} and returns the previously selected transport. + * + * @deprecated Use {@link #selectBackupTransportAsync(ComponentName, + * ISelectBackupTransportCallback)} instead. + */ + @Deprecated + @Nullable + public String selectBackupTransport(@UserIdInt int userId, String transportName) { + UserBackupManagerService userBackupManagerService = + getServiceForUserIfCallerHasPermission(userId, "selectBackupTransport()"); + + return userBackupManagerService == null + ? null + : userBackupManagerService.selectBackupTransport(transportName); + } + @Override public void selectBackupTransportAsyncForUser(int userId, ComponentName transport, ISelectBackupTransportCallback listener) throws RemoteException { if (isUserReadyForBackup(userId)) { - mService.selectBackupTransportAsync(userId, transport, listener); + selectBackupTransportAsync(userId, transport, listener); } else { if (listener != null) { try { @@ -896,10 +913,26 @@ public class Trampoline extends IBackupManager.Stub { } } + /** + * Selects transport {@code transportComponent} asynchronously and notifies {@code listener} + * with the result upon completion. + */ + public void selectBackupTransportAsync( + @UserIdInt int userId, + ComponentName transportComponent, + ISelectBackupTransportCallback listener) { + UserBackupManagerService userBackupManagerService = + getServiceForUserIfCallerHasPermission(userId, "selectBackupTransportAsync()"); + + if (userBackupManagerService != null) { + userBackupManagerService.selectBackupTransportAsync(transportComponent, listener); + } + } + @Override public Intent getConfigurationIntentForUser(int userId, String transport) throws RemoteException { - return isUserReadyForBackup(userId) ? mService.getConfigurationIntent(userId, transport) + return isUserReadyForBackup(userId) ? getConfigurationIntent(userId, transport) : null; } @@ -909,9 +942,24 @@ public class Trampoline extends IBackupManager.Stub { return getConfigurationIntentForUser(binderGetCallingUserId(), transport); } + /** + * Supply the configuration intent for the given transport. If the name is not one of the + * available transports, or if the transport does not supply any configuration UI, the method + * returns {@code null}. + */ + @Nullable + public Intent getConfigurationIntent(@UserIdInt int userId, String transportName) { + UserBackupManagerService userBackupManagerService = + getServiceForUserIfCallerHasPermission(userId, "getConfigurationIntent()"); + + return userBackupManagerService == null + ? null + : userBackupManagerService.getConfigurationIntent(transportName); + } + @Override public String getDestinationStringForUser(int userId, String transport) throws RemoteException { - return isUserReadyForBackup(userId) ? mService.getDestinationString(userId, transport) + return isUserReadyForBackup(userId) ? getDestinationString(userId, transport) : null; } @@ -920,11 +968,30 @@ public class Trampoline extends IBackupManager.Stub { return getDestinationStringForUser(binderGetCallingUserId(), transport); } + /** + * Supply the current destination string for the given transport. If the name is not one of the + * registered transports the method will return null. + * + * <p>This string is used VERBATIM as the summary text of the relevant Settings item. + * + * @param transportName The name of the registered transport. + * @return The current destination string or null if the transport is not registered. + */ + @Nullable + public String getDestinationString(@UserIdInt int userId, String transportName) { + UserBackupManagerService userBackupManagerService = + getServiceForUserIfCallerHasPermission(userId, "getDestinationString()"); + + return userBackupManagerService == null + ? null + : userBackupManagerService.getDestinationString(transportName); + } + @Override public Intent getDataManagementIntentForUser(int userId, String transport) throws RemoteException { return isUserReadyForBackup(userId) - ? mService.getDataManagementIntent(userId, transport) : null; + ? getDataManagementIntent(userId, transport) : null; } @Override @@ -933,13 +1000,38 @@ public class Trampoline extends IBackupManager.Stub { return getDataManagementIntentForUser(binderGetCallingUserId(), transport); } + /** Supply the manage-data intent for the given transport. */ + @Nullable + public Intent getDataManagementIntent(@UserIdInt int userId, String transportName) { + UserBackupManagerService userBackupManagerService = + getServiceForUserIfCallerHasPermission(userId, "getDataManagementIntent()"); + + return userBackupManagerService == null + ? null + : userBackupManagerService.getDataManagementIntent(transportName); + } + @Override public CharSequence getDataManagementLabelForUser(int userId, String transport) throws RemoteException { - return isUserReadyForBackup(userId) ? mService.getDataManagementLabel(userId, transport) + return isUserReadyForBackup(userId) ? getDataManagementLabel(userId, transport) : null; } + /** + * Supply the menu label for affordances that fire the manage-data intent for the given + * transport. + */ + @Nullable + public CharSequence getDataManagementLabel(@UserIdInt int userId, String transportName) { + UserBackupManagerService userBackupManagerService = + getServiceForUserIfCallerHasPermission(userId, "getDataManagementLabel()"); + + return userBackupManagerService == null + ? null + : userBackupManagerService.getDataManagementLabel(transportName); + } + @Override public IRestoreSession beginRestoreSessionForUser( int userId, String packageName, String transportID) throws RemoteException { diff --git a/services/robotests/backup/src/com/android/server/backup/BackupManagerServiceTest.java b/services/robotests/backup/src/com/android/server/backup/BackupManagerServiceTest.java index ae6bcc3aad0b..e5a82ab11ccb 100644 --- a/services/robotests/backup/src/com/android/server/backup/BackupManagerServiceTest.java +++ b/services/robotests/backup/src/com/android/server/backup/BackupManagerServiceTest.java @@ -41,7 +41,6 @@ import android.app.Application; import android.app.backup.IBackupManagerMonitor; import android.app.backup.IBackupObserver; import android.app.backup.IFullBackupRestoreObserver; -import android.app.backup.ISelectBackupTransportCallback; import android.content.Context; import android.content.Intent; import android.os.ParcelFileDescriptor; @@ -284,159 +283,6 @@ public class BackupManagerServiceTest { "dataManagementLabel"); } - /** Test that the backup service routes methods correctly to the user that requests it. */ - @Test - public void testSelectBackupTransport_onRegisteredUser_callsMethodForUser() throws Exception { - registerUser(mUserOneId, mUserOneService); - BackupManagerService backupManagerService = createService(); - setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false); - - backupManagerService.selectBackupTransport(mUserOneId, TEST_TRANSPORT); - - verify(mUserOneService).selectBackupTransport(TEST_TRANSPORT); - } - - /** Test that the backup service does not route methods for non-registered users. */ - @Test - public void testSelectBackupTransport_onUnknownUser_doesNotPropagateCall() throws Exception { - registerUser(mUserOneId, mUserOneService); - BackupManagerService backupManagerService = createService(); - setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false); - - backupManagerService.selectBackupTransport(mUserTwoId, TEST_TRANSPORT); - - verify(mUserOneService, never()).selectBackupTransport(TEST_TRANSPORT); - } - - /** Test that the backup service routes methods correctly to the user that requests it. */ - @Test - public void testSelectTransportAsync_onRegisteredUser_callsMethodForUser() throws Exception { - registerUser(mUserOneId, mUserOneService); - BackupManagerService backupManagerService = createService(); - setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false); - TransportData transport = backupTransport(); - ISelectBackupTransportCallback callback = mock(ISelectBackupTransportCallback.class); - - backupManagerService.selectBackupTransportAsync( - mUserOneId, transport.getTransportComponent(), callback); - - verify(mUserOneService) - .selectBackupTransportAsync(transport.getTransportComponent(), callback); - } - - /** Test that the backup service does not route methods for non-registered users. */ - @Test - public void testSelectBackupTransportAsync_onUnknownUser_doesNotPropagateCall() - throws Exception { - registerUser(mUserOneId, mUserOneService); - BackupManagerService backupManagerService = createService(); - setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false); - TransportData transport = backupTransport(); - ISelectBackupTransportCallback callback = mock(ISelectBackupTransportCallback.class); - - backupManagerService.selectBackupTransportAsync( - mUserTwoId, transport.getTransportComponent(), callback); - - verify(mUserOneService, never()) - .selectBackupTransportAsync(transport.getTransportComponent(), callback); - } - - /** Test that the backup service routes methods correctly to the user that requests it. */ - @Test - public void testGetConfigurationIntent_onRegisteredUser_callsMethodForUser() throws Exception { - registerUser(mUserOneId, mUserOneService); - BackupManagerService backupManagerService = createService(); - setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false); - - backupManagerService.getConfigurationIntent(mUserOneId, TEST_TRANSPORT); - - verify(mUserOneService).getConfigurationIntent(TEST_TRANSPORT); - } - - /** Test that the backup service does not route methods for non-registered users. */ - @Test - public void testGetConfigurationIntent_onUnknownUser_doesNotPropagateCall() throws Exception { - registerUser(mUserOneId, mUserOneService); - BackupManagerService backupManagerService = createService(); - setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false); - - backupManagerService.getConfigurationIntent(mUserTwoId, TEST_TRANSPORT); - - verify(mUserOneService, never()).getConfigurationIntent(TEST_TRANSPORT); - } - - /** Test that the backup service routes methods correctly to the user that requests it. */ - @Test - public void testGetDestinationString_onRegisteredUser_callsMethodForUser() throws Exception { - registerUser(mUserOneId, mUserOneService); - BackupManagerService backupManagerService = createService(); - setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false); - - backupManagerService.getDestinationString(mUserOneId, TEST_TRANSPORT); - - verify(mUserOneService).getDestinationString(TEST_TRANSPORT); - } - - /** Test that the backup service does not route methods for non-registered users. */ - @Test - public void testGetDestinationString_onUnknownUser_doesNotPropagateCall() throws Exception { - registerUser(mUserOneId, mUserOneService); - BackupManagerService backupManagerService = createService(); - setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false); - - backupManagerService.getDestinationString(mUserTwoId, TEST_TRANSPORT); - - verify(mUserOneService, never()).getDestinationString(TEST_TRANSPORT); - } - - /** Test that the backup service routes methods correctly to the user that requests it. */ - @Test - public void testGetDataManagementIntent_onRegisteredUser_callsMethodForUser() throws Exception { - registerUser(mUserOneId, mUserOneService); - BackupManagerService backupManagerService = createService(); - setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false); - - backupManagerService.getDataManagementIntent(mUserOneId, TEST_TRANSPORT); - - verify(mUserOneService).getDataManagementIntent(TEST_TRANSPORT); - } - - /** Test that the backup service does not route methods for non-registered users. */ - @Test - public void testGetDataManagementIntent_onUnknownUser_doesNotPropagateCall() throws Exception { - registerUser(mUserOneId, mUserOneService); - BackupManagerService backupManagerService = createService(); - setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false); - - backupManagerService.getDataManagementIntent(mUserTwoId, TEST_TRANSPORT); - - verify(mUserOneService, never()).getDataManagementIntent(TEST_TRANSPORT); - } - - /** Test that the backup service routes methods correctly to the user that requests it. */ - @Test - public void testGetDataManagementLabel_onRegisteredUser_callsMethodForUser() throws Exception { - registerUser(mUserOneId, mUserOneService); - BackupManagerService backupManagerService = createService(); - setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false); - - backupManagerService.getDataManagementLabel(mUserOneId, TEST_TRANSPORT); - - verify(mUserOneService).getDataManagementLabel(TEST_TRANSPORT); - } - - /** Test that the backup service does not route methods for non-registered users. */ - @Test - public void testGetDataManagementLabel_onUnknownUser_doesNotPropagateCall() throws Exception { - registerUser(mUserOneId, mUserOneService); - BackupManagerService backupManagerService = createService(); - setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false); - - backupManagerService.getDataManagementLabel(mUserTwoId, TEST_TRANSPORT); - - verify(mUserOneService, never()).getDataManagementLabel(TEST_TRANSPORT); - } - // --------------------------------------------- // Settings tests // --------------------------------------------- diff --git a/services/robotests/backup/src/com/android/server/backup/TrampolineRoboTest.java b/services/robotests/backup/src/com/android/server/backup/TrampolineRoboTest.java index f24be47a4836..0b889a9b4dee 100644 --- a/services/robotests/backup/src/com/android/server/backup/TrampolineRoboTest.java +++ b/services/robotests/backup/src/com/android/server/backup/TrampolineRoboTest.java @@ -19,6 +19,8 @@ package com.android.server.backup; import static android.Manifest.permission.BACKUP; import static android.Manifest.permission.INTERACT_ACROSS_USERS_FULL; +import static com.android.server.backup.testing.TransportData.backupTransport; + import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.mock; @@ -28,6 +30,7 @@ import static org.robolectric.Shadows.shadowOf; import android.annotation.UserIdInt; import android.app.Application; +import android.app.backup.ISelectBackupTransportCallback; import android.content.Context; import android.os.IBinder; import android.os.Process; @@ -36,6 +39,7 @@ import android.os.UserManager; import android.platform.test.annotations.Presubmit; import android.util.SparseArray; +import com.android.server.backup.testing.TransportData; import com.android.server.testing.shadows.ShadowApplicationPackageManager; import com.android.server.testing.shadows.ShadowBinder; import com.android.server.testing.shadows.ShadowEnvironment; @@ -398,6 +402,159 @@ public class TrampolineRoboTest { verify(mUserOneService, never()).listAllTransportComponents(); } + /** Test that the backup service routes methods correctly to the user that requests it. */ + @Test + public void testSelectBackupTransport_onRegisteredUser_callsMethodForUser() throws Exception { + Trampoline backupManagerService = createService(); + registerUser(backupManagerService, mUserOneId, mUserOneService); + setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false); + + backupManagerService.selectBackupTransport(mUserOneId, TEST_TRANSPORT); + + verify(mUserOneService).selectBackupTransport(TEST_TRANSPORT); + } + + /** Test that the backup service does not route methods for non-registered users. */ + @Test + public void testSelectBackupTransport_onUnknownUser_doesNotPropagateCall() throws Exception { + Trampoline backupManagerService = createService(); + registerUser(backupManagerService, mUserOneId, mUserOneService); + setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false); + + backupManagerService.selectBackupTransport(mUserTwoId, TEST_TRANSPORT); + + verify(mUserOneService, never()).selectBackupTransport(TEST_TRANSPORT); + } + + /** Test that the backup service routes methods correctly to the user that requests it. */ + @Test + public void testSelectTransportAsync_onRegisteredUser_callsMethodForUser() throws Exception { + Trampoline backupManagerService = createService(); + registerUser(backupManagerService, mUserOneId, mUserOneService); + setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false); + TransportData transport = backupTransport(); + ISelectBackupTransportCallback callback = mock(ISelectBackupTransportCallback.class); + + backupManagerService.selectBackupTransportAsync( + mUserOneId, transport.getTransportComponent(), callback); + + verify(mUserOneService) + .selectBackupTransportAsync(transport.getTransportComponent(), callback); + } + + /** Test that the backup service does not route methods for non-registered users. */ + @Test + public void testSelectBackupTransportAsync_onUnknownUser_doesNotPropagateCall() + throws Exception { + Trampoline backupManagerService = createService(); + registerUser(backupManagerService, mUserOneId, mUserOneService); + setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false); + TransportData transport = backupTransport(); + ISelectBackupTransportCallback callback = mock(ISelectBackupTransportCallback.class); + + backupManagerService.selectBackupTransportAsync( + mUserTwoId, transport.getTransportComponent(), callback); + + verify(mUserOneService, never()) + .selectBackupTransportAsync(transport.getTransportComponent(), callback); + } + + /** Test that the backup service routes methods correctly to the user that requests it. */ + @Test + public void testGetConfigurationIntent_onRegisteredUser_callsMethodForUser() throws Exception { + Trampoline backupManagerService = createService(); + registerUser(backupManagerService, mUserOneId, mUserOneService); + setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false); + + backupManagerService.getConfigurationIntent(mUserOneId, TEST_TRANSPORT); + + verify(mUserOneService).getConfigurationIntent(TEST_TRANSPORT); + } + + /** Test that the backup service does not route methods for non-registered users. */ + @Test + public void testGetConfigurationIntent_onUnknownUser_doesNotPropagateCall() throws Exception { + Trampoline backupManagerService = createService(); + registerUser(backupManagerService, mUserOneId, mUserOneService); + setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false); + + backupManagerService.getConfigurationIntent(mUserTwoId, TEST_TRANSPORT); + + verify(mUserOneService, never()).getConfigurationIntent(TEST_TRANSPORT); + } + + /** Test that the backup service routes methods correctly to the user that requests it. */ + @Test + public void testGetDestinationString_onRegisteredUser_callsMethodForUser() throws Exception { + Trampoline backupManagerService = createService(); + registerUser(backupManagerService, mUserOneId, mUserOneService); + setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false); + + backupManagerService.getDestinationString(mUserOneId, TEST_TRANSPORT); + + verify(mUserOneService).getDestinationString(TEST_TRANSPORT); + } + + /** Test that the backup service does not route methods for non-registered users. */ + @Test + public void testGetDestinationString_onUnknownUser_doesNotPropagateCall() throws Exception { + Trampoline backupManagerService = createService(); + registerUser(backupManagerService, mUserOneId, mUserOneService); + setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false); + + backupManagerService.getDestinationString(mUserTwoId, TEST_TRANSPORT); + + verify(mUserOneService, never()).getDestinationString(TEST_TRANSPORT); + } + + /** Test that the backup service routes methods correctly to the user that requests it. */ + @Test + public void testGetDataManagementIntent_onRegisteredUser_callsMethodForUser() throws Exception { + Trampoline backupManagerService = createService(); + registerUser(backupManagerService, mUserOneId, mUserOneService); + setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false); + + backupManagerService.getDataManagementIntent(mUserOneId, TEST_TRANSPORT); + + verify(mUserOneService).getDataManagementIntent(TEST_TRANSPORT); + } + + /** Test that the backup service does not route methods for non-registered users. */ + @Test + public void testGetDataManagementIntent_onUnknownUser_doesNotPropagateCall() throws Exception { + Trampoline backupManagerService = createService(); + registerUser(backupManagerService, mUserOneId, mUserOneService); + setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false); + + backupManagerService.getDataManagementIntent(mUserTwoId, TEST_TRANSPORT); + + verify(mUserOneService, never()).getDataManagementIntent(TEST_TRANSPORT); + } + + /** Test that the backup service routes methods correctly to the user that requests it. */ + @Test + public void testGetDataManagementLabel_onRegisteredUser_callsMethodForUser() throws Exception { + Trampoline backupManagerService = createService(); + registerUser(backupManagerService, mUserOneId, mUserOneService); + setCallerAndGrantInteractUserPermission(mUserOneId, /* shouldGrantPermission */ false); + + backupManagerService.getDataManagementLabel(mUserOneId, TEST_TRANSPORT); + + verify(mUserOneService).getDataManagementLabel(TEST_TRANSPORT); + } + + /** Test that the backup service does not route methods for non-registered users. */ + @Test + public void testGetDataManagementLabel_onUnknownUser_doesNotPropagateCall() throws Exception { + Trampoline backupManagerService = createService(); + registerUser(backupManagerService, mUserOneId, mUserOneService); + setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false); + + backupManagerService.getDataManagementLabel(mUserTwoId, TEST_TRANSPORT); + + verify(mUserOneService, never()).getDataManagementLabel(TEST_TRANSPORT); + } + private Trampoline createService() { return new Trampoline(mContext); } diff --git a/services/tests/servicestests/src/com/android/server/backup/TrampolineTest.java b/services/tests/servicestests/src/com/android/server/backup/TrampolineTest.java index 12ab899283f3..c1ac5fadb632 100644 --- a/services/tests/servicestests/src/com/android/server/backup/TrampolineTest.java +++ b/services/tests/servicestests/src/com/android/server/backup/TrampolineTest.java @@ -42,7 +42,6 @@ import android.app.backup.ISelectBackupTransportCallback; import android.app.job.JobScheduler; import android.content.ComponentName; import android.content.Context; -import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.UserInfo; import android.os.ConditionVariable; @@ -663,23 +662,6 @@ public class TrampolineTest { } @Test - public void selectBackupTransportForUser_forwarded() throws Exception { - - mTrampoline.selectBackupTransportForUser(mUserId, TRANSPORT_NAME); - - verify(mBackupManagerServiceMock).selectBackupTransport(mUserId, TRANSPORT_NAME); - } - - @Test - public void selectBackupTransport_forwarded() throws Exception { - TrampolineTestable.sCallingUserId = mUserId; - - mTrampoline.selectBackupTransport(TRANSPORT_NAME); - - verify(mBackupManagerServiceMock).selectBackupTransport(mUserId, TRANSPORT_NAME); - } - - @Test public void selectBackupTransportAsyncForUser_beforeUserUnlocked_notifiesBackupNotAllowed() throws Exception { mUserServices.clear(); @@ -729,102 +711,6 @@ public class TrampolineTest { } @Test - public void selectBackupTransportAsyncForUser_forwarded() throws Exception { - - mTrampoline.selectBackupTransportAsyncForUser(mUserId, TRANSPORT_COMPONENT_NAME, null); - - verify(mBackupManagerServiceMock) - .selectBackupTransportAsync(mUserId, TRANSPORT_COMPONENT_NAME, null); - } - - @Test - public void getConfigurationIntentForUser_forwarded() throws Exception { - Intent configurationIntentStub = new Intent(); - when(mBackupManagerServiceMock.getConfigurationIntent(mUserId, TRANSPORT_NAME)).thenReturn( - configurationIntentStub); - - assertEquals( - configurationIntentStub, - mTrampoline.getConfigurationIntentForUser(mUserId, TRANSPORT_NAME)); - verify(mBackupManagerServiceMock).getConfigurationIntent(mUserId, TRANSPORT_NAME); - } - - @Test - public void getConfigurationIntent_forwarded() throws Exception { - TrampolineTestable.sCallingUserId = mUserId; - Intent configurationIntentStub = new Intent(); - when(mBackupManagerServiceMock.getConfigurationIntent(mUserId, TRANSPORT_NAME)).thenReturn( - configurationIntentStub); - - assertEquals(configurationIntentStub, mTrampoline.getConfigurationIntent(TRANSPORT_NAME)); - verify(mBackupManagerServiceMock).getConfigurationIntent(mUserId, TRANSPORT_NAME); - } - - @Test - public void getDestinationStringForUser_forwarded() throws Exception { - when(mBackupManagerServiceMock.getDestinationString(mUserId, TRANSPORT_NAME)).thenReturn( - DESTINATION_STRING); - - assertEquals( - DESTINATION_STRING, - mTrampoline.getDestinationStringForUser(mUserId, TRANSPORT_NAME)); - verify(mBackupManagerServiceMock).getDestinationString(mUserId, TRANSPORT_NAME); - } - - @Test - public void getDestinationString_forwarded() throws Exception { - TrampolineTestable.sCallingUserId = mUserId; - when(mBackupManagerServiceMock.getDestinationString(mUserId, TRANSPORT_NAME)).thenReturn( - DESTINATION_STRING); - - assertEquals(DESTINATION_STRING, mTrampoline.getDestinationString(TRANSPORT_NAME)); - verify(mBackupManagerServiceMock).getDestinationString(mUserId, TRANSPORT_NAME); - } - - @Test - public void getDataManagementIntentForUser_forwarded() throws Exception { - Intent dataManagementIntent = new Intent(); - when(mBackupManagerServiceMock.getDataManagementIntent(mUserId, TRANSPORT_NAME)).thenReturn( - dataManagementIntent); - - assertEquals( - dataManagementIntent, - mTrampoline.getDataManagementIntentForUser(mUserId, TRANSPORT_NAME)); - verify(mBackupManagerServiceMock).getDataManagementIntent(mUserId, TRANSPORT_NAME); - } - - @Test - public void getDataManagementIntent_forwarded() throws Exception { - TrampolineTestable.sCallingUserId = mUserId; - Intent dataManagementIntent = new Intent(); - when(mBackupManagerServiceMock.getDataManagementIntent(mUserId, TRANSPORT_NAME)).thenReturn( - dataManagementIntent); - - assertEquals(dataManagementIntent, mTrampoline.getDataManagementIntent(TRANSPORT_NAME)); - verify(mBackupManagerServiceMock).getDataManagementIntent(mUserId, TRANSPORT_NAME); - } - - @Test - public void getDataManagementLabelForUser_forwarded() throws Exception { - when(mBackupManagerServiceMock.getDataManagementLabel(mUserId, TRANSPORT_NAME)).thenReturn( - DATA_MANAGEMENT_LABEL); - - assertEquals( - DATA_MANAGEMENT_LABEL, - mTrampoline.getDataManagementLabelForUser(mUserId, TRANSPORT_NAME)); - verify(mBackupManagerServiceMock).getDataManagementLabel(mUserId, TRANSPORT_NAME); - } - - @Test - public void beginRestoreSessionForUser_forwarded() throws Exception { - - mTrampoline.beginRestoreSessionForUser(mUserId, PACKAGE_NAME, TRANSPORT_NAME); - - verify(mBackupManagerServiceMock) - .beginRestoreSession(mUserId, PACKAGE_NAME, TRANSPORT_NAME); - } - - @Test public void getAvailableRestoreTokenForUser_forwarded() { when(mBackupManagerServiceMock.getAvailableRestoreToken(mUserId, PACKAGE_NAME)) .thenReturn(123L); |