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

Commit d3f17d7d authored by arthurhung's avatar arthurhung
Browse files

Pass window type to the InputWindowHandle of embedded window

A windowless SurfaceControl could grant input via
IWindowSession.grantInputChannel, but other window may receive the
obscured events because of the type value of input window is always 0.

The obscured or partially obscured flag indicates that the window
received this motion event is wholly or partially obscured by another
visible window above it.

We have to filter out the trusted overlap so the motion event could
properly dispatch to the view if it is a security sensitive application.

Bug: 156063505
Test: enter split window mode and check the motion event
Change-Id: I10f63ea131a70ee8cc7d5c4b3e5ca4e5f06fdbad
parent 6efab8db
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -336,7 +336,7 @@ interface IWindowSession {
    * an input channel where the client can receive input.
    */
    void grantInputChannel(int displayId, in SurfaceControl surface, in IWindow window,
            in IBinder hostInputToken, int flags, out InputChannel outInputChannel);
            in IBinder hostInputToken, int flags, int type, out InputChannel outInputChannel);

    /**
     * Update the flags on an input channel associated with a particular surface.
+2 −2
Original line number Diff line number Diff line
@@ -143,7 +143,7 @@ public class WindowlessWindowManager implements IWindowSession {
                WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL) == 0)) {
            try {
                mRealWm.grantInputChannel(displayId, sc, window, mHostInputToken, attrs.flags,
                        outInputChannel);
                        attrs.type, outInputChannel);
            } catch (RemoteException e) {
                Log.e(TAG, "Failed to grant input to surface: ", e);
            }
@@ -432,7 +432,7 @@ public class WindowlessWindowManager implements IWindowSession {

    @Override
    public void grantInputChannel(int displayId, SurfaceControl surface, IWindow window,
            IBinder hostInputToken, int flags, InputChannel outInputChannel) {
            IBinder hostInputToken, int flags, int type, InputChannel outInputChannel) {
    }

    @Override
+3 −1
Original line number Diff line number Diff line
@@ -135,6 +135,7 @@ class EmbeddedWindowController {
        final int mOwnerPid;
        final WindowManagerService mWmService;
        InputChannel mInputChannel;
        final int mWindowType;

        /**
         * @param clientToken client token used to clean up the map if the embedding process dies
@@ -146,7 +147,7 @@ class EmbeddedWindowController {
         * @param ownerPid  calling pid used for anr blaming
         */
        EmbeddedWindow(WindowManagerService service, IWindow clientToken,
                WindowState hostWindowState, int ownerUid, int ownerPid) {
                WindowState hostWindowState, int ownerUid, int ownerPid, int windowType) {
            mWmService = service;
            mClient = clientToken;
            mHostWindowState = hostWindowState;
@@ -154,6 +155,7 @@ class EmbeddedWindowController {
                    : null;
            mOwnerUid = ownerUid;
            mOwnerPid = ownerPid;
            mWindowType = windowType;
        }

        String getName() {
+8 −2
Original line number Diff line number Diff line
@@ -661,17 +661,23 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {

    @Override
    public void grantInputChannel(int displayId, SurfaceControl surface,
            IWindow window, IBinder hostInputToken, int flags, InputChannel outInputChannel) {
            IWindow window, IBinder hostInputToken, int flags, int type,
            InputChannel outInputChannel) {
        if (hostInputToken == null && !mCanAddInternalSystemWindow) {
            // Callers without INTERNAL_SYSTEM_WINDOW permission cannot grant input channel to
            // embedded windows without providing a host window input token
            throw new SecurityException("Requires INTERNAL_SYSTEM_WINDOW permission");
        }

        if (!mCanAddInternalSystemWindow && type != 0) {
            Slog.w(TAG_WM, "Requires INTERNAL_SYSTEM_WINDOW permission if assign type to"
                    + " input");
        }

        final long identity = Binder.clearCallingIdentity();
        try {
            mService.grantInputChannel(mUid, mPid, displayId, surface, window, hostInputToken,
                    flags, outInputChannel);
                    flags, mCanAddInternalSystemWindow ? type : 0, outInputChannel);
        } finally {
            Binder.restoreCallingIdentity(identity);
        }
+7 −6
Original line number Diff line number Diff line
@@ -8027,14 +8027,15 @@ public class WindowManagerService extends IWindowManager.Stub
     * views.
     */
    void grantInputChannel(int callingUid, int callingPid, int displayId, SurfaceControl surface,
            IWindow window, IBinder hostInputToken, int flags, InputChannel outInputChannel) {
            IWindow window, IBinder hostInputToken, int flags, int type,
            InputChannel outInputChannel) {
        final InputApplicationHandle applicationHandle;
        final String name;
        final InputChannel clientChannel;
        synchronized (mGlobalLock) {
            EmbeddedWindowController.EmbeddedWindow win =
                    new EmbeddedWindowController.EmbeddedWindow(this, window,
                            mInputToWindowMap.get(hostInputToken), callingUid, callingPid);
                            mInputToWindowMap.get(hostInputToken), callingUid, callingPid, type);
            clientChannel = win.openInputChannel();
            mEmbeddedWindowController.add(clientChannel.getToken(), win);
            applicationHandle = win.getApplicationHandle();
@@ -8042,7 +8043,7 @@ public class WindowManagerService extends IWindowManager.Stub
        }

        updateInputChannel(clientChannel.getToken(), callingUid, callingPid, displayId, surface,
                name, applicationHandle, flags, null /* region */);
                name, applicationHandle, flags, type, null /* region */);

        clientChannel.transferTo(outInputChannel);
        clientChannel.dispose();
@@ -8050,7 +8051,7 @@ public class WindowManagerService extends IWindowManager.Stub

    private void updateInputChannel(IBinder channelToken, int callingUid, int callingPid,
            int displayId, SurfaceControl surface, String name,
            InputApplicationHandle applicationHandle, int flags, Region region) {
            InputApplicationHandle applicationHandle, int flags, int type, Region region) {
        InputWindowHandle h = new InputWindowHandle(applicationHandle, displayId);
        h.token = channelToken;
        h.name = name;
@@ -8058,7 +8059,7 @@ public class WindowManagerService extends IWindowManager.Stub
        final int sanitizedFlags = flags & (LayoutParams.FLAG_NOT_TOUCHABLE
                | LayoutParams.FLAG_SLIPPERY);
        h.layoutParamsFlags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | sanitizedFlags;
        h.layoutParamsType = 0;
        h.layoutParamsType = type;
        h.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
        h.canReceiveKeys = false;
        h.hasFocus = false;
@@ -8105,7 +8106,7 @@ public class WindowManagerService extends IWindowManager.Stub
        }

        updateInputChannel(channelToken, win.mOwnerUid, win.mOwnerPid, displayId, surface, name,
                applicationHandle, flags, region);
                applicationHandle, flags, win.mWindowType, region);
    }

    /** Return whether layer tracing is enabled */