646d106e141d
feat: Phase 10 — ChirpPairScreen, BirdAnimation three-act Canvas (waiting/listening/connected), SAS verification overlay, ChirpPairViewModel wired to runChirpPairing (v2.1.10)
- time
- 2026-06-03 00:28 UTC · 5 months ago
- machine
- koh2
- agent
- claude-opus-4-8
- session
- phase 8-12 sync autofill codex integrations
- parent
- f57a25c175bd
↓ peach-android-646d106e.tar.gzatlas at this save
files changed5 files
app/build.gradle+2 −2app/src/main/java/com/peachpasswords/ui/PeachAppNavHost.kt+2 −1app/src/main/java/com/peachpasswords/ui/components/BirdAnimation.kt+178 −0app/src/main/java/com/peachpasswords/ui/pairing/ChirpPairScreen.kt+205 −0app/src/main/java/com/peachpasswords/ui/pairing/ChirpPairViewModel.kt+138 −0app/build.gradle+2 −2
@@ -16,8 +16,8 @@1616 applicationId "com.peachpasswords"1717 minSdk 261818 targetSdk 3519- versionCode 20100920- versionName "2.1.9"19+ versionCode 20101020+ versionName "2.1.10"2121 2222 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"2323 vectorDrawables {app/src/main/java/com/peachpasswords/ui/PeachAppNavHost.kt+2 −1
@@ -13,6 +13,7 @@1313 import androidx.navigation.compose.rememberNavController1414 import androidx.navigation.navArgument1515 import com.peachpasswords.ui.lock.LockScreen16+import com.peachpasswords.ui.pairing.ChirpPairScreen1617 import com.peachpasswords.ui.screens.SimpleStub1718 import com.peachpasswords.ui.settings.SettingsScreen1819 import com.peachpasswords.ui.theme.PeachMotion@@ -90,7 +91,7 @@9091 composable(PeachNav.SettingsPro.route) { SimpleStub("Peach Pro", back) }9192 composable(PeachNav.CodexGenerate.route) { SimpleStub("Codex backup", back) }9293 composable(PeachNav.CodexRestore.route) { SimpleStub("Codex restore", back) }93- composable(PeachNav.ChirpPair.route) { SimpleStub("Pair a device", back) }94+ composable(PeachNav.ChirpPair.route) { ChirpPairScreen(onBack = back) }9495 composable(PeachNav.Health.route) { SimpleStub("Vault health", back) }9596 composable(PeachNav.Trash.route) { SimpleStub("Trash", back) }9697 composable(PeachNav.Import.route) { SimpleStub("Import", back) }app/src/main/java/com/peachpasswords/ui/components/BirdAnimation.kt+178 −0
@@ -0,0 +1,178 @@1+package com.peachpasswords.ui.components2+3+import androidx.compose.animation.core.FastOutSlowInEasing4+import androidx.compose.animation.core.LinearEasing5+import androidx.compose.animation.core.RepeatMode6+import androidx.compose.animation.core.animateFloat7+import androidx.compose.animation.core.animateFloatAsState8+import androidx.compose.animation.core.infiniteRepeatable9+import androidx.compose.animation.core.rememberInfiniteTransition10+import androidx.compose.animation.core.spring11+import androidx.compose.animation.core.tween12+import androidx.compose.foundation.Canvas13+import androidx.compose.runtime.Composable14+import androidx.compose.runtime.getValue15+import androidx.compose.ui.Modifier16+import androidx.compose.ui.geometry.Offset17+import androidx.compose.ui.geometry.Size18+import androidx.compose.ui.graphics.Color19+import androidx.compose.ui.graphics.Path20+import androidx.compose.ui.graphics.drawscope.DrawScope21+import androidx.compose.ui.graphics.drawscope.Stroke22+import com.peachpasswords.ui.theme.LocalPeachAccent23+import kotlin.math.sin24+25+/** The three acts of the pairing animation, bound to the audio protocol. */26+enum class PairingAnimState { WAITING, LISTENING, CONNECTED }27+28+private val BodyHi = Color(0xFFFFB082)29+private val BodyLo = Color(0xFFE5805C)30+private val Beak = Color(0xFFF2B45A)31+private val Eye = Color(0xFF1F0A10)32+33+/**34+ * Two finches that drift toward each other as pairing progresses. Act 135+ * (waiting) holds them apart with a slow breath-bob; Act 2 (listening) pulses36+ * inaudible sound arcs between them; Act 3 (connected) resolves the arcs into a37+ * glowing accent link and a synchronised flutter. Stylised from the browser38+ * ChirpPairingFlow birds — same coral/apricot palette, simpler geometry.39+ */40+@Composable41+fun BirdAnimation(42+ state: PairingAnimState,43+ modifier: Modifier = Modifier,44+) {45+ val accent = LocalPeachAccent.current46+47+ val leftX by animateFloatAsState(48+ targetValue = when (state) {49+ PairingAnimState.WAITING -> 0.16f50+ PairingAnimState.LISTENING -> 0.22f51+ PairingAnimState.CONNECTED -> 0.39f52+ },53+ animationSpec = spring(dampingRatio = 0.6f, stiffness = 200f),54+ label = "leftX",55+ )56+ val rightX by animateFloatAsState(57+ targetValue = when (state) {58+ PairingAnimState.WAITING -> 0.84f59+ PairingAnimState.LISTENING -> 0.78f60+ PairingAnimState.CONNECTED -> 0.61f61+ },62+ animationSpec = spring(dampingRatio = 0.6f, stiffness = 200f),63+ label = "rightX",64+ )65+66+ val transition = rememberInfiniteTransition(label = "bird")67+ val bob by transition.animateFloat(68+ initialValue = 0f, targetValue = (2f * Math.PI).toFloat(),69+ animationSpec = infiniteRepeatable(tween(2200, easing = LinearEasing)),70+ label = "bob",71+ )72+ // Sound-arc sweep (LISTENING) and connection-glow pulse (CONNECTED).73+ val pulse by transition.animateFloat(74+ initialValue = 0f, targetValue = 1f,75+ animationSpec = infiniteRepeatable(76+ tween(if (state == PairingAnimState.CONNECTED) 1600 else 900, easing = FastOutSlowInEasing),77+ repeatMode = RepeatMode.Restart,78+ ),79+ label = "pulse",80+ )81+82+ Canvas(modifier = modifier) {83+ val h = size.height84+ val cy = h * 0.52f85+ val leftCenter = Offset(size.width * leftX, cy + sin(bob) * 4f)86+ val rightCenter = Offset(size.width * rightX, cy + sin(bob + Math.PI.toFloat()) * 4f)87+ val birdScale = (size.minDimension / 220f).coerceIn(0.5f, 1.4f)88+89+ if (state == PairingAnimState.LISTENING) {90+ drawSoundArcs(leftCenter, rightCenter, pulse, accent)91+ }92+ if (state == PairingAnimState.CONNECTED) {93+ drawConnection(leftCenter, rightCenter, pulse, accent)94+ }95+96+ drawBird(leftCenter, birdScale, facingRight = true, listening = state != PairingAnimState.WAITING)97+ drawBird(rightCenter, birdScale, facingRight = false, listening = state != PairingAnimState.WAITING)98+ }99+}100+101+private fun DrawScope.drawSoundArcs(left: Offset, right: Offset, pulse: Float, accent: Color) {102+ val mid = Offset((left.x + right.x) / 2f, (left.y + right.y) / 2f)103+ val span = (right.x - left.x) / 2f104+ for (i in 0 until 3) {105+ val t = (pulse + i / 3f) % 1f106+ val radius = span * (0.2f + t * 0.8f)107+ val alpha = (1f - t) * 0.5f108+ drawCircle(109+ color = accent.copy(alpha = alpha),110+ radius = radius,111+ center = mid,112+ style = Stroke(width = 1.6f),113+ )114+ }115+}116+117+private fun DrawScope.drawConnection(left: Offset, right: Offset, pulse: Float, accent: Color) {118+ val beakL = Offset(left.x + 26f, left.y - 4f)119+ val beakR = Offset(right.x - 26f, right.y - 4f)120+ val mid = Offset((beakL.x + beakR.x) / 2f, (beakL.y + beakR.y) / 2f)121+ drawLine(accent.copy(alpha = 0.5f), beakL, beakR, strokeWidth = 1.4f)122+ val glow = 3f + sin(pulse * 2f * Math.PI.toFloat()) * 2f + 4f123+ drawCircle(accent.copy(alpha = 0.22f), radius = glow * 2.4f, center = mid)124+ drawCircle(accent, radius = glow, center = mid)125+}126+127+/** A compact finch: body blob, wing, head, beak, eye. */128+private fun DrawScope.drawBird(129+ center: Offset,130+ scale: Float,131+ facingRight: Boolean,132+ listening: Boolean,133+) {134+ val dir = if (facingRight) 1f else -1f135+ fun p(dx: Float, dy: Float) = Offset(center.x + dx * scale * dir, center.y + dy * scale)136+137+ // Shadow138+ drawOval(139+ color = Color(0x33000000),140+ topLeft = Offset(center.x - 30f * scale, center.y + 42f * scale),141+ size = Size(60f * scale, 7f * scale),142+ )143+144+ // Body145+ val body = Path().apply {146+ moveTo(p(-30f, 6f).x, p(-30f, 6f).y)147+ cubicTo(p(-36f, -22f).x, p(-36f, -22f).y, p(-8f, -44f).x, p(-8f, -44f).y, p(24f, -40f).x, p(24f, -40f).y)148+ cubicTo(p(52f, -36f).x, p(52f, -36f).y, p(60f, -10f).x, p(60f, -10f).y, p(50f, 18f).x, p(50f, 18f).y)149+ cubicTo(p(40f, 40f).x, p(40f, 40f).y, p(-2f, 44f).x, p(-2f, 44f).y, p(-26f, 32f).x, p(-26f, 32f).y)150+ cubicTo(p(-34f, 24f).x, p(-34f, 24f).y, p(-32f, 14f).x, p(-32f, 14f).y, p(-30f, 6f).x, p(-30f, 6f).y)151+ close()152+ }153+ drawPath(body, BodyHi)154+155+ // Wing (lifts when listening)156+ val wingLift = if (listening) -6f else 0f157+ val wing = Path().apply {158+ moveTo(p(-6f, -14f + wingLift).x, p(-6f, -14f + wingLift).y)159+ cubicTo(p(14f, -22f + wingLift).x, p(14f, -22f + wingLift).y, p(40f, -10f).x, p(40f, -10f).y, p(34f, 6f).x, p(34f, 6f).y)160+ cubicTo(p(20f, 14f).x, p(20f, 14f).y, p(-2f, 8f).x, p(-2f, 8f).y, p(-10f, -2f).x, p(-10f, -2f).y)161+ close()162+ }163+ drawPath(wing, BodyLo)164+165+ // Head166+ drawCircle(BodyHi, radius = 22f * scale, center = p(34f, -30f))167+ // Beak168+ val beak = Path().apply {169+ moveTo(p(52f, -30f).x, p(52f, -30f).y)170+ lineTo(p(72f, -27f).x, p(72f, -27f).y)171+ lineTo(p(53f, -22f).x, p(53f, -22f).y)172+ close()173+ }174+ drawPath(beak, Beak)175+ // Eye176+ drawCircle(Eye, radius = 4.2f * scale, center = p(42f, -33f))177+ drawCircle(Color(0xFFFFF0E1), radius = 1.4f * scale, center = p(43.5f, -34.5f))178+}app/src/main/java/com/peachpasswords/ui/pairing/ChirpPairScreen.kt+205 −0
@@ -0,0 +1,205 @@1+package com.peachpasswords.ui.pairing2+3+import androidx.compose.foundation.background4+import androidx.compose.foundation.clickable5+import androidx.compose.foundation.layout.Arrangement6+import androidx.compose.foundation.layout.Box7+import androidx.compose.foundation.layout.Column8+import androidx.compose.foundation.layout.Row9+import androidx.compose.foundation.layout.Spacer10+import androidx.compose.foundation.layout.fillMaxSize11+import androidx.compose.foundation.layout.fillMaxWidth12+import androidx.compose.foundation.layout.height13+import androidx.compose.foundation.layout.padding14+import androidx.compose.foundation.layout.size15+import androidx.compose.foundation.layout.systemBarsPadding16+import androidx.compose.foundation.shape.CircleShape17+import androidx.compose.foundation.shape.RoundedCornerShape18+import androidx.compose.material3.Text19+import androidx.compose.runtime.Composable20+import androidx.compose.runtime.getValue21+import androidx.compose.ui.Alignment22+import androidx.compose.ui.Modifier23+import androidx.compose.ui.draw.clip24+import androidx.compose.ui.graphics.Color25+import androidx.compose.ui.text.font.FontStyle26+import androidx.compose.ui.text.style.TextAlign27+import androidx.compose.ui.unit.dp28+import androidx.compose.ui.unit.sp29+import androidx.hilt.navigation.compose.hiltViewModel30+import androidx.lifecycle.compose.collectAsStateWithLifecycle31+import com.peachpasswords.sync.PairingPhase32+import com.peachpasswords.ui.components.BirdAnimation33+import com.peachpasswords.ui.components.PairingAnimState34+import com.peachpasswords.ui.theme.LocalPeachAccent35+import com.peachpasswords.ui.theme.PeachColors36+import com.peachpasswords.ui.theme.PeachType37+import com.peachpasswords.ui.theme.ShellBackground38+39+@Composable40+fun ChirpPairScreen(41+ onBack: () -> Unit,42+ vm: ChirpPairViewModel = hiltViewModel(),43+) {44+ val progress by vm.progress.collectAsStateWithLifecycle()45+ val sas by vm.sasCode.collectAsStateWithLifecycle()46+ val accent = LocalPeachAccent.current47+ val phase = progress.phase48+49+ ShellBackground {50+ Column(modifier = Modifier.fillMaxSize().systemBarsPadding().padding(horizontal = 24.dp)) {51+ // Header52+ Row(53+ modifier = Modifier.fillMaxWidth().height(56.dp),54+ verticalAlignment = Alignment.CenterVertically,55+ ) {56+ Text(57+ text = "‹",58+ color = PeachColors.T1,59+ fontSize = 26.sp,60+ modifier = Modifier.clip(CircleShape).clickable(onClick = onBack).padding(horizontal = 8.dp),61+ )62+ Spacer(Modifier.size(8.dp))63+ Text("Sync", color = PeachColors.T0, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 19.sp)64+ }65+66+ StatusChip(phase, accent)67+68+ Box(69+ modifier = Modifier.fillMaxWidth().weight(1f),70+ contentAlignment = Alignment.Center,71+ ) {72+ BirdAnimation(73+ state = animState(phase),74+ modifier = Modifier.fillMaxWidth().height(220.dp),75+ )76+ }77+78+ Copy(phase, progress.peerDeviceName, progress.errorMessage)79+80+ Spacer(Modifier.height(20.dp))81+ PrimaryAction(phase, vm)82+ Spacer(Modifier.height(28.dp))83+ }84+85+ if (sas != null) {86+ SasOverlay(87+ code = sas!!,88+ accent = accent,89+ onConfirm = { if (vm.isDebug && progress.phase == PairingPhase.HANDSHAKE) vm.demoComplete() else vm.confirmSas(true) },90+ onCancel = { vm.confirmSas(false); vm.reset() },91+ )92+ }93+ }94+}95+96+private fun animState(phase: PairingPhase): PairingAnimState = when (phase) {97+ PairingPhase.IDLE -> PairingAnimState.WAITING98+ PairingPhase.LISTENING, PairingPhase.CHIRPING, PairingPhase.HANDSHAKE -> PairingAnimState.LISTENING99+ PairingPhase.PAIRED -> PairingAnimState.CONNECTED100+ else -> PairingAnimState.WAITING101+}102+103+@Composable104+private fun StatusChip(phase: PairingPhase, accent: Color) {105+ val (label, dot) = when (phase) {106+ PairingPhase.IDLE -> "ready" to PeachColors.T2107+ PairingPhase.LISTENING, PairingPhase.CHIRPING -> "listening" to accent108+ PairingPhase.HANDSHAKE -> "verifying" to accent109+ PairingPhase.PAIRED -> "paired" to Color(0xFF7FB069)110+ PairingPhase.MIC_DENIED -> "mic blocked" to PeachColors.Breach111+ else -> "interrupted" to PeachColors.Breach112+ }113+ Row(verticalAlignment = Alignment.CenterVertically) {114+ Box(Modifier.size(6.dp).clip(CircleShape).background(dot))115+ Spacer(Modifier.size(6.dp))116+ Text(label, color = PeachColors.T1, fontFamily = PeachType.Mono, fontSize = 9.sp)117+ }118+}119+120+@Composable121+private fun Copy(phase: PairingPhase, peer: String?, error: String?) {122+ val (headline, sub) = when (phase) {123+ PairingPhase.IDLE -> "Pair a device" to "Peach pairs over a short, inaudible chirp — no codes typed, no servers."124+ PairingPhase.LISTENING, PairingPhase.CHIRPING -> "Listening…" to "Hold this phone near the other device and start pairing there too."125+ PairingPhase.HANDSHAKE -> "Almost there" to "Check that the code below matches on ${peer ?: "the other device"}."126+ PairingPhase.PAIRED -> "Paired" to "${peer ?: "Your devices"} will now keep your vault in step over the local network."127+ PairingPhase.TIMEOUT -> "No chirp heard" to "Nothing answered. Move the devices closer and try again."128+ PairingPhase.MIC_DENIED -> "Microphone needed" to "Pairing listens for an inaudible chirp. Grant mic access to continue."129+ PairingPhase.VERSION_MISMATCH -> "Version mismatch" to "Update Peach on both devices, then try pairing again."130+ else -> "Pairing interrupted" to (error ?: "Something went wrong. Try again.")131+ }132+ Column(modifier = Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {133+ Text(headline, color = PeachColors.T0, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 26.sp, textAlign = TextAlign.Center)134+ Spacer(Modifier.height(8.dp))135+ Text(sub, color = PeachColors.T2, fontFamily = PeachType.Body, fontSize = 13.sp, textAlign = TextAlign.Center)136+ }137+}138+139+@Composable140+private fun PrimaryAction(phase: PairingPhase, vm: ChirpPairViewModel) {141+ val accent = LocalPeachAccent.current142+ when (phase) {143+ PairingPhase.IDLE -> PillButton("Start pairing", accent, filled = true) { vm.startPairing() }144+ PairingPhase.LISTENING, PairingPhase.CHIRPING, PairingPhase.HANDSHAKE ->145+ PillButton("Cancel", PeachColors.T2, filled = false) { vm.reset() }146+ PairingPhase.PAIRED -> PillButton("Done", accent, filled = true) { vm.reset() }147+ else -> PillButton("Try again", accent, filled = true) { vm.startPairing() }148+ }149+ if (vm.isDebug && phase == PairingPhase.IDLE) {150+ Spacer(Modifier.height(10.dp))151+ Text(152+ "demo flow",153+ color = PeachColors.T3,154+ fontFamily = PeachType.Mono,155+ fontSize = 9.sp,156+ modifier = Modifier.fillMaxWidth().clickable { vm.runDemo() }.padding(8.dp),157+ textAlign = TextAlign.Center,158+ )159+ }160+}161+162+@Composable163+private fun PillButton(label: String, color: Color, filled: Boolean, onClick: () -> Unit) {164+ val accent = LocalPeachAccent.current165+ Box(166+ modifier = Modifier167+ .fillMaxWidth()168+ .clip(RoundedCornerShape(14.dp))169+ .background(if (filled) accent.copy(alpha = 0.14f) else Color.Transparent)170+ .clickable(onClick = onClick)171+ .padding(vertical = 15.dp),172+ contentAlignment = Alignment.Center,173+ ) {174+ Text(label, color = if (filled) accent else color, fontFamily = PeachType.Mono, fontSize = 13.sp)175+ }176+}177+178+@Composable179+private fun SasOverlay(code: String, accent: Color, onConfirm: () -> Unit, onCancel: () -> Unit) {180+ Box(181+ modifier = Modifier.fillMaxSize().background(Color(0xCC0C0A06)),182+ contentAlignment = Alignment.Center,183+ ) {184+ Column(185+ modifier = Modifier.fillMaxWidth().padding(horizontal = 36.dp),186+ horizontalAlignment = Alignment.CenterHorizontally,187+ ) {188+ Text("Verify the code", color = PeachColors.T0, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 22.sp)189+ Spacer(Modifier.height(6.dp))190+ Text("It must match on both devices.", color = PeachColors.T2, fontFamily = PeachType.Body, fontSize = 13.sp, textAlign = TextAlign.Center)191+ Spacer(Modifier.height(28.dp))192+ Text(193+ text = code,194+ color = accent,195+ fontFamily = PeachType.Mono,196+ fontSize = 38.sp,197+ letterSpacing = 6.sp,198+ )199+ Spacer(Modifier.height(34.dp))200+ PillButton("They match — pair", accent, filled = true, onClick = onConfirm)201+ Spacer(Modifier.height(10.dp))202+ PillButton("Cancel", PeachColors.T2, filled = false, onClick = onCancel)203+ }204+ }205+}app/src/main/java/com/peachpasswords/ui/pairing/ChirpPairViewModel.kt+138 −0
@@ -0,0 +1,138 @@1+package com.peachpasswords.ui.pairing2+3+import android.content.Context4+import androidx.lifecycle.ViewModel5+import androidx.lifecycle.viewModelScope6+import com.peachpasswords.BuildConfig7+import com.peachpasswords.sync.AudioIO8+import com.peachpasswords.sync.ChirpPairingDeps9+import com.peachpasswords.sync.LocalChirpIdentity10+import com.peachpasswords.sync.PairedDevice11+import com.peachpasswords.sync.PairingEndpoint12+import com.peachpasswords.sync.PairingPhase13+import com.peachpasswords.sync.PairingProgress14+import com.peachpasswords.sync.PairingRole15+import com.peachpasswords.sync.PairingServer16+import com.peachpasswords.sync.PairingTransport17+import com.peachpasswords.sync.buildLocalIdentity18+import com.peachpasswords.sync.openAndroidAudioIO19+import com.peachpasswords.sync.runChirpPairing20+import com.peachpasswords.vault.VaultCrypto21+import com.peachpasswords.vault.VaultRepository22+import dagger.hilt.android.lifecycle.HiltViewModel23+import dagger.hilt.android.qualifiers.ApplicationContext24+import kotlinx.coroutines.CompletableDeferred25+import kotlinx.coroutines.delay26+import kotlinx.coroutines.flow.MutableStateFlow27+import kotlinx.coroutines.flow.StateFlow28+import kotlinx.coroutines.flow.asStateFlow29+import kotlinx.coroutines.launch30+import javax.inject.Inject31+32+/**33+ * Drives the Chirp pairing flow and surfaces its phase + SAS code to34+ * [ChirpPairScreen]. The real audio bridge ([openAndroidAudioIO]) lands in35+ * Phase 12; until then [startPairing] runs the genuine orchestrator and36+ * surfaces the audio-unavailable phase honestly, while [runDemo] (DEBUG only)37+ * steps the visuals through all three acts so the animation and SAS screen can38+ * be verified on a single device.39+ */40+@HiltViewModel41+class ChirpPairViewModel @Inject constructor(42+ @ApplicationContext private val context: Context,43+ private val vault: VaultRepository,44+) : ViewModel() {45+46+ private val _progress = MutableStateFlow(PairingProgress(PairingPhase.IDLE))47+ val progress: StateFlow<PairingProgress> = _progress.asStateFlow()48+49+ private val _sasCode = MutableStateFlow<String?>(null)50+ val sasCode: StateFlow<String?> = _sasCode.asStateFlow()51+52+ val isDebug: Boolean = BuildConfig.DEBUG53+54+ private var sasGate: CompletableDeferred<Boolean>? = null55+56+ fun startPairing() {57+ val master = vault.syncMasterKey() ?: run {58+ _progress.value = PairingProgress(PairingPhase.HANDSHAKE_FAILED, errorMessage = "vault_locked")59+ return60+ }61+ _progress.value = PairingProgress(PairingPhase.LISTENING)62+ viewModelScope.launch {63+ try {64+ runChirpPairing(deps(master), role = PairingRole.INITIATOR)65+ } catch (e: Exception) {66+ if (_progress.value.phase.let { it != PairingPhase.TIMEOUT && it != PairingPhase.MIC_DENIED }) {67+ _progress.value = PairingProgress(68+ PairingPhase.HANDSHAKE_FAILED,69+ errorMessage = e.message ?: "pairing_failed",70+ )71+ }72+ } finally {73+ VaultCrypto.zero(master)74+ }75+ }76+ }77+78+ fun confirmSas(accepted: Boolean) {79+ sasGate?.complete(accepted)80+ _sasCode.value = null81+ }82+83+ fun reset() {84+ sasGate?.complete(false)85+ sasGate = null86+ _sasCode.value = null87+ _progress.value = PairingProgress(PairingPhase.IDLE)88+ }89+90+ /** DEBUG: walk the three acts so the screen can be exercised without a peer. */91+ fun runDemo() {92+ if (!isDebug) return93+ viewModelScope.launch {94+ _progress.value = PairingProgress(PairingPhase.IDLE)95+ delay(700)96+ _progress.value = PairingProgress(PairingPhase.LISTENING)97+ delay(1800)98+ _progress.value = PairingProgress(PairingPhase.HANDSHAKE, peerDeviceName = "June's Laptop")99+ _sasCode.value = "418 207"100+ }101+ }102+103+ /** DEBUG: complete the demo into the paired act after SAS confirmation. */104+ fun demoComplete() {105+ _sasCode.value = null106+ _progress.value = PairingProgress(PairingPhase.PAIRED, peerDeviceName = "June's Laptop")107+ }108+109+ private fun deps(masterKey: ByteArray): ChirpPairingDeps = object : ChirpPairingDeps {110+ override val chirpTimeoutMs: Long = 15_000111+112+ override suspend fun fetchLocalIdentity(): LocalChirpIdentity =113+ buildLocalIdentity(context, masterKey)114+115+ override suspend fun completePairing(paired: PairedDevice) {116+ // A paired-device registry lands with sync persistence; the flow's117+ // success is reflected through the PAIRED progress phase for now.118+ }119+120+ override suspend fun confirmSAS(sas: String): Boolean {121+ val gate = CompletableDeferred<Boolean>()122+ sasGate = gate123+ _sasCode.value = sas124+ return gate.await()125+ }126+127+ override suspend fun cacheLastKnownIp(pubkeyHex: String, ip: String) {}128+ override suspend fun getLocalSubnet(): String? = null129+ override suspend fun openPairingTransport(endpoint: PairingEndpoint): PairingTransport =130+ throw UnsupportedOperationException("pairing transport not wired until sync persistence")131+ override suspend fun openPairingServer(): PairingServer =132+ throw UnsupportedOperationException("pairing server not wired until sync persistence")133+ override suspend fun openAudio(): AudioIO = openAndroidAudioIO()134+ override fun onProgress(progress: PairingProgress) {135+ _progress.value = progress136+ }137+ }138+}