MSDKSurfaceCallback
SDK-level SurfaceCallback that handles rendering the MSDK MapView on Android Auto's surface.
This class encapsulates the full VirtualDisplay → Presentation → MapView rendering pipeline that any MSDK-based Android Auto app needs. It handles:
Surface lifecycle: VirtualDisplay and Presentation creation/destruction, and the release of each car Surface once nothing draws on it
MapView lifecycle: Creation, initialization (via MapViewDelegate), state observation, cleanup
Gesture handling: Pan (onScroll), pinch-to-zoom (onScale), button zoom, zoomToRect
Dark mode: Observes the map's day/night mode — the car's, or the user's choice when it is not AADayNightMode.AUTO (AAMapState.isMapDark) — and applies the map style via MapViewDelegate
Overlay support: Custom overlay views via OverlayViewProvider (e.g., speed limit display)
Vehicle positioning: Adapts vehicle icon position to visible area via VehiclePositionStrategy
Phone state: Observes phone app readiness and triggers MapView initialization
State Access
This class accesses Android Auto state through focused sub-holders:
resolvedConnectionState (AAConnectionState): Phone state, callbacks, closing
resolvedScreenState (AAScreenStateHolder): Loading state, screen state
resolvedMapState (AAMapState): Day/night mode, zoom handlers, camera, vehicle position
Sub-holders can be injected via constructor (for testability) or resolved lazily from AndroidAutoSurfaceManager (for framework-created instances).
Loading State
The loading state (AAScreenStateHolder) tells the root screen which template to return, and it outlives the surface: the host taking the surface away leaves it unchanged (see onSurfaceDestroyed). This class writes it in two cases only: AndroidAutoLoadingState.MAP_READY once a car MapView is ready (onAAMapViewReady), and AndroidAutoLoadingState.ERROR whenever the car map cannot be built, so that a failure shows the root screen's error message rather than a black map area. The state goes back to AndroidAutoLoadingState.IDLE only when the session ends.
All behavior is configurable via SurfaceCallbackConfig. Defaults match standard navigation app behavior.
Rendering Strategy
The MSDK's MapView cannot render directly on an Android Auto Surface. This class creates a VirtualDisplay from the AA Surface, creates a Presentation on that display, and initializes a fresh MapView with the Presentation's context. The MapView is wrapped in a FrameLayout to support overlay views on top of the map.
Gesture Handling: Live Camera State
During GPS tracking (GUIDANCE_VIEW_AUTO), the MSDK moves the map camera without updating the ViewModel. Gesture handlers read live camera state from MapView.getCurrentMapState() instead of the ViewModel's stale state. This prevents the map from jumping to an old position during pan/zoom operations.
Parameters
CarContext for accessing system services
Configuration for all customizable behaviors
Optional holder for MapController/Delegate access. If null, falls back to AndroidAutoSurfaceManager dynamic lookup.
Callback invoked when the MapView is fully initialized and ready.
Optional AAConnectionState for direct holder injection. If null, resolved lazily from AndroidAutoSurfaceManager.
Optional AAScreenStateHolder for direct holder injection. If null, resolved lazily from AndroidAutoSurfaceManager.
Optional AAMapState for direct holder injection. If null, resolved lazily from AndroidAutoSurfaceManager.
See also
Constructors
Functions
Builds the car map pipeline on the surface the host hands over: a VirtualDisplay on the surface, a Presentation on that display, then the phone-state observation, which creates the MapView once the phone app is PhoneAppState.READY.
Releases the pipeline built on the surface the host is destroying, then the surface itself, and tells the phone app (PhoneAppCallback.onAAReleasing()), which can show the map on the phone again.