Android-Scanner-Compat-Library icon indicating copy to clipboard operation
Android-Scanner-Compat-Library copied to clipboard

Scan occassionally returns no results until restarted

Open albertmoravec opened this issue 3 years ago • 3 comments

I am currently trying to implement low-power background scanning using hardware batching, but on my device I sometimes get 0 ScanResults back after starting particular scan. Restarting the scan with identical settings fixes the issue and I get results normally.

Here's how I configure and start the scan:

val scanSettings = ScanSettings.Builder()
  .setUseHardwareFilteringIfSupported(true)
  .setUseHardwareBatchingIfSupported(true)
  .setScanMode(ScanSettings.SCAN_MODE_BALANCED)
  .setReportDelay(10 * 1000)
  .build()

val macFilter = ScanFilter.Builder()
  .setManufacturerData(
    0xFFFF,
    ubyteArrayOf(49u, 53u, 57u, 54u).toByteArray(),
    ubyteArrayOf(0xFFu, 0xFFu, 0xFFu, 0xFFu).toByteArray()
  )
  .build()

scanner.startScan(mutableListOf(macFilter), scanSettings, callback)

I am also able to reproduce the issue without using any scan filter, so it is not an issue in filter configuration. The issue is present with both SCAN_MODE_BALANCED and SCAN_MODE_LOW_POWER (seems to be an issue even with SCAN_MODE_LOW_LATENCY, but I wasn't able to reproduce it at least twice).

Full example can be seen here.

Device used: Model: Xiaomi Mi 9T Pro Android: 11

I personally think this issue is going to be hardware-related, but I'm looking for any possible clues.

albertmoravec avatar Nov 11 '22 12:11 albertmoravec

I managed to start a scan which returns no ScanResults even with report delay 0. EDIT: After a few minutes of scanning I managed to receive 1 ScanResult out of 5 I should've been able to receive, but I'm getting no further advertisements.

I got standard onScannerRegistered() log message, so the scan itself should've started correctly: D/BluetoothLeScanner( 4390): onScannerRegistered() - status=0 scannerId=27 mScannerId=0

Any ideas on what I should try to be able to scan reliably?

albertmoravec avatar Nov 11 '22 12:11 albertmoravec

Android has a limitation of only few scans per 30 second. If you start and stop scanning number of times in short period of time it will not return and scan results until you wait a bit. Can it be related?

philips77 avatar Nov 19 '22 06:11 philips77

Cannot rule it out entirely, but it's very unlikely, as the scanner got registered successfully (the onScannerRegistered() log message would indicate status=6 and scannerId=-1 otherwise AFAIK).

albertmoravec avatar Nov 19 '22 22:11 albertmoravec