Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e06eebf4 authored by Roozbeh Pournader's avatar Roozbeh Pournader
Browse files

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
parent 57d15971
Loading
Loading
Loading
Loading
+16 −16
Original line number Original line Diff line number Diff line
@@ -250,7 +250,7 @@ public class Editor {
    SuggestionRangeSpan mSuggestionRangeSpan;
    SuggestionRangeSpan mSuggestionRangeSpan;
    private Runnable mShowSuggestionRunnable;
    private Runnable mShowSuggestionRunnable;


    Drawable mCursorDrawable = null;
    Drawable mDrawableForCursor = null;


    private Drawable mSelectHandleLeft;
    private Drawable mSelectHandleLeft;
    private Drawable mSelectHandleRight;
    private Drawable mSelectHandleRight;
@@ -1678,7 +1678,7 @@ public class Editor {
            mCorrectionHighlighter.draw(canvas, cursorOffsetVertical);
            mCorrectionHighlighter.draw(canvas, cursorOffsetVertical);
        }
        }


        if (highlight != null && selectionStart == selectionEnd && mCursorDrawable != null) {
        if (highlight != null && selectionStart == selectionEnd && mDrawableForCursor != null) {
            drawCursor(canvas, cursorOffsetVertical);
            drawCursor(canvas, cursorOffsetVertical);
            // Rely on the drawable entirely, do not draw the cursor line.
            // 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.
            // 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) {
    private void drawCursor(Canvas canvas, int cursorOffsetVertical) {
        final boolean translate = cursorOffsetVertical != 0;
        final boolean translate = cursorOffsetVertical != 0;
        if (translate) canvas.translate(0, cursorOffsetVertical);
        if (translate) canvas.translate(0, cursorOffsetVertical);
        if (mCursorDrawable != null) {
        if (mDrawableForCursor != null) {
            mCursorDrawable.draw(canvas);
            mDrawableForCursor.draw(canvas);
        }
        }
        if (translate) canvas.translate(0, -cursorOffsetVertical);
        if (translate) canvas.translate(0, -cursorOffsetVertical);
    }
    }
@@ -1933,7 +1933,7 @@ public class Editor {


    void updateCursorPosition() {
    void updateCursorPosition() {
        if (mTextView.mCursorDrawableRes == 0) {
        if (mTextView.mCursorDrawableRes == 0) {
            mCursorDrawable = null;
            mDrawableForCursor = null;
            return;
            return;
        }
        }


@@ -2314,17 +2314,17 @@ public class Editor {
    @VisibleForTesting
    @VisibleForTesting
    @Nullable
    @Nullable
    public Drawable getCursorDrawable() {
    public Drawable getCursorDrawable() {
        return mCursorDrawable;
        return mDrawableForCursor;
    }
    }


    private void updateCursorPosition(int top, int bottom, float horizontal) {
    private void updateCursorPosition(int top, int bottom, float horizontal) {
        if (mCursorDrawable == null) {
        if (mDrawableForCursor == null) {
            mCursorDrawable = mTextView.getContext().getDrawable(
            mDrawableForCursor = mTextView.getContext().getDrawable(
                    mTextView.mCursorDrawableRes);
                    mTextView.mCursorDrawableRes);
        }
        }
        final int left = clampHorizontalPosition(mCursorDrawable, horizontal);
        final int left = clampHorizontalPosition(mDrawableForCursor, horizontal);
        final int width = mCursorDrawable.getIntrinsicWidth();
        final int width = mDrawableForCursor.getIntrinsicWidth();
        mCursorDrawable.setBounds(left, top - mTempRect.top, left + width,
        mDrawableForCursor.setBounds(left, top - mTempRect.top, left + width,
                bottom + mTempRect.bottom);
                bottom + mTempRect.bottom);
    }
    }


@@ -4646,9 +4646,9 @@ public class Editor {
        @Override
        @Override
        protected int getCursorOffset() {
        protected int getCursorOffset() {
            int offset = super.getCursorOffset();
            int offset = super.getCursorOffset();
            if (mCursorDrawable != null) {
            if (mDrawableForCursor != null) {
                mCursorDrawable.getPadding(mTempRect);
                mDrawableForCursor.getPadding(mTempRect);
                offset += (mCursorDrawable.getIntrinsicWidth()
                offset += (mDrawableForCursor.getIntrinsicWidth()
                           - mTempRect.left - mTempRect.right) / 2;
                           - mTempRect.left - mTempRect.right) / 2;
            }
            }
            return offset;
            return offset;
@@ -4656,9 +4656,9 @@ public class Editor {


        @Override
        @Override
        int getCursorHorizontalPosition(Layout layout, int offset) {
        int getCursorHorizontalPosition(Layout layout, int offset) {
            if (mCursorDrawable != null) {
            if (mDrawableForCursor != null) {
                final float horizontal = getHorizontal(layout, offset);
                final float horizontal = getHorizontal(layout, offset);
                return clampHorizontalPosition(mCursorDrawable, horizontal) + mTempRect.left;
                return clampHorizontalPosition(mDrawableForCursor, horizontal) + mTempRect.left;
            }
            }
            return super.getCursorHorizontalPosition(layout, offset);
            return super.getCursorHorizontalPosition(layout, offset);
        }
        }
+4 −4
Original line number Original line Diff line number Diff line
@@ -6281,7 +6281,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
            final int horizontalPadding = getCompoundPaddingLeft();
            final int horizontalPadding = getCompoundPaddingLeft();
            final int verticalPadding = getExtendedPaddingTop() + getVerticalOffset(true);
            final int verticalPadding = getExtendedPaddingTop() + getVerticalOffset(true);


            if (mEditor.mCursorDrawable == null) {
            if (mEditor.mDrawableForCursor == null) {
                synchronized (TEMP_RECTF) {
                synchronized (TEMP_RECTF) {
                    /*
                    /*
                     * The reason for this concern about the thickness of the
                     * 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));
                            (int) Math.ceil(verticalPadding + TEMP_RECTF.bottom + thick));
                }
                }
            } else {
            } else {
                final Rect bounds = mEditor.mCursorDrawable.getBounds();
                final Rect bounds = mEditor.mDrawableForCursor.getBounds();
                invalidate(bounds.left + horizontalPadding, bounds.top + verticalPadding,
                invalidate(bounds.left + horizontalPadding, bounds.top + verticalPadding,
                        bounds.right + horizontalPadding, bounds.bottom + verticalPadding);
                        bounds.right + horizontalPadding, bounds.bottom + verticalPadding);
            }
            }
@@ -6360,8 +6360,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
            int bottom = mLayout.getLineBottom(lineEnd);
            int bottom = mLayout.getLineBottom(lineEnd);


            // mEditor can be null in case selection is set programmatically.
            // mEditor can be null in case selection is set programmatically.
            if (invalidateCursor && mEditor != null && mEditor.mCursorDrawable != null) {
            if (invalidateCursor && mEditor != null && mEditor.mDrawableForCursor != null) {
                final Rect bounds = mEditor.mCursorDrawable.getBounds();
                final Rect bounds = mEditor.mDrawableForCursor.getBounds();
                top = Math.min(top, bounds.top);
                top = Math.min(top, bounds.top);
                bottom = Math.max(bottom, bounds.bottom);
                bottom = Math.max(bottom, bounds.bottom);
            }
            }