Attempt at fixing a (re-) connection issue

Sometimes reconnection lead only to "Connected" state, but not "Initialized".
This probably happened when the device got disconnected earlier and then was
automatically reconnected. The reconnection closed the previous connection,
which caused the dispatch-thread to wake up and think the connection is
actually establish. Then, when the first action is invoked, it would fail
with an NPE because mBluetoothGatt passed to the action is actually null.
here
cpfeiffer 2016-02-18 23:35:55 +01:00
parent 70ae5a2a3a
commit 109146c8c1
1 changed files with 5 additions and 1 deletions

View File

@ -63,6 +63,7 @@ public final class BtLEQueue {
Transaction transaction = mTransactions.take();
if (!isConnected()) {
LOG.debug("not connected, waiting for connection...");
// TODO: request connection and initialization from the outside and wait until finished
internalGattCallback.reset();
@ -168,15 +169,17 @@ public final class BtLEQueue {
}
private void setDeviceConnectionState(State newState) {
LOG.debug("new device connection state: " + newState);
mGbDevice.setState(newState);
mGbDevice.sendDeviceUpdateIntent(mContext);
if (mConnectionLatch != null) {
if (mConnectionLatch != null && newState == State.CONNECTED) {
mConnectionLatch.countDown();
}
}
public void disconnect() {
synchronized (mGattMonitor) {
LOG.debug("disconnect()");
BluetoothGatt gatt = mBluetoothGatt;
if (gatt != null) {
mBluetoothGatt = null;
@ -189,6 +192,7 @@ public final class BtLEQueue {
}
private void handleDisconnected(int status) {
LOG.debug("handleDisconnected: " + status);
internalGattCallback.reset();
mTransactions.clear();
mAbortTransaction = true;