Skip to content

diag: log what turned the screen off and how long it stayed off - #26

Open
thiagosoeiro wants to merge 3 commits into
masterfrom
diag/screen-off-reason
Open

thiagosoeiro wants to merge 3 commits into
masterfrom
diag/screen-off-reason

Conversation

@thiagosoeiro

Copy link
Copy Markdown
Owner

Why

From the 2026-09-17 logs, the screen went off and came back on within 0.1–0.7 s three times (20:18:57.951 → .065, 20:42:51.118 → .856, 20:43:10.386 → .780 UTC), two of them confirmed by the display itself (onDisplayChanged 2 → 1 → 2).

Two different things are happening there, and the log could not tell them apart:

  • The screen going off early is this app: ScreenTimeoutByNetwork wrote set to 15 s, was 30 s at 20:42:34 on leaving the trusted Wi-Fi, and the screen died 17 s later.
  • The screen coming back is not: nothing here ran in that window, and the accessibility backend has no code that can wake a display. The only window that can (FLAG_TURN_SCREEN_ON in PasswordOverlayScreen) belongs to PasswordOverlayActivity, which only the Shizuku and Usage backends launch.

Our own export runs logcat -d, which only returns this app's pid, so the waking party never appears in the file.

What this adds

Android does not hand an ordinary app a wake reason, so this records the timing shape instead, on the screen-state receiver that already exists:

  • Screen off: how long the screen had been on, and the screen timeout in force — the setting "Screen timeout by network" writes. A countdown that ran out is told from something turning the screen off early.
  • Screen on: how long it was off, flagged as straight back on inside 2 s, plus whether the phone locked meanwhile.
Screen off 16.8 s after it came on, screen timeout 15.0 s: long enough for the timeout to have run out
Screen off 6.2 s after it came on, screen timeout 30.0 s: sooner than the timeout, so the power key or something else turned it off
Screen on after 0.4 s off, straight back on, phone locked

"After it came on" is the idle time only if the screen was left alone — a touch restarts Android's countdown and is invisible here — so a short reading is the telling one. That caveat is in the KDoc.

Diagnostics only: no behaviour changes, and the lines go through LogUtils, so they follow the logging switch.

🤖 Generated with Claude Code

thiagosoeiro and others added 3 commits September 17, 2026 19:24
The screen has been going dark sooner than expected and coming straight
back on. Nothing here can turn a display on, and our own log export only
sees this app's own pid, so the log could not say which of the two was
happening.

Screen off now records how long the screen had been on and the screen
timeout in force, which "Screen timeout by network" writes, so a screen
that ran out its own countdown is told from one something turned off.
Screen on records how long it was off, flagging a screen that came
straight back rather than being woken by hand.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The flicker is the dim before the screen goes off, repeating - dark,
bright, dark - not the screen going on and off, so the screen off and on
lines land at the wrong moment to catch it.

Two causes look the same to the eye and different in the log. Auto
brightness rewrites the brightness setting, so a run of changes in the
last seconds is the light sensor hunting; a ContentObserver on it now
logs each change with how long the screen has been on. Android's own dim
never touches that setting, so a dim repeating while the observer stays
quiet is the dim countdown being restarted - which writing the screen
timeout does, and that write now says when it landed while the screen
was on.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
# Conflicts:
#	app/src/main/java/dev/pranav/applock/services/AppLockAccessibilityService.kt
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.

1 participant