Class ConnectionHandler
-
- All Implemented Interfaces:
public final class ConnectionHandlerConnection handler handles connection states serialization, by using simple state pattern
-
-
Field Summary
Fields Modifier and Type Field Description public final static IntegerPOLAR_PREFERRED_MTUpublic final static IntegerMTU_SKIP_NEGOTIATION
-
Constructor Summary
Constructors Constructor Description ConnectionHandler(ConnectionInterface connectionInterface, ScannerInterface scannerInterface, ConnectionHandlerObserver observer, CoroutineScope scope)
-
Method Summary
Modifier and Type Method Description final UnitsetAutomaticReconnection(Boolean automaticReconnection)final BooleangetAutomaticReconnection()final Unitcancel()final UnitadvertisementHeadReceived(BDDeviceSessionImpl bleDeviceSession)final UnitconnectDevice(BDDeviceSessionImpl bleDeviceSession, Boolean bluetoothEnabled)final UnitconnectDeviceDirect(BDDeviceSessionImpl bleDeviceSession, Boolean bluetoothEnabled)Initiate a GATT connection directly by MAC address, bypassing the advertisement-connectable guard. final UnitdisconnectDevice(BDDeviceSessionImpl bleDeviceSession)final UnitconnectionInitialized(BDDeviceSessionImpl bleDeviceSession)final UnitphyUpdated(BDDeviceSessionImpl bleDeviceSession)final UnitservicesDiscovered(BDDeviceSessionImpl bleDeviceSession)final UnitmtuUpdated(BDDeviceSessionImpl bleDeviceSession)final UnitdeviceDisconnected(BDDeviceSessionImpl bleDeviceSession)final UnitsessionsRemoved(Collection<BDDeviceSessionImpl> sessions)Bulk removal must not let one removed session's queued retry start midway through cleanup. final UnitsessionRemoved(BDDeviceSessionImpl session)Called when a session object is dropped from the listener's tracking list. final UnitdispatchGattCallback(BDDeviceSessionImpl session, BluetoothGatt gatt, Runnable action)Validate a GATT callback against the session's current GATT before running it. final UnitscheduleDirectReconnect(BDDeviceSessionImpl session, Long delayMs)Queue a direct reconnect for a parked session. final UnitblePoweredOff(Collection<BDDeviceSessionImpl> trackedSessions)Escape hatch for a Bluetooth power-off. final UnitblePoweredOff()Escape hatch for a Bluetooth power-off. final UnitblePoweredOn(Collection<BDDeviceSessionImpl> trackedSessions)final UnitblePoweredOn()-
-
Constructor Detail
-
ConnectionHandler
ConnectionHandler(ConnectionInterface connectionInterface, ScannerInterface scannerInterface, ConnectionHandlerObserver observer, CoroutineScope scope)
-
-
Method Detail
-
setAutomaticReconnection
final Unit setAutomaticReconnection(Boolean automaticReconnection)
-
getAutomaticReconnection
final Boolean getAutomaticReconnection()
-
advertisementHeadReceived
final Unit advertisementHeadReceived(BDDeviceSessionImpl bleDeviceSession)
-
connectDevice
final Unit connectDevice(BDDeviceSessionImpl bleDeviceSession, Boolean bluetoothEnabled)
-
connectDeviceDirect
final Unit connectDeviceDirect(BDDeviceSessionImpl bleDeviceSession, Boolean bluetoothEnabled)
Initiate a GATT connection directly by MAC address, bypassing the advertisement-connectable guard. Call this when the peripheral is known to be reachable (e.g. via CompanionDeviceManager) but has stopped advertising.
-
disconnectDevice
final Unit disconnectDevice(BDDeviceSessionImpl bleDeviceSession)
-
connectionInitialized
final Unit connectionInitialized(BDDeviceSessionImpl bleDeviceSession)
-
phyUpdated
final Unit phyUpdated(BDDeviceSessionImpl bleDeviceSession)
-
servicesDiscovered
final Unit servicesDiscovered(BDDeviceSessionImpl bleDeviceSession)
-
mtuUpdated
final Unit mtuUpdated(BDDeviceSessionImpl bleDeviceSession)
-
deviceDisconnected
final Unit deviceDisconnected(BDDeviceSessionImpl bleDeviceSession)
-
sessionsRemoved
final Unit sessionsRemoved(Collection<BDDeviceSessionImpl> sessions)
Bulk removal must not let one removed session's queued retry start midway through cleanup.
-
sessionRemoved
final Unit sessionRemoved(BDDeviceSessionImpl session)
Called when a session object is dropped from the listener's tracking list. If it is still pinned as current the handler would otherwise stay in CONNECTING forever referencing an orphaned session, discarding every later request. Release its GATT and return to FREE.
-
dispatchGattCallback
final Unit dispatchGattCallback(BDDeviceSessionImpl session, BluetoothGatt gatt, Runnable action)
Validate a GATT callback against the session's current GATT before running it.
Android keeps delivering callbacks from a GATT object that has already been replaced by a reconnect (or torn down by a power-off). Acting on those drives the state machine with events that belong to a dead connection. The check and the action share the handler lock, so a concurrent power-off or watchdog cleanup cannot slip in between them.
-
scheduleDirectReconnect
final Unit scheduleDirectReconnect(BDDeviceSessionImpl session, Long delayMs)
Queue a direct reconnect for a parked session. Routing this through the retry queue instead of a free-standing timer means it is cancelled by cancel, sessionRemoved, a power-off, or by disabling automatic reconnection, rather than firing into a torn-down handler.
-
blePoweredOff
@JvmOverloads() final Unit blePoweredOff(Collection<BDDeviceSessionImpl> trackedSessions)
Escape hatch for a Bluetooth power-off. The listener's power-off callback iterates only its tracked session list, so it cannot reach a current session that has already been removed from that list. Reset the handler unconditionally so a Bluetooth toggle always clears a wedged CONNECTING state instead of requiring an app restart.
-
blePoweredOff
@JvmOverloads() final Unit blePoweredOff()
Escape hatch for a Bluetooth power-off. The listener's power-off callback iterates only its tracked session list, so it cannot reach a current session that has already been removed from that list. Reset the handler unconditionally so a Bluetooth toggle always clears a wedged CONNECTING state instead of requiring an app restart.
-
blePoweredOn
@JvmOverloads() final Unit blePoweredOn(Collection<BDDeviceSessionImpl> trackedSessions)
-
blePoweredOn
@JvmOverloads() final Unit blePoweredOn()
-
-
-
-