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

Commit 903925c7 authored by William Escande's avatar William Escande
Browse files

Csip: handle active device before broadcast intent

[Detail]
- When received ACTION_CSIS_DEVICE_AVAILABLE, settings or other
processes may call getGroupUuidMapByDevice() to get the group id before
csip updates the mDeviceGroupIdRankMap, which causes the caller to fail
to get the correct value.

[Solution]
- Ensure mDeviceGroupIdRankMap be updated before broadcasting
ACTION_CSIS_DEVICE_AVAILABLE
- Call handleDeviceAvailable() first

Bug: 328842373
Fix: 328842373
Flag: Exempt no-op change
Test: m . | there are no test specific for race condition
Change-Id: I2f70151b61122ccc6c0c25bb0d3a433835c3ad8d
parent 01172369
Loading
Loading
Loading
Loading
+22 −23
Original line number Diff line number Diff line
@@ -779,11 +779,11 @@ public class CsipSetCoordinatorService extends ProfileService {
        Log.d(TAG, "notifySetMemberAvailable: " + device + ", " + groupId);

        /* Sent intent as well */
        Intent intent = new Intent(BluetoothCsipSetCoordinator.ACTION_CSIS_SET_MEMBER_AVAILABLE);
        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
        intent.putExtra(BluetoothCsipSetCoordinator.EXTRA_CSIS_GROUP_ID, groupId);

        intent.addFlags(
        Intent intent =
                new Intent(BluetoothCsipSetCoordinator.ACTION_CSIS_SET_MEMBER_AVAILABLE)
                        .putExtra(BluetoothDevice.EXTRA_DEVICE, device)
                        .putExtra(BluetoothCsipSetCoordinator.EXTRA_CSIS_GROUP_ID, groupId)
                        .addFlags(
                                Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
                                        | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
        sendOrderedBroadcast(intent, BLUETOOTH_PRIVILEGED);
@@ -796,25 +796,31 @@ public class CsipSetCoordinatorService extends ProfileService {
        BluetoothDevice device = stackEvent.device;
        Log.d(TAG, "Message from native: " + stackEvent);

        Intent intent = null;
        int groupId = stackEvent.valueInt1;
        if (stackEvent.type == CsipSetCoordinatorStackEvent.EVENT_TYPE_DEVICE_AVAILABLE) {
            requireNonNull(device);

            intent = new Intent(BluetoothCsipSetCoordinator.ACTION_CSIS_DEVICE_AVAILABLE);
            intent.putExtra(BluetoothDevice.EXTRA_DEVICE, stackEvent.device);
            intent.putExtra(BluetoothCsipSetCoordinator.EXTRA_CSIS_GROUP_ID, groupId);
            intent.putExtra(
                    BluetoothCsipSetCoordinator.EXTRA_CSIS_GROUP_SIZE, stackEvent.valueInt2);
            intent.putExtra(
                    BluetoothCsipSetCoordinator.EXTRA_CSIS_GROUP_TYPE_UUID, stackEvent.valueUuid1);

            handleDeviceAvailable(
                    device,
                    groupId,
                    stackEvent.valueInt3,
                    stackEvent.valueUuid1,
                    stackEvent.valueInt2);

            Intent intent =
                    new Intent(BluetoothCsipSetCoordinator.ACTION_CSIS_DEVICE_AVAILABLE)
                            .putExtra(BluetoothDevice.EXTRA_DEVICE, stackEvent.device)
                            .putExtra(BluetoothCsipSetCoordinator.EXTRA_CSIS_GROUP_ID, groupId)
                            .putExtra(
                                    BluetoothCsipSetCoordinator.EXTRA_CSIS_GROUP_SIZE,
                                    stackEvent.valueInt2)
                            .putExtra(
                                    BluetoothCsipSetCoordinator.EXTRA_CSIS_GROUP_TYPE_UUID,
                                    stackEvent.valueUuid1)
                            .addFlags(
                                    Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
                                            | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
            sendOrderedBroadcast(intent, BLUETOOTH_PRIVILEGED);
        } else if (stackEvent.type
                == CsipSetCoordinatorStackEvent.EVENT_TYPE_SET_MEMBER_AVAILABLE) {
            requireNonNull(device);
@@ -830,13 +836,6 @@ public class CsipSetCoordinatorService extends ProfileService {
            handleGroupLockChanged(groupId, lock_status, lock_state);
        }

        if (intent != null) {
            intent.addFlags(
                    Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
                            | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
            sendOrderedBroadcast(intent, BLUETOOTH_PRIVILEGED);
        }

        synchronized (mStateMachines) {
            CsipSetCoordinatorStateMachine sm = mStateMachines.get(device);