Skip to content

Commit

Permalink
Merge pull request #885 from AltBeacon/fix-unbound-thread-leak
Browse files Browse the repository at this point in the history
Fix thread leak caused by scheduling ScanJob when no consumers bound
  • Loading branch information
davidgyoung authored May 29, 2019
2 parents 139545e + 1807398 commit 7d346db
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### Development

Bug Fixes:
- Fix thread leak caused by scheduling ScanJob when no consumers bound. (#885, David G. Young)
- Protect against a NPE when changing ranged regions. (#770, David G. Young)
- Fix intermittent failed ranging/monitoring callbacks in race conditions. (#842, David G. Young)
- Prevent duplicate callbacks on Android 8+ with a foreground service by stopping ScanJob. (#847, Stephen Ruda)
Expand Down
8 changes: 5 additions & 3 deletions lib/src/main/java/org/altbeacon/beacon/BeaconManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ public void setBackgroundMode(boolean backgroundMode) {
*
* @param enabled
*/

public void setEnableScheduledScanJobs(boolean enabled) {
if (isAnyConsumerBound()) {
LogManager.e(TAG, "ScanJob may not be configured because a consumer is" +
Expand Down Expand Up @@ -998,15 +999,16 @@ public void updateScanPeriods() throws RemoteException {

@TargetApi(18)
private void applyChangesToServices(int type, Region region) throws RemoteException {
if (!isAnyConsumerBound()) {
LogManager.w(TAG, "The BeaconManager is not bound to the service. Call beaconManager.bind(BeaconConsumer consumer) and wait for a callback to onBeaconServiceConnect()");
return;
}
if (mScheduledScanJobsEnabled) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ScanJobScheduler.getInstance().applySettingsToScheduledJob(mContext, this);
}
return;
}
if (serviceMessenger == null) {
throw new RemoteException("The BeaconManager is not bound to the service. Call beaconManager.bind(BeaconConsumer consumer) and wait for a callback to onBeaconServiceConnect()");
}
Message msg = Message.obtain(null, type, 0, 0);
if (type == BeaconService.MSG_SET_SCAN_PERIODS) {
msg.setData(new StartRMData(this.getScanPeriod(), this.getBetweenScanPeriod(), this.mBackgroundMode).toBundle());
Expand Down

0 comments on commit 7d346db

Please sign in to comment.