From 51e4c2f25d04fca66bf0d91c29b016989a18303a Mon Sep 17 00:00:00 2001 From: chaviw Date: Fri, 3 Apr 2020 13:49:45 -0700 Subject: [PATCH] Move DimLayer to Root if translucent window and not multi-window When the first window in a Task opens, the Task will animate to enter instead of the app with the introduction of hierarchal animations. This causes problems if the first window is translucent and has a dim since the dim layer will animate with the Task instead of fading in. To prevent that, we can move the dim layer to a higher up level in the hierarchy, but still maintain the relative Z order. We still place the dim at the Task level if the Task is non translucent or if the Task is in multi-window mode. We find the root task and check if it's translucent. If so, it will find the Dimmer object for the next level up in the hierarchy and create the dim layer at that level instead of the Task. If the Task is not translucent, we add the dimmer to the Task level. Since the dim layer is at the display level, translucent Tasks don't behave correctly when swiping to recents. When the dim layer was parented to the Task, the dim layer would animate with the Task when swiping up to recents. In this change, the dim layer will fade out if placed on the display level when swiping to go to recents. Test: Open assistant and see dim layer fade in Test: Open translucent app with dim layer. Swipe to recents Fixes: 148938447 Change-Id: I6e275b778da4cb7aeda3b3483a14f5f9d2796e44 --- .../java/com/android/server/wm/DisplayArea.java | 6 ++++++ .../core/java/com/android/server/wm/Task.java | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/services/core/java/com/android/server/wm/DisplayArea.java b/services/core/java/com/android/server/wm/DisplayArea.java index 90fdf19d97813..edd14b7bebf37 100644 --- a/services/core/java/com/android/server/wm/DisplayArea.java +++ b/services/core/java/com/android/server/wm/DisplayArea.java @@ -253,6 +253,12 @@ public class DisplayArea extends WindowContainer { super.prepareSurfaces(); getBounds(mTmpDimBoundsRect); + // If SystemUI is dragging for recents, we want to reset the dim state so any dim layer + // on the display level fades out. + if (forAllTasks(task -> !task.canAffectSystemUiFlags())) { + mDimmer.resetDimStates(); + } + if (mDimmer.updateDims(getPendingTransaction(), mTmpDimBoundsRect)) { scheduleAnimation(); } diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java index c891c1166a068..1236e77e9d58e 100644 --- a/services/core/java/com/android/server/wm/Task.java +++ b/services/core/java/com/android/server/wm/Task.java @@ -3347,6 +3347,21 @@ class Task extends WindowContainer { @Override Dimmer getDimmer() { + // If the window is in multi-window mode, we want to dim at the Task level to ensure the dim + // bounds match the area the app lives in + if (inMultiWindowMode()) { + return mDimmer; + } + + // If we're not at the root task level, we want to keep traversing through the parents to + // find the root. + // Once at the root task level, we want to check {@link #isTranslucent(ActivityRecord)}. + // If true, we want to get the Dimmer from the level above since we don't want to animate + // the dim with the Task. + if (!isRootTask() || isTranslucent(null)) { + return super.getDimmer(); + } + return mDimmer; }