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

Commit b41eda86 authored by Chris Li's avatar Chris Li
Browse files

Pass ActivityWindowInfo during relayout

IWindowSession#relayout can trigger Activity#onConfigurationChanged, so
we need to update ActivityWindowInfo as well.

Bug: 287582673
Bug: 329084449
Test: atest WmTests:WindowManagerServiceTests
Change-Id: I0f0e1cd9b6868527b545a77299b6cea4f4976618
parent a3b836fd
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -47,6 +47,19 @@ import java.util.List;
 * {@hide}
 */
interface IWindowSession {

    /**
     * Bundle key to store the latest sync seq id for the relayout configuration.
     * @see #relayout
     */
    const String KEY_RELAYOUT_BUNDLE_SEQID = "seqid";
    /**
     * Bundle key to store the latest ActivityWindowInfo associated with the relayout configuration.
     * Will only be set if the relayout window is an activity window.
     * @see #relayout
     */
    const String KEY_RELAYOUT_BUNDLE_ACTIVITY_WINDOW_INFO = "activity_window_info";

    int addToDisplay(IWindow window, in WindowManager.LayoutParams attrs,
            in int viewVisibility, in int layerStackId, int requestedVisibleTypes,
            out InputChannel outInputChannel, out InsetsState insetsState,
@@ -92,7 +105,7 @@ interface IWindowSession {
     * @param outSurfaceControl Object in which is placed the new display surface.
     * @param insetsState The current insets state in the system.
     * @param activeControls Objects which allow controlling {@link InsetsSource}s.
     * @param bundle A temporary object to obtain the latest SyncSeqId.
     * @param bundle A Bundle to contain the latest SyncSeqId and any extra relayout optional infos.
     * @return int Result flags, defined in {@link WindowManagerGlobal}.
     */
    int relayout(IWindow window, in WindowManager.LayoutParams attrs,
+2 −1
Original line number Diff line number Diff line
@@ -8933,7 +8933,8 @@ public final class ViewRootImpl implements ViewParent,
                    mTempInsets, mTempControls, mRelayoutBundle);
            mRelayoutRequested = true;
            final int maybeSyncSeqId = mRelayoutBundle.getInt("seqid");
            final int maybeSyncSeqId = mRelayoutBundle.getInt(
                    IWindowSession.KEY_RELAYOUT_BUNDLE_SEQID);
            if (maybeSyncSeqId > 0) {
                mSyncSeqId = maybeSyncSeqId;
            }
+2 −2
Original line number Diff line number Diff line
@@ -283,14 +283,14 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
            int lastSyncSeqId, ClientWindowFrames outFrames,
            MergedConfiguration mergedConfiguration, SurfaceControl outSurfaceControl,
            InsetsState outInsetsState, InsetsSourceControl.Array outActiveControls,
            Bundle outSyncSeqIdBundle) {
            Bundle outBundle) {
        if (false) Slog.d(TAG_WM, ">>>>>> ENTERED relayout from "
                + Binder.getCallingPid());
        Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, mRelayoutTag);
        int res = mService.relayoutWindow(this, window, attrs,
                requestedWidth, requestedHeight, viewFlags, flags, seq,
                lastSyncSeqId, outFrames, mergedConfiguration, outSurfaceControl, outInsetsState,
                outActiveControls, outSyncSeqIdBundle);
                outActiveControls, outBundle);
        Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
        if (false) Slog.d(TAG_WM, "<<<<<< EXITING relayout to "
                + Binder.getCallingPid());
+11 −3
Original line number Diff line number Diff line
@@ -304,6 +304,7 @@ import android.view.WindowManagerPolicyConstants.PointerEventListener;
import android.view.displayhash.DisplayHash;
import android.view.displayhash.VerifiedDisplayHash;
import android.view.inputmethod.ImeTracker;
import android.window.ActivityWindowInfo;
import android.window.AddToSurfaceSyncGroupResult;
import android.window.ClientWindowFrames;
import android.window.IGlobalDragListener;
@@ -2213,7 +2214,7 @@ public class WindowManagerService extends IWindowManager.Stub
            int lastSyncSeqId, ClientWindowFrames outFrames,
            MergedConfiguration outMergedConfiguration, SurfaceControl outSurfaceControl,
            InsetsState outInsetsState, InsetsSourceControl.Array outActiveControls,
            Bundle outSyncIdBundle) {
            Bundle outBundle) {
        if (outActiveControls != null) {
            outActiveControls.set(null);
        }
@@ -2544,6 +2545,13 @@ public class WindowManagerService extends IWindowManager.Stub
            if (outFrames != null && outMergedConfiguration != null) {
                win.fillClientWindowFramesAndConfiguration(outFrames, outMergedConfiguration,
                        false /* useLatestConfig */, shouldRelayout);
                if (Flags.activityWindowInfoFlag() && outBundle != null
                        && win.mActivityRecord != null) {
                    final ActivityWindowInfo activityWindowInfo = win.mActivityRecord
                            .getActivityWindowInfo();
                    outBundle.putParcelable(IWindowSession.KEY_RELAYOUT_BUNDLE_ACTIVITY_WINDOW_INFO,
                            activityWindowInfo);
                }

                // Set resize-handled here because the values are sent back to the client.
                win.onResizeHandled();
@@ -2573,7 +2581,7 @@ public class WindowManagerService extends IWindowManager.Stub
                        win.isVisible() /* visible */, false /* removed */);
            }

            if (outSyncIdBundle != null) {
            if (outBundle != null) {
                final int maybeSyncSeqId;
                if (win.syncNextBuffer() && viewVisibility == View.VISIBLE
                        && win.mSyncSeqId > lastSyncSeqId) {
@@ -2582,7 +2590,7 @@ public class WindowManagerService extends IWindowManager.Stub
                } else {
                    maybeSyncSeqId = -1;
                }
                outSyncIdBundle.putInt("seqid", maybeSyncSeqId);
                outBundle.putInt(IWindowSession.KEY_RELAYOUT_BUNDLE_SEQID, maybeSyncSeqId);
            }

            if (configChanged) {
+31 −0
Original line number Diff line number Diff line
@@ -90,6 +90,7 @@ import android.util.ArraySet;
import android.util.MergedConfiguration;
import android.view.ContentRecordingSession;
import android.view.IWindow;
import android.view.IWindowSession;
import android.view.InputChannel;
import android.view.InsetsSourceControl;
import android.view.InsetsState;
@@ -99,6 +100,7 @@ import android.view.View;
import android.view.WindowInsets;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.window.ActivityWindowInfo;
import android.window.ClientWindowFrames;
import android.window.InputTransferToken;
import android.window.ScreenCapture;
@@ -1216,6 +1218,35 @@ public class WindowManagerServiceTests extends WindowTestsBase {
        mWm.reportKeepClearAreasChanged(session, window, new ArrayList<>(), new ArrayList<>());
    }

    @Test
    public void testRelayout_appWindowSendActivityWindowInfo() {
        mSetFlagsRule.enableFlags(Flags.FLAG_ACTIVITY_WINDOW_INFO_FLAG);

        // Skip unnecessary operations of relayout.
        spyOn(mWm.mWindowPlacerLocked);
        doNothing().when(mWm.mWindowPlacerLocked).performSurfacePlacement(anyBoolean());

        final Task task = createTask(mDisplayContent);
        final WindowState win = createAppWindow(task, ACTIVITY_TYPE_STANDARD, "appWindow");
        mWm.mWindowMap.put(win.mClient.asBinder(), win);

        final int w = 100;
        final int h = 200;
        final ClientWindowFrames outFrames = new ClientWindowFrames();
        final MergedConfiguration outConfig = new MergedConfiguration();
        final SurfaceControl outSurfaceControl = new SurfaceControl();
        final InsetsState outInsetsState = new InsetsState();
        final InsetsSourceControl.Array outControls = new InsetsSourceControl.Array();
        final Bundle outBundle = new Bundle();

        mWm.relayoutWindow(win.mSession, win.mClient, win.mAttrs, w, h, View.GONE, 0, 0, 0,
                outFrames, outConfig, outSurfaceControl, outInsetsState, outControls, outBundle);

        final ActivityWindowInfo activityWindowInfo = outBundle.getParcelable(
                IWindowSession.KEY_RELAYOUT_BUNDLE_ACTIVITY_WINDOW_INFO, ActivityWindowInfo.class);
        assertEquals(win.mActivityRecord.getActivityWindowInfo(), activityWindowInfo);
    }

    class TestResultReceiver implements IResultReceiver {
        public android.os.Bundle resultData;
        private final IBinder mBinder = mock(IBinder.class);