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

Commit 2827a3f9 authored by Pomai Ahlo's avatar Pomai Ahlo Committed by Gerrit Code Review
Browse files

Revert "RfcommTest: Disable HFP connections"

This reverts commit 08378c42.

Reason for revert: b/344067713

Change-Id: Ie7a2445215f70a04cadbd68ae8e011c5e85622de
parent 08378c42
Loading
Loading
Loading
Loading
+2 −39
Original line number Diff line number Diff line
@@ -31,16 +31,11 @@ import io.grpc.stub.StreamObserver
import java.time.Duration
import java.util.UUID
import java.util.concurrent.TimeUnit
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.channels.trySendBlocking
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.*
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
@@ -320,10 +315,6 @@ 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
@@ -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 {
        private val TAG = RfcommTest::class.java.getSimpleName()
        private val GRPC_TIMEOUT = Duration.ofSeconds(10)