From 9d1f25a3bd05e966456ac7cc25f8f6c9f701ef02 Mon Sep 17 00:00:00 2001 From: Louis Chang Date: Tue, 15 Jun 2021 15:00:30 +0800 Subject: [PATCH] Avoid activity positioned on top of always-on-top activities An activity was positioned on top of the Task while Task#addChild() called when the activity was started, regardless there are other always-on-top activities in the Task. There isn't an issue because the activity will be positioned below the always-on-top activity later when `task.positionChildAtTop(r)` is called (after the activity added to the Task). Bug: 181721787 Test: atest StartActivityTests#testStartActivitiesTaskOverlayStayOnTop Change-Id: If166b866acd7aed4efce90a65b994b60bfa504c2 --- .../core/java/com/android/server/wm/Task.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java index e97410d101153..3d8af5686faef 100644 --- a/services/core/java/com/android/server/wm/Task.java +++ b/services/core/java/com/android/server/wm/Task.java @@ -2420,17 +2420,16 @@ class Task extends TaskFragment { // Figure-out min/max possible position depending on if child can show for current user. int minPosition = (canShowChild) ? computeMinUserPosition(0, size) : 0; - int maxPosition = (canShowChild) ? size - 1 : computeMaxUserPosition(size - 1); - if (!hasChild(wc)) { - // Increase the maxPosition because children size will grow once wc is added. - ++maxPosition; + int maxPosition = minPosition; + if (size > 0) { + maxPosition = (canShowChild) ? size - 1 : computeMaxUserPosition(size - 1); } // Factor in always-on-top children in max possible position. if (!wc.isAlwaysOnTop()) { // We want to place all non-always-on-top containers below always-on-top ones. while (maxPosition > minPosition) { - if (!mChildren.get(maxPosition - 1).isAlwaysOnTop()) break; + if (!mChildren.get(maxPosition).isAlwaysOnTop()) break; --maxPosition; } } @@ -2441,6 +2440,12 @@ class Task extends TaskFragment { } else if (suggestedPosition == POSITION_TOP && maxPosition >= (size - 1)) { return POSITION_TOP; } + + // Increase the maxPosition because children size will grow once wc is added. + if (!hasChild(wc)) { + ++maxPosition; + } + // Reset position based on minimum/maximum possible positions. return Math.min(Math.max(suggestedPosition, minPosition), maxPosition); }