Grant CDM roles when association is created

Grant CDM roles for the corresponding CDM profiles when Associations are
being created instead of in onDeviceConnected().
Remove `simulate_connect` and `simulate_disconnect` Shell commads that
aren't needed now (have been used in CTS tests, which is now being
updated to account for the new role granting logic).

Bug: 212656822
Test: atest CtsCompanionDeviceManagerCoreTestCases
Test: atest CtsCompanionDeviceManagerUiAutomationTestCases
Test: atest CtsOsTestCases:CompanionDeviceManagerTest
Change-Id: I44f5c73a815ff60ecfc9a4143eb0f85438015ad6
This commit is contained in:
Sergey Nikolaienkov
2022-01-03 08:36:03 +01:00
parent 2d0e9deee6
commit bf5555738b
3 changed files with 17 additions and 32 deletions

View File

@@ -254,9 +254,14 @@ class AssociationRequestsProcessor {
private AssociationInfo createAssociationAndNotifyApplication(
@NonNull AssociationRequest request, @NonNull String packageName, @UserIdInt int userId,
@Nullable MacAddress macAddress, @NonNull IAssociationRequestCallback callback) {
final AssociationInfo association = mService.createAssociation(userId, packageName,
macAddress, request.getDisplayName(), request.getDeviceProfile(),
request.isSelfManaged());
final AssociationInfo association;
final long callingIdentity = Binder.clearCallingIdentity();
try {
association = mService.createAssociation(userId, packageName, macAddress,
request.getDisplayName(), request.getDeviceProfile(), request.isSelfManaged());
} finally {
Binder.restoreCallingIdentity(callingIdentity);
}
try {
callback.onAssociationCreated(association);

View File

@@ -787,6 +787,12 @@ public class CompanionDeviceManagerService extends SystemService
Slog.i(LOG_TAG, "New CDM association created=" + association);
mAssociationStore.addAssociation(association);
// If the "Device Profile" is specified, make the companion application a holder of the
// corresponding role.
if (deviceProfile != null) {
addRoleHolderForAssociation(getContext(), association);
}
updateSpecialAccessPermissionForAssociatedPackage(association);
return association;
@@ -930,14 +936,8 @@ public class CompanionDeviceManagerService extends SystemService
exemptFromAutoRevoke(packageInfo.packageName, packageInfo.applicationInfo.uid);
if (!association.isSelfManaged()) {
if (mCurrentlyConnectedDevices.contains(association.getDeviceMacAddressAsString())) {
addRoleHolderForAssociation(getContext(), association);
}
if (association.isNotifyOnDeviceNearby()) {
restartBleScan();
}
if (association.isNotifyOnDeviceNearby()) {
restartBleScan();
}
}
@@ -983,19 +983,7 @@ public class CompanionDeviceManagerService extends SystemService
void onDeviceConnected(String address) {
Slog.d(LOG_TAG, "onDeviceConnected(address = " + address + ")");
mCurrentlyConnectedDevices.add(address);
for (AssociationInfo association : mAssociationStore.getAssociationsByAddress(address)) {
if (association.getDeviceProfile() != null) {
Slog.i(LOG_TAG, "Granting role " + association.getDeviceProfile()
+ " to " + association.getPackageName()
+ " due to device connected: " + association.getDeviceMacAddress());
addRoleHolderForAssociation(getContext(), association);
}
}
onDeviceNearby(address);
}

View File

@@ -73,20 +73,12 @@ class CompanionDeviceShellCommand extends android.os.ShellCommand {
}
break;
case "simulate_connect": {
mService.onDeviceConnected(getNextArgRequired());
}
break;
case "simulate_disconnect": {
mService.onDeviceDisconnected(getNextArgRequired());
}
break;
case "clear-association-memory-cache": {
mService.persistState();
mService.loadAssociationsFromDisk();
}
break;
default:
return handleDefaultCommands(cmd);
}