Fix overlay flicker and removal race conditions#26
Merged
Conversation
- Only act on TYPE_WINDOW_STATE_CHANGED when a foreign package takes focus; content changes and scrolls from systemui or the launcher no longer clear overlays while the target app is still the active window below (e.g. a status bar update from an arriving notification). - Debounce the clear by 150ms on foreign window-state changes; a subsequent event from the target package cancels the pending clear. This absorbs transient focus changes such as a briefly pulled notification shade. - Make OverlayManager.clearOverlays consistent with forceClearOverlays: check getParent() before removeView and move the tracker removal inside the posted runnable so the list cannot diverge from the window state. - Cancel the pending clear runnable from all teardown paths (reloadRulesFromSource, reevaluateBlockingState, screen off, onInterrupt, onDestroy). https://claude.ai/code/session_018ChatjS8SFHCh8w7ySjCte
Window operations and tracker updates now happen together on the caller's thread (always main for this service) instead of being posted. A queued addView can no longer run after a clear and leave an orphan view attached but untracked, and clearOverlays can no longer empty the tracker list before removeView has actually detached the views. Callers (BaseDistractionControlService) drop the Handler argument and forceClearAllOverlays collapses to a clearAllOverlays alias, since the two paths are now equivalent. No per-element grace period: keeping an overlay past its node's disappearance would leave it pinned at a stale position while the feed scrolls beneath it (Instagram-style), which is a worse artifact than a brief flicker. https://claude.ai/code/session_018ChatjS8SFHCh8w7ySjCte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses two reported overlay artifacts: (1) overlays briefly disappearing and reappearing while still in the target app, and (2) overlays staying visible after leaving the app.
Flicker —
onAccessibilityEventis too eager to clearTYPE_WINDOW_STATE_CHANGEDfrom a foreign package now counts as a leave signal. Content changes and scrolls fromsystemui(e.g. status bar updates from an arriving notification) or the launcher no longer trigger a clear while the target app is still the active window underneath.Race —
OverlayManageradd/remove was partly async, partly syncOverlayManageroperations are now synchronous on the caller's thread (always main for the accessibility service). A queuedaddViewcan no longer run after aclearand leave an orphan view attached but untracked.clearOverlayscan no longer empty the tracker list beforeremoveViewhas actually detached the views.forceClearAllOverlayscollapses to aclearAllOverlaysalias since both paths are now equivalent.Cleanup
reloadRulesFromSource,reevaluateBlockingState, screen off,onInterrupt,onDestroy).Considered and rejected
info.packageNames = nullto receive events for unmonitored apps: would fix the case where a switch never delivers an event to the service, but increases battery cost on every other app.Test plan
https://claude.ai/code/session_018ChatjS8SFHCh8w7ySjCte