Files
chandra/compositor/host/lock.mbt
T
nandiandClaude Opus 5.5 2aa3de5741
Deploy to the handset / build-and-deploy (push) Successful in 2m14s
CI / test (push) Failing after 2m41s
Deploy to the handset from the cluster
CI builds an arm64 image (compositor, host, chandra-remote, modules) and deploys
the updater pod that installs it on the phone. chandra-remote updates go in live
(SIGUSR2 restarts it in place); the compositor waits for an idle, locked phone or
an approval, and a locked session restarts locked. Host tests: the launcher no
longer draws its label in a narrow panel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 16:34:12 -08:00

133 lines
5.1 KiB
MoonBit

///| Session lock (docs/lock.md): the compositor hides the desktop and only lets a face or
/// password bring it back. Locking is driven from the power button (when CHANDRA_LOCK=1 /
/// Settings turns on lock-on-blank) or `chandra-ctl lock`; unlocking reuses the password dialog.
///
/// The unlock check runs in chandra-polkit-agent as a real polkit authorization of the
/// `org.chandra.unlock` action (compositor/polkit/agent_loop.mbt): the agent asks polkit, polkit
/// drives the agent's own dialog, and because the `polkit-1` PAM stack carries
/// `pam_chandra_face.so` (docs/face-unlock.md) the camera is tried first, with the password as
/// the fallback. The compositor only sends `unlock` and waits for `unlocked`.
///
/// lock_now ──► request_unlock ──"unlock"──► agent ──► polkit ──► dialog (face, then password)
/// ▲ │
/// │ success: "unlocked" ───┘──► unlocked
/// └── power off / chandra-ctl lock cancel: "unlock-failed" ──► stay locked
///| While this file exists a login session starts locked. Whoever restarts a locked session (the
/// handset updater, handset/handset.sh) puts it there as root, so the restart doesn't unlock it.
pub let lock_marker : String = "/run/chandra-start-locked"
///| Lock the session if the file `path` is there (and not empty).
pub fn ChandraCompositor::lock_if_marked(self : ChandraCompositor, path : String) -> Unit {
if @sys.read_file_bytes(path).length() > 0 {
self.lock_now()
}
}
///| Whether the session is locked right now.
pub fn ChandraCompositor::is_locked(self : ChandraCompositor) -> Bool {
self.locked
}
///| Lock the session: hide the desktop and demand a face or password to return. Safe to call
/// when already locked. If the screen is on, the unlock prompt comes up at once; if it is off
/// (locked at blank), it comes up when the power button wakes the screen.
pub fn ChandraCompositor::lock_now(self : ChandraCompositor) -> Unit {
if self.locked {
return
}
// Dismiss any unrelated auth prompt before locking the session.
if self.auth is Some(_) {
self.close_auth(true)
}
self.locked = true
self.unlock_pending = false
// Nothing on the desktop keeps the keyboard or the pointer while locked.
self.set_kbd_focus(None)
self.leave_pointer()
self.osk_manual_show = false
self.osk_sync()
self.damage.mark_full()
self.frame_changed = true
if !self.manual_screen_off && !self.screen_off {
self.request_unlock()
}
}
///| Ask the agent to run an unlock check. No-op if not locked, already asked, or no agent runs
/// (then the session simply stays locked until an agent is available and input re-raises it).
pub fn ChandraCompositor::request_unlock(self : ChandraCompositor) -> Unit {
if !self.locked || self.unlock_pending {
return
}
match self.auth_agent {
Some(l) => {
ignore(l.conn.send(["unlock"]))
self.unlock_pending = true
self.damage.mark_full()
self.frame_changed = true
}
None => ()
}
}
///| Cancel any active or pending unlock dialog (used when turning the screen off while locked).
pub fn ChandraCompositor::cancel_unlock(self : ChandraCompositor) -> Unit {
if self.auth is Some(_) {
self.close_auth(true)
}
if self.unlock_pending {
match self.auth_agent {
Some(l) => ignore(l.conn.send(["cancel-unlock"]))
None => ()
}
self.unlock_pending = false
self.damage.mark_full()
self.frame_changed = true
}
}
///| The agent said the unlock succeeded: return to the desktop.
pub fn ChandraCompositor::unlocked(self : ChandraCompositor) -> Unit {
if !self.locked {
return
}
self.locked = false
self.unlock_pending = false
self.note_activity(@sys.monotonic_ms())
self.damage.mark_full()
self.frame_changed = true
}
///| The unlock attempt ended without success (the user cancelled, or it failed): stay locked.
/// The prompt is raised again by the next key/button press or wake, not in a tight loop here.
pub fn ChandraCompositor::unlock_failed(self : ChandraCompositor) -> Unit {
self.unlock_pending = false
self.damage.mark_full()
self.frame_changed = true
}
///| Draw the locked-screen backdrop and idle prompt when no auth card is open.
fn ChandraCompositor::lock_ops(self : ChandraCompositor) -> Array[@scene.DrawOp] {
let ops : Array[@scene.DrawOp] = []
if !self.locked {
return ops
}
let sw = self.output_w
let sh = self.output_h
let bg = @scene.Rgba::new(10, 12, 18, 225)
ops.push(@scene.DrawOp::FillRect(@scene.Rect::new(0, 0, sw, sh), bg, 0))
if self.auth is None {
let p = self.theme.palette
let fs = self.theme.font_size
let s = 44
let cx = sw / 2
let cy = sh / 2 - 20
lock_glyph(cx - s / 2, cy - s - 12, s, p.accent, bg, ops)
ops.push(@scene.DrawOp::Text(cx, cy + 8, "Screen locked", fs + 4, p.foreground, @scene.TextAlign::Center, true))
let sub = if self.unlock_pending { "Starting unlock…" } else { "Tap or press any key to unlock" }
ops.push(@scene.DrawOp::Text(cx, cy + 36, sub, fs - 1, p.foreground_muted, @scene.TextAlign::Center, false))
}
ops
}