Package 

Class BluetoothCrashResolver


  • 
    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.

    • 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

      • 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.

      • 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.

      • forceFlush

         void forceFlush()

        Used to force a recovery operation