protect against npe with ScanHelper when ScanJob thread is slow to start
@@ -51,6 +51,7 @@ public class ScanJob extends JobService {
@Nullable
private ScanState mScanState = null;
private Handler mStopHandler = new Handler();
+ @Nullable
private ScanHelper mScanHelper;
private boolean mInitialized = false;
@@ -78,9 +79,11 @@ public class ScanJob extends JobService {
for (ScanResult result : queuedScanResults) {
ScanRecord scanRecord = result.getScanRecord();
if (scanRecord != null) {
+ if (mScanHelper != null) {
mScanHelper.processScanResult(result.getDevice(), result.getRssi(), scanRecord.getBytes());
}
}
+ }
LogManager.d(TAG, "Done processing queued scan resuilts");
boolean startedScan;
@@ -156,8 +159,10 @@ public class ScanJob extends JobService {
}
else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ if (mScanHelper != null) {
mScanHelper.startAndroidOBackgroundScan(mScanState.getBeaconParsers());
}
+ }
else {
LogManager.d(TAG, "This is not Android O. No scanning between cycles when using ScanJob");
}
@@ -177,13 +182,15 @@ public class ScanJob extends JobService {
mStopHandler.removeCallbacksAndMessages(null);
stopScanning();
startPassiveScanIfNeeded();
+ if (mScanHelper != null) {
mScanHelper.terminateThreads();
-
+ }
return false;
}
private void stopScanning() {
mInitialized = false;
+ if (mScanHelper != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
mScanHelper.stopAndroidOBackgroundScan();
}
@@ -191,6 +198,7 @@ public class ScanJob extends JobService {
mScanHelper.getCycledScanner().stop();
mScanHelper.getCycledScanner().destroy();
}
+ }
LogManager.d(TAG, "Scanning stopped");
}
@@ -219,7 +227,7 @@ public class ScanJob extends JobService {
// Returns true of scanning actually was started, false if it did not need to be
private boolean restartScanning() {
- if (mScanState != null) {
+ if (mScanState != null && mScanHelper != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
mScanHelper.stopAndroidOBackgroundScan();
}
