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: I0aedd4c93b572c07dbf80ab67f9f47d0c2c668a4
This commit is contained in:
Mihir Patel
2021-07-02 18:35:36 +00:00
committed by Automerger Merge Worker

View File

@@ -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);
}
}