Don't create panel if content is empty

This CL fixes the issue where WM CTS is causing ANR in ARC.

When a menu panel is opened, the sub window for this panel is
created, but as it doesn't have any content, it's considered hidden
by SF. The problem here is that as focus has already moved to this
app at this point, InputDispatcher expects the window will get a
content soon, but this never happens and causes ANR.

So, the root problem here is that PhoneWindow creates a window with
WRAP_CONTENT even if there's no content set to the window. This
seems to be a pure bug in PhoneWindow because there's already some
logic where if it doesn't have any menu item, it aborts opening a
panel, but if this function is called twice, this return logic is
bypassed and the window is accidentally created (because whether
it goes thought the return logic depends on whether st.decorView
has an instance, and this is instantiated in the first call of
openPanel())

This CL ensures the sub window isn't created if there's no item to
be shown.

Bug: 180566381
Bug: 181543065
Test: atest CtsWindowManagerDeviceTestCases
Change-Id: I1a1ae84abf4e4466ebb4a6655a5be007ee763d78
This commit is contained in:
Kazuki Takise
2022-02-01 13:49:25 +09:00
parent 22b937d881
commit 45ae74eab8

View File

@@ -907,6 +907,12 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
}
}
if (!st.hasPanelItems()) {
// Ensure that |st.decorView| has its actual content. Otherwise, an empty window can be
// created and cause ANR.
return;
}
st.isHandled = false;
WindowManager.LayoutParams lp = new WindowManager.LayoutParams(