From e06eebf48096838bf3143042950ea191db8d7c06 Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Tue, 3 Oct 2017 12:13:46 -0700 Subject: [PATCH] Rename mCursorDrawble to mDrawableForCursor To go around app bugs caused by assuming that mCursorDrawable is an array. The apps try to manipulate mCursorDrawable by using reflection, but crash since they access it incorrectly after it changed from an array to a single Drawable in I249befaf70630bef435c8db9039e8aacf233bf7c. Bug: 66988832 Test: mmm -j frameworks/base Change-Id: I04fc930d786dd4c74b560d7a25d17353f49ea25b --- core/java/android/widget/Editor.java | 32 +++++++++++++------------- core/java/android/widget/TextView.java | 8 +++---- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java index 0f6172421fc8a..19b8c73132aa1 100644 --- a/core/java/android/widget/Editor.java +++ b/core/java/android/widget/Editor.java @@ -250,7 +250,7 @@ public class Editor { SuggestionRangeSpan mSuggestionRangeSpan; private Runnable mShowSuggestionRunnable; - Drawable mCursorDrawable = null; + Drawable mDrawableForCursor = null; private Drawable mSelectHandleLeft; private Drawable mSelectHandleRight; @@ -1678,7 +1678,7 @@ public class Editor { mCorrectionHighlighter.draw(canvas, cursorOffsetVertical); } - if (highlight != null && selectionStart == selectionEnd && mCursorDrawable != null) { + if (highlight != null && selectionStart == selectionEnd && mDrawableForCursor != null) { drawCursor(canvas, cursorOffsetVertical); // Rely on the drawable entirely, do not draw the cursor line. // Has to be done after the IMM related code above which relies on the highlight. @@ -1873,8 +1873,8 @@ public class Editor { private void drawCursor(Canvas canvas, int cursorOffsetVertical) { final boolean translate = cursorOffsetVertical != 0; if (translate) canvas.translate(0, cursorOffsetVertical); - if (mCursorDrawable != null) { - mCursorDrawable.draw(canvas); + if (mDrawableForCursor != null) { + mDrawableForCursor.draw(canvas); } if (translate) canvas.translate(0, -cursorOffsetVertical); } @@ -1933,7 +1933,7 @@ public class Editor { void updateCursorPosition() { if (mTextView.mCursorDrawableRes == 0) { - mCursorDrawable = null; + mDrawableForCursor = null; return; } @@ -2314,17 +2314,17 @@ public class Editor { @VisibleForTesting @Nullable public Drawable getCursorDrawable() { - return mCursorDrawable; + return mDrawableForCursor; } private void updateCursorPosition(int top, int bottom, float horizontal) { - if (mCursorDrawable == null) { - mCursorDrawable = mTextView.getContext().getDrawable( + if (mDrawableForCursor == null) { + mDrawableForCursor = mTextView.getContext().getDrawable( mTextView.mCursorDrawableRes); } - final int left = clampHorizontalPosition(mCursorDrawable, horizontal); - final int width = mCursorDrawable.getIntrinsicWidth(); - mCursorDrawable.setBounds(left, top - mTempRect.top, left + width, + final int left = clampHorizontalPosition(mDrawableForCursor, horizontal); + final int width = mDrawableForCursor.getIntrinsicWidth(); + mDrawableForCursor.setBounds(left, top - mTempRect.top, left + width, bottom + mTempRect.bottom); } @@ -4646,9 +4646,9 @@ public class Editor { @Override protected int getCursorOffset() { int offset = super.getCursorOffset(); - if (mCursorDrawable != null) { - mCursorDrawable.getPadding(mTempRect); - offset += (mCursorDrawable.getIntrinsicWidth() + if (mDrawableForCursor != null) { + mDrawableForCursor.getPadding(mTempRect); + offset += (mDrawableForCursor.getIntrinsicWidth() - mTempRect.left - mTempRect.right) / 2; } return offset; @@ -4656,9 +4656,9 @@ public class Editor { @Override int getCursorHorizontalPosition(Layout layout, int offset) { - if (mCursorDrawable != null) { + if (mDrawableForCursor != null) { final float horizontal = getHorizontal(layout, offset); - return clampHorizontalPosition(mCursorDrawable, horizontal) + mTempRect.left; + return clampHorizontalPosition(mDrawableForCursor, horizontal) + mTempRect.left; } return super.getCursorHorizontalPosition(layout, offset); } diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 791a8fae418f9..24ae03c37b116 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -6281,7 +6281,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener final int horizontalPadding = getCompoundPaddingLeft(); final int verticalPadding = getExtendedPaddingTop() + getVerticalOffset(true); - if (mEditor.mCursorDrawable == null) { + if (mEditor.mDrawableForCursor == null) { synchronized (TEMP_RECTF) { /* * The reason for this concern about the thickness of the @@ -6308,7 +6308,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener (int) Math.ceil(verticalPadding + TEMP_RECTF.bottom + thick)); } } else { - final Rect bounds = mEditor.mCursorDrawable.getBounds(); + final Rect bounds = mEditor.mDrawableForCursor.getBounds(); invalidate(bounds.left + horizontalPadding, bounds.top + verticalPadding, bounds.right + horizontalPadding, bounds.bottom + verticalPadding); } @@ -6360,8 +6360,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener int bottom = mLayout.getLineBottom(lineEnd); // mEditor can be null in case selection is set programmatically. - if (invalidateCursor && mEditor != null && mEditor.mCursorDrawable != null) { - final Rect bounds = mEditor.mCursorDrawable.getBounds(); + if (invalidateCursor && mEditor != null && mEditor.mDrawableForCursor != null) { + final Rect bounds = mEditor.mDrawableForCursor.getBounds(); top = Math.min(top, bounds.top); bottom = Math.max(bottom, bounds.bottom); }