Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scan occassionally returns no results until restarted #130

Open
albertmoravec opened this issue Nov 11, 2022 · 3 comments
Open

Scan occassionally returns no results until restarted #130

albertmoravec opened this issue Nov 11, 2022 · 3 comments

Comments

@albertmoravec
Copy link

albertmoravec commented Nov 11, 2022

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 albertmoravec changed the title Hardware batching occassionally returns no results Scan occassionally returns no results until restarted Nov 11, 2022
@albertmoravec
Copy link
Author

albertmoravec commented Nov 11, 2022

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?

@philips77
Copy link
Member

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?

@albertmoravec
Copy link
Author

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants