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

Commit bcd41ee7 authored by yoshiki iguchi's avatar yoshiki iguchi
Browse files

Not to remove the same animator twice

Transition.forceToEnd may be called during the execution of method
itself. In that case, an item of the map was removed during the
previous iteration and ArrayIndexOutOfBoundsException was raised.

This CL updates the loop to iterate the copy of map instead of the
original map instance, so we don't break the iteration and see
exception anymore.

Bug: 120675604
Test: Ran 'cts-tradefed run commandAndExit cts --module CtsWidgetTestCases
    --test android.widget.cts.ToolbarTest#testMenuOverflowSubmenu'
    20 times and no failure was observed.
Change-Id: Iaba2f74f29d6ed22f84d92e0d4ca106cdfca904c
parent 9620e07e
Loading
Loading
Loading
Loading
+14 −9
Original line number Diff line number Diff line
@@ -1947,19 +1947,24 @@ public abstract class Transition implements Cloneable {
     * @hide
     */
    void forceToEnd(ViewGroup sceneRoot) {
        ArrayMap<Animator, AnimationInfo> runningAnimators = getRunningAnimators();
        final ArrayMap<Animator, AnimationInfo> runningAnimators = getRunningAnimators();
        int numOldAnims = runningAnimators.size();
        if (sceneRoot != null) {
        if (sceneRoot == null || numOldAnims == 0) {
            return;
        }

        WindowId windowId = sceneRoot.getWindowId();
        final ArrayMap<Animator, AnimationInfo> oldAnimators = new ArrayMap(runningAnimators);
        runningAnimators.clear();

        for (int i = numOldAnims - 1; i >= 0; i--) {
                AnimationInfo info = runningAnimators.valueAt(i);
            AnimationInfo info = oldAnimators.valueAt(i);
            if (info.view != null && windowId != null && windowId.equals(info.windowId)) {
                    Animator anim = runningAnimators.keyAt(i);
                Animator anim = oldAnimators.keyAt(i);
                anim.end();
            }
        }
    }
    }

    /**
     * This method cancels a transition that is currently running.