Loading framework/tests/bumble/src/android/bluetooth/DckL2capClientTest.kt +20 −16 Original line number Original line Diff line number Diff line Loading @@ -47,7 +47,6 @@ import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withTimeout import kotlinx.coroutines.withTimeout import org.junit.After import org.junit.After import org.junit.Before import org.junit.Before import org.junit.Ignore import org.junit.Rule import org.junit.Rule import org.junit.Test import org.junit.Test import org.junit.runner.RunWith import org.junit.runner.RunWith Loading Loading @@ -115,7 +114,7 @@ public class DckL2capClientTest() : Closeable { val remoteDevice = val remoteDevice = bluetoothAdapter.getRemoteLeDevice( bluetoothAdapter.getRemoteLeDevice( Utils.BUMBLE_RANDOM_ADDRESS, Utils.BUMBLE_RANDOM_ADDRESS, BluetoothDevice.ADDRESS_TYPE_RANDOM BluetoothDevice.ADDRESS_TYPE_RANDOM, ) ) val gatt = connectGatt(remoteDevice) val gatt = connectGatt(remoteDevice) readDckSpsm(gatt) readDckSpsm(gatt) Loading @@ -134,21 +133,26 @@ public class DckL2capClientTest() : Closeable { } } @Test @Test @Ignore("b/365168533") fun testSend() { fun testReceive() { Log.d(TAG, "testSend") Log.d(TAG, "testReceive") val remoteDevice = val remoteDevice = bluetoothAdapter.getRemoteLeDevice( bluetoothAdapter.getRemoteLeDevice( Utils.BUMBLE_RANDOM_ADDRESS, Utils.BUMBLE_RANDOM_ADDRESS, BluetoothDevice.ADDRESS_TYPE_RANDOM BluetoothDevice.ADDRESS_TYPE_RANDOM, ) ) Log.d(TAG, "testReceive: Connect L2CAP") Log.d(TAG, "testSend: Connect L2CAP") val bluetoothSocket = createSocket(dckSpsm, remoteDevice) val bluetoothSocket = createSocket(dckSpsm, remoteDevice) runBlocking { runBlocking { val waitFlow = flow { emit(waitConnection(dckSpsm, remoteDevice)) } val waitFlow = flow { emit(waitConnection(dckSpsm, remoteDevice)) } scope.launch { bluetoothSocket.connect() } val connectJob = scope.launch { bluetoothSocket.connect() Log.d(TAG, "testSend: Bluetooth socket connected") } connectionResponse = waitFlow.first() connectionResponse = waitFlow.first() // Wait for the connection to complete connectJob.join() } } assertThat(connectionResponse).isNotNull() assertThat(connectionResponse).isNotNull() assertThat(connectionResponse.hasChannel()).isTrue() assertThat(connectionResponse.hasChannel()).isTrue() Loading @@ -161,23 +165,23 @@ public class DckL2capClientTest() : Closeable { .l2cap() .l2cap() .receive(ReceiveRequest.newBuilder().setChannel(channel).build(), receiveObserver) .receive(ReceiveRequest.newBuilder().setChannel(channel).build(), receiveObserver) Log.d(TAG, "testReceive: Send data from Android to Bumble") Log.d(TAG, "testSend: Send data from Android to Bumble") val outputStream = bluetoothSocket.outputStream val outputStream = bluetoothSocket.outputStream outputStream.write(sampleData) outputStream.write(sampleData) outputStream.flush() outputStream.flush() Log.d(TAG, "testReceive: waitReceive data on Bumble") Log.d(TAG, "testSend: waitReceive data on Bumble") val receiveData = receiveObserver.iterator().next() val receiveData = receiveObserver.iterator().next() assertThat(receiveData.data.toByteArray()).isEqualTo(sampleData) assertThat(receiveData.data.toByteArray()).isEqualTo(sampleData) bluetoothSocket.close() bluetoothSocket.close() Log.d(TAG, "testReceive: waitDisconnection") Log.d(TAG, "testSend: waitDisconnection") val waitDisconnectionRequest = val waitDisconnectionRequest = WaitDisconnectionRequest.newBuilder().setChannel(channel).build() WaitDisconnectionRequest.newBuilder().setChannel(channel).build() val disconnectionResponse = val disconnectionResponse = mBumble.l2capBlocking().waitDisconnection(waitDisconnectionRequest) mBumble.l2capBlocking().waitDisconnection(waitDisconnectionRequest) assertThat(disconnectionResponse.hasSuccess()).isTrue() assertThat(disconnectionResponse.hasSuccess()).isTrue() Log.d(TAG, "testReceive: done") Log.d(TAG, "testSend: done") } } private fun readDckSpsm(gatt: BluetoothGatt) = runBlocking { private fun readDckSpsm(gatt: BluetoothGatt) = runBlocking { Loading @@ -202,7 +206,7 @@ public class DckL2capClientTest() : Closeable { private suspend fun waitConnection( private suspend fun waitConnection( psm: Int, psm: Int, remoteDevice: BluetoothDevice remoteDevice: BluetoothDevice, ): WaitConnectionResponse { ): WaitConnectionResponse { Log.d(TAG, "waitConnection") Log.d(TAG, "waitConnection") val connectionHandle = remoteDevice.getConnectionHandle(BluetoothDevice.TRANSPORT_LE) val connectionHandle = remoteDevice.getConnectionHandle(BluetoothDevice.TRANSPORT_LE) Loading @@ -228,7 +232,7 @@ public class DckL2capClientTest() : Closeable { private fun createSocket( private fun createSocket( psm: Int, psm: Int, remoteDevice: BluetoothDevice, remoteDevice: BluetoothDevice, isSecure: Boolean = false isSecure: Boolean = false, ): BluetoothSocket { ): BluetoothSocket { var socket: BluetoothSocket var socket: BluetoothSocket var expectedType: Int var expectedType: Int Loading @@ -250,7 +254,7 @@ public class DckL2capClientTest() : Closeable { override fun onConnectionStateChange( override fun onConnectionStateChange( gatt: BluetoothGatt, gatt: BluetoothGatt, status: Int, status: Int, newState: Int newState: Int, ) { ) { Log.i(TAG, "Connection state changed to $newState.") Log.i(TAG, "Connection state changed to $newState.") connectionStateFlow.value = newState connectionStateFlow.value = newState Loading @@ -269,7 +273,7 @@ public class DckL2capClientTest() : Closeable { gatt: BluetoothGatt, gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic, characteristic: BluetoothGattCharacteristic, value: ByteArray, value: ByteArray, status: Int status: Int, ) { ) { Log.i(TAG, "onCharacteristicRead, status: $status") Log.i(TAG, "onCharacteristicRead, status: $status") Loading Loading
framework/tests/bumble/src/android/bluetooth/DckL2capClientTest.kt +20 −16 Original line number Original line Diff line number Diff line Loading @@ -47,7 +47,6 @@ import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withTimeout import kotlinx.coroutines.withTimeout import org.junit.After import org.junit.After import org.junit.Before import org.junit.Before import org.junit.Ignore import org.junit.Rule import org.junit.Rule import org.junit.Test import org.junit.Test import org.junit.runner.RunWith import org.junit.runner.RunWith Loading Loading @@ -115,7 +114,7 @@ public class DckL2capClientTest() : Closeable { val remoteDevice = val remoteDevice = bluetoothAdapter.getRemoteLeDevice( bluetoothAdapter.getRemoteLeDevice( Utils.BUMBLE_RANDOM_ADDRESS, Utils.BUMBLE_RANDOM_ADDRESS, BluetoothDevice.ADDRESS_TYPE_RANDOM BluetoothDevice.ADDRESS_TYPE_RANDOM, ) ) val gatt = connectGatt(remoteDevice) val gatt = connectGatt(remoteDevice) readDckSpsm(gatt) readDckSpsm(gatt) Loading @@ -134,21 +133,26 @@ public class DckL2capClientTest() : Closeable { } } @Test @Test @Ignore("b/365168533") fun testSend() { fun testReceive() { Log.d(TAG, "testSend") Log.d(TAG, "testReceive") val remoteDevice = val remoteDevice = bluetoothAdapter.getRemoteLeDevice( bluetoothAdapter.getRemoteLeDevice( Utils.BUMBLE_RANDOM_ADDRESS, Utils.BUMBLE_RANDOM_ADDRESS, BluetoothDevice.ADDRESS_TYPE_RANDOM BluetoothDevice.ADDRESS_TYPE_RANDOM, ) ) Log.d(TAG, "testReceive: Connect L2CAP") Log.d(TAG, "testSend: Connect L2CAP") val bluetoothSocket = createSocket(dckSpsm, remoteDevice) val bluetoothSocket = createSocket(dckSpsm, remoteDevice) runBlocking { runBlocking { val waitFlow = flow { emit(waitConnection(dckSpsm, remoteDevice)) } val waitFlow = flow { emit(waitConnection(dckSpsm, remoteDevice)) } scope.launch { bluetoothSocket.connect() } val connectJob = scope.launch { bluetoothSocket.connect() Log.d(TAG, "testSend: Bluetooth socket connected") } connectionResponse = waitFlow.first() connectionResponse = waitFlow.first() // Wait for the connection to complete connectJob.join() } } assertThat(connectionResponse).isNotNull() assertThat(connectionResponse).isNotNull() assertThat(connectionResponse.hasChannel()).isTrue() assertThat(connectionResponse.hasChannel()).isTrue() Loading @@ -161,23 +165,23 @@ public class DckL2capClientTest() : Closeable { .l2cap() .l2cap() .receive(ReceiveRequest.newBuilder().setChannel(channel).build(), receiveObserver) .receive(ReceiveRequest.newBuilder().setChannel(channel).build(), receiveObserver) Log.d(TAG, "testReceive: Send data from Android to Bumble") Log.d(TAG, "testSend: Send data from Android to Bumble") val outputStream = bluetoothSocket.outputStream val outputStream = bluetoothSocket.outputStream outputStream.write(sampleData) outputStream.write(sampleData) outputStream.flush() outputStream.flush() Log.d(TAG, "testReceive: waitReceive data on Bumble") Log.d(TAG, "testSend: waitReceive data on Bumble") val receiveData = receiveObserver.iterator().next() val receiveData = receiveObserver.iterator().next() assertThat(receiveData.data.toByteArray()).isEqualTo(sampleData) assertThat(receiveData.data.toByteArray()).isEqualTo(sampleData) bluetoothSocket.close() bluetoothSocket.close() Log.d(TAG, "testReceive: waitDisconnection") Log.d(TAG, "testSend: waitDisconnection") val waitDisconnectionRequest = val waitDisconnectionRequest = WaitDisconnectionRequest.newBuilder().setChannel(channel).build() WaitDisconnectionRequest.newBuilder().setChannel(channel).build() val disconnectionResponse = val disconnectionResponse = mBumble.l2capBlocking().waitDisconnection(waitDisconnectionRequest) mBumble.l2capBlocking().waitDisconnection(waitDisconnectionRequest) assertThat(disconnectionResponse.hasSuccess()).isTrue() assertThat(disconnectionResponse.hasSuccess()).isTrue() Log.d(TAG, "testReceive: done") Log.d(TAG, "testSend: done") } } private fun readDckSpsm(gatt: BluetoothGatt) = runBlocking { private fun readDckSpsm(gatt: BluetoothGatt) = runBlocking { Loading @@ -202,7 +206,7 @@ public class DckL2capClientTest() : Closeable { private suspend fun waitConnection( private suspend fun waitConnection( psm: Int, psm: Int, remoteDevice: BluetoothDevice remoteDevice: BluetoothDevice, ): WaitConnectionResponse { ): WaitConnectionResponse { Log.d(TAG, "waitConnection") Log.d(TAG, "waitConnection") val connectionHandle = remoteDevice.getConnectionHandle(BluetoothDevice.TRANSPORT_LE) val connectionHandle = remoteDevice.getConnectionHandle(BluetoothDevice.TRANSPORT_LE) Loading @@ -228,7 +232,7 @@ public class DckL2capClientTest() : Closeable { private fun createSocket( private fun createSocket( psm: Int, psm: Int, remoteDevice: BluetoothDevice, remoteDevice: BluetoothDevice, isSecure: Boolean = false isSecure: Boolean = false, ): BluetoothSocket { ): BluetoothSocket { var socket: BluetoothSocket var socket: BluetoothSocket var expectedType: Int var expectedType: Int Loading @@ -250,7 +254,7 @@ public class DckL2capClientTest() : Closeable { override fun onConnectionStateChange( override fun onConnectionStateChange( gatt: BluetoothGatt, gatt: BluetoothGatt, status: Int, status: Int, newState: Int newState: Int, ) { ) { Log.i(TAG, "Connection state changed to $newState.") Log.i(TAG, "Connection state changed to $newState.") connectionStateFlow.value = newState connectionStateFlow.value = newState Loading @@ -269,7 +273,7 @@ public class DckL2capClientTest() : Closeable { gatt: BluetoothGatt, gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic, characteristic: BluetoothGattCharacteristic, value: ByteArray, value: ByteArray, status: Int status: Int, ) { ) { Log.i(TAG, "onCharacteristicRead, status: $status") Log.i(TAG, "onCharacteristicRead, status: $status") Loading