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
Phone app launches, MapViewComposable initializes
MainViewModel creates a MapControllerAdapter wrapping MapViewModel
MainViewModel calls
setMapController(adapter)to share itAndroid Auto connects, SurfaceCallback creates fresh MapView
SurfaceCallback calls
getMapController()to initialize AA MapViewAA MapView uses the MapController for state and camera control
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
Functions
Clears the route display state.
Gets the cached initial position for Android Auto map centering.
Gets the shared GuidanceProvider for Android Auto navigation screen.
Gets the shared MapController for Android Auto MapView initialization.
Gets the shared MapViewDelegate for Android Auto SurfaceCallback.
Gets the shared QuickAccessProvider for Android Auto search screen.
Gets the shared SearchProvider for Android Auto search screen.
Gets the shared SettingsProvider for the Android Auto settings screen.
Checks if GuidanceProvider is available.
Checks if MapController is available.
Checks if MapViewDelegate is available.
Checks if QuickAccessProvider is available.
Checks if SearchProvider is available.
Checks if SettingsProvider is available.
Stores the cached initial position for Android Auto map centering.
Stores the GuidanceProvider for Android Auto to use.
Stores the MapController for Android Auto to use.
Stores the MapViewDelegate for Android Auto to use.
Stores the QuickAccessProvider for Android Auto to use.
Stores the SearchProvider for Android Auto to use.
Stores the SettingsProvider for Android Auto to use.
Updates the route display state.