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
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).
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.