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

Commit 3fcdd940 authored by Jack He's avatar Jack He Committed by Automerger Merge Worker
Browse files

Merge "Hap: Fix verifying input parameters" am: b97b755f am: 76455542 am: 25ea0d1b

parents a9353bfb 25ea0d1b
Loading
Loading
Loading
Loading
+13 −13
Original line number Diff line number Diff line
@@ -621,22 +621,21 @@ public class HapClientService extends ProfileService {
     * @param presetIndex is an index of one of the available presets
     */
    public void selectPresetForGroup(int groupId, int presetIndex) {
        int status = BluetoothStatusCodes.ERROR_UNKNOWN;
        int status = BluetoothStatusCodes.SUCCESS;

        if ((presetIndex == BluetoothHapClient.PRESET_INDEX_UNAVAILABLE)
                || (groupId == BluetoothCsipSetCoordinator.GROUP_ID_INVALID)) {
            if (presetIndex == BluetoothHapClient.PRESET_INDEX_UNAVAILABLE) {
                status = BluetoothStatusCodes.ERROR_HAP_INVALID_PRESET_INDEX;
            } else {
        if (!isGroupIdValid(groupId)) {
            status = BluetoothStatusCodes.ERROR_CSIP_INVALID_GROUP_ID;
        } else if (!isPresetIndexValid(groupId, presetIndex)) {
            status = BluetoothStatusCodes.ERROR_HAP_INVALID_PRESET_INDEX;
        }

        if (status != BluetoothStatusCodes.SUCCESS) {
            if (mCallbacks != null) {
                int n = mCallbacks.beginBroadcast();
                for (int i = 0; i < n; i++) {
                    try {
                        mCallbacks.getBroadcastItem(i).onPresetSelectionForGroupFailed(groupId,
                                BluetoothStatusCodes.ERROR_HAP_INVALID_PRESET_INDEX);
                        mCallbacks.getBroadcastItem(i)
                                .onPresetSelectionForGroupFailed(groupId, status);
                    } catch (RemoteException e) {
                        continue;
                    }
@@ -900,6 +899,8 @@ public class HapClientService extends ProfileService {

    private boolean isPresetIndexValid(int groupId, int presetIndex) {
        List<BluetoothDevice> all_group_devices = getGroupDevices(groupId);
        if (all_group_devices.isEmpty()) return false;

        for (BluetoothDevice device : all_group_devices) {
            if (!isPresetIndexValid(device, presetIndex)) return false;
        }
@@ -915,7 +916,7 @@ public class HapClientService extends ProfileService {
            List<Integer> groups = csipClient.getAllGroupIds(BluetoothUuid.CAP);
            return groups.contains(groupId);
        }
        return true;
        return false;
    }

    /**
@@ -959,8 +960,7 @@ public class HapClientService extends ProfileService {

        if (!isGroupIdValid(groupId)) {
            status = BluetoothStatusCodes.ERROR_CSIP_INVALID_GROUP_ID;
        }
        if (!isPresetIndexValid(groupId, presetIndex)) {
        } else if (!isPresetIndexValid(groupId, presetIndex)) {
            status = BluetoothStatusCodes.ERROR_HAP_INVALID_PRESET_INDEX;
        }
        if (status != BluetoothStatusCodes.SUCCESS) {
+3 −1
Original line number Diff line number Diff line
@@ -469,8 +469,10 @@ public class HapClientTest {
    public void testGroupSelectActivePresetNative() {
        doReturn(new ParcelUuid[]{BluetoothUuid.HAS}).when(mAdapterService)
                .getRemoteUuids(any(BluetoothDevice.class));
        testConnectingDevice(mDevice3);

        int flags = 0x01;
        mNativeInterface.onFeaturesUpdate(getByteAddress(mDevice), flags);
        mNativeInterface.onFeaturesUpdate(getByteAddress(mDevice3), flags);

        // Verify Native Interface call
        mService.selectPresetForGroup(0x03, 0x00);