Loading framework/tests/bumble/src/android/bluetooth/RfcommTest.kt +2 −39 Original line number Original line Diff line number Diff line Loading @@ -31,16 +31,11 @@ import io.grpc.stub.StreamObserver import java.time.Duration import java.time.Duration import java.util.UUID import java.util.UUID import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.* import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.channels.* import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.channels.trySendBlocking import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.callbackFlow import kotlinx.coroutines.flow.consumeAsFlow import kotlinx.coroutines.flow.consumeAsFlow import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.first import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withTimeout import org.junit.After import org.junit.After import org.junit.Before import org.junit.Before import org.junit.Rule import org.junit.Rule Loading Loading @@ -320,10 +315,6 @@ class RfcommTest { @OptIn(ExperimentalCoroutinesApi::class) @OptIn(ExperimentalCoroutinesApi::class) private suspend fun bondDevice(remoteDevice: BluetoothDevice) { 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)) { if (mAdapter.bondedDevices.contains(remoteDevice)) { Log.d(TAG, "bondDevice(): The device is already bonded") Log.d(TAG, "bondDevice(): The device is already bonded") return return Loading Loading @@ -367,34 +358,6 @@ 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 { companion object { private val TAG = RfcommTest::class.java.getSimpleName() private val TAG = RfcommTest::class.java.getSimpleName() private val GRPC_TIMEOUT = Duration.ofSeconds(10) private val GRPC_TIMEOUT = Duration.ofSeconds(10) Loading Loading
framework/tests/bumble/src/android/bluetooth/RfcommTest.kt +2 −39 Original line number Original line Diff line number Diff line Loading @@ -31,16 +31,11 @@ import io.grpc.stub.StreamObserver import java.time.Duration import java.time.Duration import java.util.UUID import java.util.UUID import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.* import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.channels.* import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.channels.trySendBlocking import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.callbackFlow import kotlinx.coroutines.flow.consumeAsFlow import kotlinx.coroutines.flow.consumeAsFlow import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.first import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withTimeout import org.junit.After import org.junit.After import org.junit.Before import org.junit.Before import org.junit.Rule import org.junit.Rule Loading Loading @@ -320,10 +315,6 @@ class RfcommTest { @OptIn(ExperimentalCoroutinesApi::class) @OptIn(ExperimentalCoroutinesApi::class) private suspend fun bondDevice(remoteDevice: BluetoothDevice) { 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)) { if (mAdapter.bondedDevices.contains(remoteDevice)) { Log.d(TAG, "bondDevice(): The device is already bonded") Log.d(TAG, "bondDevice(): The device is already bonded") return return Loading Loading @@ -367,34 +358,6 @@ 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 { companion object { private val TAG = RfcommTest::class.java.getSimpleName() private val TAG = RfcommTest::class.java.getSimpleName() private val GRPC_TIMEOUT = Duration.ofSeconds(10) private val GRPC_TIMEOUT = Duration.ofSeconds(10) Loading