Loading android/app/src/com/android/bluetooth/tbs/TbsGatt.java +7 −4 Original line number Diff line number Diff line Loading @@ -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]; Loading android/app/tests/unit/src/com/android/bluetooth/tbs/TbsGattTest.java +20 −2 Original line number Diff line number Diff line Loading @@ -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(); Loading Loading
android/app/src/com/android/bluetooth/tbs/TbsGatt.java +7 −4 Original line number Diff line number Diff line Loading @@ -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]; Loading
android/app/tests/unit/src/com/android/bluetooth/tbs/TbsGattTest.java +20 −2 Original line number Diff line number Diff line Loading @@ -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(); Loading