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

Commit 18782165 authored by Vishnu Nair's avatar Vishnu Nair
Browse files

Replace client token with a new token in InputWindowHandle

The tokens are used to map input data to its window and its channel. Currently InputWindowHandle
tokens uses the client IWindow binder token if the input is associated with a client window or a
newly generated token for temporary surfaces (drag input surface), and windowless surfaces.

These tokens are also used to send policy related events. From the token, it is not obvious what
the token represents for which component. This is a cleanup cl that removes the use of client before adding an explicit token for handling policy related events.
One use case of client token was to support pointer capture but this will move to using
the input channel socket.

Removing the client token allows windows to share its input token with other processes to enable
features like transfer focus without leaking the client token.

Bug: 134365580
Test: go/wm-smoke
Test: atest PointerCaptureTest WindowFocusTests

Change-Id: I49e4c54d977f98e855af9e7ed54443588fdb66c9
parent 503be6e6
Loading
Loading
Loading
Loading
+3 −7
Original line number Diff line number Diff line
@@ -38,10 +38,8 @@ public final class InputWindowHandle {
    // The input application handle.
    public final InputApplicationHandle inputApplicationHandle;

    // The client window.
    public final IWindow clientWindow;

    // The token associated with the window.
    // The token associates input data with a window and its input channel. The client input
    // channel and the server input channel will both contain this token.
    public IBinder token;

    // The window name.
@@ -120,10 +118,8 @@ public final class InputWindowHandle {

    private native void nativeDispose();

    public InputWindowHandle(InputApplicationHandle inputApplicationHandle,
            IWindow clientWindow, int displayId) {
    public InputWindowHandle(InputApplicationHandle inputApplicationHandle, int displayId) {
        this.inputApplicationHandle = inputApplicationHandle;
        this.clientWindow = clientWindow;
        this.displayId = displayId;
    }

+26 −42
Original line number Diff line number Diff line
@@ -71,7 +71,6 @@ import android.view.Display;
import android.view.IInputFilter;
import android.view.IInputFilterHost;
import android.view.IInputMonitorHost;
import android.view.IWindow;
import android.view.InputApplicationHandle;
import android.view.InputChannel;
import android.view.InputDevice;
@@ -186,9 +185,6 @@ public class InputManagerService extends IInputManager.Stub
    IInputFilter mInputFilter; // guarded by mInputFilterLock
    InputFilterHost mInputFilterHost; // guarded by mInputFilterLock

    private IWindow mFocusedWindow;
    private boolean mFocusedWindowHasCapture;

    private static native long nativeInit(InputManagerService service,
            Context context, MessageQueue messageQueue);
    private static native void nativeStart(long ptr);
@@ -544,20 +540,16 @@ public class InputManagerService extends IInputManager.Stub
    }

    /**
     * Registers an input channel so that it can be used as an input event target.
     * Registers an input channel so that it can be used as an input event target. The channel is
     * registered with a generated token.
     *
     * @param inputChannel The input channel to register.
     * @param inputWindowHandle The handle of the input window associated with the
     * input channel, or null if none.
     */
    public void registerInputChannel(InputChannel inputChannel, IBinder token) {
    public void registerInputChannel(InputChannel inputChannel) {
        if (inputChannel == null) {
            throw new IllegalArgumentException("inputChannel must not be null.");
        }

        if (token == null) {
            token = new Binder();
        }
        inputChannel.setToken(token);
        inputChannel.setToken(new Binder());

        nativeRegisterInputChannel(mPtr, inputChannel, Display.INVALID_DISPLAY);
    }
@@ -1513,26 +1505,9 @@ public class InputManagerService extends IInputManager.Stub

    @Override
    public void requestPointerCapture(IBinder windowToken, boolean enabled) {
        if (mFocusedWindow == null || mFocusedWindow.asBinder() != windowToken) {
            Slog.e(TAG, "requestPointerCapture called for a window that has no focus: "
                    + windowToken);
            return;
        }
        if (mFocusedWindowHasCapture == enabled) {
            Slog.i(TAG, "requestPointerCapture: already " + (enabled ? "enabled" : "disabled"));
            return;
        }
        setPointerCapture(enabled);
    }

    private void setPointerCapture(boolean enabled) {
        if (mFocusedWindowHasCapture != enabled) {
            mFocusedWindowHasCapture = enabled;
            try {
                mFocusedWindow.dispatchPointerCaptureChanged(enabled);
            } catch (RemoteException ex) {
                /* ignore */
            }
        boolean requestConfigurationRefresh =
                mWindowManagerCallbacks.requestPointerCapture(windowToken, enabled);
        if (requestConfigurationRefresh) {
            nativeSetPointerCapture(mPtr, enabled);
        }
    }
@@ -1829,16 +1804,11 @@ public class InputManagerService extends IInputManager.Stub

    // Native callback
    private void notifyFocusChanged(IBinder oldToken, IBinder newToken) {
        if (mFocusedWindow != null) {
            if (mFocusedWindow.asBinder() == newToken) {
                Slog.w(TAG, "notifyFocusChanged called with unchanged mFocusedWindow="
                        + mFocusedWindow);
                return;
            }
            setPointerCapture(false);
        final boolean requestConfigurationRefresh =
                mWindowManagerCallbacks.notifyFocusChanged(oldToken, newToken);
        if (requestConfigurationRefresh) {
            nativeSetPointerCapture(mPtr, false);
        }

        mFocusedWindow = IWindow.Stub.asInterface(newToken);
    }

    // Native callback.
@@ -2116,6 +2086,20 @@ public class InputManagerService extends IInputManager.Stub
         * @param touchedToken The token for the window that received the input event.
         */
        void onPointerDownOutsideFocus(IBinder touchedToken);

        /**
         * Called when the focused window has changed.
         *
         * @return true if we want to request a configuration refresh.
         */
        boolean notifyFocusChanged(IBinder oldToken, IBinder newToken);

        /**
         * Called by the client to request pointer capture.
         *
         * @return true if we want to request a configuration refresh.
         */
        boolean requestPointerCapture(IBinder windowToken, boolean enabled);
    }

    /**
+1 −1
Original line number Diff line number Diff line
@@ -5152,7 +5152,7 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
        // Let surface flinger to set the display ID of this input window handle because we don't
        // know which display the parent surface control is on.
        final InputWindowHandle portalWindowHandle = new InputWindowHandle(
                null /* inputApplicationHandle */, null /* clientWindow */, INVALID_DISPLAY);
                null /* inputApplicationHandle */, INVALID_DISPLAY);
        portalWindowHandle.name = name;
        portalWindowHandle.token = new Binder();
        portalWindowHandle.layoutParamsFlags =
+2 −2
Original line number Diff line number Diff line
@@ -263,7 +263,7 @@ class DragState {
            InputChannel[] channels = InputChannel.openInputChannelPair("drag");
            mServerChannel = channels[0];
            mClientChannel = channels[1];
            mService.mInputManager.registerInputChannel(mServerChannel, null);
            mService.mInputManager.registerInputChannel(mServerChannel);
            mInputEventReceiver = new DragInputEventReceiver(mClientChannel,
                    mService.mH.getLooper(), mDragDropController);

@@ -272,7 +272,7 @@ class DragState {
            mDragApplicationHandle.dispatchingTimeoutNanos =
                    WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;

            mDragWindowHandle = new InputWindowHandle(mDragApplicationHandle, null,
            mDragWindowHandle = new InputWindowHandle(mDragApplicationHandle,
                    display.getDisplayId());
            mDragWindowHandle.name = "drag";
            mDragWindowHandle.token = mServerChannel.getToken();
+2 −2
Original line number Diff line number Diff line
@@ -65,14 +65,14 @@ class InputConsumerImpl implements IBinder.DeathRecipient {
        } else {
            mClientChannel = channels[1];
        }
        mService.mInputManager.registerInputChannel(mServerChannel, null);
        mService.mInputManager.registerInputChannel(mServerChannel);

        mApplicationHandle = new InputApplicationHandle(new Binder());
        mApplicationHandle.name = name;
        mApplicationHandle.dispatchingTimeoutNanos =
                WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;

        mWindowHandle = new InputWindowHandle(mApplicationHandle, null, displayId);
        mWindowHandle = new InputWindowHandle(mApplicationHandle, displayId);
        mWindowHandle.name = name;
        mWindowHandle.token = mServerChannel.getToken();
        mWindowHandle.layoutParamsType = WindowManager.LayoutParams.TYPE_INPUT_CONSUMER;
Loading