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

Commit 70988556 authored by William Escande's avatar William Escande
Browse files

Cts Tests: Fix enable scan settings race condition

Bug: 345922132
Fix: 345922132
Test: atest CtsBluetoothTestCases:SystemBluetoothTest#bleOnlyMode
Flag: TEST_ONLY
Change-Id: Ic65904c4d6167ec66432a606411524ead3c33684
parent e925f1b0
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -75,6 +75,16 @@ object BlockingBluetoothAdapter {
        if (toggleScanSetting) {
            Log.d(TAG, "Allowing the scan to be perform while Bluetooth is OFF")
            Settings.Global.putInt(context.contentResolver, BLE_SCAN_ALWAYS_AVAILABLE, 1)
            for (i in 1..5) {
                if (adapter.isBleScanAlwaysAvailable()) {
                    break
                }
                Log.d(TAG, "Ble scan not yet available… Sleeping 20 ms $i/5")
                Thread.sleep(20)
            }
            if (!adapter.isBleScanAlwaysAvailable()) {
                throw IllegalStateException("Could not enable BLE scan")
            }
        }
        Log.d(TAG, "Call to enableBLE")
        if (!withPermissions(BLUETOOTH_CONNECT).use { adapter.enableBLE() }) {