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

Commit 4375344b 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 am: ac4e99e2

parents 1d550ff7 ac4e99e2
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -493,6 +493,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
@@ -250,35 +250,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();
@@ -291,14 +301,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)
@@ -306,7 +326,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();