Repository navigation
Let the app answer in the background before restoring focus when the screen turns on - #286
Merged
Merged
Conversation
…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.
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.
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 thatrefresh()to another thread wouldn't help, because restoring focus then sendsperformActionto the same busy app from the main thread.Change
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.onScreenStateChangedInternaluses 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.differences.mdhas a paragraph under Faster screen changes.Testing
WakeFocusWarmUpTest: the restore waits for the app, runs once after the timeout, is dropped bycancel, and a later request drops an earlier one.:talkback:testPhoneDebugUnitTest(540 tests),:lintPhoneDebug,:lintWearDebug,assemblePhoneDebugandassembleWearDebugpass.restoreLastFocusedNodeblocks are gone, and whether focus still comes back to the right item on wake.