Wake the screen on wear faster after charging

This commit is contained in:
James Babcock committed 2026-09-28 12:04:15 -07:00
1 parent 2052e268b0
commit deaa93fead
5 files changed
+71 -9

No files matched your search

+34 -5
View File
@@ -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;
+5
View File
@@ -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<void> {
await this.enqueueJavaCall(() => {
@@ -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)
@@ -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
@@ -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…"