Loading framework/tests/bumble/src/android/bluetooth/GattClientTest.java +41 −4 Original line number Diff line number Diff line Loading @@ -70,7 +70,9 @@ import pandora.HostProto.AdvertiseResponse; import pandora.HostProto.OwnAddressType; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.UUID; @RunWith(TestParameterInjector.class) Loading Loading @@ -214,7 +216,7 @@ public class GattClientTest { @Test public void clientGattWriteCharacteristic() throws Exception { registerWritableGattService(); registerGattService(); BluetoothGattCallback gattCallback = mock(BluetoothGattCallback.class); BluetoothGatt gatt = connectGattAndWaitConnection(gattCallback); Loading Loading @@ -306,7 +308,7 @@ public class GattClientTest { public void consecutiveWriteCharacteristicFails_thenSuccess() throws Exception { Assume.assumeTrue(Flags.gattFixDeviceBusy()); registerWritableGattService(); registerGattService(); BluetoothGattCallback gattCallback = mock(BluetoothGattCallback.class); BluetoothGattCallback gattCallback2 = mock(BluetoothGattCallback.class); Loading Loading @@ -384,10 +386,12 @@ public class GattClientTest { } } private void registerWritableGattService() { private void registerGattService() { GattCharacteristicParams characteristicParams = GattCharacteristicParams.newBuilder() .setProperties(BluetoothGattCharacteristic.PROPERTY_WRITE) .setProperties( BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic.PROPERTY_WRITE) .setUuid(TEST_CHARACTERISTIC_UUID.toString()) .build(); Loading Loading @@ -565,4 +569,37 @@ public class GattClientTest { disconnectAndWaitDisconnection(gatt, gattCallback); } } // Check if we can have 100 simultaneous clients @Test @RequiresFlagsEnabled(Flags.FLAG_GATT_CLIENT_DYNAMIC_ALLOCATION) public void connectGatt_multipleClients() { advertiseWithBumble(); registerGattService(); List<BluetoothGatt> gatts = new ArrayList<>(); final int repeatTimes = 100; try { for (int i = 0; i < repeatTimes; i++) { BluetoothGattCallback gattCallback = mock(BluetoothGattCallback.class); BluetoothGatt gatt = connectGattAndWaitConnection(gattCallback); gatts.add(gatt); gatt.discoverServices(); verify(gattCallback, timeout(10000)).onServicesDiscovered(any(), eq(GATT_SUCCESS)); BluetoothGattCharacteristic characteristic = gatt.getService(TEST_SERVICE_UUID) .getCharacteristic(TEST_CHARACTERISTIC_UUID); gatt.readCharacteristic(characteristic); verify(gattCallback, timeout(5000)) .onCharacteristicRead(any(), any(), any(), anyInt()); } } finally { for (BluetoothGatt gatt : gatts) { gatt.disconnect(); gatt.close(); } } } } system/bta/gatt/bta_gattc_act.cc +1 −1 Original line number Diff line number Diff line Loading @@ -192,7 +192,7 @@ void bta_gattc_register(const Uuid& app_uuid, tBTA_GATTC_CBACK* p_cback, BtaAppR } if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) { tGATT_IF client_if = GATT_Register(app_uuid, "GattClient", &bta_gattc_cl_cback, eatt_support); client_if = GATT_Register(app_uuid, "GattClient", &bta_gattc_cl_cback, eatt_support); if (client_if == 0) { log::error("Register with GATT stack failed"); status = GATT_ERROR; Loading system/stack/gatt/gatt_api.cc +1 −0 Original line number Diff line number Diff line Loading @@ -1302,6 +1302,7 @@ static tGATT_IF GATT_Register_Dynamic(const Uuid& app_uuid128, const std::string if (gatt_cb.next_gatt_if == 0) { gatt_cb.next_gatt_if = 1; } return p_reg->gatt_if; } i_gatt_if++; if (i_gatt_if == 0) { Loading Loading
framework/tests/bumble/src/android/bluetooth/GattClientTest.java +41 −4 Original line number Diff line number Diff line Loading @@ -70,7 +70,9 @@ import pandora.HostProto.AdvertiseResponse; import pandora.HostProto.OwnAddressType; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.UUID; @RunWith(TestParameterInjector.class) Loading Loading @@ -214,7 +216,7 @@ public class GattClientTest { @Test public void clientGattWriteCharacteristic() throws Exception { registerWritableGattService(); registerGattService(); BluetoothGattCallback gattCallback = mock(BluetoothGattCallback.class); BluetoothGatt gatt = connectGattAndWaitConnection(gattCallback); Loading Loading @@ -306,7 +308,7 @@ public class GattClientTest { public void consecutiveWriteCharacteristicFails_thenSuccess() throws Exception { Assume.assumeTrue(Flags.gattFixDeviceBusy()); registerWritableGattService(); registerGattService(); BluetoothGattCallback gattCallback = mock(BluetoothGattCallback.class); BluetoothGattCallback gattCallback2 = mock(BluetoothGattCallback.class); Loading Loading @@ -384,10 +386,12 @@ public class GattClientTest { } } private void registerWritableGattService() { private void registerGattService() { GattCharacteristicParams characteristicParams = GattCharacteristicParams.newBuilder() .setProperties(BluetoothGattCharacteristic.PROPERTY_WRITE) .setProperties( BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic.PROPERTY_WRITE) .setUuid(TEST_CHARACTERISTIC_UUID.toString()) .build(); Loading Loading @@ -565,4 +569,37 @@ public class GattClientTest { disconnectAndWaitDisconnection(gatt, gattCallback); } } // Check if we can have 100 simultaneous clients @Test @RequiresFlagsEnabled(Flags.FLAG_GATT_CLIENT_DYNAMIC_ALLOCATION) public void connectGatt_multipleClients() { advertiseWithBumble(); registerGattService(); List<BluetoothGatt> gatts = new ArrayList<>(); final int repeatTimes = 100; try { for (int i = 0; i < repeatTimes; i++) { BluetoothGattCallback gattCallback = mock(BluetoothGattCallback.class); BluetoothGatt gatt = connectGattAndWaitConnection(gattCallback); gatts.add(gatt); gatt.discoverServices(); verify(gattCallback, timeout(10000)).onServicesDiscovered(any(), eq(GATT_SUCCESS)); BluetoothGattCharacteristic characteristic = gatt.getService(TEST_SERVICE_UUID) .getCharacteristic(TEST_CHARACTERISTIC_UUID); gatt.readCharacteristic(characteristic); verify(gattCallback, timeout(5000)) .onCharacteristicRead(any(), any(), any(), anyInt()); } } finally { for (BluetoothGatt gatt : gatts) { gatt.disconnect(); gatt.close(); } } } }
system/bta/gatt/bta_gattc_act.cc +1 −1 Original line number Diff line number Diff line Loading @@ -192,7 +192,7 @@ void bta_gattc_register(const Uuid& app_uuid, tBTA_GATTC_CBACK* p_cback, BtaAppR } if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) { tGATT_IF client_if = GATT_Register(app_uuid, "GattClient", &bta_gattc_cl_cback, eatt_support); client_if = GATT_Register(app_uuid, "GattClient", &bta_gattc_cl_cback, eatt_support); if (client_if == 0) { log::error("Register with GATT stack failed"); status = GATT_ERROR; Loading
system/stack/gatt/gatt_api.cc +1 −0 Original line number Diff line number Diff line Loading @@ -1302,6 +1302,7 @@ static tGATT_IF GATT_Register_Dynamic(const Uuid& app_uuid128, const std::string if (gatt_cb.next_gatt_if == 0) { gatt_cb.next_gatt_if = 1; } return p_reg->gatt_if; } i_gatt_if++; if (i_gatt_if == 0) { Loading