When a device goes out of range and then comes back into range DeviceCommunicationService disposes DeviceSupport while trying to re-establish a connection.
This causes race conditions as there are multiple for path for reconnections that can be executed in parallel.
The DeviceService.ACTION_CONNECT path kills everything abruptly potential leaving the gadget with a broken connection.
partial backport from PR #4916
Fix regression introduced by 280f4fc61. We should never call
performInitialized in the initializeDevice function, as that can cause
race conditions or, in this case, a stack overflow due to the recursive
initialization.
1/2:
- rename AbstractBTLEDeviceSupport to AbstractBTLESingleDeviceSupport
- apply all BtLEQueue settings before processing starts
- introduce getServiceDiscoveryDelay to support device specific delay between STATE_CONNECTED and getServices/discoverServices
2/2:
- add a new AbstractBTLEDeviceSupport as a common super class of AbstractBTLEMultiDeviceSupport and AbstractBTLESingleDeviceSupport
1/2:
- rename AbstractBTLEDeviceSupport to AbstractBTLESingleDeviceSupport
- apply all BtLEQueue settings before processing starts
- introduce getServiceDiscoveryDelay to support device specific delay between STATE_CONNECTED and getServices/discoverServices
2/2:
- add a new AbstractBTLEDeviceSupport as a common super class of AbstractBTLEMultiDeviceSupport and AbstractBTLESingleDeviceSupport
These are probably edge cases but they do appear to happen occasionally
Fixes Exception java.lang.NullPointerException: Attempt to invoke virtual method 'int android.bluetooth.BluetoothClass.getDeviceClass()' on a null object reference
at nodomain.freeyourgadget.gadgetbridge.devices.generic_headphones.GenericHeadphonesCoordinator.supports (GenericHeadphonesCoordinator.java:45)
at nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper.resolveDeviceType (DeviceHelper.java:140)
at nodomain.freeyourgadget.gadgetbridge.activities.discovery.GBScanEventProcessor.processCandidate (GBScanEventProcessor.java:175)
at nodomain.freeyourgadget.gadgetbridge.activities.discovery.GBScanEventProcessor.processAllScanEvents (GBScanEventProcessor.java:237)
at nodomain.freeyourgadget.gadgetbridge.activities.discovery.GBScanEventProcessor.run (GBScanEventProcessor.java:81)
at nodomain.freeyourgadget.gadgetbridge.activities.discovery.GBScanEventProcessor$1.run (GBScanEventProcessor.java:103)
Fixes Exception java.lang.NullPointerException: Attempt to invoke virtual method 'int java.io.InputStream.read(byte[], int, int)' on a null object reference
at android.bluetooth.BluetoothSocket.read (BluetoothSocket.java:692)
at android.bluetooth.BluetoothInputStream.read (BluetoothInputStream.java:88)
at java.io.InputStream.read (InputStream.java:218)
at nodomain.freeyourgadget.gadgetbridge.service.btbr.BtBRQueue$1.run (BtBRQueue.java:73)