Conversation
added 2 commits
August 7, 2026 07:11
Allows consuming apps to subclass AndroidAutoService and override createHostValidator() to provide a restricted HostValidator instead of the default HostValidator.ALLOW_ALL_HOSTS_VALIDATOR.
AndroidAutoService (now open) exposes androidx.car.app types (CarAppService, HostValidator, Session) directly in its public/ overridable API surface. Consuming apps that subclass it need these types on their compile classpath, so this dependency belongs to the public API and should be an 'api' dependency, not 'implementation'.
…id-auto-service # Conflicts: # android/build.gradle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
AndroidAutoService.createHostValidator()currently hardcodesHostValidator.ALLOW_ALL_HOSTS_VALIDATOR, which allows any app on the device to bind to the Android AutoCarAppServicewith no host validation. This is fine for development but is a security concern before a production release, since apps typically want to restrict which hosts (e.g. only the official Android Auto/Automotive OS apps) can connect.Since
AndroidAutoServiceand its overridden methods were implicitlyfinal(Kotlin default), consuming apps had no way to customize this behavior without forking the plugin.What changed
1. Make
AndroidAutoServiceextensibleclass AndroidAutoService->open class AndroidAutoServiceoverride fun createHostValidator()->open override fun createHostValidator()No default behavior changes —
ALLOW_ALL_HOSTS_VALIDATORremains the default. This just allows consumers to subclass and override host validation:and register
MyAndroidAutoServicein their ownAndroidManifest.xmlinstead ofAndroidAutoService.2. Expose
androidx.car.app:appas anapidependencyimplementation("androidx.car.app:app:1.7.0")->api("androidx.car.app:app:1.7.0")Why this is good practice: Gradle's rule of thumb is to use
apiwhenever a dependency's types appear in your library's public API surface, andimplementationwhen it's purely an internal detail. SinceAndroidAutoServiceis nowopenand directly exposesandroidx.car.apptypes in overridable members:AndroidAutoServiceextendsandroidx.car.app.CarAppServicecreateHostValidator()returnsandroidx.car.app.validation.HostValidatoronCreateSession()returnsandroidx.car.app.Session...any app that subclasses
AndroidAutoService(e.g. to provide a customHostValidatoras shown above) must have these types on its own compile classpath. Before this change, consumers had to know to addandroidx.car.app:appto their ownbuild.gradlethemselves, undocumented and only discoverable via a compile error. Withapi, the dependency is now transitively exposed, so it just works out of the box — the correct outcome for a dependency that's unavoidably part of the public contract, not a leaked implementation detail.(One trade-off: consumers are now pinned to
androidx.car.app:app:1.7.0by default, though they can still override it with a newer version in their ownbuild.gradleif needed, since Gradle resolves to the highest requested version.)