From a9d27ea8692dbf6c6def6bd21754af0ad67d1675 Mon Sep 17 00:00:00 2001 From: Mihai Popa Date: Fri, 25 May 2018 11:57:17 +0100 Subject: Fix monkey crash in smart selection animation In Id65443e93d277c106ea955c867d39e94192cc55d we fixed a monkey crash happening when the smart selected text had changed while the smart selection animation was running. However, the change introduced a new crash, happening when the smart selection result was null. This CL fixes it, and lets startSelectionActionMode run even when the result is null, as there seems to be some logic there which should happen in this case. Bug: 80244201 Test: none Change-Id: I7f0304446dec85578bdcd5011d2e9ea2737d3c36 --- core/java/android/widget/SelectionActionModeHelper.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'core/java') diff --git a/core/java/android/widget/SelectionActionModeHelper.java b/core/java/android/widget/SelectionActionModeHelper.java index d22b1e66b596..6cb0eaa7f47d 100644 --- a/core/java/android/widget/SelectionActionModeHelper.java +++ b/core/java/android/widget/SelectionActionModeHelper.java @@ -285,10 +285,14 @@ public final class SelectionActionModeHelper { final Layout layout = mTextView.getLayout(); final Runnable onAnimationEndCallback = () -> { - if (result.mStart >= 0 && result.mEnd <= getText(mTextView).length() + final SelectionResult startSelectionResult; + if (result != null && result.mStart >= 0 && result.mEnd <= getText(mTextView).length() && result.mStart <= result.mEnd) { - startSelectionActionMode(result); + startSelectionResult = result; + } else { + startSelectionResult = null; } + startSelectionActionMode(startSelectionResult); }; // TODO do not trigger the animation if the change included only non-printable characters final boolean didSelectionChange = -- cgit v1.2.3