Package org.altbeacon.bluetooth
Class BluetoothCrashResolver
- java.lang.Object
-
- org.altbeacon.bluetooth.BluetoothCrashResolver
-
public class BluetoothCrashResolver extends Object
This class provides relief for Android Bug 67272. This bug in the Bluedroid stack causes crashes in Android's BluetoothService when scanning for BLE devices encounters a large number of unique devices. It is rare for most users but can be problematic for those with apps scanning for Bluetooth LE devices in the background (e.g. beacon-enabled apps), especially when these users are around Bluetooth LE devices that randomize their mac address like Gimbal beacons. This class can both recover from crashes and prevent crashes from happening in the first place. More details on the bug can be found at the following URLs: https://code.google.com/p/android/issues/detail?id=67272 https://github.com/RadiusNetworks/android-ibeacon-service/issues/16 Version 1.0 Created by dyoung on 3/24/14.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceBluetoothCrashResolver.UpdateNotifier
-
Constructor Summary
Constructors Constructor Description BluetoothCrashResolver(Context context)Constructor should be called only once per long-running process that does Bluetooth LE scanning.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidcrashDetected()voiddisableDebug()Deprecated.Since the default logger used by the android-beacon-library only logs warnings and above, this method is no logger used.voidenableDebug()Deprecated.Since the default logger used by the android-beacon-library only logs warnings and above, this method is no logger used.voidforceFlush()Used to force a recovery operationintgetDetectedCrashCount()longgetLastBluetoothCrashDetectionTime()intgetRecoveryAttemptCount()booleanisLastRecoverySucceeded()booleanisRecoveryInProgress()voidnotifyScannedDevice(BluetoothDevice device, BluetoothAdapter.LeScanCallback scanner)Call this method from your BluetoothAdapter.LeScanCallback method.voidsetUpdateNotifier(BluetoothCrashResolver.UpdateNotifier updateNotifier)voidstart()Starts looking for crashes of the Bluetooth LE system and taking proactive steps to stop crashes from happening.voidstop()Stops looking for crashes.
-
-
-
Constructor Detail
-
BluetoothCrashResolver
public BluetoothCrashResolver(Context context)
Constructor should be called only once per long-running process that does Bluetooth LE scanning. Must call start() to make it do anything.- Parameters:
context- the Activity or Service that is doing the Bluetooth scanning
-
-
Method Detail
-
start
public void start()
Starts looking for crashes of the Bluetooth LE system and taking proactive steps to stop crashes from happening. Proactive steps require calls to notifyScannedDevice(Device device) so that crashes can be predicted ahead of time.
-
stop
public void stop()
Stops looking for crashes. Does not need to be called in normal operations, but may be useful for testing.
-
enableDebug
@Deprecated public void enableDebug()
Deprecated.Since the default logger used by the android-beacon-library only logs warnings and above, this method is no logger used. To log debug messages use theLoggers.verboseLogger()Enable debug logging. By default no debug lines are logged.- See Also:
LogManager,Loggers
-
disableDebug
@Deprecated public void disableDebug()
Deprecated.Since the default logger used by the android-beacon-library only logs warnings and above, this method is no logger used. To log debug messages use theLoggers.verboseLogger()Disable debug logging.- See Also:
LogManager,Loggers
-
notifyScannedDevice
public void notifyScannedDevice(BluetoothDevice device, BluetoothAdapter.LeScanCallback scanner)
Call this method from your BluetoothAdapter.LeScanCallback method. Doing so is optional, but if you do, this class will be able to count the number of distinct Bluetooth devices scanned, and prevent crashes before they happen. This works very well if the app containing this class is the only one running bluetooth LE scans on the device, or it is constantly doing scans (e.g. is in the foreground for extended periods of time.) This will not work well if the application using this class is only scanning periodically (e.g. when in the background to save battery) and another application is also scanning on the same device, because this class will only get the counts from this application. Future augmentation of this class may improve this by somehow centralizing the list of unique scanned devices.- Parameters:
device-
-
crashDetected
public void crashDetected()
-
getLastBluetoothCrashDetectionTime
public long getLastBluetoothCrashDetectionTime()
-
getDetectedCrashCount
public int getDetectedCrashCount()
-
getRecoveryAttemptCount
public int getRecoveryAttemptCount()
-
isLastRecoverySucceeded
public boolean isLastRecoverySucceeded()
-
isRecoveryInProgress
public boolean isRecoveryInProgress()
-
setUpdateNotifier
public void setUpdateNotifier(BluetoothCrashResolver.UpdateNotifier updateNotifier)
-
forceFlush
public void forceFlush()
Used to force a recovery operation
-
-