# Android TV

Status: The Android TV app (`app/tv`, `libre` flavour only), with CE screens beside upstream's, D-pad focus helpers, the TV Compose player, Watch Next, theme music, and the screensaver. As of 2026-11-25 (`main`).

## Start here

- New TV screens and components live in `app/tv/src/main/java/dev/jdtech/jellyfin/ce/` next to upstream's `presentation/` files (TV ADR 0001). `NavigationRoot` (`app/tv/src/main/java/dev/jdtech/jellyfin/NavigationRoot.kt`) and `NavigationRoutes.kt` point each route at its CE screen (`MainScreen`, `LibraryScreen`, `CollectionScreen`, `MovieScreen`, `ShowScreen`, `SeasonScreen`, `PersonScreen`, `TvPlayerScreen`, `TvProfilePinGateScreen`, `TvProfilePinScreen`, `TvExternalRatingsScreen`, `HomeRowsScreen`, `AboutScreen`, `LicensesScreen`, `DeviceProfileScreen`).
- `MainScreen` (`app/tv/.../ce/presentation/main/MainScreen.kt`, TV ADR 0002) replaces the upstream top tab bar with a collapsed-to-rail `ModalNavigationDrawer` for profile switching, Search, Home, Favorites, libraries, and Settings, retaining per-destination state with `SaveableStateProvider`.
- D-pad focus restore, focus rings, and overscan margins live in `app/tv/.../ce/ui/focus/` (`FocusPosition`, `RestoreFocus`, `EphyraFocus`, `FocusHandOff`, `DirectionKeyClock`, `NoBringIntoView`, TV ADR 0003) and `TvSafeArea` (`app/tv/.../ce/ui/TvSafeArea.kt`).
- `TvPlayerScreen` (`app/tv/.../ce/presentation/player/TvPlayerScreen.kt`, TV ADR 0004) wraps Media3 `PlayerView` over the shared `PlayerViewModel`, paired with `TvPlayerKeyHandler`, `TvProgressReports`, `TvResumeOnReturn`, `TvUpNextCard`, and `TvTrickplayThumbnail`.
- Launcher and ambient integrations live in `app/tv/.../ce/watchnext/` (`WatchNextSync`, `WatchNextPublisher`, `WatchNextPlanner`, `WatchNextRemovedReceiver`), `app/tv/.../ce/presentation/screensaver/` (`ScreensaverService`, `ScreensaverScreen`), and `app/tv/.../ce/thememusic/` (`ThemeMusicSession`, `ExoThemeMusicPlayer`).
- Test fast: `./gradlew :app:tv:testLibreDebugUnitTest` and `./gradlew :app:tv:compileLibreDebugKotlin`.

## What it does

When Room cannot open the saved database, the launcher shows the recovery message while WorkManager clears this app's visible Watch Next programs. Cleanup retries if TvProvider is unavailable. Hidden rows and dismissal history stay available for the next sync after a compatible build opens the database.

**App shell, packaging, and startup:** `app/tv` builds only the `libre` flavour (`app/tv/build.gradle.kts`, without `player/cast` or Google Play Services), requires `android.software.leanback`, and supports `minSdk = Versions.MIN_SDK` (`28`, Android 9 / Fire OS 7, #675). Phone and TV share `applicationId = "nl.midasvo.findroid.ce"` (with `.debug` / `.staging` suffixes, TV ADR 0005), while release builds set `EphyraVersion.TV_CODE` (`EphyraVersion.CODE + 1`) so Play Store and F-Droid rank the Leanback APK above phone, and beta builds share `1_000_000 + betaBuild`. `AppVariantModule` provides `AppVariant.TV` so shared ViewModels such as `SettingsViewModel` hide phone-only features (downloads, touch gestures, file editors) without inspecting device hardware (TV ADR 0007, TV ADR 0008). On startup, `BaseApplication` runs preference migrations, sets Coil's memory cache to 30% of memory class capped at 96 MB and defaults `imageCacheSize` to 100 MB (`TV_IMAGE_CACHE_SIZE_MB`, #155/#160) so Home hero backdrop prefetching does not evict posters, plants `WarningTree` in non-debug builds so player errors still reach `logcat`, and starts `WatchNextSync` and `ServerSessionKeeper`. `MainActivity` declares `android:configChanges="keyboard|keyboardHidden|navigation"` in `app/tv/src/main/AndroidManifest.xml` so Bluetooth remotes disconnecting/reconnecting on standby do not relaunch the activity (#1008), records D-pad key presses in `DirectionKeyClock`, reads incoming `WatchNextLink` intents, and triggers `watchNextSync.requestSync()` in `onStop()`.

**Manifest and permissions:** the merged manifest asks for `INTERNET`, `ACCESS_LOCAL_NETWORK`, `ACCESS_NETWORK_STATE` (from `device`) and `WRITE_EPG_DATA` (the Watch Next row), and nothing else. `app/tv/src/main/AndroidManifest.xml` removes what libraries merge in and the TV app does not use: `WAKE_LOCK`, `FOREGROUND_SERVICE` and WorkManager's `SystemForegroundService` (only for foreground work, which no worker here does), tvprovider's `READ_EPG_DATA`, and WorkManager's `DiagnosticsReceiver`. It also removes `RECEIVE_BOOT_COMPLETED` and WorkManager's `RescheduleReceiver`, so the app does not start at boot: after a reboot the Watch Next sync is scheduled again when the app is next opened, and the row keeps what it showed until then. The TV app posts no notifications, so it does not ask for `POST_NOTIFICATIONS`. Media3's `BluetoothValidationActivity` (Bluetooth media buttons on Android 16 and 17) and profileinstaller's `ProfileInstallReceiver` (baseline profiles) stay; the `BLUETOOTH_PRIVILEGED` and `DUMP` in the manifest guard those two and are not permissions the app asks for. `TvManifestTest` pins the list (#1045).

**Drawer and CE screens:** `MainScreen` pads drawer items with `DrawerStartPadding` (`TvSafeArea.horizontal - 12.dp`) and insets pages by `ClosedDrawerWidth` (`80.dp`) so icons, labels, and the 32 dp `UserAvatar` sit inside the 48 dp horizontal / 27 dp vertical `TvSafeArea` while the rail and focus pill may bleed into the overscan margin (#539, #567). Destinations switch on OK rather than focus; `DrawerFocus` distinguishes deliberate user D-pad moves (including cold-start keys from `DirectionKeyClock`) from focus falling into the drawer while a loading page rebuilds, using `LocalRestoreFocusSuppressed` so background reloads do not steal focus back from the drawer (#533). Back returns from other drawer destinations to Home, opens the drawer on Home, and finishes the activity when the drawer is already open (TV ADR 0002). Film screens (`HomeScreen` with focus-driven hero and background refresh, `LibraryScreen` with `LetterJumpBar` and `PositionCounter`, `CollectionScreen`, `MovieScreen`, `ShowScreen`, `SeasonScreen`, `PersonScreen`, `SearchScreen`, `FavoritesScreen`) consume the shared `modes/film` ViewModels and scope displayed state via `shownTo(LocalServerSession.current.userId)` so profile switches never flash the previous user's items (#810, #866). Episodes open on their season page via `EpisodeRoute` (#130), and `TvProfilePinGateScreen` blocks `NavDisplay` (including Watch Next launches) until a locked profile's PIN is entered (#299).

**D-pad focus and text entry:** CE screens use `rememberFocusPosition()`, `focusPosition()`, and `RestoreFocus` (which waits up to 60 frames, ignores stray focus gains such as initial window focus before restoration completes, resolves saved item IDs via `FocusPosition.resolve()`, skips restoration if `LocalRestoreFocusSuppressed` holds, and falls back to the default element halfway through) instead of `LaunchedEffect(true) { requestFocus() }` (TV ADR 0003). `HandOffFocusWhenGone` moves focus away when a focused button such as Restart disappears after a wake reload (#660, #1007). `NoBringIntoView` lets detail pages (`MovieScreen`, `ShowScreen`, `PersonScreen`) scroll themselves to the focused row (#407, #514). `TvTextFieldEditing` keeps text fields `readOnly` until OK is pressed so D-pad navigation does not open the IME on focus. `EphyraFocus` defines `ephyraFocusedBorder` (3 dp `primary`, 2 dp outside or `-1.5.dp` inside clipped containers), `ephyraFocusedGlow`, and `EphyraFocusScale` (`1.06f`, or `1f` under `reducedMotion()`).

**TV player (`TvPlayerScreen`):** Hosts Media3 `PlayerView` (`useController = false`, subtitle styling applied to `subtitleView`) over the shared `PlayerViewModel`. `TvPlayerKeyHandler` keeps remote key logic in plain Kotlin: with controls hidden, Left/Right seek by `playerTvSeekBackInc` / `playerTvSeekForwardInc` (default 10 s / 30 s) and accelerate with video duration on hold via `holdSeekMs` (issuing a single `seekTo` on key-up), OK opens the controls (and pauses when `playerTvOkPauses` is enabled, consuming its matching key-up via `okDown` so it does not double-trigger Play/Pause, #459), Up/Down show controls, Back closes `TvUpNextCard` or the overlay before leaving the player, and media keys work whether controls are shown or hidden. `TvProgressReports` reports progress every 5 s (`INTERVAL_MS`) while `STARTED` and on `ON_PAUSE` (deduplicated within 1 s via `MIN_GAP_MS`, #458), `TvResumeOnReturn` restores playback on `ON_RESUME` only if `playWhenReady` was true before `ON_PAUSE` and neither Still Watching nor an error blocks it (#462), and `TvBufferingIndicator`, `TvPlaybackProblem`, `TvSeekBar`, `TvTrickplayThumbnail`, `TvUpNextCard`, `TvSelectionDialog`, and `TvSubtitleDialog` handle the overlay and error UI.

**Watch Next, theme music, and screensaver:** `WatchNextSync` runs `WatchNextSyncWorker` via `WorkManager` on start, playback stop (`PlaybackEvents.stopped`), `MainActivity.onStop()`, and every 3 hours while connected (after a reboot only once the app has been opened again, #1045). `planWatchNext` merges Continue Watching and Next Up (honouring `hideSpoilers` and `MAX_WATCH_NEXT_PROGRAMS` = 20), suppresses items the user dismissed via `WatchNextRemovedReceiver` until their position changes, and `WatchNextPublisher` publishes `WatchNextProgram` rows with a `userId`-scoped `WatchNextLink` so another user's program never auto-plays (#138). `ThemeMusicSession` plays a show's theme song through `ExoThemeMusicPlayer` once per visit to `ShowScreen` unless another app already has active audio, fading out on leave, playback, backgrounding, or screensaver (#141). `ScreensaverService` (`DreamService`, configured by `ScreensaverSettingsActivity` / `ScreensaverSettingsScreen`) cycles library backdrops and logos in `ScreensaverScreen` (`ScreensaverItems`) when signed in and wakes on any key event (#140).

## Where the code is

| Path | What |
|---|---|
| [`app/tv/build.gradle.kts`](../../app/tv/build.gradle.kts) | `libre`-only flavour, `TV_CODE` / beta `versionCode`, `ephyra-*-tv-*.apk` naming, Robolectric unit test config |
| [`app/tv/.../MainActivity.kt`](../../app/tv/src/main/java/dev/jdtech/jellyfin/MainActivity.kt), [`BaseApplication.kt`](../../app/tv/src/main/java/dev/jdtech/jellyfin/BaseApplication.kt) | D-pad clock, Watch Next intent & sync hooks, TV image cache sizing, `WarningTree`, startup migrations |
| [`app/tv/.../NavigationRoot.kt`](../../app/tv/src/main/java/dev/jdtech/jellyfin/NavigationRoot.kt), [`NavigationRoutes.kt`](../../app/tv/src/main/java/dev/jdtech/jellyfin/NavigationRoutes.kt) | Nav 3 graph pointing TV routes at CE screens, PIN gate, Watch Next launch stack |
| [`app/tv/.../di/AppVariantModule.kt`](../../app/tv/src/main/java/dev/jdtech/jellyfin/di/AppVariantModule.kt), [`TvDownloadsModule.kt`](../../app/tv/src/main/java/dev/jdtech/jellyfin/di/TvDownloadsModule.kt) | Provides `AppVariant.TV` (ADR 0008) and no-op `DownloadQueuePort.None` / `DownloadDeleter.None` / `SmartDownloadChecker.None` bindings so `app/tv` does not link `:downloads` (#1048) |
| [`app/tv/.../ce/presentation/main/MainScreen.kt`](../../app/tv/src/main/java/dev/jdtech/jellyfin/ce/presentation/main/MainScreen.kt), [`DrawerProfileItem.kt`](../../app/tv/src/main/java/dev/jdtech/jellyfin/ce/presentation/main/DrawerProfileItem.kt) | Side `ModalNavigationDrawer`, `DrawerFocus`, Back stack/drawer handling, per-destination state |
| [`app/tv/.../ce/ui/focus/`](../../app/tv/src/main/java/dev/jdtech/jellyfin/ce/ui/focus/) | `FocusPosition`, `RestoreFocus`, `EphyraFocus`, `FocusHandOff`, `DirectionKeyClock`, `NoBringIntoView` |
| [`app/tv/.../ce/ui/`](../../app/tv/src/main/java/dev/jdtech/jellyfin/ce/ui/) | `TvSafeArea`, `TvTextFieldEditing`, `QrCode`, `PersonCard`, `ItemInfoLine`, `components/` (`TvLoadError`, `TvSortByDialog`, `TvOverviewText`, `UserAvatar`) |
| [`app/tv/.../ce/presentation/film/`](../../app/tv/src/main/java/dev/jdtech/jellyfin/ce/presentation/film/) | CE TV `HomeScreen`, `LibraryScreen`, `CollectionScreen`, `MovieScreen`, `ShowScreen`, `SeasonScreen`, `PersonScreen`, `SearchScreen`, `FavoritesScreen` |
| [`app/tv/.../ce/presentation/player/`](../../app/tv/src/main/java/dev/jdtech/jellyfin/ce/presentation/player/) | `TvPlayerScreen`, `TvPlayerKeyHandler`, `TvProgressReports`, `TvResumeOnReturn`, `TvBufferingIndicator`, `TvSeekBar`, `TvTrickplayThumbnail`, `TvUpNextCard`, dialogs |
| [`app/tv/.../ce/presentation/pin/`](../../app/tv/src/main/java/dev/jdtech/jellyfin/ce/presentation/pin/), [`ce/presentation/settings/`](../../app/tv/src/main/java/dev/jdtech/jellyfin/ce/presentation/settings/) | `TvProfilePinGateScreen`, `TvProfilePinScreen`, `TvPinPad`, `TvSettingsLayout`, `HomeRowsScreen`, `TvExternalRatingsScreen`, `about/` (`AboutScreen`, `DeviceProfileScreen`, `LicensesScreen`) |
| [`app/tv/.../ce/watchnext/`](../../app/tv/src/main/java/dev/jdtech/jellyfin/ce/watchnext/) | `WatchNextSync`, `WatchNextPlanner`, `WatchNextPublisher`, `WatchNextStore`, `WatchNextLink`, `WatchNextRemovedReceiver` |
| [`app/tv/.../ce/presentation/screensaver/`](../../app/tv/src/main/java/dev/jdtech/jellyfin/ce/presentation/screensaver/), [`ce/thememusic/`](../../app/tv/src/main/java/dev/jdtech/jellyfin/ce/thememusic/) | `ScreensaverService`, `ScreensaverScreen`, `ScreensaverSettingsActivity`, `ThemeMusicSession`, `ExoThemeMusicPlayer` |
| [`scripts/tv-dpad.sh`](../../scripts/tv-dpad.sh) | `uinput` D-pad driver for TV emulators (150 ms key holds) |

## Rules

- **R1, R2, R4, R10, R11**: no Jellyfin SDK types, `JellyfinApi`, or `ServerDatabaseDao` in `app/tv`; use typed IDs (`ItemId`, `MediaSourceId`, `UserId`, `ServerId`) rather than bare `String` IDs outside the adapter; no new `Findroid*` or `Jellyfin*` types (existing `FindroidTheme` is allowlisted in `architecture/baseline/`).
- CE screens go beside upstream's (TV ADR 0001): put new TV screens and helpers under `app/tv/.../ce/` and wire routes in `NavigationRoot.kt`; do not delete unused upstream TV files unless an upstream sync conflicts.
- Focus restoration (TV ADR 0003): never add `LaunchedEffect(true) { focusRequester.requestFocus() }` in a CE screen; use `rememberFocusPosition()` / `focusPosition()` / `RestoreFocus`, show visible focus (ring/scale), and return dialog focus to the element that opened the dialog.
- No downloads on TV, and the variant decides (TV ADR 0007, TV ADR 0008): keep downloads and offline UI out of TV; gate UI differences with `AppVariant.TV` rather than `FEATURE_LEANBACK` (which stays reserved for hardware checks such as decoders, tunneling, and refresh rate).
- `app/tv` has only `libre` (no Google Play Services or Cast); use `ce_` string keys translated across all 36 languages (`check-translations.py`) and never edit upstream `values-<lang>/strings.xml` files.

## How to test it

Fastest unit test and compile commands:

```bash
./gradlew :app:tv:testLibreDebugUnitTest
./gradlew :app:tv:compileLibreDebugKotlin
```

Unit tests in `app/tv/src/test/` run on the JVM with Robolectric and `androidx.compose.ui.test.junit4` (`isIncludeAndroidResources = true`):
- **Drawer & focus restore:** `MainScreenTest`, `MainFocusReturnTest`, `MainReturnLoadsTest`, `DrawerSafeAreaTest`, `FocusPositionTest`, `FocusRingTest`, `SafeAreaTest`, `CollectionFocusRestoreTest`, `FavoritesFocusRestoreTest`, `LibraryFocusRestoreTest`, `PersonFocusRestoreTest`, `SeasonFocusRestoreTest`, `WakeReloadFocusTest`, `LicensesFocusRestoreTest`, `UsersFocusRestoreTest`.
- **Film & setup screens:** `HomeRowUpdateTest`, `HeroImagesTest`, `DetailDownToRowTest`, `DetailOverviewTest`, `MovieResumeTest`, `MovieSpinnerTest`, `SeasonEmptyTest`, `SeasonWakeReloadTest`, `SearchErrorTest`, `TvCreditsTest`, `TvLoadErrorTest`, `TvSortByDialogTest`, `TvPinPadTest`, `LoginKeyboardTest`, `LoginServerButtonFocusTest`.
- **TV player:** `TvPlayerKeyHandlerTest`, `TvProgressReportsTest`, `TvResumeOnReturnTest`, `TvBufferingIndicatorTest`, `TvPlaybackProblemTest`, `TvQueueCaptionTest`, `TvTrickplayThumbnailTest`.
- **Settings, Watch Next, theme music & screensaver:** `SettingsCapabilitiesTest`, `SettingsTreeVariantTest`, `TvSettingsLayoutTest`, `TvSettingsNumberStepsTest`, `WatchNextPlannerTest`, `WatchNextSpoilersTest`, `ThemeMusicSessionTest`, `ScreensaverTest`, `ScreensaverItemsTest`, `ScreensaverSettingsScreenTest`, `TvImageCacheSizeTest`, `DeviceTransferRulesTest`, `TvManifestTest`, `RouteIdsSerializationTest`.

For manual D-pad testing on a TV emulator (`ce_tv_1080p`, `ce_tv_4k`, or an `adb` serial):

```bash
scripts/tv-dpad.sh ce_tv_1080p down down ok
```

`scripts/tv-dpad.sh` registers a `uinput` device and holds each key for 150 ms instead of calling `adb shell input keyevent`, because virtual `input keyevent` keys do not move focus out of Compose text fields on login, search, and PIN screens and miss hold-key timing bugs.

**What unit tests do not cover:**
- Hardware playback on real TV boxes (tunneling, mono audio fallback #924, Dolby Vision/HDR, HDMI passthrough, display refresh-rate switching; see TV ADR 0004 and [mpv-checklist.md](../mpv-checklist.md)).
- Real Android TV launcher `TvProvider` Watch Next row rendering, dismissal broadcasts (`WatchNextRemovedReceiver`), and system `DreamService` activation (`ScreensaverService` / `ScreensaverSettingsActivity`).
- Visual overscan safe-area alignment, software IME interaction on text fields, and end-to-end remote navigation across screens without `scripts/tv-dpad.sh` or a physical remote.

## Before a PR

```bash
./gradlew ktfmtCheck
./gradlew :app:tv:testLibreDebugUnitTest
./gradlew :app:tv:compileLibreDebugKotlin
./gradlew :architecture:test
python .claude/skills/translate-strings/scripts/check-translations.py   # when strings changed
```

## Decisions and history

- [TV ADR 0001](../tv-research/adr/0001-new-ce-screens-next-to-upstream.md), [TV ADR 0002](../tv-research/adr/0002-side-navigation-drawer.md), [TV ADR 0003](../tv-research/adr/0003-focus-restore.md), [TV ADR 0004](../tv-research/adr/0004-tv-player-ui.md) ([#121](https://github.com/midasvo/ephyra/issues/121), [#125](https://github.com/midasvo/ephyra/issues/125), [#127](https://github.com/midasvo/ephyra/issues/127)): CE screens in `ce/` next to upstream, collapsed-to-rail side drawer, `FocusPosition` / `RestoreFocus`, and Compose TV player over `PlayerViewModel`.
- [TV ADR 0005](../tv-research/adr/0005-application-id.md), [TV ADR 0006](../tv-research/adr/0006-release-tv-apk.md), [TV ADR 0007](../tv-research/adr/0007-no-offline-on-tv.md), [TV ADR 0008](../tv-research/adr/0008-tv-flag-in-shared-modules.md) ([#124](https://github.com/midasvo/ephyra/issues/124)/[#143](https://github.com/midasvo/ephyra/pull/143), [#133](https://github.com/midasvo/ephyra/issues/133), [#173](https://github.com/midasvo/ephyra/issues/173)/[#178](https://github.com/midasvo/ephyra/pull/178)): shared `applicationId` with higher release `versionCode` (`EphyraVersion.TV_CODE`), TV beta/release APKs (`ephyra-v*-libre-tv-*.apk`), no downloads UI on TV, and `AppVariant.TV` for shared ViewModels.
- [#128](https://github.com/midasvo/ephyra/issues/128), [#130](https://github.com/midasvo/ephyra/issues/130), [#134](https://github.com/midasvo/ephyra/issues/134), [#136](https://github.com/midasvo/ephyra/issues/136), [#137](https://github.com/midasvo/ephyra/issues/137), [#211](https://github.com/midasvo/ephyra/issues/211): CE `SearchScreen`, `SeasonScreen` (opening episodes in their season), `TvTrickplayThumbnail`, `PersonScreen`, `FavoritesScreen`, and TV `AboutScreen` (with bug-report QR code) / `LicensesScreen` / `DeviceProfileScreen`.
- [#138](https://github.com/midasvo/ephyra/issues/138)/[#161](https://github.com/midasvo/ephyra/pull/161), [#140](https://github.com/midasvo/ephyra/issues/140), [#141](https://github.com/midasvo/ephyra/issues/141): launcher Watch Next sync/dismissal/deep-link, `ScreensaverService`, and `ShowScreen` theme music (`ThemeMusicSession`).
- [#155](https://github.com/midasvo/ephyra/issues/155)/[#160](https://github.com/midasvo/ephyra/pull/160), [#286](https://github.com/midasvo/ephyra/issues/286)/[#582](https://github.com/midasvo/ephyra/pull/582), [#675](https://github.com/midasvo/ephyra/pull/675): 100 MB TV image disk cache default + 30%/96 MB memory cache, `baselineprofile-tv`, and API 28 (`minSdk`) support for Fire OS 7.
- [#458](https://github.com/midasvo/ephyra/issues/458)/[#495](https://github.com/midasvo/ephyra/pull/495), [#486](https://github.com/midasvo/ephyra/issues/486)/[#565](https://github.com/midasvo/ephyra/pull/565), [#865](https://github.com/midasvo/ephyra/issues/865)/[#880](https://github.com/midasvo/ephyra/pull/880): `TvProgressReports` periodic & `ON_PAUSE` reporting, `TvBufferingIndicator`, and spoiler-free TV player queue/up-next captions.
- [#355](https://github.com/midasvo/ephyra/issues/355), [#531](https://github.com/midasvo/ephyra/pull/531), [#532](https://github.com/midasvo/ephyra/pull/532), [#533](https://github.com/midasvo/ephyra/issues/533)/[#539](https://github.com/midasvo/ephyra/issues/539)/[#540](https://github.com/midasvo/ephyra/issues/540)/[#555](https://github.com/midasvo/ephyra/pull/555), [#810](https://github.com/midasvo/ephyra/issues/810)/[#866](https://github.com/midasvo/ephyra/issues/866)/[#873](https://github.com/midasvo/ephyra/pull/873), [#1007](https://github.com/midasvo/ephyra/pull/1007), [#1008](https://github.com/midasvo/ephyra/issues/1008): D-pad audit, `DrawerFocus` + `TvSafeArea` drawer inset, profile lock polish, user-scoped `shownTo` state on profile switch, `HandOffFocusWhenGone` when wake reloads remove Restart, and `MainActivity` remote `configChanges` + `RestoreFocus` protection on recreation.

## Pitfalls

- **`adb shell input keyevent` misses TV focus bugs.** Virtual `input keyevent` keys do not move focus out of Compose text fields on login, search, or PIN screens and flatten press/hold timing; always drive TV emulators with `scripts/tv-dpad.sh` (`uinput`).
- **Never read `drawerState.currentValue` in `MainScreenLayout` composition.** The drawer opens and closes on every Left/Right move into the rail; reading `drawerState.currentValue` during composition recomposes the whole screen and its content on each move (#257). Read it only inside `BackHandler` and callbacks.
- **Keep `DrawerFocus` and `LocalRestoreFocusSuppressed` wired when changing `MainScreen`.** Returning from Settings or profile switching triggers background reloads on Home; without `LocalRestoreFocusSuppressed`, `RestoreFocus` steals focus out of the drawer back onto Home (#533). Conversely, `DrawerFocus` releases focus back to content if focus only drifted into the rail while a destination was reloading.
- **Filter shared ViewModel state by `LocalServerSession.current.userId` (`shownTo`).** `MainScreen` and its ViewModels survive user switches; without `shownTo(userId)`, the previous user's rows, libraries, search results, or favourites flash for a frame before reloading (#810, #866).
- **The setup screens reuse each other's entry on the one TV back stack.** `NavigationRoot.kt` opens the server list from Users and Login, and the Users screen from Servers and Add server, with `navigateOrReuse`: a route already on the stack is returned to and everything above it is popped (#1071). Settings and "ask who is watching" still push their Users screen with `navigate`; a walk to the server list and back from there ends on that same Users screen. The setup guide's pitfall has the rest ([`setup-and-servers.md`](setup-and-servers.md)).
- **Consuming OK-down in `TvPlayerKeyHandler` must also swallow its matching OK-up.** Showing controls moves focus onto Play/Pause; letting OK-up through presses Play/Pause immediately (`okDown` + `forgetOkPress()`, #459).
- **Do not put `focusRestorer` on `LibraryScreen` with `LetterJumpBar` or `animateItem()` in paged grids.** `focusRestorer` intercepts programmatic focus requests after a letter jump and redirects them to the old card, so `LibraryScreen` uses `focusProperties { enter = ... }` instead and avoids `animateItem()` in the paged grid (#257).
- **Respect `TvSafeArea` and focused card/button overhang.** Focused cards scale (`1.06f`) and draw `ephyraFocusedBorder` 2 dp outside their bounds (use `inside = true` when clipped, as in drawer items or settings groups); buttons near the screen edge need room like `FOCUSED_BUTTON_OVERHANG` so the focus ring is not cut off (#539).
- **A dependency can add a permission to the TV manifest without a line of ours changing.** Libraries merge their own manifest in (work-runtime brought `WAKE_LOCK` and `FOREGROUND_SERVICE`, tvprovider `READ_EPG_DATA`). `TvManifestTest` fails when the list changes: add the permission there with its reason, or remove it in the manifest with `tools:node="remove"`. A worker that calls `setForeground` or `setExpedited` needs `WAKE_LOCK`, `FOREGROUND_SERVICE` and `SystemForegroundService` back first, or it crashes (#1045).
- **A release build runs R8, and R8 removes what nothing reaches.** `app/tv/proguard-rules.pro` keeps the names of app classes and of the navigation routes, not the classes themselves (#1047, the same rules as the phone; `docs/performance.md` has the why). A class that is only created from a name in a string needs a rule of its own, and the unit tests and a debug build do not show when one is missing: build `:app:tv:assembleLibreRelease` and open the screen on an emulator.
- **Use `testLibreDebugUnitTest`, not `testDebugUnitTest`.** `app/tv` declares the `libre` product flavour (`app/tv/build.gradle.kts`), so unflavoured Gradle task names fail `check-docs.py` and Gradle builds.
