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

Commit efb8469b authored by Tiger's avatar Tiger
Browse files

Don't skip calling requestLayout to the parent view

Otherwise, the mMeasureCache of the parent view can be stale.

Fix: 381512167
Flag: EXEMPT bugfix
Test: atest ViewGroupTest
Change-Id: Ie47e68d299f870134890966967c43c12cda85647
parent 0f5e234f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -28277,7 +28277,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        mPrivateFlags |= PFLAG_FORCE_LAYOUT;
        mPrivateFlags |= PFLAG_INVALIDATED;
        if (mParent != null && !mParent.isLayoutRequested()) {
        if (mParent != null) {
            mParent.requestLayout();
        }
        if (mAttachInfo != null && mAttachInfo.mViewRequestingLayout == this) {
+42 −0
Original line number Diff line number Diff line
@@ -213,6 +213,35 @@ public class ViewGroupTest {
        assertTrue(autofillableViews.containsAll(Arrays.asList(viewA, viewC)));
    }

    @Test
    public void testMeasureCache() {
        final int spec1 = View.MeasureSpec.makeMeasureSpec(100, View.MeasureSpec.AT_MOST);
        final int spec2 = View.MeasureSpec.makeMeasureSpec(50, View.MeasureSpec.AT_MOST);
        final Context context = getInstrumentation().getContext();
        final View child = new View(context);
        final TestView parent = new TestView(context, 0);
        parent.addView(child);

        child.setPadding(1, 2, 3, 4);
        parent.measure(spec1, spec1);
        assertEquals(4, parent.getMeasuredWidth());
        assertEquals(6, parent.getMeasuredHeight());

        child.setPadding(5, 6, 7, 8);
        parent.measure(spec2, spec2);
        assertEquals(12, parent.getMeasuredWidth());
        assertEquals(14, parent.getMeasuredHeight());

        // This ends the state of forceLayout.
        parent.layout(0, 0, 50, 50);

        // The cached values should be cleared after the new setPadding is called. And the measured
        // width and height should be up-to-date.
        parent.measure(spec1, spec1);
        assertEquals(12, parent.getMeasuredWidth());
        assertEquals(14, parent.getMeasuredHeight());
    }

    private static void getUnobscuredTouchableRegion(Region outRegion, View view) {
        outRegion.set(view.getLeft(), view.getTop(), view.getRight(), view.getBottom());
        final ViewParent parent = view.getParent();
@@ -240,6 +269,19 @@ public class ViewGroupTest {
        protected void onLayout(boolean changed, int l, int t, int r, int b) {
            // We don't layout this view.
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int measuredWidth = 0;
            int measuredHeight = 0;
            final int count = getChildCount();
            for (int i = 0; i < count; i++) {
                final View child = getChildAt(i);
                measuredWidth += child.getPaddingLeft() + child.getPaddingRight();
                measuredHeight += child.getPaddingTop() + child.getPaddingBottom();
            }
            setMeasuredDimension(measuredWidth, measuredHeight);
        }
    }

    public static class AutofillableTestView extends TestView {