Class CycledLeScanner
- java.lang.Object
-
- org.altbeacon.beacon.service.scanner.CycledLeScanner
-
- Direct Known Subclasses:
CycledLeScannerForJellyBeanMr2,CycledLeScannerForLollipop
public abstract class CycledLeScanner extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static longANDROID_N_MAX_SCAN_DURATION_MILLISprotected booleanmBackgroundFlagprotected longmBetweenScanPeriodprotected BluetoothCrashResolvermBluetoothCrashResolverprotected ContextmContextprotected CycledLeScanCallbackmCycledLeScanCallbackprotected HandlermHandlerMain thread handle for scheduling scan cycle tasks.protected longmNextScanCycleStartTimeprotected booleanmRestartNeededprotected HandlermScanHandlerHandler to background thread for interacting with the low-level Android BLE scanner.protected booleanmScanningPaused
-
Constructor Summary
Constructors Modifier Constructor Description protectedCycledLeScanner(Context context, long scanPeriod, long betweenScanPeriod, boolean backgroundFlag, CycledLeScanCallback cycledLeScanCallback, BluetoothCrashResolver crashResolver)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidcancelAlarmOnUserSwitch()protected voidcancelWakeUpAlarm()protected voidcleanupCancelAlarmOnUserSwitch()static CycledLeScannercreateScanner(Context context, long scanPeriod, long betweenScanPeriod, boolean backgroundFlag, CycledLeScanCallback cycledLeScanCallback, BluetoothCrashResolver crashResolver)protected abstract booleandeferScanIfNeeded()voiddestroy()protected abstract voidfinishScan()protected BluetoothAdaptergetBluetoothAdapter()booleangetDistinctPacketsDetectedPerScan()protected PendingIntentgetWakeUpOperation()protected voidscanLeDevice(Boolean enable)protected voidscheduleScanCycleStop()voidsetDistinctPacketsDetectedPerScan(boolean detected)voidsetLongScanForcingEnabled(boolean enabled)Enables the scanner to go to extra lengths to keep scans going for longer than would otherwise be allowed.voidsetScanPeriods(long scanPeriod, long betweenScanPeriod, boolean backgroundFlag)Tells the cycler the scan rate and whether it is in operating in background mode.protected voidsetWakeUpAlarm()voidstart()protected abstract voidstartScan()voidstop()protected abstract voidstopScan()
-
-
-
Field Detail
-
ANDROID_N_MAX_SCAN_DURATION_MILLIS
public static final long ANDROID_N_MAX_SCAN_DURATION_MILLIS
- See Also:
- Constant Field Values
-
mNextScanCycleStartTime
protected long mNextScanCycleStartTime
-
mScanningPaused
protected boolean mScanningPaused
-
mContext
protected final Context mContext
-
mBetweenScanPeriod
protected long mBetweenScanPeriod
-
mHandler
@NonNull protected final Handler mHandler
Main thread handle for scheduling scan cycle tasks.Use this to schedule deferred tasks such as the following:
-
mScanHandler
@NonNull protected final Handler mScanHandler
Handler to background thread for interacting with the low-level Android BLE scanner.Use this to queue any potentially long running BLE scanner actions such as starts and stops.
-
mBluetoothCrashResolver
protected final BluetoothCrashResolver mBluetoothCrashResolver
-
mCycledLeScanCallback
protected final CycledLeScanCallback mCycledLeScanCallback
-
mBackgroundFlag
protected boolean mBackgroundFlag
-
mRestartNeeded
protected boolean mRestartNeeded
-
-
Constructor Detail
-
CycledLeScanner
protected CycledLeScanner(Context context, long scanPeriod, long betweenScanPeriod, boolean backgroundFlag, CycledLeScanCallback cycledLeScanCallback, BluetoothCrashResolver crashResolver)
-
-
Method Detail
-
createScanner
public static CycledLeScanner createScanner(Context context, long scanPeriod, long betweenScanPeriod, boolean backgroundFlag, CycledLeScanCallback cycledLeScanCallback, BluetoothCrashResolver crashResolver)
-
setLongScanForcingEnabled
public void setLongScanForcingEnabled(boolean enabled)
Enables the scanner to go to extra lengths to keep scans going for longer than would otherwise be allowed. Useful only for Android N and higher.- Parameters:
enabled-
-
setScanPeriods
@MainThread public void setScanPeriods(long scanPeriod, long betweenScanPeriod, boolean backgroundFlag)Tells the cycler the scan rate and whether it is in operating in background mode. Background mode flag is used only with the Android 5.0 scanning implementations to switch between LOW_POWER_MODE vs. LOW_LATENCY_MODE- Parameters:
backgroundFlag-
-
start
@MainThread public void start()
-
stop
@MainThread public void stop()
-
getDistinctPacketsDetectedPerScan
@AnyThread public boolean getDistinctPacketsDetectedPerScan()
-
setDistinctPacketsDetectedPerScan
@AnyThread public void setDistinctPacketsDetectedPerScan(boolean detected)
-
destroy
@MainThread public void destroy()
-
stopScan
protected abstract void stopScan()
-
deferScanIfNeeded
protected abstract boolean deferScanIfNeeded()
-
startScan
protected abstract void startScan()
-
scanLeDevice
@MainThread protected void scanLeDevice(Boolean enable)
-
scheduleScanCycleStop
@MainThread protected void scheduleScanCycleStop()
-
finishScan
protected abstract void finishScan()
-
getBluetoothAdapter
protected BluetoothAdapter getBluetoothAdapter()
-
setWakeUpAlarm
protected void setWakeUpAlarm()
-
cancelAlarmOnUserSwitch
protected void cancelAlarmOnUserSwitch()
-
cleanupCancelAlarmOnUserSwitch
protected void cleanupCancelAlarmOnUserSwitch()
-
getWakeUpOperation
protected PendingIntent getWakeUpOperation()
-
cancelWakeUpAlarm
protected void cancelWakeUpAlarm()
-
-