Validate transport before selecting in UserBackupManagerService.
Make sure transport is registered before changing current transport in UserBackupManagerService. If the input transport is not registered, throw an error to user. Fixes: 163539637 Test: 1. atest -v BackupFrameworksServicesRoboTests 2. Manual test on device. - bmgr list transports # which lists registered transports - Verify selecting transport succeeds on registered transports - Verify selecting transport throws an error on non-registered transports Change-Id: I7e3572a13df07b2dee34e295ea07f1ccff5ca505
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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;
|
||||
@@ -360,6 +360,26 @@ public class UserBackupManagerServiceTest {
|
||||
.disposeOfTransportClient(eq(mNewTransportMock.mTransportConnection), any());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
||||
Reference in New Issue
Block a user