From deaa93fead38af6e4cb45123a675278c48f4c076 Mon Sep 17 00:00:00 2001 From: James Babcock Date: Mon, 28 Sep 2026 12:04:15 -0700 Subject: [PATCH] Wake the screen on wear faster after charging --- app/g2/dashboard-controller.ts | 39 ++++++++++++++++--- app/native/faceclaw-communicator.ts | 5 +++ .../g2protocol/session/GlassesSessionCore.kt | 16 ++++++++ .../g2protocol/session/GlassesSessionSend.kt | 18 +++++++-- .../com/faceclaw/wear/ui/StatusScreen.kt | 2 +- 5 files changed, 71 insertions(+), 9 deletions(-) diff --git a/app/g2/dashboard-controller.ts b/app/g2/dashboard-controller.ts index a4aa4c06..d07b9699 100644 --- a/app/g2/dashboard-controller.ts +++ b/app/g2/dashboard-controller.ts @@ -291,6 +291,8 @@ class DashboardController { private customFirmwareConfirmed = false; private faceclawWakeLeaseState: boolean | null = null; private glassesWorn: boolean | null = null; + /** Put on while charging: Java reconnects on that, and the wake waits for the new session. */ + private wakeAfterChargingReconnect = false; private phoneLocked = false; private glassesLocked = false; // Wear OS watch remote; constructed last so it sees a fully wired shell. @@ -654,7 +656,16 @@ class DashboardController { if (!wearing && this.phoneLocked && lockScreenEnabledSetting.get()) { this.setGlassesLocked(true, "glasses removed while phone locked"); } - if (putOn) this.wakeForGlassesPutOn(); + if (!wearing) this.wakeAfterChargingReconnect = false; + if (putOn && this.phase === "charging") { + // They can't be worn in the case, so charging is over even though no + // battery poll has said so yet. Java reconnects on this same report + // (the wake barrier needs the rebuilt session), so wake after that. + this.wakeAfterChargingReconnect = true; + this.appendLog("glasses put on while charging; waking after reconnect"); + } else if (putOn) { + this.wakeForGlassesPutOn(); + } } /** @@ -669,6 +680,16 @@ class DashboardController { if (shell.wake("sidebar")) this.appendLog("screen woken: glasses put on"); } + /** + * Finish a put-on that arrived while charging. Each arm reports "connected" + * as it links, before the prelude; the ready session reports it again. + */ + private maybeWakeAfterChargingReconnect(): void { + if (!this.wakeAfterChargingReconnect || !this.communicator?.isSessionReady()) return; + this.wakeAfterChargingReconnect = false; + this.wakeForGlassesPutOn(); + } + private handlePhoneLockState(locked: boolean): void { if (locked === this.phoneLocked) return; this.phoneLocked = locked; @@ -692,10 +713,13 @@ class DashboardController { private ensureWearStateTracking(): void { const communicator = this.communicator; + // Charging counts: a session that starts in the case (firmware confirmed + // only after charging mode began) needs the OFF_HEAD snapshot so that + // putting the glasses on registers as a put-on. if ( !lockScreenEnabledSetting.get() || !this.customFirmwareConfirmed || - this.phase !== "connected" || + (this.phase !== "connected" && this.phase !== "charging") || !communicator ) { return; @@ -1358,6 +1382,7 @@ class DashboardController { this.welcomeSoundArmed = isWelcomeSoundPending(); this.firmwareWarningMessage = ""; this.glassesWorn = null; + this.wakeAfterChargingReconnect = false; this.glassesLocked = false; this.refreshBatteryOptimizationStatus(); this.refreshEvenAppStatus(); @@ -1434,13 +1459,16 @@ class DashboardController { this.pushFirmwareDebugFlags(); this.pushBrightness(true); } - if (mappedPhase !== "connected") { + if (mappedPhase !== "connected" && mappedPhase !== "charging") { // A wear snapshot is session-scoped. CFW reports a fresh value when // the transport comes back, so do not make lock decisions from a - // stale pre-disconnect value in the meantime. + // stale pre-disconnect value in the meantime. Charging keeps the + // link (and the value), so putting the glasses on registers. this.glassesWorn = null; updateGlassesPresence({ worn: null }); - // The mic enable was session-scoped too: park any live capture so + } + if (mappedPhase !== "connected") { + // The mic enable was session-scoped: park any live capture so // the next session restarts it, instead of leaving a holder that // makes every later request think the mic is already running. voiceControlBridge.handleSessionEnded(); @@ -1450,6 +1478,7 @@ class DashboardController { if (mappedPhase === "connected") { this.syncEvenHubScreenOffSetting(); this.ensureWearStateTracking(); + this.maybeWakeAfterChargingReconnect(); } else if (mappedPhase !== "charging") { this.cancelEvenHubSuspendTimer(); this.evenHubSessionSuspended = false; diff --git a/app/native/faceclaw-communicator.ts b/app/native/faceclaw-communicator.ts index ced591d5..0f8c2771 100644 --- a/app/native/faceclaw-communicator.ts +++ b/app/native/faceclaw-communicator.ts @@ -471,6 +471,11 @@ export class FaceclawCommunicatorBridge { await this.enqueueJavaCall(() => this.communicator.enableWearDetectionAndRequestState()); } + /** Whether the transport prelude has finished (each arm reports "connected" before it). */ + isSessionReady(): boolean { + return Boolean(this.communicator.isSessionReady()); + } + /** Set the compositor's output frame size. Call before configuring surfaces. */ async configureCompositorScreen(width: number, height: number): Promise { await this.enqueueJavaCall(() => { diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/session/GlassesSessionCore.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/session/GlassesSessionCore.kt index 9aa9a098..f0822e98 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/session/GlassesSessionCore.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/session/GlassesSessionCore.kt @@ -1364,10 +1364,15 @@ class GlassesSessionCore( else null var emitWearState = false + var putOnWhileCharging = false var event: G2Event? = null monitor.withLock { lastIncomingAtMs = now() if (decodedWearState >= 0 && decodedWearState != wearState) { + // An observed OFF_HEAD -> ON_HEAD means charging is over, up + // to CHARGING_BATTERY_POLL_MS before a battery poll would say + // so. Like TS's put-on wake, a first snapshot doesn't count. + putOnWhileCharging = chargingMode && wearState == 0 && decodedWearState == 1 wearState = decodedWearState emitWearState = true } @@ -1540,6 +1545,11 @@ class GlassesSessionCore( logLine(if (decodedWearState > 0) "wear state ON_HEAD" else "wear state OFF_HEAD") emitWearState(decodedWearState > 0) } + if (putOnWhileCharging) { + // After the emit, so TS sees the put-on while still in its + // charging phase and wakes once the rebuilt session is ready. + monitor.withLock { endChargingModeLocked("glasses put on while charging") } + } if (compassEvent != null) { emitCompassEvent(compassEvent) } @@ -1649,6 +1659,12 @@ class GlassesSessionCore( // Connect sequence (worker thread) internal fun connectLoopOnce() { + monitor.withLock { + // TS treats a wear snapshot as per-transport and forgets it on a + // reconnect; forget ours too, or the new session's first report + // (the CFW query reply) is deduped away and TS never relearns it. + wearState = -1 + } setStateDisplay("connecting", "Connecting to the glasses...") try { connectArm(rightAddress, true) diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/session/GlassesSessionSend.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/session/GlassesSessionSend.kt index ba36b747..44386bbe 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/session/GlassesSessionSend.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/session/GlassesSessionSend.kt @@ -1003,12 +1003,24 @@ internal fun GlassesSessionCore.updateChargingModeLocked(charging: Boolean, batt logLine("glasses are charging; pausing display communication") setStateDisplay("charging", GlassesSessionCore.chargingStatusText(battery)) } else { - chargingMode = false - logLine("glasses removed from charger; reconnecting") - handleTransportFailure("charging ended") + endChargingModeLocked("glasses removed from charger") } } +/** + * Leave charging mode, whether a battery poll or putting the glasses on + * (they can't be worn in the case) said charging is over. The rebuild goes + * through the normal reconnect loop. + */ +internal fun GlassesSessionCore.endChargingModeLocked(why: String) { + if (!chargingMode) { + return + } + chargingMode = false + logLine("$why; reconnecting") + handleTransportFailure("charging ended") +} + /** * Record, into the frame that is waiting, why it did not go out on this * pass of the send loop. Without this the export shows a bare multi-second diff --git a/wear/app/src/main/kotlin/com/faceclaw/wear/ui/StatusScreen.kt b/wear/app/src/main/kotlin/com/faceclaw/wear/ui/StatusScreen.kt index d34f659c..a8080e7b 100644 --- a/wear/app/src/main/kotlin/com/faceclaw/wear/ui/StatusScreen.kt +++ b/wear/app/src/main/kotlin/com/faceclaw/wear/ui/StatusScreen.kt @@ -47,7 +47,7 @@ fun StatusScreen(link: PhoneLink, haptics: Haptics, onOpenSettings: () -> Unit) val phaseLabel = when { state == null -> "No status yet" state?.charging == true || state?.phase == "charging" -> - state?.battery?.let { "Charging · G2 $it%" } ?: "Charging" + state?.battery?.let { "Charging" } ?: "Charging" connected -> "Connected" state?.phase == "connecting" -> "Connecting…" state?.phase == "disconnecting" -> "Disconnecting…"