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

Commit d84b2dad authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Assign display field when creating WindowState

This avoids a NPE trap in WindowManagerService#addWindow that
the WindowState is created but WindowToken#addWindow(WindowState)
is not call yet (setParent will update mDisplayContent).

Also make WindowContainer#getDisplayContent as a final method
because the hierarchy should sync the field.

Bug: 163976519
Test: CtsWindowManagerDeviceWindow

Change-Id: I5caea8288fcf0e960b9e1b7b36a847d8262d2fb1
parent 488eb985
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1106,7 +1106,7 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
        return mInsetsSourceProviders;
    }

    public DisplayContent getDisplayContent() {
    public final DisplayContent getDisplayContent() {
        return mDisplayContent;
    }

+1 −5
Original line number Diff line number Diff line
@@ -1089,6 +1089,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        mClient = c;
        mAppOp = appOp;
        mToken = token;
        mDisplayContent = token.mDisplayContent;
        mActivityRecord = mToken.asActivityRecord();
        mOwnerUid = ownerId;
        mShowUserId = showUserId;
@@ -1564,11 +1565,6 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        mOrientationChangeTimedOut = true;
    }

    @Override
    public DisplayContent getDisplayContent() {
        return mToken.getDisplayContent();
    }

    @Override
    void onDisplayChanged(DisplayContent dc) {
        if (dc != null && mDisplayContent != null && dc != mDisplayContent
+4 −19
Original line number Diff line number Diff line
@@ -66,8 +66,6 @@ import android.os.Binder;
import android.os.IBinder;
import android.platform.test.annotations.Presubmit;
import android.view.SurfaceControl;
import android.view.View;
import android.view.WindowManager;
import android.window.DisplayAreaInfo;
import android.window.IDisplayAreaOrganizer;

@@ -451,17 +449,11 @@ public class DisplayAreaTest extends WindowTestsBase {
    @Test
    public void testGetOrientation() {
        final DisplayArea.Tokens area = new DisplayArea.Tokens(mWm, ABOVE_TASKS, "test");
        final WindowToken token = createWindowToken(TYPE_APPLICATION_OVERLAY);
        spyOn(token);
        doReturn(mock(DisplayContent.class)).when(token).getDisplayContent();
        doNothing().when(token).setParent(any());
        final WindowState win = createWindowState(token);
        spyOn(win);
        doNothing().when(win).setParent(any());
        mDisplayContent.addChild(area, POSITION_TOP);
        final WindowState win = createWindow(null, TYPE_APPLICATION_OVERLAY, "overlay");
        win.mAttrs.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
        token.addChild(win, 0);
        area.addChild(token);

        win.mToken.reparent(area, POSITION_TOP);
        spyOn(win);
        doReturn(true).when(win).isVisible();

        assertEquals("Visible window can request orientation",
@@ -753,13 +745,6 @@ public class DisplayAreaTest extends WindowTestsBase {
        }
    }

    private WindowState createWindowState(WindowToken token) {
        return new WindowState(mWm, getTestSession(), new TestIWindow(), token,
                null /* parentWindow */, 0 /* appOp */, new WindowManager.LayoutParams(),
                View.VISIBLE, 0 /* ownerId */, 0 /* showUserId */,
                false /* ownerCanAddInternalSystemWindow */);
    }

    private WindowToken createWindowToken(int type) {
        return new WindowToken.Builder(mWm, new Binder(), type).build();
    }