Settings
Status: AppPreferences (over SharedPreferences), a view model per settings page over one shared SettingsTree (#969), and the phone and TV screens; adapters and downloads read preferences through ports (rule R17), and so do the view models outside settings (rule R23, #969). As of 2026-12-01 (main).
Start here
Section titled “Start here”- Preferences are stored in
AppPreferences(settings/.../domain/AppPreferences.kt) over Android’sSharedPreferences(<packageName>_preferencesincore/.../di/SharedPreferencesModule.kt), with typedPreferencedescriptors (Boolean,Int,Long,Float,String?,Set<String>). - Each settings page has its own view model in
settings/.../presentation/settings/(#969):SettingsViewModel(the top page),LanguageSettingsViewModel,InterfaceSettingsViewModel,DetailPagesSettingsViewModel,PlayerSettingsViewModel,SubtitleStyleSettingsViewModel(TV),MpvSettingsViewModel,DownloadSettingsViewModel,NetworkSettingsViewModel,CacheSettingsViewModelandPermissionsSettingsViewModel. Each lists only its own rows and extendsSettingsPageViewModel.SettingsTreeis the code they share: it filters rows byAppVariant(ADR 0008 / #133),ServerCapabilities(ServerFeature, #769),minSdkand booleandependencies, fills in the values with the bounds, and saves a change.SettingsPagemaps a route’sindexesto the page. A setting goes on the page that shows it, sosettingsstays the one module that knows every preference. - Phone screens live in
app/phone/.../presentation/settings/(SettingsScreen.kt+components/). TV routes both top-level (SettingsScreen.kt) and nested (SettingsSubScreen.kt) categories throughTvSettingsLayout(app/tv/.../ce/presentation/settings/TvSettingsLayout.kt, #347). - Adapters (
data,server/jellyfin,ratings/mdblist,device) anddownloadsnever referenceAppPreferencesdirectly (R17, R18);core/.../di/AppPreferencesPorts.ktimplements theapplicationports (DownloadSettings,CurrentServerId,NextUpMaxDays,NetworkTimeouts,ExternalRatingsSettings,ResumeThresholdsStore) overAppPreferences. - View models outside
settingsread the settings through ports too (R23, #969):PlayerSettings,StillWatchingSettings,MediaSegmentSettings,InterfaceSettings,DetailPageSettings(withDetailSections),HomeSettings,LibrarySettingsandSignedInUserinapplication/.../settings/ports/, andCurrentServerSelection(follow or pick the current server) inapplication/.../repository/. All are implemented inAppPreferencesPorts.kt. A port can return a type ofdomaininstead of the stored string:PlayerSettings.autoPlayNextis anAutoPlayNextSetting, and an unset or unknown value maps toSERVERthere (step 10 of ADR 0003). A setting a feature reads goes on the port of its area; only the view models ofsettingstakeAppPreferences. - Test fast:
./gradlew :settings:testDebugUnitTestand./gradlew :app:tv:testLibreDebugUnitTest --tests '*Settings*'.
What it does
Section titled “What it does”AppPreferences wraps SharedPreferences with getValue, observe (callbackFlow over OnSharedPreferenceChangeListener), and setValue (apply()). If reading a key fails (for example after a type mismatch), getValue resets it to defaultValue and returns that default. Alongside user-facing settings, AppPreferences holds internal state (currentServer as ServerId via currentServerId()/setCurrentServerId(), #902; cached session credentials sessionServerId, sessionBaseUrl, sessionAccessToken, sessionUserId, sessionServerType, #250, #770; playerBrokenAudioDecoders; smartDownloadsSince; localNetworkPermissionDecided; library sortBy/sortOrder/filterWatched; and one-shot migration flags). backup_rules.xml and data_extraction_rules.xml exclude the whole sharedpref domain from backups and device-to-device transfers (#731) so session tokens and mdbListApiKey never leave the device.
BaseApplication.onCreate() runs one-shot preference migrations at startup:
migrateMpvAudioOutput()(#52) moves"aaudio"inplayerMpvAotoConstants.MpvAudioOutput.AUDIOTRACKonce (mpvAoAaudioMigrated).migrateMediaSegmentActions()(#271) converts the removed global segment switches and type lists viaMediaSegmentsMigration.actions()into per-type actions (INTRO,OUTRO,RECAP,PREVIEW,COMMERCIAL), guarded bymediaSegmentActionsMigrated.removeOfflineMode()(#281) removespref_offline_modeif present.- Phone’s
BaseApplicationcallsmigrateMaxBitratePerNetwork()(#837) to copyplayerMaxBitrate(Wi-Fi/Ethernet) toplayerMaxBitrateMobileonce when the mobile key is absent; TV’sBaseApplicationcallsuseTvImageCacheSize()to defaultimageCacheSizetoTV_IMAGE_CACHE_SIZE_MB(100 MB) when unset.
A settings route holds a path of page names (indexes: List<Int>, the string IDs of the rows that open them). SettingsPage.of(indexes) walks it from the top page: each name opens the page below with that name, a name that is no such page is skipped, and title_settings ends the walk (the phone opens Settings with it). The phone’s SettingsScreen and TV’s SettingsSubScreen then take that page’s view model (settingsPageViewModel, one when per app); TV’s SettingsScreen is always the top page. Each page view model builds SettingsState from its own rows (groups) through SettingsTree.present:
- Filters by
supportedDeviceTypes(AppVariant.PHONEorAppVariant.TV, injected via each app’sAppVariantModule). The Interface and Player pages also checkWideWindow.isPossible(#622),KeepPlayerLandscape.isShown(#363) andCastBuild.isIncluded(#626, bound via each app/flavor’sCastBuildModule). - Filters groups and items by
ServerFeature(MEDIA_SEGMENTS,TRICKPLAY,THEME_SONGS) againstCurrentServerCapabilities.get(), and hides the"server"option fromplayerAutoPlayNextviawithoutServerChoice()whenautoPlayNextSettingis false (#769). - Clamps
subtitleFontScale(50..200),smartDownloadsKeepReady(>= 1), andstillWatchingPromptTimeoutSeconds(>= 5) withAppPreferences.bounded()(#559) both on load and on save (SettingsTree.save). - Formats
PreferenceIntInputlabels withnumberInputText()(#400) for plurals (suffixPluralsRes) and zero states (zeroLabelRessuch as “Off” or “No limit”). DownloadSettingsViewModelreads the download storage options onDispatchers.IOon every load and setssmartDownloadsSincewhen Smart Downloads is turned on;CacheSettingsViewModelclears Coil +HomeCacheviaAppCaches.clear()(AppCachesModule).
Dedicated sub-screens in settings/ and the apps handle custom flows: ExternalRatingsSettingsViewModel (#331), SubtitleStyleViewModel (phone’s SubtitleStyleScreen, #308), SettingsFileEditViewModel (phone’s mpv/mpv.conf and mpv/input.conf editor), HomeRowsScreen (#142), AboutScreen + LicensesScreen (and TV’s DeviceProfileScreen, #211, #384, #492), and TV’s ScreensaverSettingsActivity/ScreensaverSettingsScreen (#140).
Where the code is
Section titled “Where the code is”| Path | What |
|---|---|
settings/.../domain/AppPreferences.kt |
Typed Preference keys, SharedPreferences read/write/observe, startup migrations, currentServerId |
settings/.../domain/IntPreferenceBounds.kt, MediaSegmentsMigration.kt |
Bounded integer clamping (#559) and pure per-type segment migration (#271) |
settings/.../domain/VideoQualities.kt, QualityNetwork.kt (in domain since step 15 of #970) |
Bitrate-only quality ladder (#837, #1021) and metered-network split |
settings/.../domain/WideWindow.kt, KeepPlayerLandscape.kt, CastBuild.kt |
Visibility checks for tablet/foldable layout, orientation lock, and Cast settings |
settings/.../domain/AppCaches.kt, Constants.kt |
Cache-clearing port and default constants (subtitle style, mpv ao, still-watching min, network timeouts) |
settings/.../presentation/models/ |
Preference UI models (PreferenceSwitch, PreferenceSelect, PreferenceIntSelect, PreferenceDynamicSelect, PreferenceIntInput, PreferenceLongInput, PreferenceCategory, PreferenceAction, PreferenceFileEdit, PreferencePermission, PreferenceAppLanguage, PreferenceMultiSelect), ServerFeature, numberInputText |
settings/.../presentation/settings/SettingsTree.kt, SettingsPageViewModel.kt, SettingsPage.kt |
What every page shares (filtering, values, bounds, saving), the base view model of a page (state, events, rows that open pages and screens), and the pages with the walk from a route’s indexes |
settings/.../presentation/settings/SettingsViewModel.kt, PlayerSettingsViewModel.kt, and the other *SettingsViewModel.kt next to them |
One view model per page with that page’s rows; SettingsAction/SettingsEvent are shared |
settings/.../presentation/ratings/ExternalRatingsSettingsViewModel.kt, SubtitleStyleViewModel.kt, SettingsFileEditViewModel.kt |
Sub-screen ViewModels for MDBList ratings (#331), phone subtitle style (#308), and mpv.conf/input.conf |
core/.../di/AppPreferencesPorts.kt, AppPreferencesModule.kt, SharedPreferencesModule.kt |
AppPreferences DI and application port implementations (DownloadSettings, CurrentServerId and CurrentServerSelection, NextUpMaxDays, NetworkTimeouts, ExternalRatingsSettings, ResumeThresholdsStore, and since #969 the view models’ settings ports) |
application/.../settings/ports/ |
The settings ports of the view models, per area (#969) |
core/.../core/settings/SharedPreferencesResumeThresholdsStore.kt |
Per-server resume thresholds persisted in SharedPreferences (#637, #918) |
app/phone/.../presentation/settings/SettingsScreen.kt, components/ |
Phone settings screen, sub-screens (AboutScreen.kt, LicensesScreen.kt, SubtitleStyleScreen.kt, HomeRowsScreen.kt, ExternalRatingsScreen.kt, SettingsFileEditScreen.kt), and card/dialog components |
app/tv/.../presentation/settings/SettingsScreen.kt, SettingsSubScreen.kt, TvSettingsLayout.kt |
TV root/sub-settings screens and shared two-pane D-pad layout (#347, #419, #420) |
app/tv/.../ce/presentation/settings/about/ |
TV AboutScreen, DeviceProfileScreen, and LicensesScreen (#211) |
app/phone/.../di/AppVariantModule.kt, app/tv/.../di/AppVariantModule.kt, CastBuildModule.kt |
AppVariant.PHONE / AppVariant.TV, CastBuild per flavour, and each app’s AppCachesModule |
- R17 (
AdapterSettingsTest.kt): no production file ofdata,server/jellyfin,ratings/mdblist,device, ordownloadsmay nameAppPreferences. Expose new settings needed by adapters or the download engine through a port inapplicationand implement it incore/.../di/AppPreferencesPorts.kt(#918). - R23 (
ViewModelSettingsTest.kt): no view model outsidesettingsnamesAppPreferences,Context,Application,@ApplicationContextorAndroidViewModel. Add the setting to the port of its area inapplication/.../settings/ports/(a new port if the area has none) and implement it inAppPreferencesPorts.kt; keep the key, the default and whether it is read live or once (#969). - R18 (
AdapterDependencyTest.kt): no adapter module (data,server/jellyfin,ratings/mdblist,device) may depend on a feature module such assettingsin production. - R1, R2, R10:
settingsstays free of Jellyfin SDK types/JellyfinApi, and uses typed IDs (ServerId) rather than bareStringIDs outside the adapter. - Translations and
AppVariant: every user-visible CE string or plural must use ace_key instrings.xmland be translated into all 36 languages (check-translations.py), never editing upstream translation files. Variant-only UI decisions useAppVariant(ADR 0008), notFEATURE_LEANBACK.
How to test it
Section titled “How to test it”Fastest unit test commands:
./gradlew :settings:testDebugUnitTest./gradlew :app:tv:testLibreDebugUnitTest --tests '*Settings*'Also relevant when touching ports, backup rules, or phone licenses:
./gradlew :core:testLibreDebugUnitTest --tests '*SharedPreferencesResumeThresholdsStoreTest*'./gradlew :app:phone:testLibreDebugUnitTest --tests '*LicenseDialogTextTest*' --tests '*DeviceTransferRulesTest*'./gradlew :architecture:test --tests '*AdapterSettingsTest*'Unit tests in settings/src/test/ and app/tv/src/test/.../settings/:
settings:IntPreferenceBoundsTest,MaxBitratePerNetworkTest,MediaSegmentsMigrationTest,RemoveOfflineModeTest,VideoQualitiesTest,NumberInputTextTest,ExternalRatingsSettingsViewModelTest,SettingsPageTest(the walk from a route to a page).app/tv:SettingsCapabilitiesTest,SettingsTreeVariantTest,SettingsPagesTest(each page’s rows, bounds, dependencies, storage, Smart Downloads, Clear cache, the rows that open pages),TvSettingsLayoutTest(Robolectric Compose D-pad focus + Back behaviour),TvSettingsNumberStepsTest. TheirsettingsPageViewModelhelper picks the view model for a path as the screens do.app/phone:CastBuildSettingTest,KeepLandscapeSettingTest(onPlayerSettingsViewModel).
What unit tests do not cover:
SettingsScreenon phone (app/phone/.../presentation/settings/SettingsScreen.kt),SubtitleStyleScreen,SettingsFileEditScreen, and phone dialogs (SettingsNumberInputDialog,SettingsSelectDialog): these are checked by hand on a phone or tablet emulator.getStorageOptions()with multiple physical/emulated storage volumes (StatFson external dirs), Android 13+Settings.ACTION_APP_LOCALE_SETTINGS, runtime permission prompts (SettingsPermissionCard), and actualBaseApplicationstartup migrations on an upgraded APK.TvSettingsLayoutvisual alignment, overscan safe area, and D-pad traversal across every TV settings sub-screen on a TV emulator (scripts/tv-dpad.sh).
Before a PR
Section titled “Before a PR”./gradlew ktfmtCheck./gradlew :settings:testDebugUnitTest./gradlew :app:tv:testLibreDebugUnitTest --tests '*Settings*'./gradlew :app:phone:testLibreDebugUnitTest --tests '*LicenseDialogTextTest*' --tests '*DeviceTransferRulesTest*'./gradlew :core:testLibreDebugUnitTest --tests '*SharedPreferencesResumeThresholdsStoreTest*'./gradlew :architecture:test./gradlew :app:phone:compileLibreDebugKotlin :app:tv:compileLibreDebugKotlinpython3 .claude/skills/translate-strings/scripts/check-translations.py # when strings changedDecisions and history
Section titled “Decisions and history”- TV ADR 0008 / #133:
AppVariant(PHONEvsTV) injected from each app filters shared settings (now inSettingsTree) instead of inspecting device hardware. - #347, #524: unified
TvSettingsLayoutfor both root and nested TV settings pages, plus D-pad focus return onLeft/Back(#419), whole-second stepping for millisecond settings (#420), hiding the phone-onlyAdvancedfile-editor group on TV (#421), and screensaver summary spacing (#422). - #211, #384, #503, #492: dedicated TV
AboutScreen/DeviceProfileScreen/LicensesScreen, phone license text fallback (LicenseDialogTextTest), and Android 11+ device profile export. - #736 / #793, #918 / #927 / #926: dropped the unused Jellyfin SDK dependency from
settings, and moveddata,server/jellyfin, anddownloadsoffAppPreferencesontoapplicationports inAppPreferencesPorts.kt(rule R17). - #969: the view models outside
settingstake settings ports instead ofAppPreferences, and ports instead of aContext(AboutInfoSource,StorageVolumes,PlayerTexts,PlayerMediaSessions,PlayerDevice,PermissionDecision); rule R23. Part 2 split the oneSettingsViewModel(1850 lines) into a view model per page overSettingsTree, withSettingsPagefor the walk; a category row no longer carries the page below it (PreferenceCategory.nestedPreferenceGroupsis gone).SubtitleStyleViewModelandExternalRatingsSettingsViewModelstay onAppPreferences: they are settings screens insettings, the one module that knows the keys, and a port for them would only copy those keys. - #769:
ServerFeatureandwithoutServerChoice()hide settings for features the current server lacks (ServerCapabilities), re-evaluated on every load of a page. - #271, #281, #837, #52: one-shot migrations for per-type media segment actions (
MediaSegmentsMigration), removing Offline Mode (removeOfflineMode), splitting Wi-Fi vs mobile streaming quality (migrateMaxBitratePerNetwork), and moving mpvaooff"aaudio"(migrateMpvAudioOutput). - #400, #559, #1021: singular/plural and zero-label number formatting (
numberInputText), clamping bounded integer preferences on both load and save (AppPreferences.bounded), and bitrate-only quality labels (VideoQualities). - #950 / #958: added
navigate_backcontent description to the phone settings top bar Back button.
Pitfalls
Section titled “Pitfalls”- The settings screens reload after
OnUpdate, and a page is found by string IDs.SettingsPage.of(indexes)walksSettingsPage.nameStringResourcefrom the top (for example, TV’sNavigateToSubtitleStylemust pass bothsettings_category_playerandsubtitle_style). Renaming a page’s string resource requires updating any hardcoded navigationindexeslist too (such asNavigationRoot.ktorSettingsScreen.kton TV). A new page needs aSettingsPageentry, a view model, apageCategoryrow on its parent, and a branch in both apps’settingsPageViewModel(thewhenis exhaustive, so the build says where). - Boolean
dependenciesonly disable a row; they do not hide it. OnSettingsBaseCard(phone) andTvSettingsRow(TV),enabled = falsedims/disables interaction when anyPreferenceBackend<Boolean>independenciesisfalse. To hide a setting entirely per variant or server capability, usesupportedDeviceTypesorserverFeature, notdependencies. - TV has no
PreferenceIntInput/PreferenceLongInputtext dialog or file editor.TvSettingsLayoutedits number settings in the right details pane with+1/-1/+10/-10steps (scaled by1000LwhensuffixRes == R.string.ms, #420) and clamps at>= 0. Phone-only features likePreferenceFileEdit(mpv.conf/input.conf) andPreferenceIntSelectstreaming quality selectors must declaresupportedDeviceTypes = listOf(DeviceType.PHONE)so TV does not show an uneditable or broken row (#421). - Adding a bounded
Intpreference needsAppPreferences.bounded()on both load and save. Without clamping inIntPreferenceBounds.kt, the UI saves and displays raw out-of-range numbers such as0 seven if the consumer treats0as a minimum like5 s(#559). - Sensitive keys live in the same
SharedPreferencesfile.sessionAccessTokenandmdbListApiKeyare stored inAppPreferencesalongside UI toggles; keepsharedprefexcluded in bothbackup_rules.xmlanddata_extraction_rules.xml(DeviceTransferRulesTest, #731). - Adding a new
Preferencesubclass requires updating both UI renderers.SettingsGroupCard.kt(phone) andTvSettingsPreference/TvSettingsDetailsinTvSettingsLayout.kt(TV) switch exhaustively overPreferencesubtypes (note TV currently omitsPreferenceDynamicSelect,PreferenceIntSelect,PreferenceAppLanguage, andPreferenceFileEdit, relying onsupportedDeviceTypes = listOf(DeviceType.PHONE), becauseTvSettingsPreference’swhendoes not handle them if shown on TV). SharedPreferenceslisteners and migrations.AppPreferences.observeusesOnSharedPreferenceChangeListenerinsidecallbackFlow(SharedPreferencesholds weak references to listeners, so keep the flow collected). Startup migrations that flip a default (migrateMpvAudioOutput,migrateMediaSegmentActions) must keep a one-shot guard flag so a user’s deliberate choice afterwards is not overwritten on the next launch.
Source: docs/areas/settings.md · raw Markdown