AAConnectionState

class AAConnectionState(onPhoneStateRequiresLoadingUpdate: (AndroidAutoLoadingState) -> Unit? = null)

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:

Usage

// Standalone (for testing)
val connectionState = AAConnectionState()

// Wired with screen state (in AndroidAutoStateHolder)
val connectionState = AAConnectionState(
onPhoneStateRequiresLoadingUpdate = { loadingState ->
screenStateHolder.setLoadingState(loadingState)
}
)

Parameters

onPhoneStateRequiresLoadingUpdate

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

Constructors

Link copied to clipboard
constructor(onPhoneStateRequiresLoadingUpdate: (AndroidAutoLoadingState) -> Unit? = null)

Properties

Link copied to clipboard

Flag indicating whether Android Auto is currently connected.

Link copied to clipboard

Returns whether Android Auto is currently in the process of disconnecting.

Link copied to clipboard

Callback interface for phone app to receive events from Android Auto.

Link copied to clipboard
val phoneState: StateFlow<PhoneAppState>

Public read-only StateFlow of the phone app state.

Link copied to clipboard

Callback interface for phone app to send commands to Android Auto.

Functions

Link copied to clipboard

Gets the current phone app state.

Link copied to clipboard

Checks if the phone app is closing.

Link copied to clipboard

Resets the phone app closing flag.

Link copied to clipboard

Resets the phone state to UNKNOWN.

Link copied to clipboard
fun setAAConnected(connected: Boolean)

Sets the Android Auto connection state.

Link copied to clipboard
fun setAADisconnecting(disconnecting: Boolean)

Sets the Android Auto disconnecting flag.

Link copied to clipboard
fun setOnCloseCallback(callback: () -> Unit?)

Sets the callback to be invoked when the phone app is closing.

Link copied to clipboard

Registers the phone app callback to receive events from Android Auto.

Link copied to clipboard

Sets the phone app closing flag and triggers immediate Android Auto close.

Link copied to clipboard

Sets the current phone app state.

Link copied to clipboard

Registers the callback for phone-to-AA commands.