AndroidAutoSurfaceHolder

Holds and manages shared state for Android Auto map rendering.

This class acts as a shared holder between the phone app (where MapController lives) and the Android Auto module (where MapView is created for Android Auto).

Purpose

  • Bridge: Connects phone app's MapController to Android Auto's SurfaceCallback

  • Shared State: Allows Android Auto module to access MapController without depending on app

  • MSDK-ready: Uses interfaces instead of concrete implementations

Threading

All setter and getter methods on this class's own fields must be called from the main thread. The fields are plain var references without synchronization, relying on single-thread access for correctness.

Note: The reference to this holder (stored in AndroidAutoStateHolder.holder) is marked @Volatile and may be read from binder threads via the AndroidAutoSurfaceManager facade. This is safe because the reference itself is volatile, and the holder's fields are only mutated from the main thread (typically well before AA binder threads read them).

Architecture

Phone App (MainActivity/MainViewModel)
↓ setMapController() - shares MapController when phone map initializes
AndroidAutoSurfaceHolder (shared singleton via Hilt or manual injection)
↓ getMapController() - Android Auto retrieves to initialize AA MapView
Android Auto Module (AndroidAutoSurfaceCallback)

Flow

  1. Phone app launches, MapViewComposable initializes

  2. MainViewModel creates a MapControllerAdapter wrapping MapViewModel

  3. MainViewModel calls setMapController(adapter) to share it

  4. Android Auto connects, SurfaceCallback creates fresh MapView

  5. SurfaceCallback calls getMapController() to initialize AA MapView

  6. AA MapView uses the MapController for state and camera control

  7. On disconnect, AA MapView is destroyed

Implementation Notes

This class implements MapStateProvider to provide a standard interface for Android Auto to access the map controller and cached position.

See also

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard

StateFlow observed by Android Auto for route display.

Functions

Link copied to clipboard

Clears the route display state.

Link copied to clipboard
open override fun getCachedInitialPosition(): GeoPoint?

Gets the cached initial position for Android Auto map centering.

Link copied to clipboard

Gets the shared GuidanceProvider for Android Auto navigation screen.

Link copied to clipboard
open override fun getMapController(): MapController?

Gets the shared MapController for Android Auto MapView initialization.

Link copied to clipboard

Gets the shared MapViewDelegate for Android Auto SurfaceCallback.

Link copied to clipboard

Gets the shared QuickAccessProvider for Android Auto search screen.

Link copied to clipboard

Gets the shared SearchProvider for Android Auto search screen.

Link copied to clipboard

Gets the shared SettingsProvider for the Android Auto settings screen.

Link copied to clipboard

Checks if GuidanceProvider is available.

Link copied to clipboard
open override fun hasMapController(): Boolean

Checks if MapController is available.

Link copied to clipboard

Checks if MapViewDelegate is available.

Link copied to clipboard

Checks if QuickAccessProvider is available.

Link copied to clipboard

Checks if SearchProvider is available.

Link copied to clipboard

Checks if SettingsProvider is available.

Link copied to clipboard

Stores the cached initial position for Android Auto map centering.

Link copied to clipboard

Stores the GuidanceProvider for Android Auto to use.

Link copied to clipboard

Stores the MapController for Android Auto to use.

Link copied to clipboard

Stores the MapViewDelegate for Android Auto to use.

Link copied to clipboard

Stores the QuickAccessProvider for Android Auto to use.

Link copied to clipboard

Stores the SearchProvider for Android Auto to use.

Link copied to clipboard

Stores the SettingsProvider for Android Auto to use.

Link copied to clipboard

Updates the route display state.