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
Functions
Called when user cancels route preview from the phone.
Called when user presses back on the phone while AA is connected.
Called when user wants to open search from the phone.
Called when user selects a destination from phone-side search.
Called when user selects a route from phone-side route preview.
Called when user starts navigation from the phone.
Called when user stops navigation from the phone.