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

Commit 7dfd9e4c authored by Alan Viverette's avatar Alan Viverette Committed by Android (Google) Code Review
Browse files

Merge "Verify results of methods called during child ordering"

parents 30a70d1c a7b85e68
Loading
Loading
Loading
Loading
+85 −38
Original line number Original line Diff line number Diff line
@@ -1659,10 +1659,9 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
                    && isChildrenDrawingOrderEnabled();
                    && isChildrenDrawingOrderEnabled();
            final View[] children = mChildren;
            final View[] children = mChildren;
            for (int i = childrenCount - 1; i >= 0; i--) {
            for (int i = childrenCount - 1; i >= 0; i--) {
                final int childIndex = customOrder ? getChildDrawingOrder(childrenCount, i) : i;
                final int childIndex = getAndVerifyPreorderedIndex(childrenCount, i, customOrder);
                final View child = (preorderedList == null)
                final View child = getAndVerifyPreorderedView(preorderedList, children, childIndex);
                        ? children[childIndex] : preorderedList.get(childIndex);
                final PointF point = getLocalPoint();
                PointF point = getLocalPoint();
                if (isTransformedTouchPointInView(x, y, child, point)) {
                if (isTransformedTouchPointInView(x, y, child, point)) {
                    final PointerIcon pointerIcon = child.getPointerIcon(event, point.x, point.y);
                    final PointerIcon pointerIcon = child.getPointerIcon(event, point.x, point.y);
                    if (pointerIcon != null) {
                    if (pointerIcon != null) {
@@ -1678,6 +1677,22 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
        return super.getPointerIcon(event, x, y);
        return super.getPointerIcon(event, x, y);
    }
    }


    private int getAndVerifyPreorderedIndex(int childrenCount, int i, boolean customOrder) {
        final int childIndex;
        if (customOrder) {
            final int childIndex1 = getChildDrawingOrder(childrenCount, i);
            if (childIndex1 >= childrenCount) {
                throw new IndexOutOfBoundsException("getChildDrawingOrder() "
                        + "returned invalid index " + childIndex1
                        + " (child count is " + childrenCount + ")");
            }
            childIndex = childIndex1;
        } else {
            childIndex = i;
        }
        return childIndex;
    }

    @SuppressWarnings({"ConstantConditions"})
    @SuppressWarnings({"ConstantConditions"})
    @Override
    @Override
    protected boolean dispatchHoverEvent(MotionEvent event) {
    protected boolean dispatchHoverEvent(MotionEvent event) {
@@ -1705,9 +1720,10 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
                final View[] children = mChildren;
                final View[] children = mChildren;
                HoverTarget lastHoverTarget = null;
                HoverTarget lastHoverTarget = null;
                for (int i = childrenCount - 1; i >= 0; i--) {
                for (int i = childrenCount - 1; i >= 0; i--) {
                    int childIndex = customOrder ? getChildDrawingOrder(childrenCount, i) : i;
                    final int childIndex = getAndVerifyPreorderedIndex(
                    final View child = (preorderedList == null)
                            childrenCount, i, customOrder);
                            ? children[childIndex] : preorderedList.get(childIndex);
                    final View child = getAndVerifyPreorderedView(
                            preorderedList, children, childIndex);
                    if (!canViewReceivePointerEvents(child)
                    if (!canViewReceivePointerEvents(child)
                            || !isTransformedTouchPointInView(x, y, child, null)) {
                            || !isTransformedTouchPointInView(x, y, child, null)) {
                        continue;
                        continue;
@@ -1989,9 +2005,8 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
                    && isChildrenDrawingOrderEnabled();
                    && isChildrenDrawingOrderEnabled();
            final View[] children = mChildren;
            final View[] children = mChildren;
            for (int i = childrenCount - 1; i >= 0; i--) {
            for (int i = childrenCount - 1; i >= 0; i--) {
                int childIndex = customOrder ? getChildDrawingOrder(childrenCount, i) : i;
                final int childIndex = getAndVerifyPreorderedIndex(childrenCount, i, customOrder);
                final View child = (preorderedList == null)
                final View child = getAndVerifyPreorderedView(preorderedList, children, childIndex);
                        ? children[childIndex] : preorderedList.get(childIndex);
                if (!canViewReceivePointerEvents(child)
                if (!canViewReceivePointerEvents(child)
                        || !isTransformedTouchPointInView(x, y, child, null)) {
                        || !isTransformedTouchPointInView(x, y, child, null)) {
                    continue;
                    continue;
@@ -2138,10 +2153,10 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
                                && isChildrenDrawingOrderEnabled();
                                && isChildrenDrawingOrderEnabled();
                        final View[] children = mChildren;
                        final View[] children = mChildren;
                        for (int i = childrenCount - 1; i >= 0; i--) {
                        for (int i = childrenCount - 1; i >= 0; i--) {
                            final int childIndex = customOrder
                            final int childIndex = getAndVerifyPreorderedIndex(
                                    ? getChildDrawingOrder(childrenCount, i) : i;
                                    childrenCount, i, customOrder);
                            final View child = (preorderedList == null)
                            final View child = getAndVerifyPreorderedView(
                                    ? children[childIndex] : preorderedList.get(childIndex);
                                    preorderedList, children, childIndex);


                            // If there is a view that has accessibility focus we want it
                            // If there is a view that has accessibility focus we want it
                            // to get the event first and if not handled we will perform a
                            // to get the event first and if not handled we will perform a
@@ -2319,7 +2334,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
     * Resets the cancel next up flag.
     * Resets the cancel next up flag.
     * Returns true if the flag was previously set.
     * Returns true if the flag was previously set.
     */
     */
    private static boolean resetCancelNextUpFlag(View view) {
    private static boolean resetCancelNextUpFlag(@NonNull View view) {
        if ((view.mPrivateFlags & PFLAG_CANCEL_NEXT_UP_EVENT) != 0) {
        if ((view.mPrivateFlags & PFLAG_CANCEL_NEXT_UP_EVENT) != 0) {
            view.mPrivateFlags &= ~PFLAG_CANCEL_NEXT_UP_EVENT;
            view.mPrivateFlags &= ~PFLAG_CANCEL_NEXT_UP_EVENT;
            return true;
            return true;
@@ -2372,7 +2387,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
     * Gets the touch target for specified child view.
     * Gets the touch target for specified child view.
     * Returns null if not found.
     * Returns null if not found.
     */
     */
    private TouchTarget getTouchTarget(View child) {
    private TouchTarget getTouchTarget(@NonNull View child) {
        for (TouchTarget target = mFirstTouchTarget; target != null; target = target.next) {
        for (TouchTarget target = mFirstTouchTarget; target != null; target = target.next) {
            if (target.child == child) {
            if (target.child == child) {
                return target;
                return target;
@@ -2385,8 +2400,8 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
     * Adds a touch target for specified child to the beginning of the list.
     * Adds a touch target for specified child to the beginning of the list.
     * Assumes the target child is not already present.
     * Assumes the target child is not already present.
     */
     */
    private TouchTarget addTouchTarget(View child, int pointerIdBits) {
    private TouchTarget addTouchTarget(@NonNull View child, int pointerIdBits) {
        TouchTarget target = TouchTarget.obtain(child, pointerIdBits);
        final TouchTarget target = TouchTarget.obtain(child, pointerIdBits);
        target.next = mFirstTouchTarget;
        target.next = mFirstTouchTarget;
        mFirstTouchTarget = target;
        mFirstTouchTarget = target;
        return target;
        return target;
@@ -2448,7 +2463,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
     * Returns true if a child view can receive pointer events.
     * Returns true if a child view can receive pointer events.
     * @hide
     * @hide
     */
     */
    private static boolean canViewReceivePointerEvents(View child) {
    private static boolean canViewReceivePointerEvents(@NonNull View child) {
        return (child.mViewFlags & VISIBILITY_MASK) == VISIBLE
        return (child.mViewFlags & VISIBILITY_MASK) == VISIBLE
                || child.getAnimation() != null;
                || child.getAnimation() != null;
    }
    }
@@ -2894,7 +2909,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
                    for (int i=0; i<childrenCount; i++) {
                    for (int i=0; i<childrenCount; i++) {
                        int childIndex;
                        int childIndex;
                        try {
                        try {
                            childIndex = customOrder ? getChildDrawingOrder(childrenCount, i) : i;
                            childIndex = getAndVerifyPreorderedIndex(childrenCount, i, customOrder);
                        } catch (IndexOutOfBoundsException e) {
                        } catch (IndexOutOfBoundsException e) {
                            childIndex = i;
                            childIndex = i;
                            if (mContext.getApplicationInfo().targetSdkVersion
                            if (mContext.getApplicationInfo().targetSdkVersion
@@ -2939,9 +2954,10 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
                                throw e;
                                throw e;
                            }
                            }
                        }
                        }
                        final View child = (preorderedList == null)

                                ? children[childIndex] : preorderedList.get(childIndex);
                        final View child = getAndVerifyPreorderedView(
                        ViewStructure cstructure = structure.newChild(i);
                                preorderedList, children, childIndex);
                        final ViewStructure cstructure = structure.newChild(i);
                        child.dispatchProvideStructure(cstructure);
                        child.dispatchProvideStructure(cstructure);
                    }
                    }
                }
                }
@@ -2949,6 +2965,21 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
        }
        }
    }
    }


    private static View getAndVerifyPreorderedView(ArrayList<View> preorderedList, View[] children,
            int childIndex) {
        final View child;
        if (preorderedList != null) {
            child = preorderedList.get(childIndex);
            if (child == null) {
                throw new RuntimeException("Invalid preorderedList contained null child at index "
                        + childIndex);
            }
        } else {
            child = children[childIndex];
        }
        return child;
    }

    /** @hide */
    /** @hide */
    @Override
    @Override
    public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
    public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
@@ -3386,9 +3417,9 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
                    transientIndex = -1;
                    transientIndex = -1;
                }
                }
            }
            }
            int childIndex = customOrder ? getChildDrawingOrder(childrenCount, i) : i;

            final View child = (preorderedList == null)
            final int childIndex = getAndVerifyPreorderedIndex(childrenCount, i, customOrder);
                    ? children[childIndex] : preorderedList.get(childIndex);
            final View child = getAndVerifyPreorderedView(preorderedList, children, childIndex);
            if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE || child.getAnimation() != null) {
            if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE || child.getAnimation() != null) {
                more |= drawChild(canvas, child, drawingTime);
                more |= drawChild(canvas, child, drawingTime);
            }
            }
@@ -3508,21 +3539,21 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
     * children.
     * children.
     */
     */
    ArrayList<View> buildOrderedChildList() {
    ArrayList<View> buildOrderedChildList() {
        final int count = mChildrenCount;
        final int childrenCount = mChildrenCount;
        if (count <= 1 || !hasChildWithZ()) return null;
        if (childrenCount <= 1 || !hasChildWithZ()) return null;


        if (mPreSortedChildren == null) {
        if (mPreSortedChildren == null) {
            mPreSortedChildren = new ArrayList<View>(count);
            mPreSortedChildren = new ArrayList<>(childrenCount);
        } else {
        } else {
            mPreSortedChildren.ensureCapacity(count);
            mPreSortedChildren.ensureCapacity(childrenCount);
        }
        }


        final boolean useCustomOrder = isChildrenDrawingOrderEnabled();
        final boolean customOrder = isChildrenDrawingOrderEnabled();
        for (int i = 0; i < mChildrenCount; i++) {
        for (int i = 0; i < childrenCount; i++) {
            // add next child (in child order) to end of list
            // add next child (in child order) to end of list
            int childIndex = useCustomOrder ? getChildDrawingOrder(mChildrenCount, i) : i;
            final int childIndex = getAndVerifyPreorderedIndex(childrenCount, i, customOrder);
            View nextChild = mChildren[childIndex];
            final View nextChild = mChildren[childIndex];
            float currentZ = nextChild.getZ();
            final float currentZ = nextChild.getZ();


            // insert ahead of any Views with greater Z
            // insert ahead of any Views with greater Z
            int insertIndex = i;
            int insertIndex = i;
@@ -7481,7 +7512,11 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
        private TouchTarget() {
        private TouchTarget() {
        }
        }


        public static TouchTarget obtain(View child, int pointerIdBits) {
        public static TouchTarget obtain(@NonNull View child, int pointerIdBits) {
            if (child == null) {
                throw new IllegalArgumentException("child must be non-null");
            }

            final TouchTarget target;
            final TouchTarget target;
            synchronized (sRecycleLock) {
            synchronized (sRecycleLock) {
                if (sRecycleBin == null) {
                if (sRecycleBin == null) {
@@ -7499,6 +7534,10 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
        }
        }


        public void recycle() {
        public void recycle() {
            if (child == null) {
                throw new IllegalStateException("already recycled once");
            }

            synchronized (sRecycleLock) {
            synchronized (sRecycleLock) {
                if (sRecycledCount < MAX_RECYCLED) {
                if (sRecycledCount < MAX_RECYCLED) {
                    next = sRecycleBin;
                    next = sRecycleBin;
@@ -7528,7 +7567,11 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
        private HoverTarget() {
        private HoverTarget() {
        }
        }


        public static HoverTarget obtain(View child) {
        public static HoverTarget obtain(@NonNull View child) {
            if (child == null) {
                throw new IllegalArgumentException("child must be non-null");
            }

            final HoverTarget target;
            final HoverTarget target;
            synchronized (sRecycleLock) {
            synchronized (sRecycleLock) {
                if (sRecycleBin == null) {
                if (sRecycleBin == null) {
@@ -7545,6 +7588,10 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
        }
        }


        public void recycle() {
        public void recycle() {
            if (child == null) {
                throw new IllegalStateException("already recycled once");
            }

            synchronized (sRecycleLock) {
            synchronized (sRecycleLock) {
                if (sRecycledCount < MAX_RECYCLED) {
                if (sRecycledCount < MAX_RECYCLED) {
                    next = sRecycleBin;
                    next = sRecycleBin;