summaryrefslogtreecommitdiff
path: root/services
diff options
context:
space:
mode:
Diffstat (limited to 'services')
-rw-r--r--services/backup/java/com/android/server/backup/UserBackupManagerService.java15
-rw-r--r--services/robotests/backup/src/com/android/server/backup/UserBackupManagerServiceTest.java22
2 files changed, 34 insertions, 3 deletions
diff --git a/services/backup/java/com/android/server/backup/UserBackupManagerService.java b/services/backup/java/com/android/server/backup/UserBackupManagerService.java
index 243a7e0ed2ad..907daa34826f 100644
--- a/services/backup/java/com/android/server/backup/UserBackupManagerService.java
+++ b/services/backup/java/com/android/server/backup/UserBackupManagerService.java
@@ -160,7 +160,6 @@ import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
-import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.Queue;
@@ -3401,7 +3400,8 @@ public class UserBackupManagerService {
}
/**
- * Selects transport {@code transportName} and returns previously selected transport.
+ * Selects transport {@code transportName}, if it is already registered, and returns previously
+ * selected transport. Returns {@code null} if the transport is not registered.
*
* @deprecated Use {@link #selectBackupTransportAsync(ComponentName,
* ISelectBackupTransportCallback)} instead.
@@ -3414,6 +3414,17 @@ public class UserBackupManagerService {
final long oldId = Binder.clearCallingIdentity();
try {
+ if (!mTransportManager.isTransportRegistered(transportName)) {
+ Slog.v(
+ TAG,
+ addUserIdToLogMessage(
+ mUserId,
+ "Could not select transport "
+ + transportName
+ + ", as the transport is not registered."));
+ return null;
+ }
+
String previousTransportName = mTransportManager.selectTransport(transportName);
updateStateForTransport(transportName);
Slog.v(
diff --git a/services/robotests/backup/src/com/android/server/backup/UserBackupManagerServiceTest.java b/services/robotests/backup/src/com/android/server/backup/UserBackupManagerServiceTest.java
index 297538ad7b4b..159285a5ce5e 100644
--- a/services/robotests/backup/src/com/android/server/backup/UserBackupManagerServiceTest.java
+++ b/services/robotests/backup/src/com/android/server/backup/UserBackupManagerServiceTest.java
@@ -61,8 +61,8 @@ import com.android.server.backup.testing.BackupManagerServiceTestUtils;
import com.android.server.backup.testing.TransportData;
import com.android.server.backup.testing.TransportTestUtils.TransportMock;
import com.android.server.backup.transport.TransportNotRegisteredException;
-import com.android.server.testing.shadows.ShadowBackupEligibilityRules;
import com.android.server.testing.shadows.ShadowApplicationPackageManager;
+import com.android.server.testing.shadows.ShadowBackupEligibilityRules;
import com.android.server.testing.shadows.ShadowBinder;
import com.android.server.testing.shadows.ShadowKeyValueBackupJob;
import com.android.server.testing.shadows.ShadowKeyValueBackupTask;
@@ -361,6 +361,26 @@ public class UserBackupManagerServiceTest {
}
/**
+ * Test verifying that {@link UserBackupManagerService#selectBackupTransport(String)} does not
+ * switch the current transport to the inputted transport, when the inputted transport is not
+ * registered.
+ */
+ @Test
+ public void testSelectBackupTransport_nonRegisteredTransport() throws Exception {
+ setUpForSelectTransport();
+ mShadowContext.grantPermissions(android.Manifest.permission.BACKUP);
+ when(mTransportManager.isTransportRegistered(eq(mNewTransport.transportName)))
+ .thenReturn(false);
+ UserBackupManagerService backupManagerService = createUserBackupManagerServiceAndRunTasks();
+
+ String oldTransport = backupManagerService.selectBackupTransport(
+ mNewTransport.transportName);
+
+ assertThat(getSettingsTransport()).isNotEqualTo(mNewTransport.transportName);
+ assertThat(oldTransport).isEqualTo(null);
+ }
+
+ /**
* Test verifying that {@link UserBackupManagerService#selectBackupTransport(String)} throws a
* {@link SecurityException} if the caller does not have backup permission.
*/