AAConnectionState
Focused state holder for Android Auto connection and phone app communication.
This class manages the connection lifecycle between the phone app and Android Auto, including:
Android Auto connection and disconnection state
Phone app state (lifecycle observable by AA)
Bidirectional callbacks (phone ↔ AA)
Phone app closing coordination
Cross-Holder Dependency
When the phone reports PhoneAppState.ONBOARDING, this holder needs to update the loading state (owned by AAScreenStateHolder). This is solved via the onPhoneStateRequiresLoadingUpdate lambda, which the orchestrator (AndroidAutoStateHolder) wires to screenStateHolder.setLoadingState(...).
Thread Safety
This class is accessed from multiple threads:
Main thread: UI operations, callback registrations
Binder threads: Android Auto session callbacks
Thread safety is ensured through:
AtomicBoolean for lock-free flag operations (_isAADisconnecting)
StateFlow for reactive state (_phoneState) — inherently thread-safe
@Volatile for simple flag reads/writes (isPhoneAppClosing)
Usage
// Standalone (for testing)
val connectionState = AAConnectionState()
// Wired with screen state (in AndroidAutoStateHolder)
val connectionState = AAConnectionState(
onPhoneStateRequiresLoadingUpdate = { loadingState ->
screenStateHolder.setLoadingState(loadingState)
}
)Parameters
Optional lambda called when setPhoneState detects that the phone is in PhoneAppState.ONBOARDING and the loading state should be set to AndroidAutoLoadingState.ONBOARDING_REQUIRED. Defaults to null (no cross-holder notification) for standalone use and testing.
See also
Properties
Flag indicating whether Android Auto is currently connected.
Returns whether Android Auto is currently in the process of disconnecting.
Callback interface for phone app to receive events from Android Auto.
Public read-only StateFlow of the phone app state.
Callback interface for phone app to send commands to Android Auto.
Functions
Gets the current phone app state.
Checks if the phone app is closing.
Resets the phone app closing flag.
Resets the phone state to UNKNOWN.
Sets the Android Auto connection state.
Sets the Android Auto disconnecting flag.
Sets the callback to be invoked when the phone app is closing.
Registers the phone app callback to receive events from Android Auto.
Sets the phone app closing flag and triggers immediate Android Auto close.
Sets the current phone app state.
Registers the callback for phone-to-AA commands.