Loading framework/tests/bumble/src/android/bluetooth/RfcommTest.kt +39 −2 Original line number Diff line number Diff line Loading @@ -31,11 +31,16 @@ import io.grpc.stub.StreamObserver import java.time.Duration import java.util.UUID import java.util.concurrent.TimeUnit import kotlinx.coroutines.* import kotlinx.coroutines.channels.* import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.channels.trySendBlocking import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.callbackFlow import kotlinx.coroutines.flow.consumeAsFlow import kotlinx.coroutines.flow.first import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withTimeout import org.junit.After import org.junit.Before import org.junit.Rule Loading Loading @@ -315,6 +320,10 @@ class RfcommTest { @OptIn(ExperimentalCoroutinesApi::class) private suspend fun bondDevice(remoteDevice: BluetoothDevice) { // TODO: b/345842833 // HFP will try to connect, and bumble doesn't support HFP yet disableHfp() if (mAdapter.bondedDevices.contains(remoteDevice)) { Log.d(TAG, "bondDevice(): The device is already bonded") return Loading Loading @@ -358,6 +367,34 @@ class RfcommTest { } } private fun disableHfp() = runBlocking<Unit> { val proxy = headsetFlow().first() proxy.setConnectionPolicy(mBumbleDevice, BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) } private suspend fun headsetFlow(): Flow<BluetoothHeadset> { return callbackFlow { val listener = object : BluetoothProfile.ServiceListener { lateinit var mBluetoothHeadset: BluetoothHeadset override fun onServiceConnected(profile: Int, proxy: BluetoothProfile) { mBluetoothHeadset = proxy as BluetoothHeadset trySend(mBluetoothHeadset) } override fun onServiceDisconnected(profile: Int) {} } mAdapter.getProfileProxy(mContext, listener, BluetoothProfile.HEADSET) awaitClose { mAdapter.closeProfileProxy(BluetoothProfile.HEADSET, listener.mBluetoothHeadset) } } } companion object { private val TAG = RfcommTest::class.java.getSimpleName() private val GRPC_TIMEOUT = Duration.ofSeconds(10) Loading Loading
framework/tests/bumble/src/android/bluetooth/RfcommTest.kt +39 −2 Original line number Diff line number Diff line Loading @@ -31,11 +31,16 @@ import io.grpc.stub.StreamObserver import java.time.Duration import java.util.UUID import java.util.concurrent.TimeUnit import kotlinx.coroutines.* import kotlinx.coroutines.channels.* import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.channels.trySendBlocking import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.callbackFlow import kotlinx.coroutines.flow.consumeAsFlow import kotlinx.coroutines.flow.first import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withTimeout import org.junit.After import org.junit.Before import org.junit.Rule Loading Loading @@ -315,6 +320,10 @@ class RfcommTest { @OptIn(ExperimentalCoroutinesApi::class) private suspend fun bondDevice(remoteDevice: BluetoothDevice) { // TODO: b/345842833 // HFP will try to connect, and bumble doesn't support HFP yet disableHfp() if (mAdapter.bondedDevices.contains(remoteDevice)) { Log.d(TAG, "bondDevice(): The device is already bonded") return Loading Loading @@ -358,6 +367,34 @@ class RfcommTest { } } private fun disableHfp() = runBlocking<Unit> { val proxy = headsetFlow().first() proxy.setConnectionPolicy(mBumbleDevice, BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) } private suspend fun headsetFlow(): Flow<BluetoothHeadset> { return callbackFlow { val listener = object : BluetoothProfile.ServiceListener { lateinit var mBluetoothHeadset: BluetoothHeadset override fun onServiceConnected(profile: Int, proxy: BluetoothProfile) { mBluetoothHeadset = proxy as BluetoothHeadset trySend(mBluetoothHeadset) } override fun onServiceDisconnected(profile: Int) {} } mAdapter.getProfileProxy(mContext, listener, BluetoothProfile.HEADSET) awaitClose { mAdapter.closeProfileProxy(BluetoothProfile.HEADSET, listener.mBluetoothHeadset) } } } companion object { private val TAG = RfcommTest::class.java.getSimpleName() private val GRPC_TIMEOUT = Duration.ofSeconds(10) Loading