Skip to content

Overnight dark window: a deliberate wake keeps control (fixes #138)#141

Merged
starbrightlab merged 1 commit into
mainfrom
fix/overnight-dark-wake-138
Jul 9, 2026
Merged

Overnight dark window: a deliberate wake keeps control (fixes #138)#141
starbrightlab merged 1 commit into
mainfrom
fix/overnight-dark-wake-138

Conversation

@starbrightlab

Copy link
Copy Markdown
Owner

Problem

Reported in #138 (fresh on 1.60). With overnight screen-off (dark mode) enabled, tapping to wake the device inside the window wakes the screen and then it "turns off the instant it lights up."

Root cause

The dark window ends in ScreenControl.sleep (device-admin lockNow), with no night session active. A tap fires ACTION_DREAMING_STOPPED:

  1. classifyDreamStop sees pm.isInteractive == true (the user just woke it) → verdict REDREAM (PresenceState.kt, "force-woken but still awake → someone's here").
  2. REDREAM routes into SleepScheduler.handleRedreamDuringOvernight.
  3. classifyOvernightRedream(inWindow=true, nightSessionActive=false, nightClock=false)REBLANKScreenControl.sleep.

The subtlety: every redream that reaches this path is already interactive — that is precisely what makes the verdict REDREAM — so interactivity alone can't distinguish a real user wake from a stray sibling/system dream cycle (the #73 case). The old code treated the whole class as a stray cycle and reblanked, which is why the deliberate wake got slammed off. #87's "keep control" session is normally started by HomeActivity.onResume, but in dark mode the reblank wins the race before the launcher resumes (night-clock mode is unaffected because the clock Activity holds the screen).

Fix

Use the real user-input signal (USER_PRESENT / a launcher touch) to tell a wake from a stray cycle:

  • onInteraction now starts a night session when inside the window with none active, instead of only renewing an existing one — handing the user the device on a dark-window wake.
  • A lastUserWakeAt timestamp feeds a new userWokeRecently input to classifyOvernightRedream: a redream within USER_WAKE_GRACE_MS (4s) of a real wake LEAVEs (and the caller starts the session) rather than reblanking, covering the race where the dream-stop broadcast beats USER_PRESENT.
  • Stray cycles (no recent user wake) still REBLANK, so Screensaver during sleep hours flickers on every few mins briefly. #73 stays fixed.

Testing

Needs on-device confirmation

The pure logic is unit-tested, but the wake-event sequence on hardware is device-specific — in particular whether a dark-window tap emits ACTION_USER_PRESENT (which this fix keys on) and its ordering vs. the dream-stop. @leapon0507-alt — if you're able, a logcat of a wake during the window, or just a retest once this lands, would confirm it. The change degrades safely (stray-cycle behaviour is unchanged).

Closes #138.

🤖 Generated with Claude Code


Generated by Claude Code

In the dark overnight window the screen is off via lockNow. A tap to wake
fires ACTION_DREAMING_STOPPED; classifyDreamStop sees the device is interactive
and returns REDREAM, so handleRedreamDuringOvernight runs. With no night session
active it hit REBLANK and slept the screen again the instant it lit up.

The catch: every redream that reaches this path is already interactive (that is
what makes the verdict REDREAM), so interactivity alone cannot tell a real user
wake from a stray sibling/system dream cycle (issue #73). Use the real
user-input signal instead:

- onInteraction (USER_PRESENT / a launcher touch) now STARTS a night session
  when inside the window with none active, instead of only renewing an existing
  one - handing the user the device on a dark-window wake.
- A lastUserWakeAt timestamp feeds a new userWokeRecently input to
  classifyOvernightRedream: a redream within USER_WAKE_GRACE_MS of a real wake
  LEAVEs (and the caller starts the session) rather than reblanking, covering
  the race where the dream-stop broadcast beats USER_PRESENT. Stray cycles (no
  recent user wake) still REBLANK, so #73 stays fixed.

Pure-classifier unit tests cover both the #138 wake case and the #73 stray-cycle
case.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01H4SmhtgSd5B5sdTiV216XM
@starbrightlab starbrightlab merged commit 28e2a3b into main Jul 9, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable screensaver->overnight screen-off,After the screen is turned off at the set time, tapping the screen fails to wake it up normally.

2 participants