summaryrefslogtreecommitdiff
path: root/core/java/android/widget/TextView.java
diff options
context:
space:
mode:
authorMihir Patel <mkpatel@google.com>2021-07-02 18:36:11 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-07-02 18:36:11 +0000
commitd27d3a5d90fe3d34761dc07cb150d50c36f69bcd (patch)
tree345a3f7ed2c8a18e53e5a7b2ad4c17c204798e63 /core/java/android/widget/TextView.java
parent9ebcd1f658e5e09167fba6a02bfdc16ce7d4f088 (diff)
parent59fe064d7506e1f3f2b6b0c5ac3212bfae721c81 (diff)
Merge "Guarding against null pointer exception when setting view structure info for content capture" into sc-dev am: 59fe064d75
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15067633 Change-Id: Ia3dcf12f9ed361c99fb8809cc4049a727863400d
Diffstat (limited to 'core/java/android/widget/TextView.java')
-rw-r--r--core/java/android/widget/TextView.java35
1 files changed, 20 insertions, 15 deletions
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 87301dcaa5dd..ca6e735f86b4 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -11854,23 +11854,28 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
// Get the text and trim it to the range we are reporting.
CharSequence text = getText();
- if (expandedTopChar > 0 || expandedBottomChar < text.length()) {
- text = text.subSequence(expandedTopChar, expandedBottomChar);
- }
- if (viewFor == VIEW_STRUCTURE_FOR_AUTOFILL) {
- structure.setText(text);
- } else {
- structure.setText(text, selStart - expandedTopChar, selEnd - expandedTopChar);
-
- final int[] lineOffsets = new int[bottomLine - topLine + 1];
- final int[] lineBaselines = new int[bottomLine - topLine + 1];
- final int baselineOffset = getBaselineOffset();
- for (int i = topLine; i <= bottomLine; i++) {
- lineOffsets[i - topLine] = layout.getLineStart(i);
- lineBaselines[i - topLine] = layout.getLineBaseline(i) + baselineOffset;
+ if (text != null) {
+ if (expandedTopChar > 0 || expandedBottomChar < text.length()) {
+ text = text.subSequence(expandedTopChar, expandedBottomChar);
+ }
+
+ if (viewFor == VIEW_STRUCTURE_FOR_AUTOFILL) {
+ structure.setText(text);
+ } else {
+ structure.setText(text,
+ selStart - expandedTopChar,
+ selEnd - expandedTopChar);
+
+ final int[] lineOffsets = new int[bottomLine - topLine + 1];
+ final int[] lineBaselines = new int[bottomLine - topLine + 1];
+ final int baselineOffset = getBaselineOffset();
+ for (int i = topLine; i <= bottomLine; i++) {
+ lineOffsets[i - topLine] = layout.getLineStart(i);
+ lineBaselines[i - topLine] = layout.getLineBaseline(i) + baselineOffset;
+ }
+ structure.setTextLines(lineOffsets, lineBaselines);
}
- structure.setTextLines(lineOffsets, lineBaselines);
}
}