Reputation: 452
For the specific application, I need to keep the android bluetooth scanning the LE devices but I find it will stops itself without any logging in some devices. My sample code is as follows:
mBluetoothLeScanner.startScan(null, mScanSettings, leScanCallback);
I'm sure I never call
mBluetoothLeScanner.stopScan(leScanCallback)
So that I try to look into the "btsnoop_hci.log". I find the controller didn't send the broadcast message to host in a period of time, perhaps 5 minutes or 10 more minutes. In this example, it stops at 864.833537 seconds. Did anyone help me to solve this issue?
Upvotes: 2
Views: 3342
Reputation: 2781
Android 7.0 introduced a BLE scan timeout, where any scan running for 30 minutes or more is effectively stopped automatically and only resumed "opportunistically" which essentially means that if another process does a scan, it can get the results as well.
You can see this by setting up code to start a Bluetooth LE scan and leave it running indefinitely. After exactly 30 minutes, the scan will stop, and you will see entries like this in LogCat:
06-11 19:00:22.848 5123 5147 D BtGatt.ScanManager: clientIf set to scan opportunisticly: 6
06-11 19:00:22.848 5123 5147 D BtGatt.ScanManager: configureRegularScanParams() - queue=1
06-11 19:00:22.848 5123 5147 D BtGatt.ScanManager: configureRegularScanParams() - ScanSetting Scan mode=-1 mLastConfiguredScanSetting=2
06-11 19:00:22.848 5123 5147 D BtGatt.ScanManager: configureRegularScanParams() - queue emtpy, scan stopped 06-11 19:00:22.849 5123 5147 D BtGatt.ScanManager: stop scan
You can see the code that does this in the AOSP source here:
A workaround for this is to not keep scans going that long. You can simply stop them and restart them periodically.
EDITED:
Upvotes: 3