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

Commit ea92d977 authored by Wale Ogunwale's avatar Wale Ogunwale
Browse files

Don't return null in WS.getTopParentWindow on child detach

Fixed issue with WindowState.getTopParentWindow() returning null when
the child window is removed from it's parent. In this case it should
return itself as the method documentation states.

Change-Id: Iae40ca21241306048cae136887afc88593a6898d
Fixes: 33446267
Test: bit FrameworksServicesTests:com.android.server.wm.WindowStateTests
parent 3c41744b
Loading
Loading
Loading
Loading
+13 −6
Original line number Diff line number Diff line
@@ -2883,7 +2883,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        mShowToOwnerOnly = showToOwnerOnly;
    }

    boolean isHiddenFromUserLocked() {
    private boolean isHiddenFromUserLocked() {
        // Child windows are evaluated based on their parent window.
        final WindowState win = getTopParentWindow();
        if (win.mAttrs.type < FIRST_SYSTEM_WINDOW
@@ -3552,16 +3552,23 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP

    /** Returns the topmost parent window if this is a child of another window, else this. */
    WindowState getTopParentWindow() {
        WindowState w = this;
        while (w != null && w.mIsChildWindow) {
            w = w.getParentWindow();
        WindowState current = this;
        WindowState topParent = current;
        while (current != null && current.mIsChildWindow) {
            current = current.getParentWindow();
            // Parent window can be null if the child is detached from it's parent already, but
            // someone still has a reference to access it. So, we return the top parent value we
            // already have instead of null.
            if (current != null) {
                topParent = current;
            }
        return w;
        }
        return topParent;
    }

    boolean isParentWindowHidden() {
        final WindowState parent = getParentWindow();
        return (parent == null) ? false : parent.mHidden;
        return parent != null && parent.mHidden;
    }

    void setWillReplaceWindow(boolean animate) {
+5 −0
Original line number Diff line number Diff line
@@ -116,6 +116,11 @@ public class WindowStateTests extends WindowTestsBase {
        assertEquals(root, child1.getTopParentWindow());
        assertEquals(child1, child2.getParentWindow());
        assertEquals(root, child2.getTopParentWindow());

        // Test case were child is detached from parent.
        root.removeChild(child1);
        assertEquals(child1, child1.getTopParentWindow());
        assertEquals(child1, child2.getParentWindow());
    }

    @Test