PhoneToAACallback

Callback interface for the phone app to send commands to Android Auto.

This interface enables bidirectional communication between the phone and AA. While PhoneAppCallback handles AA → Phone events, this interface handles Phone → AA commands, allowing the phone UI to affect the AA screen state.

Purpose

  • Bidirectional sync: Phone actions can navigate AA screens

  • Mirror navigation: Phone back button triggers AA back

  • User choice: User can interact from either screen

Usage

Implemented by the AA module (AndroidAutoSession) and registered with the manager. Registration is deferred to ensureInfrastructureReady(), which runs when the phone signals READY (not directly in onCreate()):

// In AndroidAutoSession
private fun createPhoneToAACallback(): PhoneToAACallback {
return object : PhoneToAACallback {
override fun onPhoneRequestsBack() { screenManager.pop() }
override fun onPhoneRequestsSearch() {
screenManager.push(AndroidAutoSearchScreen(carContext))
}
// ...
}
}

private fun ensureInfrastructureReady() {
if (AndroidAutoSurfaceManager.phoneToAACallback == null) {
AndroidAutoSurfaceManager.setPhoneToAACallback(createPhoneToAACallback())
}
}

Called from the phone app via MainViewModel:

// In MainViewModel
fun onPhoneBackPressed() {
AndroidAutoSurfaceManager.phoneToAACallback?.onPhoneRequestsBack()
}

See also

AndroidAutoSurfaceManager

Functions

Link copied to clipboard
abstract fun onPhoneCancelsRoute()

Called when user cancels route preview from the phone.

Link copied to clipboard
abstract fun onPhoneRequestsBack()

Called when user presses back on the phone while AA is connected.

Link copied to clipboard
abstract fun onPhoneRequestsSearch()

Called when user wants to open search from the phone.

Link copied to clipboard
abstract fun onPhoneSelectsDestination(latitude: Double, longitude: Double, title: String)

Called when user selects a destination from phone-side search.

Link copied to clipboard
abstract fun onPhoneSelectsRoute(index: Int)

Called when user selects a route from phone-side route preview.

Link copied to clipboard
abstract fun onPhoneStartsNavigation(destinationTitle: String, useDemoMode: Boolean = false)

Called when user starts navigation from the phone.

Link copied to clipboard
abstract fun onPhoneStopsNavigation()

Called when user stops navigation from the phone.