Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bf555573 authored by Sergey Nikolaienkov's avatar Sergey Nikolaienkov
Browse files

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
parent 2d0e9dee
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -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);
+8 −20
Original line number Diff line number Diff line
@@ -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,16 +936,10 @@ 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();
        }
    }
    }

    private void exemptFromAutoRevoke(String packageName, int uid) {
        try {
@@ -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);
    }

+1 −9
Original line number Diff line number Diff line
@@ -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);
            }