Setup, servers and users
Status: built, on phone and TV; Jellyfin is the only server type with an adapter. As of 2026-11-23 (main at b24b19d54).
Start here
Section titled “Start here”- Setup is
setup/:SetupRepositoryImpl(servers, addresses, users in Room through the roles of the server store,StoredServers,ServerAddresses,StoredUsers,UserLocks, #967) and the ViewModels insetup/.../presentation/. - It talks to a server through the
ServerConnectorport; Jellyfin’s isJellyfinServerConnectorinserver/jellyfin. - The server in use is one
ActiveServeronActiveServerHolder, switched whole (rule R16);CurrentMediaServerincorepicks the adapter. - Ports: the device’s
RuntimePermissions(the permission screen andLocalNetworkAccessImpl) andNetworkSignals(ServerReachability), both implemented indevice(#998, R28);ServerConnector(before a session),MediaServerand itsServerSession(after: the session keeper and reachability), the roles of the server store (StoredServers,ServerAddresses,StoredUsers,UserLocks: servers, addresses, users and their locks in Room),ActiveServerHolder. - Test fast:
./gradlew :setup:testDebugUnitTest :core:testLibreDebugUnitTest. On a device: userstester,second,nopass;forward.pyfor a second address. - A setup flow PR that no review bot read gets an independent review before it merges.
What it does
Section titled “What it does”Setup finds a server (discovery on the local network, or an address typed in), checks it, saves it and signs a user in: with a password, a public user’s tile or Quick Connect. Later the user adds and removes servers, addresses and users, and switches between them. The server in use is one ActiveServer value (type, address, token, user) on ActiveServerHolder: a switch replaces it whole, so a request never sees one server’s adapter with another’s address or token (#899). CurrentMediaServer picks the adapter by the server’s type. At start, SavedSessionRestorer puts the last session back from a copy in preferences, without waiting for Room. While the app runs, ServerSessionKeeper keeps the server’s session open and signs out a revoked token, and ServerReachability follows whether the server answers (phone only). Profiles and the PIN lock are their own area (profiles: setup/.../presentation/pin/, docs/profiles/).
Where the code is
Section titled “Where the code is”| Path | What |
|---|---|
setup/.../setup/data/SetupRepositoryImpl.kt |
Servers, addresses and users in Room; talks to a server through its connector; one of the two places that call switchTo |
setup/.../setup/domain/SetupRepository.kt |
Its interface; also AddressRejected, LocalNetworkAccess, ServerLocalNetworkBlock there |
setup/.../setup/presentation/ |
ViewModels and State/Action: addserver, addresses, login, servers, users, welcome (actions only), localnetwork, permission, quickconnect (approving another device’s code from the profile sheet, #855) |
domain/.../domain/ports/ServerConnector.kt |
The port before there is a session: discover, resolve, find an address, public users, login, Quick Connect, end a session. Two calls take a token: endSession and authorizeQuickConnect (#855), which approves the code another device shows |
server/jellyfin/.../server/jellyfin/JellyfinServerConnector.kt |
The Jellyfin implementation; bound in JellyfinServerModule.kt |
domain/.../domain/ports/ActiveServer.kt |
ActiveServer and ActiveServerHolder (switchTo, onSameServer) |
core/.../core/server/ |
CurrentMediaServer, ServerConnectors (by ServerType), UnsupportedMediaServer, StoredType.kt |
core/.../di/ApiSession.kt |
SavedSessionRestorer: the session at start, and its copy in preferences; the other switchTo caller |
core/.../core/session/ServerSessionKeeper.kt |
The WebSocket that keeps the server’s session; sign-out after a revoked token (#334) |
core/.../core/reachability/ |
ServerReachability, ServerReachabilityMonitor, ServerReachabilityTracker (the pure rules); the network itself comes from NetworkSignals (#998) |
application/.../repository/StoredServers.kt |
One of the roles of the server store (#967: StoredServers, ServerAddresses, StoredUsers, UserLocks); Room in data/.../database/RoomServerStore.kt |
core/.../viewmodels/MainViewModel.kt |
Whether there are servers and a user at start, the unreachable banner |
app/phone/.../presentation/setup/ |
Phone screens: welcome, add server, addresses, login, servers, users, permission |
app/tv/.../presentation/setup/ |
TV screens (no addresses screen) |
testing/.../testing/FakeServerConnector.kt, ServerConnectorContract.kt |
The fake and the contract suite every connector passes |
- R16: the server in use is written as one
ActiveServer. OnlyActiveServer.ktkeeps a mutable one; onlyApiSession.ktandSetupRepositoryImpl.ktcall.switchTo(; nocopy(type = …)on anActiveServeroutside the holder; nothing calls the SDK client’supdate(…). - R1, R2, R3: the SDK is only in
server/jellyfin. Setup talks to a server throughServerConnector; failures areServerException. - R4, R9: Room through the roles of the server store;
setupandcoredo not depend ondata(their tests may). - R10:
ServerId,UserIdandServerAddressId(#929), indomain/.../models/Ids.kt; never aStringorjava.util.UUIDid outside the adapter. Do not add a line toarchitecture/baseline/to get past the rule. - R11: no
Jellyfin*type outside the adapter. - What a server can do is
ServerCapabilities(Quick Connect, public users, the login disclaimer), never a version check. - Project rules (
CLAUDE.md): a setup flow PR that no bot reviewed gets an independent review posted on the PR before it merges. CE strings in 36 languages; upstream’s setup texts are not edited, ace_key replaces them.
How to test it
Section titled “How to test it”Unit tests:
./gradlew :domain:test :application:test :architecture:test # ServerTypeTest, ServerFailuresTest, R16./gradlew :setup:testDebugUnitTest # SetupRepositoryConnectorTest, AddSavedServerSessionTest, Login*, AddServer*, ServerAddressesFeedbackTest, ServerAddressSelectTest./gradlew :core:testLibreDebugUnitTest # CurrentMediaServer*Test, ServerConnectorsTest, ServerSessionKeeperTest, ServerReachability*Test, SavedSessionRestorerTest./gradlew :data:testDebugUnitTest --tests '*RoomServerStoreTest*'./gradlew :server:jellyfin:testDebugUnitTest # JellyfinServerConnector*Test, SwitchDuringRequestTest, SocketAcrossASwitchTest, contract tests./gradlew :testing:test # the fake against the contract suites./gradlew :app:tv:testLibreDebugUnitTest # LoginKeyboardTest, LoginServerButtonFocusTest, UsersFocusRestoreTestThe connector contract tests replay recordings in server/jellyfin/src/test/resources/contract/. With EPHYRA_TEST_SERVER=http://localhost:8096 they run against the test server instead, as EPHYRA_TEST_USER (default contract, which setup.sh does not create) and EPHYRA_TEST_PASSWORD; -Dcontract.record=true records again. .github/workflows/live-contracts.yml runs the suites live once a week against the latest Jellyfin image, and on a pull request that changes it; other pull requests only replay.
On a device: the test server (docs/dev-environment.md, tools/test-server/setup.sh, test-server skill). From an emulator the address is http://10.0.2.2:8096.
- Users:
tester(normal),nodownload(may not download),second(a second user on the same server, for user switching),nopass(empty password). Never log in to the app asadmin. Add your own withpython3 tools/test-server/user.py add <name>(--no-password) when someone else tests at the same time. - A second address of the same server:
python3 tools/test-server/forward.pylistens on 8097 and passes to 8096; addhttp://10.0.2.2:8097on the Addresses screen, or through Settings > Servers > Add server. Stopping the script takes that address away. With other sessions testing, give it a port of your own (forward.py 8984 8096). - A second server:
setup.shwith otherEPHYRA_TEST_SERVER_DIR,EPHYRA_TEST_SERVER_PORTandEPHYRA_TEST_SERVER_NAMEruns one next to the first. - Server gone, internet still there (phone or tablet AVD):
adb root, thenadb shell iptables -I OUTPUT -d 10.0.2.2 -p tcp --dport 8096 -j REJECT --reject-with tcp-reset;-Dremoves it. On TV useforward.pyinstead. - A fresh login:
ce_phone_tmpis the AVD for throwaway logins. On TV, type into text fields withscripts/tv-dpad.sh, notadb shell input keyevent. - The local network permission (
LocalNetworkAccess, #376) applies from Android 17 only; the standard AVDs are Android 14. - A script that logs in to the server needs its own
DeviceId: a second login with the same one ends the first session.
Before a PR
Section titled “Before a PR”./gradlew ktfmtCheck./gradlew :domain:test :application:test :architecture:test./gradlew :setup:testDebugUnitTest :core:testLibreDebugUnitTest :server:jellyfin:testDebugUnitTest./gradlew :app:phone:compileLibreDebugKotlin :app:tv:compileLibreDebugKotlinpython3 .claude/skills/translate-strings/scripts/check-translations.py # when strings changedThen walk the flow on an emulator: add the server, log in, switch user, switch server, remove an address. If no review bot reviewed the PR, get the independent review first.
Decisions and history
Section titled “Decisions and history”- ADR 0001 and 0002; T7 in
docs/architecture/5-hexagonal-ddd.md; the ports as they are now indocs/architecture/README.md. - #761: discovery, login and Quick Connect move behind
ServerConnector. - #763: session keeper and reachability go through
ServerSession. - #770: servers have a type; the
MediaServerand connector are chosen by it. - #819: adding a server does not count as traffic of the server in use.
- #899: the server store (split by role in #967; #913) and the switch as one
ActiveServer(#915), rule R16. - #281:
ServerReachabilityand the unreachable banner. - #334: sessions closed with the app; a revoked token signs out.
- #250: the session at start from a copy in preferences, not Room.
- #425: adding a saved server again keeps its user signed in.
- #376, #571: say when Android 17’s local network permission blocks a server.
- #998: the permission checks and the network callbacks move to
devicebehindRuntimePermissionsandNetworkSignals;LocalNetworkAccessImplpasses the permission’s id, asdevicemay not takesettings(R18), and rule R28 keepsConnectivityManagerandcheckSelfPermissionindeviceand the apps. - #606: Quick Connect failures in plain words.
- #855: a signed-in user approves the Quick Connect code of another device (
ServerConnector.authorizeQuickConnect,QuickConnectApproval). It sits on the connector rather than onServerSession, next to the rest of Quick Connect and its contract tests, and takes the address and the token as one read ofActiveServerHolder(SetupRepositoryImpl.authorizeQuickConnect). Jellyfin answers an unknown code with 404, and Quick Connect turned off with 401. - #918:
data, the adapter anddownloadsread settings through ports, notAppPreferences(rule R17); address ids areServerAddressId(#929).
Pitfalls
Section titled “Pitfalls”- The current server id is a preference, not only
ActiveServer.AddServerViewModelandServersViewModelwrite it throughCurrentServerSelection.select(#969);SetupRepositoryImplswitches the holder. Several ViewModels read the preference throughCurrentServerIdorCurrentServerSelection, and so doesMediaRepositoryImpl. A change to the switch must keep both in step (#918, #926). - What runs and what is saved must name the same address. The copy of the session in preferences (
pref_session_base_url) follows Room’scurrentServerAddressId, notActiveServer, and a start reads that copy. Re-adding a saved server by another address pointedActiveServerthere and left Room’s current address as it was, so a restart went back to the old address (#984). NowsaveServerInDatabasemakes that address current in Room in the same step, and every write ofbaseUrl(setCurrentServer,setCurrentAddress) comes from Room’s current address. This happens at Connect, before anyone signs in, on purpose: the running session moves there at Connect, so the saved address does too (R16), and backing out of the login screen or picking the server’s LAN entry in discovery leaves that address current until the user picks another one on the Addresses screen or Home’s server sheet.setCurrentAddressandsaveServerInDatabaseshare one lock, so two of them never leave Room and the session on different addresses. Check it on a device withrun-as … sqlite3 databases/serversand the preferences file, then force-stop and start. - A server row changes one column at a time.
StoredServershas no whole-row update: the name, the current address and the current user each have their own write (renameServer,setCurrentAddress,setCurrentUser,clearCurrentUser). Writing back aServerread a moment before undid a write in between, such as a sign-out clearing the current user (#988). A new column gets its ownUPDATEquery too. - A tap on the Addresses screen makes the address current (of any server; the app moves only for the server in use). Upstream’s Compose screen (#1012 upstream) had left the tap empty; Home’s server sheet could always switch the address of the server in use. The server lists show
ServerWithAddresses.currentAddress, not the first address. - Checking another server’s address must run unwatched, or its silence shows the unreachable banner for the server in use (#819,
addAddress). - Users and Servers reuse each other’s entry on the back stack. Both
NavigationRoot.ktfiles open the server list from the Users and Login screens, and the Users screen from the Servers and Add server screens, withnavigateOrReuse: when the route is already on the stack, everything above it is popped instead of a second entry being added (#1071: with a plain push, Back from Users went to the server list and then to an older Users screen). The reused Users entry keeps itsUsersViewModel; it shows the server just picked only because the screen callsloadUsers()each time it enters composition, andloadUsers()cancels the load before it: the previous server’s public users are a network request and may answer last (UsersReloadTest). A Users screen opened from Settings, the profile button or “ask who is watching” is still a plain push. - Deleting the active user is allowed: the guard in
SetupRepositoryImpl.deleteUseris commented out (setup-02 indocs/open-decisions.md). It now clears the current user and the token. - A server type without an adapter gets
UnsupportedMediaServer: every request fails; its downloads open from Room. - Reachability follows the app’s own requests.
ServerReachabilityalso probes the server on a network change, on return to the app and after a failed request, with conditions: no probe for a failed request while the server already counts as unreachable, none on return when it answered seconds ago (ServerReachabilityTrackerhas the rules). Phone screens read it throughLocalServerStatusand show the unreachable banner (ServerOrErrorCard) with a way to Downloads. - Reachability does not run on TV (
serverReachability.start()is only inapp/phone’sBaseApplication). - Profile switch race: an unplayed mark during a profile switch may clear the other user’s last-played date (#907, open).
- Downgrade: builds with the #1127 startup check preserve the database and show a message when they cannot open a newer schema. Install a compatible build to access the saved account. APKs released before #1127 can still erase the database on downgrade, including saved servers and logins.
Source: docs/areas/setup-and-servers.md · raw Markdown