AAScreenStateHolder

class AAScreenStateHolder(onAAScreenStateChanged: (AndroidAutoScreenState) -> Unit? = null)

Focused state holder for Android Auto screen state and loading lifecycle.

This class manages the state related to which screen is active on Android Auto, the loading/initialization lifecycle, and current guidance session information:

  • Screen state: Which AA screen is currently displayed (AndroidAutoScreenState)

  • Loading state: Initialization progress with multi-level guard logic (AndroidAutoLoadingState)

  • Phone equivalent state: What AA screen the phone's current state maps to (for sync on reconnect)

  • Guidance session: Current destination and demo mode (for mid-session AA sync)

Loading State Guards

The setLoadingState method contains critical guard logic to prevent state downgrades:

These guards provide defense-in-depth against race conditions where stale phone state re-emissions trigger loading state changes after the map is already rendering.

Cross-Holder Dependency

When the AA screen state changes, the phone app needs to be notified via PhoneAppCallback.onAAScreenStateChanged(). Since the callback is owned by AAConnectionState, this holder accepts an onAAScreenStateChanged lambda that the orchestrator wires to the connection state's callback.

Thread Safety

  • @Volatile for loadingState (written from GL thread, read from main thread)

  • @Volatile for stateListener (set from main thread, read from GL thread)

  • StateFlow for reactive state (inherently thread-safe)

Parameters

onAAScreenStateChanged

Optional lambda called when the AA screen state changes (for notifying PhoneAppCallback). Defaults to null for standalone use and testing.

See also

Constructors

Link copied to clipboard
constructor(onAAScreenStateChanged: (AndroidAutoScreenState) -> Unit? = null)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Public read-only StateFlow of the AA screen state.

Link copied to clipboard

Public read-only StateFlow of the phone's equivalent AA state.

Functions

Link copied to clipboard

Clears the current guidance session state.

Link copied to clipboard

Gets the current AA screen state.

Link copied to clipboard

Gets the current guidance destination title.

Link copied to clipboard

Gets the current loading state.

Link copied to clipboard

Gets the phone's equivalent AA screen state.

Link copied to clipboard

Gets whether the current guidance session is in demo mode.

Link copied to clipboard

Resets the AA screen state to DISCONNECTED.

Link copied to clipboard

Resets the loading state to IDLE.

Link copied to clipboard

Sets the current Android Auto screen state.

Link copied to clipboard
fun setCurrentGuidanceState(destinationTitle: String, isDemoMode: Boolean)

Sets the current guidance session state.

Link copied to clipboard

Sets the current loading state and notifies the listener.

Link copied to clipboard

Sets the phone's equivalent AA screen state.

Link copied to clipboard

Registers a listener to be notified of loading state changes.