Repository navigation
fix(android): dispatch helper taps and keys without the global animation wait #4609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
thymikee
wants to merge
16
commits into
main
Choose a base branch
from
t3/android-press-timeout
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+699
−74
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9280f05
fix(android): dispatch helper taps and keys without the global animat…
thymikee 08b7884
test(android): scan the whole helper source tree for direct input inj…
thymikee affdba3
fix(android): report an unavailable animation sync apart from a refus…
thymikee 4bcd7ad
docs(android): state why a refused press end gets no cancel
thymikee 342b1a1
fix(android): release a timed-out press start instead of retrying it
thymikee 206e2e8
test(android): pin that a timed-out press start fails as a timeout wi…
thymikee b18555d
refactor(android): share one touch event builder and keep typed press…
thymikee 3dc041e
fix(android): bound a press by the host budget and report a refused c…
thymikee 53dd31c
refactor(android): release every refused press start and bound the re…
thymikee 604873e
fix(android): derive the helper press budget from the request's remai…
thymikee f728193
fix(android): run a press without a budget as a no-retry press
thymikee b23aeaa
fix(android): refuse a press whose request has no room for one injection
thymikee b2765da
test(android): name the budget test's catch parameter error
thymikee 1a51b2e
docs(android): state what the input timeout covers and why a budget r…
thymikee 818a200
fix(android): admit input on one attempt's cost and check fill's time…
thymikee 218e157
test(android): pin fill's typed refusal when text entry no longer fits
thymikee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
94 changes: 94 additions & 0 deletions
94
...snapshot-helper/src/main/java/com/callstack/agentdevice/snapshothelper/PressSequence.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| package com.callstack.agentdevice.snapshothelper; | ||
|
|
||
| /** | ||
| * Sequences one tap or key press: a start event, then an end event with the same down time. | ||
| * | ||
| * <p>Every refused start is released before anything else is decided: the verifier and the policy | ||
| * record a start even when the dispatcher drops it, and a start refused by the injection timeout | ||
| * was delivered. Without the framework's animation wait, a start is often refused only because a | ||
| * transition leaves nothing able to receive it, so it is retried once after the animation sync, | ||
| * with a fresh down time, when the host's deadline still has room for that retry. | ||
| */ | ||
| final class PressSequence { | ||
| /** | ||
| * The room a retry decision reserves: the framework's animation-sync cap | ||
| * ({@code WindowManagerService.ANIMATION_COMPLETED_TIMEOUT_MS}) plus the retried start's injection | ||
| * deadline ({@code InputManagerService.INJECTION_TIMEOUT_MILLIS}). The end is not reserved: it | ||
| * blocks only while the app does not finish handling it, which a press without a retry meets the | ||
| * same way, and a 60 s press request could never reserve a second 30 s deadline. | ||
| */ | ||
| static final long RETRY_WORST_CASE_MS = 5_000 + 30_000; | ||
|
thymikee marked this conversation as resolved.
Resolved
|
||
|
|
||
| /** Builds and injects the platform events of one press. */ | ||
| interface Injections { | ||
| long now(); | ||
|
|
||
| /** Whether {@link #start} skips the framework's animation wait on this runtime. */ | ||
| boolean skipsAnimationWait(); | ||
|
|
||
| boolean start(long downTime); | ||
|
|
||
| boolean end(long downTime); | ||
|
|
||
| /** Releases a refused start that has this down time; the receiver may hold it. */ | ||
| void releaseRefusedStart(long downTime); | ||
|
|
||
| /** Waits for the framework's animation sync; false when the runtime cannot wait separately. */ | ||
| boolean awaitAnimations(); | ||
| } | ||
|
|
||
| enum Outcome { | ||
| DISPATCHED, | ||
| START_REFUSED, | ||
| END_REFUSED, | ||
| ANIMATION_SYNC_UNAVAILABLE, | ||
| } | ||
|
|
||
| private PressSequence() {} | ||
|
|
||
| /** Runs one press that must answer by {@code deadline}, on the {@link Injections#now} clock. */ | ||
| static Outcome run(Injections injections, long deadline) { | ||
| long downTime = injections.now(); | ||
| if (!injections.start(downTime)) { | ||
| release(injections, downTime); | ||
| if (!injections.skipsAnimationWait() | ||
| || deadline - injections.now() < RETRY_WORST_CASE_MS) { | ||
| return Outcome.START_REFUSED; | ||
| } | ||
| if (!injections.awaitAnimations()) return Outcome.ANIMATION_SYNC_UNAVAILABLE; | ||
| downTime = injections.now(); | ||
| if (!injections.start(downTime)) { | ||
| release(injections, downTime); | ||
| return Outcome.START_REFUSED; | ||
| } | ||
| } | ||
| // A refused end gets no cancel. The verifier records an event before the dispatcher drops it, | ||
| // so the press is closed there and a cancel would be inconsistent. The dispatcher drops an end | ||
| // only when no pointer or focus is still down, after it cancelled the receiving window itself | ||
| // ("touched window was removed", "focus left window"). A timed-out end was already enqueued, | ||
| // so the live window still receives it. | ||
| return injections.end(downTime) ? Outcome.DISPATCHED : Outcome.END_REFUSED; | ||
| } | ||
|
|
||
| /** Turns an outcome into the helper's response: a typed exception for each failed press. */ | ||
| static void requireDispatched(Outcome outcome, String kind) { | ||
| switch (outcome) { | ||
| case DISPATCHED: | ||
| return; | ||
| case ANIMATION_SYNC_UNAVAILABLE: | ||
| throw new UnsupportedOperationException( | ||
| kind + " injection was refused and this runtime cannot wait for animations to retry it"); | ||
| case START_REFUSED: | ||
| case END_REFUSED: | ||
| throw new IllegalStateException(kind + " injection was refused"); | ||
| } | ||
| } | ||
|
|
||
| private static void release(Injections injections, long downTime) { | ||
| try { | ||
| injections.releaseRefusedStart(downTime); | ||
| } catch (RuntimeException ignored) { | ||
| // The refused start stays the reported outcome. | ||
| } | ||
| } | ||
| } | ||
31 changes: 31 additions & 0 deletions
31
...d/snapshot-helper/src/main/java/com/callstack/agentdevice/snapshothelper/TouchEvents.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package com.callstack.agentdevice.snapshothelper; | ||
|
|
||
| import android.view.InputDevice; | ||
| import android.view.MotionEvent; | ||
|
|
||
| /** Builds the touchscreen finger events that taps and touch plans inject. */ | ||
| final class TouchEvents { | ||
| private TouchEvents() {} | ||
|
|
||
| /** One pointer per coordinate pair; pointer ids follow the array order. */ | ||
| static MotionEvent obtain( | ||
| long downTime, long eventTime, int action, float[] x, float[] y, int flags) { | ||
| int count = x.length; | ||
| MotionEvent.PointerProperties[] properties = new MotionEvent.PointerProperties[count]; | ||
| MotionEvent.PointerCoords[] coords = new MotionEvent.PointerCoords[count]; | ||
| for (int index = 0; index < count; index += 1) { | ||
| properties[index] = new MotionEvent.PointerProperties(); | ||
| properties[index].id = index; | ||
| properties[index].toolType = MotionEvent.TOOL_TYPE_FINGER; | ||
| coords[index] = new MotionEvent.PointerCoords(); | ||
| coords[index].x = x[index]; | ||
| coords[index].y = y[index]; | ||
| coords[index].pressure = 1.0f; | ||
| coords[index].size = 1.0f; | ||
| } | ||
| MotionEvent event = MotionEvent.obtain(downTime, eventTime, action, count, properties, coords, | ||
| 0, 0, 1.0f, 1.0f, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, flags); | ||
| event.setSource(InputDevice.SOURCE_TOUCHSCREEN); | ||
| return event; | ||
| } | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.