Android TV Does Not Sleep When Idle (Screen Goes Black but Device Stays On) #4
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Android TV Does Not Sleep When Idle (Screen Goes Black but Device Stays On)
Header
Confirmed534f5f4d— fix(android): remove insecure SSL bypass + proper MediaSession lifecycle (MediaSession never deactivates)fix/firestick-black-screen-remove-visibility-toggle— removal ofvideoLayout.setVisibility(INVISIBLE)on idle (video surface stays VISIBLE)Summary
When the user is idle in AnimeTV (not playing anything — e.g. sitting on the
homepage/browse screen or paused), the Android TV no longer goes to sleep as it
used to. Instead the screen turns black (display timeout) but the device stays
powered on. This is consistent with the app holding the system in an "active
media" state, which inhibits the Android TV screensaver/standby.
The root cause is an always-active MediaSession: once playback starts, the
MediaSessionis activated and is never deactivated, because the only codepath that updates the media state can report
STATE_PLAYINGorSTATE_PAUSEDbut never a stopped/none state. Android TV treats an active media session as a
reason to keep the device awake.
Key Findings
1. The only screen-keep-on flag is correctly scoped to playback
In
AnimeView.java,setKeepScreenOnis only applied to the video surface andis cleared on pause/stop:
There is no window-level
FLAG_KEEP_SCREEN_ONand noPowerManagerwake lock, and ExoPlayer's
setWakeModeis not used. So the keep-screen-onbehavior is not the cause.
2. MediaSession is activated based on state, but never receives a "stopped" state
MainActivity.mediaSetState()(added in commit534f5f4d):The intent was: activate when PLAYING/PAUSED/BUFFERING, deactivate otherwise.
3. The caller can never produce a "deactivate" state
mediaSetState()is only ever called from one place, inside the ExoPlayerAnalyticsListenerinAnimeView.java:This callback (
onIsPlayingChanged) can only ever emitSTATE_PLAYINGorSTATE_PAUSED. There is no code path that passesSTATE_NONE,STATE_STOPPED, orSTATE_IDLE.Consequence:
STATE_PLAYING→mSession.setActive(true).STATE_PAUSED→
shouldBeActiveis stilltrue→ the session stays active.in
onDestroy().4. Why an active MediaSession keeps Android TV awake
Android TV's standby/screensaver (Daydream) is inhibited while an app holds an
active media session, because the system assumes media playback (or paused
media that may resume) is in progress. With the session stuck active in
STATE_PAUSED, the OS blanks the display on its normal timeout but does not putthe device to sleep — exactly the reported symptom.
Comparison (Before / After the regression)
534f5f4d534f5f4d(current)setActivemanagement → TV sleepsactive(PAUSED) → TV does not sleep, screen goes black onlyThis matches the user's phrasing: "but now" — the behavior changed after the
MediaSession activation logic was introduced.
Secondary Finding — Idle video surface left VISIBLE (post-v5.14.4)
A change on the current branch
(
fix/firestick-black-screen-remove-visibility-toggle) removed thevideoLayout.setVisibility(View.INVISIBLE)call from the idle/stop branch ofvideoSetUrlinAnimeView.java. Previously, clearing the URL(
videoSetUrl("")) hid the video surface; now the surface is left attached andVISIBLE between streams.
Evidence of the removal (current
videoSetUrlWithPosition, theurl.equals("")branch now only calls
videoPlayerStop()+videoSetSource(""), with novisibility toggle), plus a now-stale comment near
videoPlayerStop()thatstill claims "The
videoLayout.setVisibility(View.INVISIBLE)invideoSetUrl("")already prevents the last-frame flash" — that call no longerexists.
Why this matters for standby:
/ Shield devices, contribute to the system keeping the compositor/device
active even after playback stops.
better than the MediaSession bug alone.
Constraint (important): the visibility toggle was intentionally removed to
fix the Fire TV / Shield black-screen-audio-only bug documented in
2026-07-03_miruro-hls-black-screen-audio-only-firestick-shield.md. Any fix forthe standby issue must not re-introduce the surface-recreation bug. Prefer
addressing standby via the MediaSession deactivation path (Recommended Actions
below) rather than re-adding the visibility toggle.
Failure Scenarios
for the rest of the app's lifetime, wasting power and generating heat.
increases burn-in exposure over long idle periods.
may behave unexpectedly.
Recommended Actions
Immediate / short-term fix
Deactivate the MediaSession when playback is genuinely stopped, not merely
paused. Options (any one resolves the core issue):
Add a stopped/none state path — call
mediaSetState(PlaybackState.STATE_NONE, 0)(orSTATE_STOPPED) fromvideoPlayerStop()/ when the player transitions to IDLE/ENDED, and removeSTATE_PAUSEDfrom theshouldBeActiveset so a paused-and-idle session candeactivate. (Note: keeping PAUSED active is standard for resumable media, so
prefer option 2 for the idle case.)
Deactivate the session when the app goes to background / stops — in
MainActivity.onStop()(orAnimeView.onStartPause(false)), if not activelyplaying, call
mSession.setActive(false). This ensures that once the userleaves playback / goes idle, the session no longer inhibits standby.
Deactivate on player IDLE/ENDED — hook
onPlaybackStateChanged(state1=IDLE/4=ENDED) to report a stopped media state so the sessiondeactivates when there is nothing to resume.
Recommended combination: report a stopped state from the player's IDLE/ENDED /
videoPlayerStop()path and deactivate ononStop()when not playing.Long-term
emits an explicit terminal state, so the MediaSession lifecycle cannot get
"stuck".
confirm the TV enters standby within the OS timeout.
Files Involved
app/src/main/java/com/amarullz/androidtv/animetvjmto/MainActivity.javamediaSetState()MediaSession activation logic;onStop()/onPause()lifecycleapp/src/main/java/com/amarullz/androidtv/animetvjmto/AnimeView.javaAnalyticsListener(only caller ofmediaSetState);videoPlayerPlay/Pause/Stop,onStartPauseRelated Commits
534f5f4d63df455b7d886337Status Notes
mediaSetStatecannotproduce a deactivating state, so the session remains active after any playback.
dumpsys power/dumpsys media_session, butthe code path is unambiguous. On-device confirmation recommended:
adb shell dumpsys media_sessionshould show the AnimeTV session asactive=truewhile idle after playback.adb shell dumpsys powershould show the display allowed to sleep but thedevice kept awake by media.