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

Commit a8805a38 authored by Jakub Pawłowski's avatar Jakub Pawłowski Committed by Automerger Merge Worker
Browse files

Merge "CsipSetCoordinator: Fix handling locking unknown group" am: 2a28ada5...

Merge "CsipSetCoordinator: Fix handling locking unknown group" am: 2a28ada5 am: ac4e99e2 am: 4375344b am: 2144c0d0

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2064770



Change-Id: I3a69476a8162d2514077ac40503533198dfd6911
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents b0bc7f7f 2144c0d0
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -498,6 +498,19 @@ public class CsipSetCoordinatorService extends ProfileService {
            return null;
        }

        synchronized (mGroupIdToUuidMap) {
            if (!mGroupIdToUuidMap.containsKey(groupId)) {
                try {
                    callback.onGroupLockSet(groupId,
                            BluetoothStatusCodes.ERROR_CSIP_INVALID_GROUP_ID,
                            false);
                } catch (RemoteException e) {
                    throw e.rethrowFromSystemServer();
                }
                return null;
            }
        }

        UUID uuid = UUID.randomUUID();
        synchronized (mLocks) {
            if (mLocks.containsKey(groupId)) {
+34 −14
Original line number Diff line number Diff line
@@ -252,35 +252,45 @@ public class CsipSetCoordinatorServiceTest {
     */
    @Test
    public void testGroupLockSetNative() {
        int group = 0x02;
        int group_id = 0x01;
        int group_size = 0x01;
        long uuidLsb = 0x01;
        long uuidMsb = 0x01;
        UUID uuid = new UUID(uuidMsb, uuidLsb);

        doCallRealMethod()
                .when(mCsipSetCoordinatorNativeInterface)
                .onDeviceAvailable(any(byte[].class), anyInt(), anyInt(), anyLong(), anyLong());
        mCsipSetCoordinatorNativeInterface.onDeviceAvailable(
                getByteAddress(mTestDevice), group_id, group_size, uuidLsb, uuidMsb);

        UUID lock_uuid = mService.lockGroup(group, mCsipSetCoordinatorLockCallback);
        UUID lock_uuid = mService.lockGroup(group_id, mCsipSetCoordinatorLockCallback);
        Assert.assertNotNull(lock_uuid);
        verify(mCsipSetCoordinatorNativeInterface, times(1)).groupLockSet(eq(group), eq(true));
        verify(mCsipSetCoordinatorNativeInterface, times(1)).groupLockSet(eq(group_id), eq(true));

        doCallRealMethod()
                .when(mCsipSetCoordinatorNativeInterface)
                .onGroupLockChanged(anyInt(), anyBoolean(), anyInt());
        mCsipSetCoordinatorNativeInterface.onGroupLockChanged(
                group, true, IBluetoothCsipSetCoordinator.CSIS_GROUP_LOCK_SUCCESS);
                group_id, true, IBluetoothCsipSetCoordinator.CSIS_GROUP_LOCK_SUCCESS);

        try {
            verify(mCsipSetCoordinatorLockCallback, times(1))
                    .onGroupLockSet(group, BluetoothStatusCodes.SUCCESS,
                    .onGroupLockSet(group_id, BluetoothStatusCodes.SUCCESS,
                        true);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }

        mService.unlockGroup(lock_uuid);
        verify(mCsipSetCoordinatorNativeInterface, times(1)).groupLockSet(eq(group), eq(false));
        verify(mCsipSetCoordinatorNativeInterface, times(1)).groupLockSet(eq(group_id), eq(false));

        mCsipSetCoordinatorNativeInterface.onGroupLockChanged(
                group, false, IBluetoothCsipSetCoordinator.CSIS_GROUP_LOCK_SUCCESS);
                group_id, false, IBluetoothCsipSetCoordinator.CSIS_GROUP_LOCK_SUCCESS);

        try {
            verify(mCsipSetCoordinatorLockCallback, times(1))
                    .onGroupLockSet(group, BluetoothStatusCodes.SUCCESS,
                    .onGroupLockSet(group_id, BluetoothStatusCodes.SUCCESS,
                        false);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
@@ -293,14 +303,24 @@ public class CsipSetCoordinatorServiceTest {
     */
    @Test
    public void testGroupExclusiveLockSet() {
        int group = 0x02;
        int group_id = 0x01;
        int group_size = 0x01;
        long uuidLsb = 0x01;
        long uuidMsb = 0x01;
        UUID uuid = new UUID(uuidMsb, uuidLsb);

        doCallRealMethod()
                .when(mCsipSetCoordinatorNativeInterface)
                .onDeviceAvailable(any(byte[].class), anyInt(), anyInt(), anyLong(), anyLong());
        mCsipSetCoordinatorNativeInterface.onDeviceAvailable(
                getByteAddress(mTestDevice), group_id, group_size, uuidLsb, uuidMsb);

        UUID lock_uuid = mService.lockGroup(group, mCsipSetCoordinatorLockCallback);
        verify(mCsipSetCoordinatorNativeInterface, times(1)).groupLockSet(eq(group), eq(true));
        UUID lock_uuid = mService.lockGroup(group_id, mCsipSetCoordinatorLockCallback);
        verify(mCsipSetCoordinatorNativeInterface, times(1)).groupLockSet(eq(group_id), eq(true));
        Assert.assertNotNull(lock_uuid);

        lock_uuid = mService.lockGroup(group, mCsipSetCoordinatorLockCallback);
        verify(mCsipSetCoordinatorNativeInterface, times(1)).groupLockSet(eq(group), eq(true));
        lock_uuid = mService.lockGroup(group_id, mCsipSetCoordinatorLockCallback);
        verify(mCsipSetCoordinatorNativeInterface, times(1)).groupLockSet(eq(group_id), eq(true));

        doCallRealMethod()
                .when(mCsipSetCoordinatorNativeInterface)
@@ -308,7 +328,7 @@ public class CsipSetCoordinatorServiceTest {

        try {
            verify(mCsipSetCoordinatorLockCallback, times(1))
                    .onGroupLockSet(group,
                    .onGroupLockSet(group_id,
                    BluetoothStatusCodes.ERROR_CSIP_GROUP_LOCKED_BY_OTHER, true);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();