Skip to content

Let the app answer in the background before restoring focus when the screen turns on - #286

Merged
trypsynth merged 1 commit into
masterfrom
wake-focus-warmup
Oct 27, 2026
Merged

trypsynth merged 1 commit into
masterfrom
wake-focus-warmup

Conversation

@trypsynth

Copy link
Copy Markdown
Owner

For #152

Problem

Devin's retest on build 318 showed 13 main-thread blocks of 101 to 275 ms when the watch screen turns on. Six of them are FocusActorForScreenStateChange.restoreLastFocusedNode -> FocusActionRecord.getFocusableNodeFromFocusRecord -> AccessibilityNodeInfo.refresh, waiting 101 to 298 ms. When the screen turns on, the app in front is busy drawing again, and the first request sent to it waits until that's done. Moving just that refresh() to another thread wouldn't help, because restoring focus then sends performAction to the same busy app from the main thread.

Change

  • New focusmanagement/WakeFocusWarmUp.kt. It fetches the last focused item on a background thread, then runs the restore on the main thread once the app has answered, when its requests are quick. If the app hasn't answered after 500 ms, the restore runs anyway, as before.
  • FocusProcessorForScreenStateChange.onScreenStateChangedInternal uses it only for the first screen state after waking, when there is a focus record for the active window. Everything else runs at once, as before.
  • A waiting restore is dropped when the screen state changes again, and skipped if focus was moved while the app was answering, so it never takes focus away from the user.
  • differences.md has a paragraph under Faster screen changes.

Testing

…screen turns on

When the screen turns on, the app in front is busy drawing again, and restoring focus asked it for
the last focused item from the main thread, which waited 100 to 300 ms on a watch (#152). The item
is now fetched on a background thread first, and focus is restored once the app has answered,
when its requests are quick, or after 500 ms at most. A restore still waiting is dropped when the
screen changes again, or when focus moved in the meantime.
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