Skip to content

Commit

Permalink
Attempt to fix crash when ScanJob starts scanning right after it stop…
Browse files Browse the repository at this point in the history
…s it in a thread race condition.
  • Loading branch information
davidgyoung committed Jun 25, 2019
1 parent bebca7a commit 2bc0de0
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/src/main/java/org/altbeacon/beacon/service/ScanJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class ScanJob extends JobService {
@Nullable
private ScanHelper mScanHelper;
private boolean mInitialized = false;
private boolean mStopCalled = false;

@Override
public boolean onStartJob(final JobParameters jobParameters) {
Expand Down Expand Up @@ -87,6 +88,12 @@ public void run() {
}
LogManager.d(TAG, "Done processing queued scan resuilts");

if (mStopCalled) {
LogManager.d(TAG, "Quitting scan job before we even start. Somebody told us to stop.");
ScanJob.this.jobFinished(jobParameters , false);
return;
}

boolean startedScan;
if (mInitialized) {
LogManager.d(TAG, "Scanning already started. Resetting for current parameters");
Expand Down Expand Up @@ -176,6 +183,7 @@ private void startPassiveScanIfNeeded() {

@Override
public boolean onStopJob(JobParameters params) {
mStopCalled = true;
if (params.getJobId() == getPeriodicScanJobId(this)) {
LogManager.i(TAG, "onStopJob called for periodic scan " + this);
}
Expand Down

0 comments on commit 2bc0de0

Please sign in to comment.