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

Commit 4381c2c6 authored by Chavi Weingarten's avatar Chavi Weingarten Committed by Android (Google) Code Review
Browse files

Merge "Add transferTouchGesture ability for SurfaceControlInputReceiver" into main

parents 63718879 25f2a6bf
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -54447,9 +54447,9 @@ package android.view {
    method @Deprecated public android.view.Display getDefaultDisplay();
    method @NonNull public default android.view.WindowMetrics getMaximumWindowMetrics();
    method public default boolean isCrossWindowBlurEnabled();
    method @FlaggedApi("com.android.window.flags.surface_control_input_receiver") public default void registerBatchedSurfaceControlInputReceiver(int, @NonNull android.window.InputTransferToken, @NonNull android.view.SurfaceControl, @NonNull android.view.Choreographer, @NonNull android.view.SurfaceControlInputReceiver);
    method @FlaggedApi("com.android.window.flags.surface_control_input_receiver") @NonNull public default android.window.InputTransferToken registerBatchedSurfaceControlInputReceiver(int, @NonNull android.window.InputTransferToken, @NonNull android.view.SurfaceControl, @NonNull android.view.Choreographer, @NonNull android.view.SurfaceControlInputReceiver);
    method @FlaggedApi("com.android.window.flags.trusted_presentation_listener_for_window") public default void registerTrustedPresentationListener(@NonNull android.os.IBinder, @NonNull android.window.TrustedPresentationThresholds, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<java.lang.Boolean>);
    method @FlaggedApi("com.android.window.flags.surface_control_input_receiver") public default void registerUnbatchedSurfaceControlInputReceiver(int, @NonNull android.window.InputTransferToken, @NonNull android.view.SurfaceControl, @NonNull android.os.Looper, @NonNull android.view.SurfaceControlInputReceiver);
    method @FlaggedApi("com.android.window.flags.surface_control_input_receiver") @NonNull public default android.window.InputTransferToken registerUnbatchedSurfaceControlInputReceiver(int, @NonNull android.window.InputTransferToken, @NonNull android.view.SurfaceControl, @NonNull android.os.Looper, @NonNull android.view.SurfaceControlInputReceiver);
    method public default void removeCrossWindowBlurEnabledListener(@NonNull java.util.function.Consumer<java.lang.Boolean>);
    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>);
+36 −14
Original line number Diff line number Diff line
@@ -6157,12 +6157,15 @@ public interface WindowManager extends ViewManager {
     *                               rendering Choreographer.
     * @param receiver               The SurfaceControlInputReceiver that will receive the input
     *                               events
     * @return Returns the {@link InputTransferToken} that can be used to transfer touch gesture
     * to or from other windows.
     */
    @FlaggedApi(Flags.FLAG_SURFACE_CONTROL_INPUT_RECEIVER)
    default void registerBatchedSurfaceControlInputReceiver(int displayId,
    @NonNull
    default InputTransferToken registerBatchedSurfaceControlInputReceiver(int displayId,
            @NonNull InputTransferToken hostInputTransferToken,
            @NonNull SurfaceControl surfaceControl,
            @NonNull Choreographer choreographer, @NonNull SurfaceControlInputReceiver receiver) {
            @NonNull SurfaceControl surfaceControl, @NonNull Choreographer choreographer,
            @NonNull SurfaceControlInputReceiver receiver) {
        throw new UnsupportedOperationException(
                "registerBatchedSurfaceControlInputReceiver is not implemented");
    }
@@ -6187,9 +6190,12 @@ public interface WindowManager extends ViewManager {
     * @param looper                 The looper to use when invoking callbacks.
     * @param receiver               The SurfaceControlInputReceiver that will receive the input
     *                               events.
     * @return Returns the {@link InputTransferToken} that can be used to transfer touch gesture
     * to or from other windows.
     */
    @FlaggedApi(Flags.FLAG_SURFACE_CONTROL_INPUT_RECEIVER)
    default void registerUnbatchedSurfaceControlInputReceiver(int displayId,
    @NonNull
    default InputTransferToken registerUnbatchedSurfaceControlInputReceiver(int displayId,
            @NonNull InputTransferToken hostInputTransferToken,
            @NonNull SurfaceControl surfaceControl, @NonNull Looper looper,
            @NonNull SurfaceControlInputReceiver receiver) {
@@ -6242,9 +6248,21 @@ public interface WindowManager extends ViewManager {
     * transferToToken.
     * <p><br>
     * This requires that the fromToken and toToken are associated with each other. The association
     * can be done by creating a {@link SurfaceControlViewHost} and passing the host's
     * can be done different ways, depending on how the embedded window is created.
     * <ul>
     * <li>
     * Creating a {@link SurfaceControlViewHost} and passing the host's
     * {@link InputTransferToken} for
     * {@link SurfaceControlViewHost#SurfaceControlViewHost(Context, Display, InputTransferToken)}.
     * </li>
     * <li>
     * Registering a SurfaceControl for input and passing the host's token to either
     * {@link #registerBatchedSurfaceControlInputReceiver(int, InputTransferToken, SurfaceControl,
     * Choreographer, SurfaceControlInputReceiver)} or
     * {@link #registerUnbatchedSurfaceControlInputReceiver(int, InputTransferToken,
     * SurfaceControl, Looper, SurfaceControlInputReceiver)}.
     * </li>
     * </ul>
     * <p>
     * The host is likely to be an {@link AttachedSurfaceControl} so the host token can be
     * retrieved via {@link AttachedSurfaceControl#getInputTransferToken()}.
@@ -6254,12 +6272,16 @@ public interface WindowManager extends ViewManager {
     * transfer.
     * <p><br>
     * When the host wants to transfer touch gesture to the embedded, it can retrieve the embedded
     * token via {@link SurfaceControlViewHost.SurfacePackage#getInputTransferToken()} and pass its
     * own token as the transferFromToken.
     * token via {@link SurfaceControlViewHost.SurfacePackage#getInputTransferToken()} or use the
     * value returned from either
     * {@link #registerBatchedSurfaceControlInputReceiver(int, InputTransferToken, SurfaceControl,
     * Choreographer, SurfaceControlInputReceiver)} or
     * {@link #registerUnbatchedSurfaceControlInputReceiver(int, InputTransferToken, SurfaceControl,
     * Looper, SurfaceControlInputReceiver)} and pass its own token as the transferFromToken.
     * <p>
     * When the embedded wants to transfer touch gesture to the host, it can pass in its own token
     * as the transferFromToken and use the associated host's {@link InputTransferToken} as the
     * transferToToken
     * When the embedded wants to transfer touch gesture to the host, it can pass in its own
     * token as the transferFromToken and use the associated host's {@link InputTransferToken} as
     * the transferToToken
     * <p><br>
     * 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.
@@ -6268,10 +6290,10 @@ public interface WindowManager extends ViewManager {
     * events for this gesture. It does not receive any of the previous events of this gesture that
     * the originating window received.
     * <p>
     * The transferTouchGesture 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.
     * The transferTouchGesture 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.
     *
     * @param transferFromToken the InputTransferToken for the currently active gesture
     * @param transferToToken   the InputTransferToken to transfer the gesture to.
+8 −4
Original line number Diff line number Diff line
@@ -839,14 +839,15 @@ public final class WindowManagerGlobal {
        mTrustedPresentationListener.removeListener(listener);
    }

    void registerBatchedSurfaceControlInputReceiver(int displayId,
    InputTransferToken registerBatchedSurfaceControlInputReceiver(int displayId,
            @NonNull InputTransferToken hostToken, @NonNull SurfaceControl surfaceControl,
            @NonNull Choreographer choreographer, @NonNull SurfaceControlInputReceiver receiver) {
        IBinder clientToken = new Binder();
        InputTransferToken inputTransferToken = new InputTransferToken();
        InputChannel inputChannel = new InputChannel();
        try {
            WindowManagerGlobal.getWindowSession().grantInputChannel(displayId, surfaceControl,
                    clientToken, hostToken, 0, 0, TYPE_APPLICATION, 0, null, null,
                    clientToken, hostToken, 0, 0, TYPE_APPLICATION, 0, null, inputTransferToken,
                    surfaceControl.getName(), inputChannel);
        } catch (RemoteException e) {
            Log.e(TAG, "Failed to create input channel", e);
@@ -865,16 +866,18 @@ public final class WindowManagerGlobal {
                                }
                            }));
        }
        return inputTransferToken;
    }

    void registerUnbatchedSurfaceControlInputReceiver(int displayId,
    InputTransferToken registerUnbatchedSurfaceControlInputReceiver(int displayId,
            @NonNull InputTransferToken hostToken, @NonNull SurfaceControl surfaceControl,
            @NonNull Looper looper, @NonNull SurfaceControlInputReceiver receiver) {
        IBinder clientToken = new Binder();
        InputTransferToken inputTransferToken = new InputTransferToken();
        InputChannel inputChannel = new InputChannel();
        try {
            WindowManagerGlobal.getWindowSession().grantInputChannel(displayId, surfaceControl,
                    clientToken, hostToken, 0, 0, TYPE_APPLICATION, 0, null, null,
                    clientToken, hostToken, 0, 0, TYPE_APPLICATION, 0, null, inputTransferToken,
                    surfaceControl.getName(), inputChannel);
        } catch (RemoteException e) {
            Log.e(TAG, "Failed to create input channel", e);
@@ -892,6 +895,7 @@ public final class WindowManagerGlobal {
                                }
                            }));
        }
        return inputTransferToken;
    }

    void unregisterSurfaceControlInputReceiver(SurfaceControl surfaceControl) {
+7 −5
Original line number Diff line number Diff line
@@ -533,22 +533,24 @@ public final class WindowManagerImpl implements WindowManager {
        mGlobal.unregisterTrustedPresentationListener(listener);
    }

    @NonNull
    @Override
    public void registerBatchedSurfaceControlInputReceiver(int displayId,
    public InputTransferToken registerBatchedSurfaceControlInputReceiver(int displayId,
            @NonNull InputTransferToken hostInputTransferToken,
            @NonNull SurfaceControl surfaceControl, @NonNull Choreographer choreographer,
            @NonNull SurfaceControlInputReceiver receiver) {
        mGlobal.registerBatchedSurfaceControlInputReceiver(displayId, hostInputTransferToken,
        return mGlobal.registerBatchedSurfaceControlInputReceiver(displayId, hostInputTransferToken,
                surfaceControl, choreographer, receiver);
    }

    @NonNull
    @Override
    public void registerUnbatchedSurfaceControlInputReceiver(int displayId,
    public InputTransferToken registerUnbatchedSurfaceControlInputReceiver(int displayId,
            @NonNull InputTransferToken hostInputTransferToken,
            @NonNull SurfaceControl surfaceControl, @NonNull Looper looper,
            @NonNull SurfaceControlInputReceiver receiver) {
        mGlobal.registerUnbatchedSurfaceControlInputReceiver(displayId, hostInputTransferToken,
                surfaceControl, looper, receiver);
        return mGlobal.registerUnbatchedSurfaceControlInputReceiver(displayId,
                hostInputTransferToken, surfaceControl, looper, receiver);
    }

    @Override
+12 −0
Original line number Diff line number Diff line
@@ -20,8 +20,12 @@ import android.annotation.FlaggedApi;
import android.annotation.NonNull;
import android.os.Binder;
import android.os.IBinder;
import android.os.Looper;
import android.os.Parcel;
import android.os.Parcelable;
import android.view.Choreographer;
import android.view.SurfaceControl;
import android.view.SurfaceControlInputReceiver;
import android.view.SurfaceControlViewHost;

import com.android.window.flags.Flags;
@@ -32,6 +36,14 @@ import java.util.Objects;
 * A token that can be used to request focus on or to transfer touch gesture to a
 * {@link SurfaceControlViewHost} or {@link android.view.SurfaceControl} that has an input channel.
 * <p>
 * The {@link android.view.SurfaceControl} needs to have been registered for input via
 * {@link android.view.WindowManager#registerUnbatchedSurfaceControlInputReceiver(int,
 * InputTransferToken, SurfaceControl, Looper, SurfaceControlInputReceiver)} or
 * {@link android.view.WindowManager#registerBatchedSurfaceControlInputReceiver(int,
 * InputTransferToken, SurfaceControl, Choreographer, SurfaceControlInputReceiver)} and the
 * returned token can be used to call
 * {@link android.view.WindowManager#transferTouchGesture(InputTransferToken, InputTransferToken)}
 * <p>
 * For {@link SurfaceControlViewHost}, the token can be retrieved via
 * {@link SurfaceControlViewHost.SurfacePackage#getInputTransferToken()}
 *