mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-10 09:01:55 +01:00
BtLEQueue: update device state on main looper
If the device connection state is updated from two threads simultaneously (as in, from the main looper and from the thread that handles BluetoothDevice.connectGatt), a second update may get overridden by the first update if the broadcasts are handled out-of-order by the LocalBroadcastManager. By updating the device state through a handler on the main looper, the broadcasts are sent in order as they are processed from the looper's queue. This may be a potential solve for issue #3524.
This commit is contained in:
parent
7955bdfb6f
commit
8a7de15841
@ -227,7 +227,12 @@ public final class BtLEQueue {
|
||||
}
|
||||
|
||||
protected boolean isConnected() {
|
||||
return mGbDevice.isConnected();
|
||||
if (mGbDevice.isConnected()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
LOG.debug("isConnected(): current state = {}", mGbDevice.getState());
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -285,11 +290,12 @@ public final class BtLEQueue {
|
||||
return result;
|
||||
}
|
||||
|
||||
private void setDeviceConnectionState(State newState) {
|
||||
LOG.debug("new device connection state: " + newState);
|
||||
|
||||
mGbDevice.setState(newState);
|
||||
mGbDevice.sendDeviceUpdateIntent(mContext, GBDevice.DeviceUpdateSubject.CONNECTION_STATE);
|
||||
private void setDeviceConnectionState(final State newState) {
|
||||
new Handler(Looper.getMainLooper()).post(() -> {
|
||||
LOG.debug("new device connection state: " + newState);
|
||||
mGbDevice.setState(newState);
|
||||
mGbDevice.sendDeviceUpdateIntent(mContext, GBDevice.DeviceUpdateSubject.CONNECTION_STATE);
|
||||
});
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
|
Loading…
Reference in New Issue
Block a user