QuickAccessProvider
Interface for providing quick access destinations to Android Auto.
This interface abstracts the quick access functionality, allowing different apps to provide their own implementations while sharing the same Android Auto integration code. It follows the same pattern as SearchProvider and MapController.
Purpose
Abstraction: Decouples Android Auto module from specific storage implementations
Reusability: Allows the Android Auto module to be used by different apps
MSDK Integration: Designed to be migrated into the MSDK in the future
Quick Access Categories
The provider manages three categories of destinations:
Home Address: User's home location (single, stored in Room)
Work Address: User's work location (single, stored in Room)
Recent Destinations: Last navigated destinations (max 5, stored in SharedPreferences)
Implementation Notes
The implementation is responsible for:
Observing Room database for Home/Work address changes
Loading recent destinations from SharedPreferences
Converting internal types to QuickAccessItem
Managing the combined state via quickAccessState StateFlow
Adding new recent destinations (with FIFO and deduplication logic)
Filtering expired recent destinations (30-day expiration)
Example Implementation
class QuickAccessProviderImpl(
private val getHomeAddress: GetHomeAddress,
private val getWorkAddress: GetWorkAddress,
private val androidAutoPreferences: AndroidAutoPreferences
) : QuickAccessProvider {
private val _quickAccessState = MutableStateFlow(QuickAccessState(isLoading = true))
override val quickAccessState: StateFlow<QuickAccessState> = _quickAccessState.asStateFlow()
private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
init {
// Observe Home address from Room
scope.launch {
getHomeAddress().collect { homeAddress ->
updateState { it.copy(homeAddress = homeAddress?.toQuickAccessItem()) }
}
}
// Similar for Work address
// Load recents from SharedPreferences
}
override fun addRecentDestination(item: QuickAccessItem) {
// Add to SharedPreferences with FIFO logic
// Update state
}
override fun clearRecentDestinations() {
// Clear from SharedPreferences
// Update state
}
override fun dispose() {
scope.cancel()
}
}