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

Commit 047bc0ce authored by Garfield Tan's avatar Garfield Tan
Browse files

Allow the use of input features for windowless windows

In particular spy windows are specified in input features. Windowless
windows are more lightweight than regular windows in implementing spy
windows.

It also helps overlays (e.g. window decorations) to pass input events to
app content, and only consume them when necessary.

Bug: 266866903
Test: Input of window decorations still work.
Test: atest WmTests:WindowManagerServiceTests
Change-Id: Ifbd2bc1a5966325b5bc28e58a19fcd3e05aafdf2
parent 2a3e8d60
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -304,7 +304,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, int privateFlags, int type,
            in IBinder hostInputToken, int flags, int privateFlags, int inputFeatures, int type,
            in IBinder windowToken, in IBinder focusGrantToken, String inputHandleName,
            out InputChannel outInputChannel);

@@ -312,7 +312,8 @@ interface IWindowSession {
     * Update the flags on an input channel associated with a particular surface.
     */
    oneway void updateInputChannel(in IBinder channelToken, int displayId,
            in SurfaceControl surface, int flags, int privateFlags, in Region region);
            in SurfaceControl surface, int flags, int privateFlags, int inputFeatures,
            in Region region);

    /**
     * Transfer window focus to an embedded window if the calling window has focus.
+16 −12
Original line number Diff line number Diff line
@@ -139,7 +139,7 @@ public class WindowlessWindowManager implements IWindowSession {
                try {
                    mRealWm.updateInputChannel(state.mInputChannelToken, state.mDisplayId,
                            state.mSurfaceControl, state.mParams.flags, state.mParams.privateFlags,
                            state.mInputRegion);
                            state.mParams.inputFeatures, state.mInputRegion);
                } catch (RemoteException e) {
                    Log.e(TAG, "Failed to update surface input channel: ", e);
                }
@@ -189,12 +189,13 @@ public class WindowlessWindowManager implements IWindowSession {
                    mRealWm.grantInputChannel(displayId,
                            new SurfaceControl(sc, "WindowlessWindowManager.addToDisplay"),
                            window, mHostInputToken,
                            attrs.flags, attrs.privateFlags, attrs.type, attrs.token,
                            mFocusGrantToken, attrs.getTitle().toString(), outInputChannel);
                            attrs.flags, attrs.privateFlags, attrs.inputFeatures, attrs.type,
                            attrs.token, mFocusGrantToken, attrs.getTitle().toString(),
                            outInputChannel);
                } else {
                    mRealWm.grantInputChannel(displayId, sc, window, mHostInputToken, attrs.flags,
                            attrs.privateFlags, attrs.type, attrs.token, mFocusGrantToken,
                            attrs.getTitle().toString(), outInputChannel);
                            attrs.privateFlags, attrs.inputFeatures, attrs.type, attrs.token,
                            mFocusGrantToken, attrs.getTitle().toString(), outInputChannel);
                }
            } catch (RemoteException e) {
                Log.e(TAG, "Failed to grant input to surface: ", e);
@@ -381,16 +382,19 @@ public class WindowlessWindowManager implements IWindowSession {
            outMergedConfiguration.setConfiguration(mConfiguration, mConfiguration);
        }

        if ((attrChanges & WindowManager.LayoutParams.FLAGS_CHANGED) != 0
                && state.mInputChannelToken != null) {
        final int inputChangeMask = WindowManager.LayoutParams.FLAGS_CHANGED
                | WindowManager.LayoutParams.INPUT_FEATURES_CHANGED;
        if ((attrChanges & inputChangeMask) != 0 && state.mInputChannelToken != null) {
            try {
                if (mRealWm instanceof IWindowSession.Stub) {
                    mRealWm.updateInputChannel(state.mInputChannelToken, state.mDisplayId,
                            new SurfaceControl(sc, "WindowlessWindowManager.relayout"),
                            attrs.flags, attrs.privateFlags, state.mInputRegion);
                            attrs.flags, attrs.privateFlags, attrs.inputFeatures,
                            state.mInputRegion);
                } else {
                    mRealWm.updateInputChannel(state.mInputChannelToken, state.mDisplayId, sc,
                            attrs.flags, attrs.privateFlags, state.mInputRegion);
                            attrs.flags, attrs.privateFlags, attrs.inputFeatures,
                            state.mInputRegion);
                }
            } catch (RemoteException e) {
                Log.e(TAG, "Failed to update surface input channel: ", e);
@@ -564,14 +568,14 @@ public class WindowlessWindowManager implements IWindowSession {

    @Override
    public void grantInputChannel(int displayId, SurfaceControl surface, IWindow window,
            IBinder hostInputToken, int flags, int privateFlags, int type,
            IBinder hostInputToken, int flags, int privateFlags, int inputFeatures, int type,
            IBinder windowToken, IBinder focusGrantToken, String inputHandleName,
            InputChannel outInputChannel) {
    }

    @Override
    public void updateInputChannel(IBinder channelToken, int displayId, SurfaceControl surface,
            int flags, int privateFlags, Region region) {
            int flags, int privateFlags, int inputFeatures, Region region) {
    }

    @Override
+2 −0
Original line number Diff line number Diff line
@@ -103,6 +103,7 @@ class DragResizeInputListener implements AutoCloseable {
                    null /* hostInputToken */,
                    FLAG_NOT_FOCUSABLE,
                    PRIVATE_FLAG_TRUSTED_OVERLAY,
                    0 /* inputFeatures */,
                    TYPE_APPLICATION,
                    null /* windowToken */,
                    mFocusGrantToken,
@@ -208,6 +209,7 @@ class DragResizeInputListener implements AutoCloseable {
                    mDecorationSurface,
                    FLAG_NOT_FOCUSABLE,
                    PRIVATE_FLAG_TRUSTED_OVERLAY,
                    0 /* inputFeatures */,
                    touchRegion);
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
+4 −4
Original line number Diff line number Diff line
@@ -862,7 +862,7 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
    @Override
    public void grantInputChannel(int displayId, SurfaceControl surface,
            IWindow window, IBinder hostInputToken, int flags, int privateFlags, int type,
            IBinder windowToken, IBinder focusGrantToken, String inputHandleName,
            int inputFeatures, IBinder windowToken, IBinder focusGrantToken, String inputHandleName,
            InputChannel outInputChannel) {
        if (hostInputToken == null && !mCanAddInternalSystemWindow) {
            // Callers without INTERNAL_SYSTEM_WINDOW permission cannot grant input channel to
@@ -874,7 +874,7 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
        try {
            mService.grantInputChannel(this, mUid, mPid, displayId, surface, window, hostInputToken,
                    flags, mCanAddInternalSystemWindow ? privateFlags : 0,
                    type, windowToken, focusGrantToken, inputHandleName,
                    type, inputFeatures, windowToken, focusGrantToken, inputHandleName,
                    outInputChannel);
        } finally {
            Binder.restoreCallingIdentity(identity);
@@ -883,11 +883,11 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {

    @Override
    public void updateInputChannel(IBinder channelToken, int displayId, SurfaceControl surface,
            int flags, int privateFlags, Region region) {
            int flags, int privateFlags, int inputFeatures, Region region) {
        final long identity = Binder.clearCallingIdentity();
        try {
            mService.updateInputChannel(channelToken, displayId, surface, flags,
                    mCanAddInternalSystemWindow ? privateFlags : 0, region);
                    mCanAddInternalSystemWindow ? privateFlags : 0, inputFeatures, region);
        } finally {
            Binder.restoreCallingIdentity(identity);
        }
+9 −7
Original line number Diff line number Diff line
@@ -8753,8 +8753,8 @@ public class WindowManagerService extends IWindowManager.Stub
     */
    void grantInputChannel(Session session, int callingUid, int callingPid, int displayId,
            SurfaceControl surface, IWindow window, IBinder hostInputToken,
            int flags, int privateFlags, int type, IBinder windowToken, IBinder focusGrantToken,
            String inputHandleName, InputChannel outInputChannel) {
            int flags, int privateFlags, int inputFeatures, int type, IBinder windowToken,
            IBinder focusGrantToken, String inputHandleName, InputChannel outInputChannel) {
        final int sanitizedType = sanitizeWindowType(session, displayId, windowToken, type);
        final InputApplicationHandle applicationHandle;
        final String name;
@@ -8771,7 +8771,7 @@ public class WindowManagerService extends IWindowManager.Stub
        }

        updateInputChannel(clientChannel.getToken(), callingUid, callingPid, displayId, surface,
                name, applicationHandle, flags, privateFlags, sanitizedType,
                name, applicationHandle, flags, privateFlags, inputFeatures, sanitizedType,
                null /* region */, window);

        clientChannel.copyTo(outInputChannel);
@@ -8812,13 +8812,14 @@ 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,
            int privateFlags, int type, Region region, IWindow window) {
            int privateFlags, int inputFeatures, int type, Region region, IWindow window) {
        final InputWindowHandle h = new InputWindowHandle(applicationHandle, displayId);
        h.token = channelToken;
        h.setWindowToken(window);
        h.name = name;

        flags = sanitizeFlagSlippery(flags, name, callingUid, callingPid);
        inputFeatures = sanitizeSpyWindow(inputFeatures, name, callingUid, callingPid);

        final int sanitizedLpFlags =
                (flags & (FLAG_NOT_TOUCHABLE | FLAG_SLIPPERY | LayoutParams.FLAG_NOT_FOCUSABLE))
@@ -8828,7 +8829,7 @@ public class WindowManagerService extends IWindowManager.Stub

        // Do not allow any input features to be set without sanitizing them first.
        h.inputConfig = InputConfigAdapter.getInputConfigFromWindowParams(
                        type, sanitizedLpFlags, 0 /*inputFeatures*/);
                        type, sanitizedLpFlags, inputFeatures);


        if ((flags & LayoutParams.FLAG_NOT_FOCUSABLE) != 0) {
@@ -8865,7 +8866,7 @@ public class WindowManagerService extends IWindowManager.Stub
     * is undefined.
     */
    void updateInputChannel(IBinder channelToken, int displayId, SurfaceControl surface,
            int flags, int privateFlags, Region region) {
            int flags, int privateFlags, int inputFeatures, Region region) {
        final InputApplicationHandle applicationHandle;
        final String name;
        final EmbeddedWindowController.EmbeddedWindow win;
@@ -8880,7 +8881,8 @@ public class WindowManagerService extends IWindowManager.Stub
        }

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

    /** Return whether layer tracing is enabled */
Loading