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

Commit 123463fc authored by Charlie Boutier's avatar Charlie Boutier
Browse files

BumbleBluetoothTests: Thread accept pairing logic

Bug: 355328584
Test: atest BumbleBluetoothTest
Change-Id: I943fad280c175eb85be2a42f83eaec1e2b2e9519
parent 46c88ce2
Loading
Loading
Loading
Loading
+16 −6
Original line number Diff line number Diff line
@@ -72,13 +72,17 @@ public class Host(context: Context) : Closeable {
        runBlocking(scope.coroutineContext) {
            withTimeout(TIMEOUT) {
                Truth.assertThat(remoteDevice.createBond()).isTrue()
                val pairingRequestJob = launch {
                    Log.d(TAG, "Waiting for ACTION_PAIRING_REQUEST")
                    flow
                    .filter { it.getAction() == BluetoothDevice.ACTION_PAIRING_REQUEST }
                        .filter { it.action == BluetoothDevice.ACTION_PAIRING_REQUEST }
                        .filter { it.getBluetoothDeviceExtra() == remoteDevice }
                        .first()

                    remoteDevice.setPairingConfirmation(true)
                }

                Log.d(TAG, "Waiting for ACTION_BOND_STATE_CHANGED")
                flow
                    .filter { it.action == BluetoothDevice.ACTION_BOND_STATE_CHANGED }
                    .filter { it.getBluetoothDeviceExtra() == remoteDevice }
@@ -87,6 +91,11 @@ public class Host(context: Context) : Closeable {
                            BluetoothDevice.BOND_BONDED
                    }
                    .first()

                if (pairingRequestJob.isActive) {
                    pairingRequestJob.cancel()
                }

                Log.d(TAG, "createBondAndVerify: bonded")
            }
        }
@@ -118,6 +127,7 @@ public class Host(context: Context) : Closeable {
            val broadcastReceiver: BroadcastReceiver =
                object : BroadcastReceiver() {
                    override fun onReceive(context: Context, intent: Intent) {
                        Log.d(TAG, "intentFlow: onReceive: ${intent.action}")
                        scope.launch { trySendBlocking(intent) }
                    }
                }