Skip to content

Commit

Permalink
TandemBluetoothHandler: automatically unbond when unable to progress …
Browse files Browse the repository at this point in the history
…past initialPumpConnection

This is an attempt to work around what is presumed to be an Android bug with bonded peripherals
which results in the phone never receiving a reply after an initial connection is established
and the first auth packet is sent to the pump. Manually unbonding the peripheral in Bluetooth
settings seems to resolve this problem when it occurs.
  • Loading branch information
jwoglom committed May 3, 2023
1 parent b2a0025 commit 7fb0d3f
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,19 @@ private synchronized void checkIfInitialPumpConnectionEstablished(BluetoothPerip
}

tandemPump.onInitialPumpConnection(peripheral);

handler.postDelayed(() -> {
if (remainingConnectionInitializationSteps.contains(ConnectionInitializationStep.ALREADY_INITIALIZED)) {
int requestsSent = Packetize.txId.get();
int repliesReceived = PumpState.processedResponseMessages;
Timber.i("InitialPumpConnectionChecker: requestsSent=%d repliesReceived=%d", requestsSent, repliesReceived);
if (requestsSent > 0 && repliesReceived == 0) {
Timber.i("InitialPumpConnectionStuck: not getting pump replies. Disconnecting and unbonding: bondState=%s", peripheral.getBondState());
peripheral.cancelConnection();
central.removeBond(peripheral.getAddress());
}
}
}, 5000);
} else if (!remainingConnectionInitializationSteps.contains(ConnectionInitializationStep.ALREADY_INITIALIZED)) {
Timber.i("TandemBluetoothHandler: initial pump connection is waiting for: %s", remainingConnectionInitializationSteps);
}
Expand Down

0 comments on commit 7fb0d3f

Please sign in to comment.