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

Commit 9fd2b649 authored by Chavi Weingarten's avatar Chavi Weingarten
Browse files

Create generic transferTouchGesture API

Instead of specifying from host to embedded or vice versa for
tranferTouchGesture, create a generic API that allows you to request
transferring touch gesture from an InputTransferToken to another
InputTransferToken.

Test: SurfaceControlInputReceiverTests
Test: AttachedSurfaceControlTest
Test: SurfaceControlViewHostTests
Flag: ACONFIG com.android.window.flags.surface_control_input_receiver TRUNKFOOD
Bug: 278757236
Change-Id: I58beb1fe041f251db6c9cf90688bd2554bd2b399
parent b3929115
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -50519,7 +50519,6 @@ package android.view {
    method public default void removeOnBufferTransformHintChangedListener(@NonNull android.view.AttachedSurfaceControl.OnBufferTransformHintChangedListener);
    method public default void setChildBoundingInsets(@NonNull android.graphics.Rect);
    method public default void setTouchableRegion(@Nullable android.graphics.Region);
    method @FlaggedApi("com.android.window.flags.transfer_gesture_to_embedded") public default boolean transferHostTouchGestureToEmbedded(@NonNull android.view.SurfaceControlViewHost.SurfacePackage);
  }
  @UiThread public static interface AttachedSurfaceControl.OnBufferTransformHintChangedListener {
@@ -52237,6 +52236,7 @@ package android.view {
  public static final class SurfaceControlViewHost.SurfacePackage implements android.os.Parcelable {
    ctor public SurfaceControlViewHost.SurfacePackage(@NonNull android.view.SurfaceControlViewHost.SurfacePackage);
    method public int describeContents();
    method @FlaggedApi("com.android.window.flags.surface_control_input_receiver") @Nullable public android.window.InputTransferToken getInputTransferToken();
    method @NonNull public android.view.SurfaceControl getSurfaceControl();
    method public void notifyConfigurationChanged(@NonNull android.content.res.Configuration);
    method public void notifyDetachedFromWindow();
@@ -54379,6 +54379,7 @@ package android.view {
    method public default void removeProposedRotationListener(@NonNull java.util.function.IntConsumer);
    method @FlaggedApi("com.android.window.flags.screen_recording_callbacks") @RequiresPermission(android.Manifest.permission.DETECT_SCREEN_RECORDING) public default void removeScreenRecordingCallback(@NonNull java.util.function.Consumer<java.lang.Integer>);
    method public void removeViewImmediate(android.view.View);
    method @FlaggedApi("com.android.window.flags.surface_control_input_receiver") public default boolean transferTouchGesture(@NonNull android.window.InputTransferToken, @NonNull android.window.InputTransferToken);
    method @FlaggedApi("com.android.window.flags.surface_control_input_receiver") public default void unregisterSurfaceControlInputReceiver(@NonNull android.view.SurfaceControl);
    method @FlaggedApi("com.android.window.flags.trusted_presentation_listener_for_window") public default void unregisterTrustedPresentationListener(@NonNull java.util.function.Consumer<java.lang.Boolean>);
    field public static final String PROPERTY_ACTIVITY_EMBEDDING_ALLOW_SYSTEM_OVERRIDE = "android.window.PROPERTY_ACTIVITY_EMBEDDING_ALLOW_SYSTEM_OVERRIDE";
+0 −34
Original line number Diff line number Diff line
@@ -202,38 +202,4 @@ public interface AttachedSurfaceControl {
        throw new UnsupportedOperationException("The getInputTransferToken needs to be "
                + "implemented before making this call.");
    }

    /**
     * Transfer the currently in progress touch gesture from the host to the requested
     * {@link SurfaceControlViewHost.SurfacePackage}. This requires that the
     * SurfaceControlViewHost was created with the current host's inputToken.
     * <p>
     * When the touch is transferred, the window currently receiving touch gets an ACTION_CANCEL
     * and does not receive any further input events for this gesture.
     * <p>
     * The transferred-to window receives an ACTION_DOWN event and then the remainder of the
     * input events for this gesture. It does not receive any of the previous events of this gesture
     * that the originating window received.
     * <p>
     * The "transferTouch" API only works for the current gesture. When a new gesture arrives,
     * input dispatcher will do a new round of hit testing. So, if the "host" window is still the
     * first thing that's being touched, then it will receive the new gesture again. It will
     * again be up to the host to transfer this new gesture to the embedded.
     * <p>
     * Once the transferred-to window receives the gesture, it can choose to give up this gesture
     * and send it to another window that it's linked to (it can't be an arbitrary window for
     * security reasons) using the same transferTouch API. Only the window currently receiving
     * touch is allowed to transfer the gesture.
     *
     * @param surfacePackage The SurfacePackage to transfer the gesture to.
     * @return Whether the touch stream was transferred.
     * @see SurfaceControlViewHost#transferTouchGestureToHost() for the reverse to transfer touch
     * gesture from the embedded to the host.
     */
    @FlaggedApi(Flags.FLAG_TRANSFER_GESTURE_TO_EMBEDDED)
    default boolean transferHostTouchGestureToEmbedded(
            @NonNull SurfaceControlViewHost.SurfacePackage surfacePackage) {
        throw new UnsupportedOperationException(
                "transferHostTouchGestureToEmbedded is unimplemented");
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -1098,4 +1098,7 @@ interface IWindowManager
     * (ie. not handled by any window which can handle the drag).
     */
    void setUnhandledDragListener(IUnhandledDragListener listener);

    boolean transferTouchGesture(in InputTransferToken transferFromToken,
            in InputTransferToken transferToToken);
}
+0 −5
Original line number Diff line number Diff line
@@ -370,11 +370,6 @@ interface IWindowSession {
     */
    boolean cancelDraw(IWindow window);

    boolean transferEmbeddedTouchFocusToHost(IWindow embeddedWindow);

    boolean transferHostTouchGestureToEmbedded(IWindow hostWindow,
        in InputTransferToken transferTouchToken);

    /**
     * Moves the focus to the adjacent window if there is one in the given direction. This can only
     * move the focus to the window in the same leaf task.
+15 −14
Original line number Diff line number Diff line
@@ -293,12 +293,12 @@ public class SurfaceControlViewHost {
        /**
         * Gets an {@link InputTransferToken} which can be used to request focus on the embedded
         * surface or to transfer touch gesture to the embedded surface.
         * @return the InputTransferToken associated with {@link SurfacePackage}
         * @see AttachedSurfaceControl#transferHostTouchGestureToEmbedded(SurfacePackage)
         *
         * @hide
         * @return the InputTransferToken associated with {@link SurfacePackage} or {@code null} if
         * the embedded hasn't set up its view or doesn't have input.
         * @see WindowManager#transferTouchGesture(InputTransferToken, InputTransferToken)
         */
        @Nullable
        @FlaggedApi(Flags.FLAG_SURFACE_CONTROL_INPUT_RECEIVER)
        public InputTransferToken getInputTransferToken() {
            return mInputTransferToken;
        }
@@ -577,9 +577,9 @@ public class SurfaceControlViewHost {
    }

    /**
     * Transfer the currently in progress touch gesture to the parent
     * (if any) of this SurfaceControlViewHost. This requires that the
     * SurfaceControlViewHost was created with an associated hostInputToken.
     * Transfer the currently in progress touch gesture to the parent (if any) of this
     * SurfaceControlViewHost. This requires that the SurfaceControlViewHost was created with an
     * associated host {@link InputTransferToken}.
     *
     * @return Whether the touch stream was transferred.
     */
@@ -587,13 +587,14 @@ public class SurfaceControlViewHost {
        if (mViewRoot == null) {
            return false;
        }

        final IWindowSession realWm = WindowManagerGlobal.getWindowSession();
        try {
            return realWm.transferEmbeddedTouchFocusToHost(mViewRoot.mWindow);
        } catch (RemoteException e) {
            e.rethrowAsRuntimeException();
        }
        final WindowManager wm =
                (WindowManager) mViewRoot.mContext.getSystemService(Context.WINDOW_SERVICE);
        InputTransferToken embeddedToken = getInputTransferToken();
        InputTransferToken hostToken = mWm.mHostInputTransferToken;
        if (embeddedToken == null || hostToken == null) {
            Log.w(TAG, "Failed to transferTouchGestureToHost. Host or embedded token is null");
            return false;
        }
        return wm.transferTouchGesture(getInputTransferToken(), mWm.mHostInputTransferToken);
    }
}
Loading