MSDKSession

abstract class MSDKSession : Session

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.isDarkMode when the session is created, started and re-opened (onNewIntent), and on every onCarConfigurationChanged

  • Phone 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:

Surface holder access (MapController, providers) remains via AndroidAutoSurfaceManager since AndroidAutoSurfaceHolder management is a separate concern.

What subclasses implement

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 it

See also

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val carContext: @NonNull CarContext
Link copied to clipboard
open val lifecycle: @NonNull Lifecycle

Functions

Link copied to clipboard
open override fun onCarConfigurationChanged(newConfiguration: Configuration)

Records a change of the car's day/night mode in mapState.

Link copied to clipboard
open override fun onCreateScreen(intent: Intent): Screen
Link copied to clipboard
open override fun onNewIntent(intent: Intent)

Re-reads the car's day/night mode when the host re-opens this session.

Link copied to clipboard
open fun setCarContextInternal(carContext: @NonNull CarContext)
Link copied to clipboard
open fun setLifecycleRegistryInternal(registry: @NonNull LifecycleRegistry)