From 2bc0de0165b3cf8c990e36ee43bbdcd39d793814 Mon Sep 17 00:00:00 2001 From: "David G. Young" Date: Mon, 24 Jun 2019 22:09:33 -0400 Subject: [PATCH] Attempt to fix crash when ScanJob starts scanning right after it stops it in a thread race condition. --- .../main/java/org/altbeacon/beacon/service/ScanJob.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/src/main/java/org/altbeacon/beacon/service/ScanJob.java b/lib/src/main/java/org/altbeacon/beacon/service/ScanJob.java index 9e30960f6..e2f6a3e2d 100644 --- a/lib/src/main/java/org/altbeacon/beacon/service/ScanJob.java +++ b/lib/src/main/java/org/altbeacon/beacon/service/ScanJob.java @@ -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) { @@ -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"); @@ -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); }