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

Commit dacfdf14 authored by Abel Lucas's avatar Abel Lucas Committed by Automerger Merge Worker
Browse files

Merge "PandoraServer: remove scannning from `connectLe`" into main am:...

Merge "PandoraServer: remove scannning from `connectLe`" into main am: b9c6ad99 am: 1a13c350 am: f2800a1b

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2758425



Change-Id: I9fb4e386dc16719aa793a6a984c4d32bf8349e16
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents edc943d5 f2800a1b
Loading
Loading
Loading
Loading
+1 −34
Original line number Diff line number Diff line
@@ -437,7 +437,7 @@ class Host(
                        throw IllegalArgumentException("Request address field must be set")
                }
            Log.i(TAG, "connectLE: $address")
            val bluetoothDevice = scanLeDevice(address.decodeAsMacAddressToString(), type)!!
            val bluetoothDevice = bluetoothAdapter.getRemoteLeDevice(address.decodeAsMacAddressToString(), type)
            initiatedConnection.add(bluetoothDevice)
            GattInstance(bluetoothDevice, TRANSPORT_LE, context)
                .waitForState(BluetoothProfile.STATE_CONNECTED)
@@ -447,39 +447,6 @@ class Host(
        }
    }

    private fun scanLeDevice(address: String, addressType: Int): BluetoothDevice? {
        Log.d(TAG, "scanLeDevice")
        var bluetoothDevice: BluetoothDevice? = null
        runBlocking {
            val flow = callbackFlow {
                val leScanCallback =
                    object : ScanCallback() {
                        override fun onScanFailed(errorCode: Int) {
                            super.onScanFailed(errorCode)
                            Log.d(TAG, "onScanFailed: errorCode: $errorCode")
                            trySendBlocking(null)
                        }
                        override fun onScanResult(callbackType: Int, result: ScanResult) {
                            super.onScanResult(callbackType, result)
                            val deviceAddress = result.device.address
                            val deviceAddressType = result.device.addressType
                            if (deviceAddress == address && deviceAddressType == addressType) {
                                Log.d(TAG, "found device address: $deviceAddress")
                                trySendBlocking(result.device)
                            }
                        }
                    }
                val bluetoothLeScanner = bluetoothAdapter.bluetoothLeScanner
                val leScanFilters: List<ScanFilter> = listOf()
                val leScanSettings = ScanSettings.Builder().setLegacy(false).build()
                bluetoothLeScanner?.startScan(leScanFilters, leScanSettings, leScanCallback) ?: run { trySendBlocking(null) }
                awaitClose { bluetoothLeScanner?.stopScan(leScanCallback) }
            }
            bluetoothDevice = flow.first()
        }
        return bluetoothDevice
    }

    override fun advertise(
        request: AdvertiseRequest,
        responseObserver: StreamObserver<AdvertiseResponse>