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

Commit 0baed3bc authored by Robin Lee's avatar Robin Lee
Browse files

Remove WindowList

WindowList is a thin wrapper around ArrayList. It only has three methods: addFirst, peekLast, and peekFirst. These methods can be easily implemented in WindowContainer.

Change-Id: I53b4aefb029eaddfb25ddf648d9f042a81d3468f
Flag: EXEMPT refactor removing redundant class
Test: atest CtsWindowManagerDeviceAm
Test: atest CtsWindowManagerDeviceAnimations
Fix: 322790232
parent ef2629a5
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
@@ -179,7 +179,7 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<

    // List of children for this window container. List is in z-order as the children appear on
    // screen with the top-most window container at the tail of the list.
    protected final WindowList<E> mChildren = new WindowList<E>();
    protected final ArrayList<E> mChildren = new ArrayList<E>();

    // The specified orientation for this window container.
    // Shouldn't be accessed directly since subclasses can override getOverrideOrientation.
@@ -855,7 +855,7 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
            mSurfaceFreezer.unfreeze(getSyncTransaction());
        }
        while (!mChildren.isEmpty()) {
            final E child = mChildren.peekLast();
            final E child = mChildren.getLast();
            child.removeImmediately();
            // Need to do this after calling remove on the child because the child might try to
            // remove/detach itself from its parent which will cause an exception if we remove
@@ -979,7 +979,7 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<

        switch (position) {
            case POSITION_TOP:
                if (mChildren.peekLast() != child) {
                if (getTopChild() != child) {
                    mChildren.remove(child);
                    mChildren.add(child);
                    onChildPositionChanged(child);
@@ -990,7 +990,7 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
                }
                break;
            case POSITION_BOTTOM:
                if (mChildren.peekFirst() != child) {
                if (getBottomChild() != child) {
                    mChildren.remove(child);
                    mChildren.addFirst(child);
                    onChildPositionChanged(child);
@@ -1445,7 +1445,13 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<

    /** Returns the top child container. */
    E getTopChild() {
        return mChildren.peekLast();
        final int n = mChildren.size();
        return n == 0 ? null : mChildren.get(n - 1);
    }

    E getBottomChild() {
        final int n = mChildren.size();
        return n == 0 ? null : mChildren.get(0);
    }

    /**
@@ -2550,7 +2556,7 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
        }

        if (mParent != null && mParent == other.mParent) {
            final WindowList<WindowContainer> list = mParent.mChildren;
            final ArrayList<WindowContainer> list = mParent.mChildren;
            return list.indexOf(this) > list.indexOf(other) ? 1 : -1;
        }

@@ -2587,7 +2593,7 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<

            // The position of the first non-common ancestor in the common ancestor list determines
            // which is greater the which.
            final WindowList<WindowContainer> list = commonAncestor.mChildren;
            final ArrayList<WindowContainer> list = commonAncestor.mChildren;
            return list.indexOf(thisParentChain.peekLast()) > list.indexOf(otherParentChain.peekLast())
                    ? 1 : -1;
        } finally {
+0 −38
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package com.android.server.wm;

import java.util.ArrayList;

/**
 * An {@link ArrayList} with extended functionality to be used as the children data structure in
 * {@link WindowContainer}.
 */
class WindowList<E> extends ArrayList<E> {

    public void addFirst(E e) {
        add(0, e);
    }

    E peekLast() {
        return size() > 0 ? get(size() - 1) : null;
    }

    E peekFirst() {
        return size() > 0 ? get(0) : null;
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -1580,7 +1580,7 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub
            case OP_TYPE_REORDER_TO_BOTTOM_OF_TASK: {
                final Task task = taskFragment.getTask();
                if (task != null) {
                    if (task.mChildren.peekFirst() != taskFragment) {
                    if (task.getBottomChild() != taskFragment) {
                        task.mChildren.remove(taskFragment);
                        task.mChildren.add(0, taskFragment);
                        if (!taskFragment.hasChild()) {
@@ -1596,7 +1596,7 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub
            case OP_TYPE_REORDER_TO_TOP_OF_TASK: {
                final Task task = taskFragment.getTask();
                if (task != null) {
                    if (task.mChildren.peekLast() != taskFragment) {
                    if (task.getTopChild() != taskFragment) {
                        task.mChildren.remove(taskFragment);
                        task.mChildren.add(taskFragment);
                        if (!taskFragment.hasChild()) {
+2 −2
Original line number Diff line number Diff line
@@ -2482,10 +2482,10 @@ public class ActivityRecordTests extends WindowTestsBase {
        assertTrue(activity.mChildren.contains(win4));

        // The starting window should be on-top of all other windows.
        assertEquals(startingWin, activity.mChildren.peekLast());
        assertEquals(startingWin, activity.getTopChild());

        // The base application window should be below all other windows.
        assertEquals(baseWin, activity.mChildren.peekFirst());
        assertEquals(baseWin, activity.getBottomChild());
        activity.removeImmediately();
    }