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

Commit d57801ec authored by Chavi Weingarten's avatar Chavi Weingarten
Browse files

Add surface_control_input_receiver native API

Bug: 324271765
Test: ASurfaceControlInputReceiverTest
Change-Id: Ia85a07af09878846c681e552c1f8471652f932fc
parent da3a3284
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -54419,9 +54419,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") @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.surface_control_input_receiver") @NonNull public default android.window.InputTransferToken registerBatchedSurfaceControlInputReceiver(@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") @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 @FlaggedApi("com.android.window.flags.surface_control_input_receiver") @NonNull public default android.window.InputTransferToken registerUnbatchedSurfaceControlInputReceiver(@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>);
+11 −17
Original line number Diff line number Diff line
@@ -6193,9 +6193,6 @@ public interface WindowManager extends ViewManager {
     * caller must invoke {@link #unregisterSurfaceControlInputReceiver(SurfaceControl)} to clean up
     * the resources when no longer needing to use the {@link SurfaceControlInputReceiver}
     *
     * @param displayId              The display that the SurfaceControl will be placed on. Input
     *                               will only work if SurfaceControl is on that display and that
     *                               display  was touched.
     * @param surfaceControl         The SurfaceControl to register the InputChannel for
     * @param hostInputTransferToken The host token to link the embedded. This is used to handle
     *                               transferring touch gesture from host to embedded and for ANRs
@@ -6210,7 +6207,7 @@ public interface WindowManager extends ViewManager {
     */
    @FlaggedApi(Flags.FLAG_SURFACE_CONTROL_INPUT_RECEIVER)
    @NonNull
    default InputTransferToken registerBatchedSurfaceControlInputReceiver(int displayId,
    default InputTransferToken registerBatchedSurfaceControlInputReceiver(
            @NonNull InputTransferToken hostInputTransferToken,
            @NonNull SurfaceControl surfaceControl, @NonNull Choreographer choreographer,
            @NonNull SurfaceControlInputReceiver receiver) {
@@ -6221,15 +6218,12 @@ public interface WindowManager extends ViewManager {
    /**
     * Registers a {@link SurfaceControlInputReceiver} for a {@link SurfaceControl} that will
     * receive every input event. This is different than calling
     * {@link #registerBatchedSurfaceControlInputReceiver(int, InputTransferToken, SurfaceControl,
     * {@link #registerBatchedSurfaceControlInputReceiver(InputTransferToken, SurfaceControl,
     * Choreographer, SurfaceControlInputReceiver)} in that the input events are received
     * unbatched.
     * The caller must invoke {@link #unregisterSurfaceControlInputReceiver(SurfaceControl)} to
     * clean up the resources when no longer needing to use the {@link SurfaceControlInputReceiver}
     *
     * @param displayId              The display that the SurfaceControl will be placed on. Input
     *                               will only work if SurfaceControl is on that display and that
     *                               display  was touched.
     * @param surfaceControl         The SurfaceControl to register the InputChannel for
     * @param hostInputTransferToken The host token to link the embedded. This is used to handle
     *                               transferring touch gesture from host to embedded and for ANRs
@@ -6243,7 +6237,7 @@ public interface WindowManager extends ViewManager {
     */
    @FlaggedApi(Flags.FLAG_SURFACE_CONTROL_INPUT_RECEIVER)
    @NonNull
    default InputTransferToken registerUnbatchedSurfaceControlInputReceiver(int displayId,
    default InputTransferToken registerUnbatchedSurfaceControlInputReceiver(
            @NonNull InputTransferToken hostInputTransferToken,
            @NonNull SurfaceControl surfaceControl, @NonNull Looper looper,
            @NonNull SurfaceControlInputReceiver receiver) {
@@ -6256,9 +6250,9 @@ public interface WindowManager extends ViewManager {
     * specified token.
     * <p>
     * Must be called on the same {@link Looper} thread to which was passed to the
     * {@link #registerBatchedSurfaceControlInputReceiver(int, InputTransferToken, SurfaceControl,
     * {@link #registerBatchedSurfaceControlInputReceiver(InputTransferToken, SurfaceControl,
     * Choreographer, SurfaceControlInputReceiver)} or
     * {@link #registerUnbatchedSurfaceControlInputReceiver(int, InputTransferToken, SurfaceControl,
     * {@link #registerUnbatchedSurfaceControlInputReceiver(InputTransferToken, SurfaceControl,
     * Looper, SurfaceControlInputReceiver)}
     *
     * @param surfaceControl The SurfaceControl to remove and unregister the input channel for.
@@ -6272,9 +6266,9 @@ public interface WindowManager extends ViewManager {
    /**
     * Returns the input client token for the {@link SurfaceControl}. This will only return non
     * null if the SurfaceControl was registered for input via
     * {@link #registerBatchedSurfaceControlInputReceiver(int, InputTransferToken, SurfaceControl,
     * {@link #registerBatchedSurfaceControlInputReceiver(InputTransferToken, SurfaceControl,
     * Choreographer, SurfaceControlInputReceiver)} or
     * {@link #registerUnbatchedSurfaceControlInputReceiver(int, InputTransferToken,
     * {@link #registerUnbatchedSurfaceControlInputReceiver(InputTransferToken,
     * SurfaceControl, Looper, SurfaceControlInputReceiver)}.
     * <p>
     * This is helpful for testing to ensure the test waits for the layer to be registered with
@@ -6304,9 +6298,9 @@ public interface WindowManager extends ViewManager {
     * </li>
     * <li>
     * Registering a SurfaceControl for input and passing the host's token to either
     * {@link #registerBatchedSurfaceControlInputReceiver(int, InputTransferToken, SurfaceControl,
     * {@link #registerBatchedSurfaceControlInputReceiver(InputTransferToken, SurfaceControl,
     * Choreographer, SurfaceControlInputReceiver)} or
     * {@link #registerUnbatchedSurfaceControlInputReceiver(int, InputTransferToken,
     * {@link #registerUnbatchedSurfaceControlInputReceiver(InputTransferToken,
     * SurfaceControl, Looper, SurfaceControlInputReceiver)}.
     * </li>
     * </ul>
@@ -6321,9 +6315,9 @@ public interface WindowManager extends ViewManager {
     * When the host wants to transfer touch gesture to the embedded, it can retrieve the embedded
     * token via {@link SurfaceControlViewHost.SurfacePackage#getInputTransferToken()} or use the
     * value returned from either
     * {@link #registerBatchedSurfaceControlInputReceiver(int, InputTransferToken, SurfaceControl,
     * {@link #registerBatchedSurfaceControlInputReceiver(InputTransferToken, SurfaceControl,
     * Choreographer, SurfaceControlInputReceiver)} or
     * {@link #registerUnbatchedSurfaceControlInputReceiver(int, InputTransferToken, SurfaceControl,
     * {@link #registerUnbatchedSurfaceControlInputReceiver(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
+32 −24
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.view;

import static android.view.Display.INVALID_DISPLAY;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;

import android.animation.ValueAnimator;
@@ -839,20 +840,40 @@ public final class WindowManagerGlobal {
        mTrustedPresentationListener.removeListener(listener);
    }

    InputTransferToken registerBatchedSurfaceControlInputReceiver(int displayId,
    private static InputChannel createInputChannel(@NonNull IBinder clientToken,
            @NonNull InputTransferToken hostToken, @NonNull SurfaceControl surfaceControl,
            @NonNull Choreographer choreographer, @NonNull SurfaceControlInputReceiver receiver) {
        IBinder clientToken = new Binder();
        InputTransferToken inputTransferToken = new InputTransferToken();
            @Nullable InputTransferToken inputTransferToken) {
        InputChannel inputChannel = new InputChannel();
        try {
            WindowManagerGlobal.getWindowSession().grantInputChannel(displayId, surfaceControl,
                    clientToken, hostToken, 0, 0, TYPE_APPLICATION, 0, null, inputTransferToken,
                    surfaceControl.getName(), inputChannel);
            // TODO (b/329860681): Use INVALID_DISPLAY for now because the displayId will be
            // selected in  SurfaceFlinger. This should be cleaned up so grantInputChannel doesn't
            // take in a displayId at all
            WindowManagerGlobal.getWindowSession().grantInputChannel(INVALID_DISPLAY,
                    surfaceControl, clientToken, hostToken, 0, 0, TYPE_APPLICATION, 0, null,
                    inputTransferToken, surfaceControl.getName(), inputChannel);
        } catch (RemoteException e) {
            Log.e(TAG, "Failed to create input channel", e);
            e.rethrowAsRuntimeException();
        }
        return inputChannel;
    }

    private static void removeInputChannel(IBinder clientToken) {
        try {
            WindowManagerGlobal.getWindowSession().remove(clientToken);
        } catch (RemoteException e) {
            Log.e(TAG, "Failed to remove input channel", e);
            e.rethrowAsRuntimeException();
        }
    }

    InputTransferToken registerBatchedSurfaceControlInputReceiver(
            @NonNull InputTransferToken hostToken, @NonNull SurfaceControl surfaceControl,
            @NonNull Choreographer choreographer, @NonNull SurfaceControlInputReceiver receiver) {
        IBinder clientToken = new Binder();
        InputTransferToken inputTransferToken = new InputTransferToken();
        InputChannel inputChannel = createInputChannel(clientToken, hostToken,
                surfaceControl, inputTransferToken);

        synchronized (mSurfaceControlInputReceivers) {
            mSurfaceControlInputReceivers.put(surfaceControl.getLayerId(),
@@ -869,20 +890,13 @@ public final class WindowManagerGlobal {
        return inputTransferToken;
    }

    InputTransferToken registerUnbatchedSurfaceControlInputReceiver(int displayId,
    InputTransferToken registerUnbatchedSurfaceControlInputReceiver(
            @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, inputTransferToken,
                    surfaceControl.getName(), inputChannel);
        } catch (RemoteException e) {
            Log.e(TAG, "Failed to create input channel", e);
            e.rethrowAsRuntimeException();
        }
        InputChannel inputChannel = createInputChannel(clientToken, hostToken,
                surfaceControl, inputTransferToken);

        synchronized (mSurfaceControlInputReceivers) {
            mSurfaceControlInputReceivers.put(surfaceControl.getLayerId(),
@@ -909,13 +923,7 @@ public final class WindowManagerGlobal {
            Log.w(TAG, "No registered input event receiver with sc: " + surfaceControl);
            return;
        }
        try {
            WindowManagerGlobal.getWindowSession().remove(
                    surfaceControlInputReceiverInfo.mClientToken);
        } catch (RemoteException e) {
            Log.e(TAG, "Failed to remove input channel", e);
            e.rethrowAsRuntimeException();
        }
        removeInputChannel(surfaceControlInputReceiverInfo.mClientToken);

        surfaceControlInputReceiverInfo.mInputEventReceiver.dispose();
    }
+4 −4
Original line number Diff line number Diff line
@@ -535,7 +535,7 @@ public final class WindowManagerImpl implements WindowManager {

    @NonNull
    @Override
    public InputTransferToken registerBatchedSurfaceControlInputReceiver(int displayId,
    public InputTransferToken registerBatchedSurfaceControlInputReceiver(
            @NonNull InputTransferToken hostInputTransferToken,
            @NonNull SurfaceControl surfaceControl, @NonNull Choreographer choreographer,
            @NonNull SurfaceControlInputReceiver receiver) {
@@ -543,13 +543,13 @@ public final class WindowManagerImpl implements WindowManager {
        Objects.requireNonNull(surfaceControl);
        Objects.requireNonNull(choreographer);
        Objects.requireNonNull(receiver);
        return mGlobal.registerBatchedSurfaceControlInputReceiver(displayId, hostInputTransferToken,
        return mGlobal.registerBatchedSurfaceControlInputReceiver(hostInputTransferToken,
                surfaceControl, choreographer, receiver);
    }

    @NonNull
    @Override
    public InputTransferToken registerUnbatchedSurfaceControlInputReceiver(int displayId,
    public InputTransferToken registerUnbatchedSurfaceControlInputReceiver(
            @NonNull InputTransferToken hostInputTransferToken,
            @NonNull SurfaceControl surfaceControl, @NonNull Looper looper,
            @NonNull SurfaceControlInputReceiver receiver) {
@@ -557,7 +557,7 @@ public final class WindowManagerImpl implements WindowManager {
        Objects.requireNonNull(surfaceControl);
        Objects.requireNonNull(looper);
        Objects.requireNonNull(receiver);
        return mGlobal.registerUnbatchedSurfaceControlInputReceiver(displayId,
        return mGlobal.registerUnbatchedSurfaceControlInputReceiver(
                hostInputTransferToken, surfaceControl, looper, receiver);
    }

+2 −2
Original line number Diff line number Diff line
@@ -38,9 +38,9 @@ import java.util.Objects;
 * {@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,
 * {@link android.view.WindowManager#registerUnbatchedSurfaceControlInputReceiver(
 * InputTransferToken, SurfaceControl, Looper, SurfaceControlInputReceiver)} or
 * {@link android.view.WindowManager#registerBatchedSurfaceControlInputReceiver(int,
 * {@link android.view.WindowManager#registerBatchedSurfaceControlInputReceiver(
 * InputTransferToken, SurfaceControl, Choreographer, SurfaceControlInputReceiver)} and the
 * returned token can be used to call
 * {@link android.view.WindowManager#transferTouchGesture(InputTransferToken, InputTransferToken)}
Loading