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

Commit 0636e012 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Consolidate filling of window frames and config for client

The data for client window are only used in WMS#relayoutWindow
and WS#reportResized, so the operations can be done in a single
method fillClientWindowFramesAndConfiguration.

This also eliminates redundant operation when calling
setLastReportedMergedConfiguration with the value returned by
getLastReportedMergedConfiguration.

Bug: 159103089
Test: CtsWindowManagerDeviceTestCases
Change-Id: Idb93b3a80d3dd0c60e3d9567ca79c10060fca55c
parent 6a39b82e
Loading
Loading
Loading
Loading
+2 −19
Original line number Diff line number Diff line
@@ -2458,29 +2458,12 @@ public class WindowManagerService extends IWindowManager.Stub
                win.mResizedWhileGone = false;
            }

            // We must always send the latest {@link MergedConfiguration}, regardless of whether we
            // have already reported it. The client might not have processed the previous value yet
            // and needs process it before handling the corresponding window frame. the variable
            // {@code mergedConfiguration} is an out parameter that will be passed back to the
            // client over IPC and checked there.
            // Note: in the cases where the window is tied to an activity, we should not send a
            // configuration update when the window has requested to be hidden. Doing so can lead
            // to the client erroneously accepting a configuration that would have otherwise caused
            // an activity restart. We instead hand back the last reported
            // {@link MergedConfiguration}.
            if (shouldRelayout && (!win.shouldCheckTokenVisibleRequested()
                    || win.mToken.isVisibleRequested())) {
                win.getMergedConfiguration(mergedConfiguration);
            } else {
                win.getLastReportedMergedConfiguration(mergedConfiguration);
            }

            win.setLastReportedMergedConfiguration(mergedConfiguration);
            win.fillClientWindowFramesAndConfiguration(outFrames, mergedConfiguration,
                    false /* useLatestConfig */, shouldRelayout);

            // Set resize-handled here because the values are sent back to the client.
            win.onResizeHandled();

            win.fillClientWindowFrames(outFrames);
            outInsetsState.set(win.getCompatInsetsState(), win.isClientLocal());
            if (DEBUG) {
                Slog.v(TAG_WM, "Relayout given client " + client.asBinder()
+36 −25
Original line number Diff line number Diff line
@@ -2919,21 +2919,6 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        return processConfig;
    }

    void getMergedConfiguration(MergedConfiguration outConfiguration) {
        final Configuration globalConfig = getProcessGlobalConfiguration();
        final Configuration overrideConfig = getMergedOverrideConfiguration();
        outConfiguration.setConfiguration(globalConfig, overrideConfig);
    }

    void setLastReportedMergedConfiguration(MergedConfiguration config) {
        mLastReportedConfiguration.setTo(config);
        mLastConfigReportedToClient = true;
    }

    void getLastReportedMergedConfiguration(MergedConfiguration config) {
        config.setTo(mLastReportedConfiguration);
    }

    private Configuration getLastReportedConfiguration() {
        return mLastReportedConfiguration.getMergedConfiguration();
    }
@@ -3712,7 +3697,17 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        return wpc != null && wpc.registeredForDisplayAreaConfigChanges();
    }

    void fillClientWindowFrames(ClientWindowFrames outFrames) {
    /**
     * Fills the given window frames and merged configuration for the client.
     *
     * @param outFrames The frames that will be sent to the client.
     * @param outMergedConfiguration The configuration that will be sent to the client.
     * @param useLatestConfig Whether to use the latest configuration.
     * @param relayoutVisible Whether to consider visibility to use the latest configuration.
     */
    void fillClientWindowFramesAndConfiguration(ClientWindowFrames outFrames,
            MergedConfiguration outMergedConfiguration, boolean useLatestConfig,
            boolean relayoutVisible) {
        outFrames.frame.set(mWindowFrames.mCompatFrame);
        outFrames.displayFrame.set(mWindowFrames.mDisplayFrame);
        if (mInvGlobalScale != 1.0f && hasCompatScale()) {
@@ -3737,6 +3732,23 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
            final DisplayInfo displayInfo = getDisplayInfo();
            backdropFrame.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
        }

        // Note: in the cases where the window is tied to an activity, we should not send a
        // configuration update when the window has requested to be hidden. Doing so can lead to
        // the client erroneously accepting a configuration that would have otherwise caused an
        // activity restart. We instead hand back the last reported {@link MergedConfiguration}.
        if (useLatestConfig || (relayoutVisible && (shouldCheckTokenVisibleRequested()
                || mToken.isVisibleRequested()))) {
            final Configuration globalConfig = getProcessGlobalConfiguration();
            final Configuration overrideConfig = getMergedOverrideConfiguration();
            outMergedConfiguration.setConfiguration(globalConfig, overrideConfig);
            if (outMergedConfiguration != mLastReportedConfiguration) {
                mLastReportedConfiguration.setTo(outMergedConfiguration);
            }
        } else {
            outMergedConfiguration.setTo(mLastReportedConfiguration);
        }
        mLastConfigReportedToClient = true;
    }

    void reportResized() {
@@ -3764,9 +3776,6 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
            ProtoLog.i(WM_DEBUG_ORIENTATION, "Resizing %s WITH DRAW PENDING", this);
        }

        getMergedConfiguration(mLastReportedConfiguration);
        mLastConfigReportedToClient = true;

        final boolean reportOrientation = mReportOrientationChanged;
        // Always reset these states first, so if {@link IWindow#resized} fails, this
        // window won't be added to {@link WindowManagerService#mResizingWindows} and set
@@ -3776,18 +3785,20 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        mDragResizingChangeReported = true;
        mWindowFrames.clearReportResizeHints();

        final MergedConfiguration mergedConfiguration = mLastReportedConfiguration;
        fillClientWindowFramesAndConfiguration(mClientWindowFrames, mLastReportedConfiguration,
                true /* useLatestConfig */, false /* relayoutVisible */);
        final boolean reportDraw = drawPending || useBLASTSync() || !mRedrawForSyncReported;
        final boolean forceRelayout = reportOrientation || isDragResizeChanged() || !mRedrawForSyncReported;
        final int displayId = getDisplayId();
        fillClientWindowFrames(mClientWindowFrames);
        final DisplayContent displayContent = getDisplayContent();
        final boolean alwaysConsumeSystemBars =
                displayContent.getDisplayPolicy().areSystemBarsForcedShownLw(this);
        final int displayId = displayContent.getDisplayId();

        markRedrawForSyncReported();

        try {
            mClient.resized(mClientWindowFrames, reportDraw, mergedConfiguration, forceRelayout,
                    getDisplayContent().getDisplayPolicy().areSystemBarsForcedShownLw(this),
                    displayId);
            mClient.resized(mClientWindowFrames, reportDraw, mLastReportedConfiguration,
                    forceRelayout, alwaysConsumeSystemBars, displayId);
            if (drawPending && reportOrientation && mOrientationChanging) {
                mOrientationChangeRedrawRequestTime = SystemClock.elapsedRealtime();
                ProtoLog.v(WM_DEBUG_ORIENTATION,