From bbe3d7d21245d846585f5a24fa06f24fec8fcf62 Mon Sep 17 00:00:00 2001 From: Jorge Gil Date: Wed, 20 Sep 2023 05:40:40 +0000 Subject: Use immutable window decor Configuration in RelayoutParams Previously, the Context's Configuration was passed in as the mWindowDecorConfig in relayout params to perfom diff checks against the previous relayout's Configuration (e.g. to check for densityDpi changes). However, the Configuration was passed in as a reference which meant that when the context's config changed (e.g. density value), the reference held by the window decoration set from the params was mutating immediately and when diff checks were made both the old and the new Configurations were actually the same object with the density being current on both. This resulted in false-negatives as oldDensity==newDensity comparisons always evaluated to true even if the density had just changed. To actually compare the old vs new Configuration, a copy needs to be passed in to relayout params that won't be mutated when the context configuration changes. Bug: 301119301 Test: `adb shell wm density 300`, then 400 - verify oldDensityDpi and newDensityDpi reflect 300 and 400 respectively, causing the views to be released and reinflated. Change-Id: Id29feb5567cc7f865aa4c158a200d5079f674b31 --- .../shell/windowdecor/DesktopModeWindowDecoration.java | 18 ++++++++++++++---- .../android/wm/shell/windowdecor/WindowDecoration.java | 3 ++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java index dbff20e6026a..0cacdfc835e6 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java @@ -183,10 +183,20 @@ public class DesktopModeWindowDecoration extends WindowDecoration final int oldDensityDpi = mWindowDecorConfig.densityDpi; mWindowDecorConfig = params.mWindowDecorConfig != null ? params.mWindowDecorConfig : mTaskInfo.getConfiguration(); - if (oldDensityDpi != mWindowDecorConfig.densityDpi + final int newDensityDpi = mWindowDecorConfig.densityDpi; + if (oldDensityDpi != newDensityDpi || mDisplay == null || mDisplay.getDisplayId() != mTaskInfo.displayId || oldLayoutResId != mLayoutResId) { -- cgit v1.2.3-59-g8ed1b