2

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?

James Fu
  • 444
  • 1
  • 8
  • 21
  • I find that if I turn off the wifi entirely, and it seems to work fine on bluetooth scanning. Anyone experience with the BLE scanning and WiFi in the same time before? How to avoid from stopping the BLE scanning without any notification? – James Fu Nov 30 '17 at 09:45

1 Answers1

2

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:

Source code

A workaround for this is to not keep scans going that long. You can simply stop them and restart them periodically.

EDITED:

Check on this link

Ankit Patidar
  • 2,731
  • 1
  • 14
  • 22
  • Thanks for your reply. I know this limitation in Android 7.0. But I find this issue in android 6.0 device. And it stops in 5 minutes or 10 more minutes so that I try to figure out the reason from btsnoop_hci.log. – James Fu Nov 28 '17 at 03:20
  • I thought it would be the solution before, so that I also implement the same way (stop and restart every 1 minute. It still stops working after several minutes (ps. no broadcast message in the btsnoop_hci.log). This is the weirdest thing. – James Fu Nov 29 '17 at 02:17
  • @JamesFu i also have same problem it keep stop in 6.0 but work find in other latest's versions do you find any soutions?? – Jayman Jani May 22 '20 at 13:22