diff options
| author | Mihai Popa <popam@google.com> | 2018-05-08 19:18:43 +0100 |
|---|---|---|
| committer | Mihai Popa <popam@google.com> | 2018-05-09 10:33:02 +0000 |
| commit | cce6e82d35b5a6c8eb29e76fbae53eae8b70e99a (patch) | |
| tree | 0695a18ada026a4a8dbf4afc3df76b2e323da622 /core/java/android/widget/SelectionActionModeHelper.java | |
| parent | 5ecf769595a0e93f951894fee4c0f8cc1387c892 (diff) | |
Fix crash after smart selection animation
At the end of the smart selection animation, we run a callback that sets
the selection on the TextView (subsequently starting the action mode
toolbar and showing the handles). However, when the text changes before
the animation finishes, the selection might not be valid, and might get
out of the text bounds, which was producing a crash. This was observed
in a monkey crash. This CL fixes this bug by refusing to set the
selection when the text has changed between the time the animation has
started and the time it ends.
Bug: 69919777
Test: manual testing before and after the fix
Change-Id: Iea043f320004d45ad16dd7e9e5b47e5256e6d9fa
Diffstat (limited to 'core/java/android/widget/SelectionActionModeHelper.java')
| -rw-r--r-- | core/java/android/widget/SelectionActionModeHelper.java | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/core/java/android/widget/SelectionActionModeHelper.java b/core/java/android/widget/SelectionActionModeHelper.java index 1f2b90a11616..3820798c0d6a 100644 --- a/core/java/android/widget/SelectionActionModeHelper.java +++ b/core/java/android/widget/SelectionActionModeHelper.java @@ -282,7 +282,12 @@ public final class SelectionActionModeHelper { @Nullable SelectionResult result) { final Layout layout = mTextView.getLayout(); - final Runnable onAnimationEndCallback = () -> startSelectionActionMode(result); + final String originalText = getText(mTextView).toString(); + final Runnable onAnimationEndCallback = () -> { + if (TextUtils.equals(getText(mTextView), originalText)) { + startSelectionActionMode(result); + } + }; // TODO do not trigger the animation if the change included only non-printable characters final boolean didSelectionChange = result != null && (mTextView.getSelectionStart() != result.mStart |
