Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bbe3d7d2 authored by Jorge Gil's avatar Jorge Gil
Browse files

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
parent 8f9a09b3
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -183,10 +183,20 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
        mRelayoutParams.mCaptionHeightId = getCaptionHeightId();
        mRelayoutParams.mShadowRadiusId = shadowRadiusID;
        mRelayoutParams.mApplyStartTransactionOnDraw = applyStartTransactionOnDraw;

        mRelayoutParams.mWindowDecorConfig = DesktopTasksController.isDesktopDensityOverrideSet()
                ? mContext.getResources().getConfiguration() // Use system context
                : mTaskInfo.configuration; // Use task configuration
        // The configuration used to lay out the window decoration. The system context's config is
        // used when the task density has been overridden to a custom density so that the resources
        // and views of the decoration aren't affected and match the rest of the System UI, if not
        // then just use the task's configuration. A copy is made instead of using the original
        // reference so that the configuration isn't mutated on config changes and diff checks can
        // be made in WindowDecoration#relayout using the pre/post-relayout configuration.
        // See b/301119301.
        // TODO(b/301119301): consider moving the config data needed for diffs to relayout params
        // instead of using a whole Configuration as a parameter.
        final Configuration windowDecorConfig = new Configuration();
        windowDecorConfig.setTo(DesktopTasksController.isDesktopDensityOverrideSet()
                ? mContext.getResources().getConfiguration() // Use system context.
                : mTaskInfo.configuration); // Use task configuration.
        mRelayoutParams.mWindowDecorConfig = windowDecorConfig;

        mRelayoutParams.mCornerRadius =
                (int) ScreenDecorationsUtils.getWindowCornerRadius(mContext);
+2 −1
Original line number Diff line number Diff line
@@ -196,7 +196,8 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
        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) {