From b1525b85e1b1905e3394a7415fb9402466a8c00f Mon Sep 17 00:00:00 2001 From: Beverly Date: Fri, 15 Jul 2022 16:51:10 +0000 Subject: [PATCH] Remove view based on known index of the view on exception There's no need to findViewLocked - if the view didn't already exist, then the view is added to the end of the mViews list. findViewLocked will need to iterate over all the views which is unnecessary. Test: manual Fixes: 238954722 Change-Id: I3a22f59df84f512d4e914f0e3566927450284298 --- core/java/android/view/WindowManagerGlobal.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/java/android/view/WindowManagerGlobal.java b/core/java/android/view/WindowManagerGlobal.java index ac4c2ea448ac8..d37756551db3c 100644 --- a/core/java/android/view/WindowManagerGlobal.java +++ b/core/java/android/view/WindowManagerGlobal.java @@ -404,7 +404,7 @@ public final class WindowManagerGlobal { try { root.setView(view, wparams, panelParentView, userId); } catch (RuntimeException e) { - final int viewIndex = findViewLocked(view, false); + final int viewIndex = (index >= 0) ? index : (mViews.size() - 1); // BadTokenException or InvalidDisplayException, clean up. if (viewIndex >= 0) { removeViewLocked(viewIndex, true);