MSDKSession
Base Session class for MSDK-based Android Auto apps.
Handles all the generic session infrastructure that any MSDK client needs:
Session lifecycle (connect, start, stop, disconnect)
Phone state observation with deferred surface allocation
Phone state carried over to the next session while the phone app runs (AAConnectionState.onSessionCreated, AAConnectionState.onSessionDestroyed)
Loading state transitions (IDLE → ONBOARDING_REQUIRED → INITIALIZING_MAPS → MAP_READY), and back to IDLE only when the session ends: the loading state outlives the map surface
Car day/night mode: read from
CarContext.isDarkModewhen the session is created, started and re-opened (onNewIntent), and on every onCarConfigurationChangedPhone app launch when AA starts first
Screen navigation via AANavigationCoordinator with state machine validation
SurfaceCallback registration/unregistration
Phone state sync after map is ready
State Access
This class accesses Android Auto state through focused sub-holders:
connectionState (AAConnectionState): Connection lifecycle, phone state, callbacks
screenState (AAScreenStateHolder): Screen state, loading state, guidance session
mapState (AAMapState): The car's dark mode (read when the session is created, started and re-opened, and on car configuration changes)
Surface holder access (MapController, providers) remains via AndroidAutoSurfaceManager since AndroidAutoSurfaceHolder management is a separate concern.
What subclasses implement
createMainScreen: Root screen for the AA app
createSurfaceCallback: App-specific SurfaceCallback (with map rendering, overlays)
createScreenFactory: Factory for creating app-specific screens (search, route preview, navigation)
Screen Navigation
Phone-to-AA screen navigation is handled by AANavigationCoordinator which uses AAScreenFactory to create screens and AANavigationStateMachine to validate transitions. The subclass only provides the factory — the coordinator handles all push/pop logic and state tracking.
Lifecycle Flow
onCreate → read car dark mode → create coordinator → drop a phone state that does not carry over
→ setAAConnected(true) → launch phone app → start observer (replays a carried-over READY at once)
↓ (phone signals READY)
ensureInfrastructureReady → registerSurfaceCallback → MAP_READY
↓ (MapView ready)
syncToPhoneState (via coordinator) → push screens to match phone
↓ (user disconnects)
onDestroy → reset coordinator → cancel jobs → unregister callbacks → loading state IDLE
→ setAAConnected(false) → keep the phone state for the next session, or reset itSee also
Functions
Records a change of the car's day/night mode in mapState.
Re-reads the car's day/night mode when the host re-opens this session.