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

Commit 3a7ed95f authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "tbs: Set reponse status to control point operation succeed" am: 58cdcf74

parents 8ff4345d 58cdcf74
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -621,16 +621,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
@@ -555,15 +555,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();