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

Commit ff4ac8cb authored by Grzegorz Kołodziejczyk's avatar Grzegorz Kołodziejczyk Committed by Grzegorz Kolodziejczyk
Browse files

tbs: Set reponse status to control point operation succeed

When write characteristic to TBS control point succed, GATT success
status should be set.

Tag: #feature
Bug: 278821645
Test: atest TbsGattTest
Change-Id: I8f733c3174eb53d2233bec2ecbddb56ebbfbdb5f
parent 39b6f072
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -561,16 +561,19 @@ public class TbsGatt {
        public void handleWriteRequest(BluetoothDevice device, int requestId,
                boolean responseNeeded, byte[] value) {
            int status;
            if (value.length == 0) {
                // at least opcode is required
            if (value.length < 2) {
                // at least opcode is required and value is at least 1 byte
                status = BluetoothGatt.GATT_INVALID_ATTRIBUTE_LENGTH;
            } else {
                status = BluetoothGatt.GATT_SUCCESS;
            }

            if (responseNeeded) {
                mBluetoothGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_FAILURE, 0,
                        value);
                mBluetoothGattServer.sendResponse(device, requestId, status, 0, value);
            }

            if (status != BluetoothGatt.GATT_SUCCESS) {
                return;
            }

            int opcode = (int) value[0];
+20 −2
Original line number Diff line number Diff line
@@ -564,15 +564,33 @@ public class TbsGattTest {
                getCharacteristic(TbsGatt.UUID_CALL_CONTROL_POINT);

        // Call the internal GATT callback as if peer device accepts the call
        byte[] value = new byte[] {0x00, /* opcode */ 0x0A, /* argument */ };
        byte[] value = new byte[] {0x00 /* opcode */, 0x0A /* argument */};
        mTbsGatt.mGattServerCallback.onCharacteristicWriteRequest(mFirstDevice, 1, characteristic,
                false, false, 0, value);
                false, true, 0, value);

        verify(mMockGattServer).sendResponse(eq(mFirstDevice), eq(1),
                eq(BluetoothGatt.GATT_SUCCESS), eq(0), aryEq(new byte[] {0x00, 0x0A}));

        // Verify the higher layer callback call
        verify(mMockTbsGattCallback).onCallControlPointRequest(eq(mFirstDevice), eq(0x00),
                aryEq(new byte[] {0x0A}));
    }

    @Test
    public void testHandleControlPointInvalidLengthRequest() {
        prepareDefaultService();
        BluetoothGattCharacteristic characteristic =
                getCharacteristic(TbsGatt.UUID_CALL_CONTROL_POINT);

        // Call the internal GATT callback as if peer device accepts the call
        byte[] value = new byte[] {0x00 /* opcode */};
        mTbsGatt.mGattServerCallback.onCharacteristicWriteRequest(mFirstDevice, 1, characteristic,
                false, true, 0, value);

        verify(mMockGattServer).sendResponse(eq(mFirstDevice), eq(1),
                eq(BluetoothGatt.GATT_INVALID_ATTRIBUTE_LENGTH), eq(0), aryEq(new byte[] {0x00}));
    }

    @Test
    public void testSetInbandRingtoneTwice() {
        prepareDefaultService();