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:

  1. Home Address: User's home location (single, stored in Room)

  2. Work Address: User's work location (single, stored in Room)

  3. 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()
}
}

See also

Properties

Link copied to clipboard
abstract val quickAccessState: StateFlow<QuickAccessState>

StateFlow of current quick access state for reactive observation.

Functions

Link copied to clipboard

Adds a destination to the recent destinations list.

Link copied to clipboard

Clears all recent destinations.

Link copied to clipboard
abstract fun dispose()

Disposes of the quick access provider and releases all resources.

Link copied to clipboard
abstract fun refresh()

Refreshes the quick access state from storage.

Link copied to clipboard
abstract fun reinitialize()

Reinitializes the provider after disposal.

Link copied to clipboard

Removes a specific recent destination by its ID.