Skip to content

Commit

Permalink
Merge pull request #578 from AltBeacon/fix-cme-on-start-passive-scan
Browse files Browse the repository at this point in the history
Fix ConcurrentModificationException starting passive scan on Android 8
  • Loading branch information
davidgyoung authored Sep 21, 2017
2 parents 72e21bc + 3614439 commit 41e6f06
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
### Development

Bug Fixes:
- Fix ConcurrentModificationException crashing app on Android 8 when monitored regions are
changed at the same time the app shifts from active scanning to passive scanning.
(#578, David G. Young)
- Fix ConcurrentModifictionExceptions starting ScanJobs. (#584, #588, David G. Young)
- Fix NullPointerException when BluetoothLeScanner cannot be obtained.
(#583, David G. Young)

### 2.12.2 / 2017-08-31

[Full Changelog](https://github.com/AltBeacon/android-beacon-library/compare/2.12.1...2.12.2)
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/altbeacon/beacon/service/ScanJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.altbeacon.beacon.distance.ModelSpecificDistanceCalculator;
import org.altbeacon.beacon.logging.LogManager;
import org.altbeacon.beacon.utils.ProcessUtils;

import java.util.ArrayList;
import java.util.List;


Expand Down Expand Up @@ -103,7 +105,9 @@ public void run() {
private void startPassiveScanIfNeeded() {
LogManager.d(TAG, "Checking to see if we need to start a passive scan");
boolean insideAnyRegion = false;
for (Region region : mScanState.getMonitoringStatus().regions()) {
// Clone the collection before iterating to prevent ConcurrentModificationException per #577
List<Region> regions = new ArrayList<>(mScanState.getMonitoringStatus().regions());
for (Region region : regions) {
RegionMonitoringState state = mScanState.getMonitoringStatus().stateOf(region);
if (state != null && state.getInside()) {
insideAnyRegion = true;
Expand Down

0 comments on commit 41e6f06

Please sign in to comment.