Profiles and PIN
Status: saved users on a server as profiles with avatars (#245) and an optional local PIN (#299) or phone unlock pattern (#330); built on phone and TV. As of 2026-11-25 (main).
Start here
Section titled “Start here”- Lock rules, pattern geometry, and PBKDF2 hashing live in
application/.../profilelock/:ProfileLock(process-wide singleton bound indata’sDatabaseModule),ProfilePinHasher,ProfilePattern, andProfileLockEntry. - Switching and PIN/pattern prompts live in
setup/.../presentation/:UsersViewModel,ProfilePinGateViewModel,ProfilePinSettingsViewModel, andPinPrompt. - Phone UI lives in
app/phone/.../presentation/setup/pin/(ProfilePinGateScreen,ProfilePinScreen,PinDialog,PatternGrid,PatternDialog,SwitchPinDialog) andProfileBottomSheet(app/phone/.../presentation/film/components/ProfileBottomSheet.kt). TV UI lives inapp/tv/.../ce/presentation/pin/(TvProfilePinGateScreen,TvProfilePinScreen,TvPinDialog,TvPinPad,TvSwitchPinDialog) andapp/tv/.../presentation/setup/users/UsersScreen.kt. - Start-up gating (
MainState.profileLockedandMainState.askUserOnStart) is derived inMainViewModel(core/.../viewmodels/MainViewModel.kt) and enforced in bothNavigationRoots before Home renders. - Reference screenshots for phone and TV are in
docs/profiles/pin/. - Test fast:
./gradlew :application:test,./gradlew :data:testDebugUnitTest --tests '*ProfileLockTest*', and./gradlew :setup:testDebugUnitTest --tests '*Pin*'.
What it does
Section titled “What it does”Each signed-in user on a server is stored in Room’s users table (UserEntity / User). EphyraAvatar (core/.../presentation/ephyra/EphyraAvatar.kt) shows the user’s Jellyfin picture when User.primaryImageTag is present, or initials (avatarInitials, falling back to "?" when blank) on one of four theme container colours picked deterministically from UserId (avatarColorIndex, preserving pre-#773 UUID hash colours). A locked profile (User.hasPin) displays a lock badge; the signed-in user gets a check badge (current). Phone and TV wrap EphyraAvatar as UserAvatar.
Users switch profiles from HomeHeader → ProfileBottomSheet on phone (which lists other saved users and server public users), from the drawer’s profile header (MainScreen) → UsersScreen on TV, or from Settings → Users. Both ProfileBottomSheet and UsersScreen drive UsersViewModel. On phone the sheet also offers “Approve a Quick Connect code” (#855): QuickConnectApproveDialog takes the six digits another device (a TV, a browser) shows, and QuickConnectApproveViewModel (setup/.../presentation/quickconnect/) approves them as the signed-in user, so that device is signed in as them. The entry is hidden when the server type has no Quick Connect (ServerCapabilities.quickConnect) or the server says it is turned off. TV has no such entry. When appPreferences.askUserOnStart is enabled and the active server has more than one saved user, MainState.askUserOnStart is true and both NavigationRoots push UsersRoute once per app start (rememberSaveable; on TV a WatchNextLink takes precedence).
A profile may hold one local lock at a time (User.pinHash, User.pinSalt, User.lockType, User.pinOnStart):
- PIN (
ProfileLockType.PIN, phone and TV): 4 to 6 ASCII digits (ProfilePinHasher.MIN_LENGTH..MAX_LENGTH). - Pattern (
ProfileLockType.PATTERN, phone only): 4 to 9 distinct dots on a 3×3 grid numbered0..8(ProfilePattern), serialized as dash-separated indices (e.g."0-1-2-5-8"). A straight line across an unconnected middle dot automatically connects that dot (ProfilePattern.connect). Setting one type replaces the other (ProfileLock.setPin,ProfileLock.setPattern). - Both secrets are hashed locally by
ProfilePinHasher(PBKDF2-HMAC-SHA256, 20,000 iterations, 16-byte random salt, 256-bit key, constant-timeMessageDigest.isEqualcomparison) and never leave the device.
ProfileLock keeps in-memory unlock state for the process lifetime: lastUnlockedUserId tracks the single active profile, while unlockedUserIds accumulates profiles unlocked or switched to in this process so MainViewModel.profileLocked does not flash the start gate on the outgoing profile while Room catches up. Switching to another locked profile requires its lock (ProfileLock.needsPinToSwitch). Setting a PIN/pattern or toggling pinOnStart from inside Settings unlocks that profile immediately.
On a new process, ProfileLock.isLockedOnStart is true when the current user has a lock, pinOnStart is true (default), and user.id !in unlockedUserIds. Both NavigationRoots render ProfilePinGateScreen / TvProfilePinGateScreen instead of Home while setupComplete && profileLocked, so Home loads nothing until unlocked (and on TV a Watch Next deep link waits on the back stack underneath). Cancelling at start (ProfilePinGateAction.OnCancel or Back) calls SetupRepository.clearCurrentUser(), dropping to UsersRoute.
Settings → Profile lock (phone) / Settings → Profile PIN (TV, switched by AppVariant in SettingsViewModel) opens ProfilePinScreen / TvProfilePinScreen backed by ProfilePinSettingsViewModel. Setting a new lock asks twice (PinStep.New, PinStep.Confirm); changing, switching type, or removing asks for the current lock first (PinStep.Current). A forgotten lock cannot be recovered: the user must remove the profile or sign in again, which clears the lock.
Where the code is
Section titled “Where the code is”| Path | What |
|---|---|
domain/.../models/User.kt |
User, ProfileLockType (PIN, PATTERN), User.hasPin, User.profileLockType |
application/.../profilelock/ProfileLock.kt |
Process unlock state, setPin, setPattern, clearPin, verify, needsPinToSwitch, isLockedOnStart |
application/.../profilelock/ProfilePinHasher.kt |
PBKDF2-HMAC-SHA256 hashing (ProfilePinHasher), ProfilePattern, ProfileLockEntry |
application/.../repository/UserLocks.kt |
Store port for writing pinHash, pinSalt, lockType, and pinOnStart |
data/.../database/RoomServerStore.kt |
Room UserLocks implementation over ServerDatabaseDao and UserEntity; singleton ProfileLock bound in DatabaseModule |
setup/.../presentation/pin/ |
ProfilePinGateViewModel, ProfilePinSettingsViewModel (PinStep), PinPrompt (PinError) |
setup/.../presentation/users/UsersViewModel.kt |
Profile switching, public user refresh, switch lock prompt |
core/.../viewmodels/MainViewModel.kt |
Derives MainState.profileLocked and MainState.askUserOnStart |
core/.../presentation/ephyra/EphyraAvatar.kt |
Shared avatar (picture, initials, deterministic colour, lock/current badges); ErrorShake.kt for errorShake |
app/phone/.../presentation/setup/pin/ |
ProfilePinGateScreen, ProfilePinScreen, PinDialog, PatternGrid, PatternDialog, SwitchPinDialog |
setup/.../presentation/quickconnect/ |
QuickConnectApproveViewModel, QuickConnectApproveState (QuickConnectApproveStatus), QuickConnectApproveAction (#855) |
app/phone/.../presentation/film/components/ProfileBottomSheet.kt |
Phone Home profile sheet; QuickConnectApproveDialog; HomeHeader, UserAvatar, UsersScreen |
app/tv/.../ce/presentation/pin/ |
TvProfilePinGateScreen, TvProfilePinScreen, TvPinDialog, TvPinPad, TvSwitchPinDialog |
app/tv/.../presentation/setup/users/UsersScreen.kt |
TV user picker, UserItem, drawer item in MainScreen |
app/phone/.../NavigationRoot.kt, app/tv/.../NavigationRoot.kt |
Gates Home behind ProfilePinGateScreen / TvProfilePinGateScreen, pushes UsersRoute for askUserOnStart, hosts ProfilePinRoute |
- R4: no production file outside
dataimportsServerDatabaseDao.ProfileLockreads users throughStoredUsersand writes locks throughUserLocks. - R9: only the apps depend on
data;setup,settings, andcorenever depend ondata(DatabaseModuleindataprovidesUserLocksand the singletonProfileLockto Hilt). - R10:
UserIdandServerIdare value classes (Ids.kt), neverStringorjava.util.UUIDin production signatures outside the adapter. - R19:
application/.../profilelock/stays pure Kotlin (ProfilePinHasheruses only JDKjavax.crypto,java.security, andjava.util.Base64). - Translations: all CE profile/lock strings (
ce_profile_*,ce_users_*,ce_settings_profile_*) must be added tostrings_ce.xmlin all 36 languages and passcheck-translations.py.
How to test it
Section titled “How to test it”./gradlew :application:test./gradlew :data:testDebugUnitTest --tests '*ProfileLockTest*'./gradlew :setup:testDebugUnitTest --tests '*Pin*'./gradlew :setup:testDebugUnitTest --tests '*QuickConnectApprove*'./gradlew :core:testLibreDebugUnitTest --tests '*EphyraAvatarTest*'./gradlew :app:phone:testLibreDebugUnitTest --tests '*ProfileBottomSheetTest*'./gradlew :app:tv:testLibreDebugUnitTest --tests '*TvPinPadTest*' --tests '*MainReturnLoadsTest*'Unit tests cover hashing and pattern geometry (ProfilePinHasherTest, ProfilePatternTest), lock state and cross-type verification (ProfileLockTest), switch/gate/settings flows over FakeRoles (ProfilePinSwitchTest), avatar initials and legacy UUID colour stability (EphyraAvatarTest), landscape profile sheet layout (ProfileBottomSheetTest), approving a Quick Connect code and when the entry shows (QuickConnectApproveTest), TV remote key handling (TvPinPadTest), and TV drawer user reload on return (MainReturnLoadsTest).
On a device or emulator, tools/test-server/setup.sh creates multiple users (tester, second, nopass, nodownload; see test-environment.md) so multi-profile switching, askUserOnStart, and PIN/pattern locks can be exercised against http://10.0.2.2:8096.
What unit tests do not cover:
PatternGridtouch-drag gestures,errorShaketiming, andProfileBottomSheetcross-window hiding onHomeScreen(#872).- Room auto-migrations (14→15, 16→17, 17→18) preserving existing logins and lock rows on upgrade (
ProfilePinSwitchTestandProfileLockTestrun against in-memoryFakeRoles). - TV Watch Next deep links launching into a locked profile (holding the Watch Next stack beneath
TvProfilePinGateScreenuntil unlocked) and physical remote Enter/OK quirks.
Before a PR
Section titled “Before a PR”./gradlew ktfmtCheck./gradlew :application:test :architecture:test./gradlew :data:testDebugUnitTest --tests '*ProfileLockTest*'./gradlew :setup:testDebugUnitTest --tests '*Pin*'./gradlew :app:phone:compileLibreDebugKotlin :app:tv:compileLibreDebugKotlinpython3 .claude/skills/start-work/scripts/check-docs.pypython3 .claude/skills/translate-strings/scripts/check-translations.py # when strings changedDecisions and history
Section titled “Decisions and history”- #245 / #248: profile switching UI (
ProfileBottomSheet,UsersScreen),EphyraAvatardeterministic initials/colours (preserving legacyUUID.hashCode()colours in #773),User.primaryImageTag, andaskUserOnStart. - #299 / #329: local profile PIN stored as a salted PBKDF2-HMAC-SHA256 hash on the
Userrow (20,000 iterations so slow TV boxes check without a visible wait: it keeps out someone on the couch, not someone who extracts the database; no attempt lockout or inactivity re-lock),ProfileLocksingleton, start gate before Home,TvPinPad, and Settings → Profile PIN. - #330 / #333: unlock pattern on phone (
ProfileLockType,ProfilePattern,PatternGrid,PatternDialog), reusingpinHash/pinSaltso each profile has one lock at a time, and extendingProfilePinSettingsViewModel/PinPromptwhile keeping TV’s exhaustivewhenbranches untouched. - #408, #409 / #532: TV drawer reloads the user on every return (
loadsOnReturn) so the lock badge tracks PIN changes immediately;TvPinPadmoves focus to OK on a remote number key press so OK submits instead of typing a digit. - #440:
ProfileBottomSheetopens fully (skipPartiallyExpanded = true) and scrolls vertically in short landscape windows so Settings remains reachable. - #866 / #873, #872 / #881: tab root ViewModels (
FavoritesViewModel,SearchViewModel,DownloadsViewModel) andHomeScreen(SessionUser, hiding the sheet before removal,key(state.user?.id)) drop the previous user’s rows immediately on switch. - #855: the phone profile sheet approves the Quick Connect code of another device. A whole code only, one request at a time; the field stays filled after a failure so a typo can be fixed. See setup-and-servers for the port.
- #967, #988: user lock writes live behind
UserLocks(RoomServerStore), andsetCurrentUserupdates onlycurrentUserIdinstead of replacing theServerEntityrow.
Pitfalls
Section titled “Pitfalls”- tv-material button closure capture (
TvPinPad.kt):androidx.tv.material3.Buttonretains the click lambda from its first composition for D-pad OK. Because multi-step dialogs (TvProfilePinScreen) pass a newpinstate per step,TvPinPadreadspinandonSubmitviarememberUpdatedState. Without it, Change PIN re-saves the old PIN. - Remote OK vs number keys (
TvPinPad.kt, #409):TvPinPadintercepts digit keys regardless of focused button, so a digit key must also request focus onokKey;Key.Enter/Key.DirectionCenteris deliberately not handled inonPreviewKeyEventbecause some remotes send Enter for D-pad OK. - Re-authenticating wipes the lock (
SetupRepositoryImpl.kt):insertUserusesOnConflictStrategy.REPLACEwith defaultpinHash = null, so signing in again as a locked user clears their local PIN/pattern (the documented recovery path for a forgotten lock). - Do not shrink
unlockedUserIdson switch (ProfileLock.kt):unlockedUserIdsintentionally keeps previously unlocked user IDs whilelastUnlockedUserIdtracks only the latest profile. Removing the old user ID immediately on switch causesMainViewModel.profileLockedto flash the start gate on the outgoing profile while Room catches up. - Cross-user frame leakage on switch (#866, #872):
ProfileBottomSheetswitches users whileHomeScreenand tab root ViewModels remain alive; user-scoped content must be gated withshownTo(userId)/LocalServerSession.current.userId(andSessionUseronHomeScreen) rather than waiting for Room’s flow. - Keep
PinStepandPinErrorTV-safe:ProfilePinSettingsViewModelandPinPromptare shared by phone and TV; adding newPinSteporPinErrorsubtypes breaks TV’s exhaustivewhenbranches unless TV is updated in the same change.
Source: docs/areas/profiles.md · raw Markdown