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

Commit 21610f8c authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Store process of window in Session

Currently all logic assume that the owner process of window
is the process that creates the Session.

This also makes the tests closer to real case.

Bug: 163976519
Test: atest WindowStateTests DragDropControllerTests
Change-Id: Ia46dd49a3427bd28dfac9b5153556432ea38f6a9
parent a93ce5ac
Loading
Loading
Loading
Loading
+20 −10
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import static com.android.server.wm.WindowManagerDebugConfig.DEBUG;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TASK_POSITIONING;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.PendingIntent;
import android.content.ClipData;
@@ -100,6 +101,8 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
    final IWindowSessionCallback mCallback;
    final int mUid;
    final int mPid;
    @NonNull
    final WindowProcessController mProcess;
    private final String mStringName;
    SurfaceSession mSurfaceSession;
    private int mNumWindow = 0;
@@ -126,11 +129,23 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
    final boolean mSetsUnrestrictedKeepClearAreas;

    public Session(WindowManagerService service, IWindowSessionCallback callback) {
        this(service, callback, Binder.getCallingPid(), Binder.getCallingUid());
    }

    @VisibleForTesting
    Session(WindowManagerService service, IWindowSessionCallback callback,
            int callingPid, int callingUid) {
        mService = service;
        mCallback = callback;
        mUid = Binder.getCallingUid();
        mPid = Binder.getCallingPid();
        mPid = callingPid;
        mUid = callingUid;
        synchronized (service.mGlobalLock) {
            mLastReportedAnimatorScale = service.getCurrentAnimatorScale();
            mProcess = service.mAtmService.mProcessMap.getProcess(mPid);
        }
        if (mProcess == null) {
            throw new IllegalStateException("Unknown pid=" + mPid + " uid=" + mUid);
        }
        mCanAddInternalSystemWindow = service.mContext.checkCallingOrSelfPermission(
                INTERNAL_SYSTEM_WINDOW) == PERMISSION_GRANTED;
        mCanForceShowingInsets = service.mAtmService.isCallerRecents(mUid)
@@ -715,13 +730,8 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {

    void windowAddedLocked() {
        if (mPackageName == null) {
            final WindowProcessController wpc = mService.mAtmService.mProcessMap.getProcess(mPid);
            if (wpc != null) {
                mPackageName = wpc.mInfo.packageName;
            mPackageName = mProcess.mInfo.packageName;
            mRelayoutTag = "relayoutWindow: " + mPackageName;
            } else {
                Slog.e(TAG_WM, "Unknown process pid=" + mPid);
            }
        }
        if (mSurfaceSession == null) {
            if (DEBUG) {
+8 −13
Original line number Diff line number Diff line
@@ -754,8 +754,6 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP

    static final int BLAST_TIMEOUT_DURATION = 5000; /* milliseconds */

    private final WindowProcessController mWpcForDisplayAreaConfigChanges;

    class DrawHandler {
        Consumer<SurfaceControl.Transaction> mConsumer;
        int mSeqId;
@@ -1129,7 +1127,6 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
            mBaseLayer = 0;
            mSubLayer = 0;
            mWinAnimator = null;
            mWpcForDisplayAreaConfigChanges = null;
            mOverrideScale = 1f;
            return;
        }
@@ -1186,11 +1183,6 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
            ProtoLog.v(WM_DEBUG_ADD_REMOVE, "Adding %s to %s", this, parentWindow);
            parentWindow.addChild(this, sWindowSubLayerComparator);
        }

        // System process or invalid process cannot register to display area config change.
        mWpcForDisplayAreaConfigChanges = (s.mPid == MY_PID || s.mPid < 0)
                ? null
                : service.mAtmService.getProcessController(s.mPid, s.mUid);
    }

    boolean shouldWindowHandleBeTrusted(Session s) {
@@ -3621,14 +3613,17 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
    /** @return {@code true} if the process registered to a display area as a config listener. */
    private boolean registeredForDisplayAreaConfigChanges() {
        final WindowState parentWindow = getParentWindow();
        final WindowProcessController wpc = parentWindow != null
                ? parentWindow.mWpcForDisplayAreaConfigChanges
                : mWpcForDisplayAreaConfigChanges;
        return wpc != null && wpc.registeredForDisplayAreaConfigChanges();
        final Session session = parentWindow != null ? parentWindow.mSession : mSession;
        if (session.mPid == MY_PID) {
            // System process cannot register to display area config change.
            return false;
        }
        return session.mProcess.registeredForDisplayAreaConfigChanges();
    }

    @NonNull
    WindowProcessController getProcess() {
        return mWpcForDisplayAreaConfigChanges;
        return mSession.mProcess;
    }

    /**
+3 −20
Original line number Diff line number Diff line
@@ -147,14 +147,12 @@ import android.view.DisplayInfo;
import android.view.IRemoteAnimationFinishedCallback;
import android.view.IRemoteAnimationRunner.Stub;
import android.view.IWindowManager;
import android.view.IWindowSession;
import android.view.InsetsSource;
import android.view.InsetsState;
import android.view.RemoteAnimationAdapter;
import android.view.RemoteAnimationTarget;
import android.view.Surface;
import android.view.WindowManager;
import android.view.WindowManagerGlobal;
import android.window.TaskSnapshot;

import androidx.test.filters.MediumTest;
@@ -2072,7 +2070,7 @@ public class ActivityRecordTests extends WindowTestsBase {
                WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
        params.width = params.height = WindowManager.LayoutParams.MATCH_PARENT;
        final TestWindowState w = new TestWindowState(
                mAtm.mWindowManager, mock(Session.class), new TestIWindow(), params, activity);
                mAtm.mWindowManager, getTestSession(), new TestIWindow(), params, activity);
        activity.addWindow(w);

        // Assume the activity is launching in different rotation, and there was an available
@@ -2082,23 +2080,8 @@ public class ActivityRecordTests extends WindowTestsBase {
                .build();
        setRotatedScreenOrientationSilently(activity);
        activity.setVisible(false);

        final IWindowSession session = WindowManagerGlobal.getWindowSession();
        spyOn(session);
        try {
            // Return error to skip unnecessary operation.
            doReturn(WindowManagerGlobal.ADD_STARTING_NOT_NEEDED).when(session).addToDisplay(
                    any() /* window */,  any() /* attrs */,
                    anyInt() /* viewVisibility */, anyInt() /* displayId */,
                    anyInt() /* requestedVisibleTypes */, any() /* outInputChannel */,
                    any() /* outInsetsState */, any() /* outActiveControls */,
                    any() /* outAttachedFrame */, any() /* outSizeCompatScale */);
        mAtm.mWindowManager.mStartingSurfaceController
                .createTaskSnapshotSurface(activity, snapshot);
        } catch (RemoteException ignored) {
        } finally {
            reset(session);
        }

        // Because the rotation of snapshot and the corresponding top activity are different, fixed
        // rotation should be applied when creating snapshot surface if the display rotation may be
+1 −0
Original line number Diff line number Diff line
@@ -337,6 +337,7 @@ public class BackNavigationControllerTests extends WindowTestsBase {
        WindowState appWindow = task.getTopVisibleAppMainWindow();
        WindowOnBackInvokedDispatcher dispatcher =
                new WindowOnBackInvokedDispatcher(context);
        spyOn(appWindow.mSession);
        doAnswer(invocation -> {
            appWindow.setOnBackInvokedCallbackInfo(invocation.getArgument(1));
            return null;
+1 −1
Original line number Diff line number Diff line
@@ -700,7 +700,7 @@ public class DisplayAreaTest extends WindowTestsBase {
    }

    private WindowState createWindowState(WindowToken token) {
        return new WindowState(mWm, mock(Session.class), new TestIWindow(), token,
        return new WindowState(mWm, getTestSession(), new TestIWindow(), token,
                null /* parentWindow */, 0 /* appOp */, new WindowManager.LayoutParams(),
                View.VISIBLE, 0 /* ownerId */, 0 /* showUserId */,
                false /* ownerCanAddInternalSystemWindow */);
Loading