summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Abodunrinwa Toki <toki@google.com> 2017-03-07 12:54:47 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2017-03-07 12:54:52 +0000
commit0f502cb1b6af28234e918aea8078961abf4198ff (patch)
tree55b3d376f2ad14fe83d7dc65fff788aa867002d9
parentc068aa22090f9eb1a6af7f7acbdb29a3bac28f90 (diff)
parent792d820cc9970cd08f3861e89bf5da641e55442a (diff)
Merge "Prevent crashes when in insertion mode."
-rw-r--r--core/java/android/view/textclassifier/TextClassifierImpl.java2
-rw-r--r--core/java/android/widget/SelectionActionModeHelper.java15
2 files changed, 12 insertions, 5 deletions
diff --git a/core/java/android/view/textclassifier/TextClassifierImpl.java b/core/java/android/view/textclassifier/TextClassifierImpl.java
index 97a36fd71c0f..536d7e088021 100644
--- a/core/java/android/view/textclassifier/TextClassifierImpl.java
+++ b/core/java/android/view/textclassifier/TextClassifierImpl.java
@@ -201,7 +201,7 @@ final class TextClassifierImpl implements TextClassifier {
Preconditions.checkArgument(text != null);
Preconditions.checkArgument(startIndex >= 0);
Preconditions.checkArgument(endIndex <= text.length());
- Preconditions.checkArgument(endIndex >= startIndex);
+ Preconditions.checkArgument(endIndex > startIndex);
}
/**
diff --git a/core/java/android/widget/SelectionActionModeHelper.java b/core/java/android/widget/SelectionActionModeHelper.java
index 679053299666..b75193536f32 100644
--- a/core/java/android/widget/SelectionActionModeHelper.java
+++ b/core/java/android/widget/SelectionActionModeHelper.java
@@ -60,14 +60,14 @@ final class SelectionActionModeHelper {
mEditor = Preconditions.checkNotNull(editor);
final TextView textView = mEditor.getTextView();
mTextClassificationHelper = new TextClassificationHelper(
- textView.getTextClassifier(), textView.getText(),
- textView.getSelectionStart(), textView.getSelectionEnd());
+ textView.getTextClassifier(), textView.getText(), 0, 1);
}
public void startActionModeAsync() {
cancelAsyncTask();
- if (isNoOpTextClassifier()) {
+ if (isNoOpTextClassifier() || !hasSelection()) {
// No need to make an async call for a no-op TextClassifier.
+ // Do not call the TextClassifier if there is no selection.
startActionMode(null);
} else {
resetTextClassificationHelper();
@@ -84,8 +84,9 @@ final class SelectionActionModeHelper {
public void invalidateActionModeAsync() {
cancelAsyncTask();
- if (isNoOpTextClassifier()) {
+ if (isNoOpTextClassifier() || !hasSelection()) {
// No need to make an async call for a no-op TextClassifier.
+ // Do not call the TextClassifier if there is no selection.
invalidateActionMode(null);
} else {
resetTextClassificationHelper();
@@ -126,6 +127,11 @@ final class SelectionActionModeHelper {
return mEditor.getTextView().getTextClassifier() == TextClassifier.NO_OP;
}
+ private boolean hasSelection() {
+ final TextView textView = mEditor.getTextView();
+ return textView.getSelectionEnd() > textView.getSelectionStart();
+ }
+
private void startActionMode(@Nullable SelectionResult result) {
final TextView textView = mEditor.getTextView();
final CharSequence text = textView.getText();
@@ -311,6 +317,7 @@ final class SelectionActionModeHelper {
CharSequence text, int selectionStart, int selectionEnd) {
mTextClassifier = Preconditions.checkNotNull(textClassifier);
mText = Preconditions.checkNotNull(text).toString();
+ Preconditions.checkArgument(selectionEnd > selectionStart);
mSelectionStart = selectionStart;
mSelectionEnd = selectionEnd;
}