Skip to content

Commit

Permalink
Merge pull request #558 from AltBeacon/fix-bugs-with-nonzero-foregrou…
Browse files Browse the repository at this point in the history
…nd-between-scan-period

Fix bugs with  nonzero foreground betweenScanPeriod
  • Loading branch information
davidgyoung authored Aug 16, 2017
2 parents 04bb521 + 4bf2d9f commit b34a2ff
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
### Development

Enhancements:

Bug Fixes:

- Fix "Scanning too frequently" error with non-zero betweenScanPeriod
and scanPeriod+betweenScanPeriod < 6000, and full-power scanning
staying on for foreground scans with a non-zero betweenScanPeriod
(#555, David G. Young)


### 2.12 / 2017-08-07

Enhancements:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,20 @@ protected boolean deferScanIfNeeded() {
if (secsSinceLastDetection > BACKGROUND_L_SCAN_DETECTION_PERIOD_MILLIS) {
mBackgroundLScanStartTime = SystemClock.elapsedRealtime();
mBackgroundLScanFirstDetectionTime = 0l;
LogManager.d(TAG, "This is Android L. Doing a filtered scan for the background.");

LogManager.d(TAG, "This is Android L. Preparing to do a filtered scan for the background.");
// On Android L, between scan cycles do a scan with a filter looking for any beacon
// if we see one of those beacons, we need to deliver the results
startScan();
// Only scan between cycles if the between can cycle time > 6 seconds. A shorter low
// power scan is unlikely to be useful, and might trigger a "scanning too frequently"
// error on Android N.
if (mBetweenScanPeriod > 6000l) {
startScan();
}
else {
LogManager.d(TAG, "Suppressing scan between cycles because the between scan cycle is too short.");
}


} else {
// TODO: Consider starting a scan with delivery based on the filters *NOT* being seen
// This API is now available in Android M
Expand Down Expand Up @@ -157,19 +166,21 @@ protected void startScan() {
return;
}
List<ScanFilter> filters = new ArrayList<ScanFilter>();
ScanSettings settings;
ScanSettings settings = null;

if (mBackgroundFlag && !mMainScanCycleActive) {
if (!mMainScanCycleActive) {
LogManager.d(TAG, "starting filtered scan in SCAN_MODE_LOW_POWER");
settings = (new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_POWER)).build();
filters = new ScanFilterUtils().createScanFiltersForBeaconParsers(
mBeaconManager.getBeaconParsers());
mBeaconManager.getBeaconParsers());
} else {
LogManager.d(TAG, "starting non-filtered scan in SCAN_MODE_LOW_LATENCY");
settings = (new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)).build();
}

postStartLeScan(filters, settings);
if (settings != null) {
postStartLeScan(filters, settings);
}
}

@Override
Expand Down

0 comments on commit b34a2ff

Please sign in to comment.