MSDKSurfaceCallback

open class MSDKSurfaceCallback(carContext: CarContext, config: SurfaceCallbackConfig = SurfaceCallbackConfig(), androidAutoSurfaceHolder: AndroidAutoSurfaceHolder? = null, onMapReady: () -> Unit? = null, connectionState: AAConnectionState? = null, screenStateHolder: AAScreenStateHolder? = null, mapState: AAMapState? = null) : SurfaceCallback

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:

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

CarContext for accessing system services

config

Configuration for all customizable behaviors

androidAutoSurfaceHolder

Optional holder for MapController/Delegate access. If null, falls back to AndroidAutoSurfaceManager dynamic lookup.

onMapReady

Callback invoked when the MapView is fully initialized and ready.

connectionState

Optional AAConnectionState for direct holder injection. If null, resolved lazily from AndroidAutoSurfaceManager.

screenStateHolder

Optional AAScreenStateHolder for direct holder injection. If null, resolved lazily from AndroidAutoSurfaceManager.

mapState

Optional AAMapState for direct holder injection. If null, resolved lazily from AndroidAutoSurfaceManager.

See also

Constructors

Link copied to clipboard
constructor(carContext: CarContext, config: SurfaceCallbackConfig = SurfaceCallbackConfig(), androidAutoSurfaceHolder: AndroidAutoSurfaceHolder? = null, onMapReady: () -> Unit? = null, connectionState: AAConnectionState? = null, screenStateHolder: AAScreenStateHolder? = null, mapState: AAMapState? = null)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open fun onClick(x: Float, y: Float)
Link copied to clipboard
open override fun onFling(velocityX: Float, velocityY: Float)

Fling gesture callback (quick swipe and release).

Link copied to clipboard
open override fun onScale(focusX: Float, focusY: Float, scaleFactor: Float)

Pinch-to-zoom gesture. Uses log2(scaleFactor) for zoom delta with live camera state.

Link copied to clipboard
open override fun onScroll(distanceX: Float, distanceY: Float)

Pan gesture. Reads live camera state from MapView to avoid stale ViewModel issue.

Link copied to clipboard
open override fun onStableAreaChanged(stableArea: Rect)
Link copied to clipboard
open override fun onSurfaceAvailable(container: SurfaceContainer)
Link copied to clipboard
open override fun onSurfaceDestroyed(container: SurfaceContainer)
Link copied to clipboard
open override fun onVisibleAreaChanged(visibleArea: Rect)