diff options
| author | Wale Ogunwale <ogunwale@google.com> | 2020-07-21 01:03:03 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-07-21 01:03:03 +0000 |
| commit | 309cfa34315f2edf07441e40af04b4ac55487588 (patch) | |
| tree | bfe4653281cda714b7f5f9d9e3d1c158860a7c14 /core/java | |
| parent | 4daab7b2d64b4779895492abe33c480efaa17448 (diff) | |
| parent | 0ebe70cb0fa685693d7834b4b4ee94515149c8fb (diff) | |
Merge "Prevent exception when surrounding text retrieval" into rvc-dev
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/view/inputmethod/EditorInfo.java | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/core/java/android/view/inputmethod/EditorInfo.java b/core/java/android/view/inputmethod/EditorInfo.java index 07fef76961f9..c5f2299e4f83 100644 --- a/core/java/android/view/inputmethod/EditorInfo.java +++ b/core/java/android/view/inputmethod/EditorInfo.java @@ -27,6 +27,7 @@ import android.os.LocaleList; import android.os.Parcel; import android.os.Parcelable; import android.os.UserHandle; +import android.text.Editable; import android.text.InputType; import android.text.TextUtils; import android.util.Printer; @@ -567,7 +568,8 @@ public class EditorInfo implements InputType, Parcelable { * editor wants to trim out the first 10 chars, subTextStart should be 10. */ public void setInitialSurroundingSubText(@NonNull CharSequence subText, int subTextStart) { - Objects.requireNonNull(subText); + CharSequence newSubText = Editable.Factory.getInstance().newEditable(subText); + Objects.requireNonNull(newSubText); // Swap selection start and end if necessary. final int subTextSelStart = initialSelStart > initialSelEnd @@ -575,7 +577,7 @@ public class EditorInfo implements InputType, Parcelable { final int subTextSelEnd = initialSelStart > initialSelEnd ? initialSelStart - subTextStart : initialSelEnd - subTextStart; - final int subTextLength = subText.length(); + final int subTextLength = newSubText.length(); // Unknown or invalid selection. if (subTextStart < 0 || subTextSelStart < 0 || subTextSelEnd > subTextLength) { mInitialSurroundingText = new InitialSurroundingText(); @@ -589,12 +591,12 @@ public class EditorInfo implements InputType, Parcelable { } if (subTextLength <= MEMORY_EFFICIENT_TEXT_LENGTH) { - mInitialSurroundingText = new InitialSurroundingText(subText, subTextSelStart, + mInitialSurroundingText = new InitialSurroundingText(newSubText, subTextSelStart, subTextSelEnd); return; } - trimLongSurroundingText(subText, subTextSelStart, subTextSelEnd); + trimLongSurroundingText(newSubText, subTextSelStart, subTextSelEnd); } /** |
