EARHORNMUSIC UPnP · Android TV · Phones · Android Auto · GNU/Linux
Release 0.5.0

EarhornCarAppService.kt

Each line, with the release that last changed it.

0.5.01package dev.stave.cartemplate
2
3import androidx.car.app.CarAppService
4import androidx.car.app.Session
5import androidx.car.app.validation.HostValidator
6
7/**
8 * Car App Library entry point. Declared in AndroidManifest.xml under the
9 * <action android:name="androidx.car.app.CarAppService" />
10 * <category android:name="androidx.car.app.category.MEDIA" />
11 * intent filter, which is what makes Auto's launcher offer a custom UI
12 * instead of falling back to the MediaLibraryService template.
13 *
14 * The actual UI lives in [EarhornCarSession] and the [androidx.car.app.Screen]
15 * subclasses it pushes onto the ScreenManager stack. This service is just
16 * the lifecycle anchor that Auto binds to.
17 *
18 * Coexistence: the existing [dev.stave.playback.PlaybackService] is also
19 * declared as a media-browser-compatible service. Auto picks whichever
20 * surface the host supports; on hosts that support the Car App Library
21 * MEDIA category, this service wins. Older hosts continue to use
22 * PlaybackService's MediaLibrarySession unchanged.
23 *
24 * No Hilt injection here — the only dependency we need is the
25 * application Context (for the MediaController bind), which Service
26 * provides natively. Keeping this Hilt-free avoids the need to modify
27 * any existing DI graph.
28 */
29class EarhornCarAppService : CarAppService() {
30
31 override fun onCreate() {
32 super.onCreate()
33 android.util.Log.i("EarhornCar", "╔══ EarhornCarAppService.onCreate ══╗")
34 }
35
36 // Only Google's car hosts may bind (design decision 2026-09-02, I.76).
37 // ALLOW_ALL_HOSTS_VALIDATOR let any app on the phone act as the car.
38 override fun createHostValidator(): HostValidator =
39 HostValidator.Builder(applicationContext)
40 .addAllowedHosts(androidx.car.app.R.array.hosts_allowlist_sample)
41 .build()
42
43 override fun onCreateSession(): Session {
44 android.util.Log.i("EarhornCar", "╠══ onCreateSession — Auto host bound ══╣")
45 return EarhornCarSession()
46 }
47}