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

Commit d245cab3 authored by Nicolo' Mazzucato's avatar Nicolo' Mazzucato
Browse files

Ensure up-to-date WindowContext resources before configuration change

Updates resources associated with a WindowContext before dispatching the new configuration to the root view.  Previously, resources weren't updated until after the configuration change was propagated to the root view, leading to outdated configurations being received in onConfigurationChanged. This was mainly happening on foldable devices: after folding/unfolding the configuration was always the one for the wrong screen.

Bug: 362719719
Bug: 394527409
Test: Checked the config received by the root view is the expected one from a window added from a window context after folding/unfolding
Flag: com.android.window.flags.enable_window_context_resources_update_on_config_change
Change-Id: I238a7fcc892dccfda2703b764c94cfaeb0bd1402
parent 65d2cf71
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
@@ -133,6 +133,7 @@ import static android.window.DesktopModeFlags.ENABLE_CAPTION_COMPAT_INSET_FORCE_
import static com.android.internal.annotations.VisibleForTesting.Visibility.PACKAGE;
import static com.android.text.flags.Flags.disableHandwritingInitiatorForIme;
import static com.android.window.flags.Flags.enableBufferTransformHintFromDisplay;
import static com.android.window.flags.Flags.enableWindowContextResourcesUpdateOnConfigChange;
import static com.android.window.flags.Flags.predictiveBackSwipeEdgeNoneApi;
import static com.android.window.flags.Flags.setScPropertiesInClient;
@@ -271,7 +272,9 @@ import android.window.OnBackInvokedCallback;
import android.window.OnBackInvokedDispatcher;
import android.window.ScreenCapture;
import android.window.SurfaceSyncGroup;
import android.window.WindowContext;
import android.window.WindowOnBackInvokedDispatcher;
import android.window.WindowTokenClient;
import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
@@ -6609,12 +6612,26 @@ public final class ViewRootImpl implements ViewParent,
            mActivityConfigCallback.onConfigurationChanged(overrideConfig, newDisplayId,
                    activityWindowInfo);
        } else {
            // There is no activity callback - update the configuration right away.
            if (enableWindowContextResourcesUpdateOnConfigChange()) {
                // There is no activity callback - update resources for window token, if needed.
                final WindowTokenClient windowTokenClient = getWindowTokenClient();
                if (windowTokenClient != null) {
                    windowTokenClient.onConfigurationChanged(
                            mLastReportedMergedConfiguration.getMergedConfiguration(),
                            newDisplayId == INVALID_DISPLAY ? mDisplay.getDisplayId()
                                    : newDisplayId);
                }
            }
            updateConfiguration(newDisplayId);
        }
        mForceNextConfigUpdate = false;
    }
    private WindowTokenClient getWindowTokenClient() {
        if (!(mContext instanceof WindowContext)) return null;
        return (WindowTokenClient) mContext.getWindowContextToken();
    }
    /**
     * Update display and views if last applied merged configuration changed.
     * @param newDisplayId Id of new display if moved, {@link Display#INVALID_DISPLAY} otherwise.
+0 −1
Original line number Diff line number Diff line
@@ -106,7 +106,6 @@ public class WindowTokenClient extends Binder {
     * @param newConfig the updated {@link Configuration}
     * @param newDisplayId the updated {@link android.view.Display} ID
     */
    @VisibleForTesting(visibility = PACKAGE)
    @MainThread
    public void onConfigurationChanged(Configuration newConfig, int newDisplayId) {
        onConfigurationChanged(newConfig, newDisplayId, true /* shouldReportConfigChange */);
+11 −0
Original line number Diff line number Diff line
@@ -659,6 +659,17 @@ flag {
    }
}

flag {
    name: "enable_window_context_resources_update_on_config_change"
    namespace: "lse_desktop_experience"
    description: "Updates window context resources before the view receives the config change callback."
    bug: "394527409"
    is_fixed_read_only: true
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "enable_desktop_tab_tearing_minimize_animation_bugfix"
    namespace: "lse_desktop_experience"