-
public class BluetoothCrashResolver
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 public interface
BluetoothCrashResolver.UpdateNotifier
-
Field Summary
Fields Modifier and Type Field Description private long
lastBluetoothCrashDetectionTime
private int
detectedCrashCount
private int
recoveryAttemptCount
private BluetoothCrashResolver.UpdateNotifier
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
Modifier and Type Method Description long
getLastBluetoothCrashDetectionTime()
int
getDetectedCrashCount()
int
getRecoveryAttemptCount()
void
setUpdateNotifier(BluetoothCrashResolver.UpdateNotifier updateNotifier)
void
start()
Starts looking for crashes of the Bluetooth LE system and taking proactive steps to stop crashes from happening. void
stop()
Stops looking for crashes. void
enableDebug()
Enable debug logging. void
disableDebug()
Disable debug logging. void
notifyScannedDevice(BluetoothDevice device, BluetoothAdapter.LeScanCallback scanner)
Call this method from your BluetoothAdapter.LeScanCallback method. void
crashDetected()
boolean
isLastRecoverySucceeded()
boolean
isRecoveryInProgress()
void
forceFlush()
Used to force a recovery operation -
-
Constructor Detail
-
BluetoothCrashResolver
BluetoothCrashResolver(Context context)
Constructor should be called only once per long-running process that does Bluetooth LE scanning.- Parameters:
context
- the Activity or Service that is doing the Bluetooth scanning
-
-
Method Detail
-
getLastBluetoothCrashDetectionTime
long getLastBluetoothCrashDetectionTime()
-
getDetectedCrashCount
int getDetectedCrashCount()
-
getRecoveryAttemptCount
int getRecoveryAttemptCount()
-
setUpdateNotifier
void setUpdateNotifier(BluetoothCrashResolver.UpdateNotifier updateNotifier)
-
start
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
void stop()
Stops looking for crashes. Does not need to be called in normal operations, but may be useful for testing.
-
enableDebug
@Deprecated() void enableDebug()
Enable debug logging. By default no debug lines are logged.
-
disableDebug
@Deprecated() void disableDebug()
Disable debug logging.
-
notifyScannedDevice
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.
-
crashDetected
void crashDetected()
-
isLastRecoverySucceeded
boolean isLastRecoverySucceeded()
-
isRecoveryInProgress
boolean isRecoveryInProgress()
-
forceFlush
void forceFlush()
Used to force a recovery operation
-
-
-
-