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

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

Merge "Expose InputTransferToken API and usages of it as public API" into main

parents 3092a907 849f2ad9
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -50515,7 +50515,7 @@ package android.view {
    method public boolean applyTransactionOnDraw(@NonNull android.view.SurfaceControl.Transaction);
    method @Nullable public android.view.SurfaceControl.Transaction buildReparentTransaction(@NonNull android.view.SurfaceControl);
    method public default int getBufferTransformHint();
    method @FlaggedApi("com.android.window.flags.get_host_token_api") @Nullable public default android.os.IBinder getHostToken();
    method @FlaggedApi("com.android.window.flags.surface_control_input_receiver") @NonNull public default android.window.InputTransferToken getInputTransferToken();
    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);
@@ -52225,6 +52225,7 @@ package android.view {
  public class SurfaceControlViewHost {
    ctor public SurfaceControlViewHost(@NonNull android.content.Context, @NonNull android.view.Display, @Nullable android.os.IBinder);
    ctor @FlaggedApi("com.android.window.flags.surface_control_input_receiver") public SurfaceControlViewHost(@NonNull android.content.Context, @NonNull android.view.Display, @Nullable android.window.InputTransferToken);
    method @Nullable public android.view.SurfaceControlViewHost.SurfacePackage getSurfacePackage();
    method @Nullable public android.view.View getView();
    method public void relayout(int, int);
@@ -54371,9 +54372,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.os.IBinder, @NonNull android.view.SurfaceControl, @NonNull android.view.Choreographer, @NonNull android.view.SurfaceControlInputReceiver);
    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.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.os.IBinder, @NonNull android.view.SurfaceControl, @NonNull android.os.Looper, @NonNull android.view.SurfaceControlInputReceiver);
    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 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>);
@@ -61354,6 +61355,12 @@ package android.window {
    field public static final int EDGE_RIGHT = 1; // 0x1
  }
  @FlaggedApi("com.android.window.flags.surface_control_input_receiver") public final class InputTransferToken implements android.os.Parcelable {
    method public int describeContents();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.window.InputTransferToken> CREATOR;
  }
  public interface OnBackAnimationCallback extends android.window.OnBackInvokedCallback {
    method public default void onBackCancelled();
    method public default void onBackProgressed(@NonNull android.window.BackEvent);
+16 −22
Original line number Diff line number Diff line
@@ -19,10 +19,11 @@ import android.annotation.FlaggedApi;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UiThread;
import android.content.Context;
import android.graphics.Rect;
import android.graphics.Region;
import android.hardware.HardwareBuffer;
import android.os.IBinder;
import android.os.Looper;
import android.window.InputTransferToken;
import android.window.SurfaceSyncGroup;

@@ -179,33 +180,26 @@ public interface AttachedSurfaceControl {
    default void setChildBoundingInsets(@NonNull Rect insets) {
    }

    /**
     * Gets the token used for associating this {@link AttachedSurfaceControl} with
     * {@link SurfaceControlViewHost} instances.
     *
     * <p>This token should be passed to {@link SurfaceControlViewHost}'s constructor.
     * This token will be {@code null} if the window does not have an input channel.
     *
     * @return The SurfaceControlViewHost link token.
     */
    @Nullable
    @FlaggedApi(Flags.FLAG_GET_HOST_TOKEN_API)
    default IBinder getHostToken() {
        throw new UnsupportedOperationException("The getHostToken needs to be "
            + "implemented before making this call.");
    }

    /**
     * Gets the token used for associating this {@link AttachedSurfaceControl} with an embedded
     * {@link SurfaceControlViewHost} or {@link SurfaceControl}
     *
     * @return The SurfaceControlViewHost link token.  This can return {@code null} if the
     * {@link AttachedSurfaceControl} was created with no registered input
     * @hide
     * <p>This token should be passed to
     * {@link SurfaceControlViewHost#SurfaceControlViewHost(Context, Display, InputTransferToken)}
     * or
     * {@link WindowManager#registerBatchedSurfaceControlInputReceiver(int, InputTransferToken,
     * SurfaceControl, Choreographer, SurfaceControlInputReceiver)} or
     * {@link WindowManager#registerUnbatchedSurfaceControlInputReceiver(int, InputTransferToken,
     * SurfaceControl, Looper, SurfaceControlInputReceiver)}
     *
     * @return The SurfaceControlViewHost link token.
     * @throws IllegalStateException if the {@link AttachedSurfaceControl} was created with no
     * registered input
     */
    @Nullable
    @NonNull
    @FlaggedApi(Flags.FLAG_SURFACE_CONTROL_INPUT_RECEIVER)
    default InputTransferToken getInputTransferToken() {
        throw new UnsupportedOperationException("The getHostToken needs to be "
        throw new UnsupportedOperationException("The getInputTransferToken needs to be "
                + "implemented before making this call.");
    }

+22 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.view;

import android.annotation.FlaggedApi;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.TestApi;
@@ -33,6 +34,8 @@ import android.window.ISurfaceSyncGroup;
import android.window.InputTransferToken;
import android.window.WindowTokenClient;

import com.android.window.flags.Flags;

import dalvik.system.CloseGuard;

import java.util.Objects;
@@ -347,6 +350,25 @@ public class SurfaceControlViewHost {
            @Nullable IBinder hostToken) {
        this(context, display, hostToken == null ? null : new InputTransferToken(hostToken),
                "untracked");

    }

    /**
     * Construct a new SurfaceControlViewHost. The root Surface will be
     * allocated internally and is accessible via getSurfacePackage().
     * <p>
     * The hostInputTransferToken parameter allows the host and embedded to be associated with
     * each other to allow transferring touch gesture and focus. This is also used for ANR
     * reporting. It's accessible from {@link AttachedSurfaceControl#getInputTransferToken()}.
     *
     * @param context                The Context object for your activity or application.
     * @param display                The Display the hierarchy will be placed on.
     * @param hostInputTransferToken The host input transfer token, as discussed above.
     */
    @FlaggedApi(Flags.FLAG_SURFACE_CONTROL_INPUT_RECEIVER)
    public SurfaceControlViewHost(@NonNull Context context, @NonNull Display display,
            @Nullable InputTransferToken hostInputTransferToken) {
        this(context, display, hostInputTransferToken, "untracked");
    }

    /**
+3 −15
Original line number Diff line number Diff line
@@ -103,7 +103,6 @@ import android.accessibilityservice.AccessibilityService;
import android.animation.AnimationHandler;
import android.animation.LayoutTransition;
import android.annotation.AnyThread;
import android.annotation.FlaggedApi;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Size;
@@ -240,7 +239,6 @@ import com.android.internal.view.BaseSurfaceHolder;
import com.android.internal.view.RootViewSurfaceTaker;
import com.android.internal.view.SurfaceCallbackHelper;
import com.android.modules.expresslog.Counter;
import com.android.window.flags.Flags;
import java.io.IOException;
import java.io.OutputStream;
@@ -11219,26 +11217,16 @@ public final class ViewRootImpl implements ViewParent,
        return mInputEventReceiver.getToken();
    }
    /**
     * @return Returns a token used for associating the root surface
     * to {@link SurfaceControlViewHost}.
     */
    @Nullable
    @Override
    @FlaggedApi(Flags.FLAG_GET_HOST_TOKEN_API)
    public IBinder getHostToken() {
        return getInputToken();
    }
    /**
     * {@inheritDoc}
     */
    @Nullable
    @NonNull
    @Override
    public InputTransferToken getInputTransferToken() {
        IBinder inputToken = getInputToken();
        if (inputToken == null) {
            return null;
            throw new IllegalStateException(
                    "Called getInputTransferToken for Window with no input channel");
        }
        return new InputTransferToken(inputToken);
    }
+45 −37
Original line number Diff line number Diff line
@@ -123,6 +123,7 @@ import android.view.WindowInsets.Side.InsetsSide;
import android.view.WindowInsets.Type;
import android.view.WindowInsets.Type.InsetsType;
import android.view.accessibility.AccessibilityNodeInfo;
import android.window.InputTransferToken;
import android.window.TaskFpsCallback;
import android.window.TrustedPresentationThresholds;

@@ -6097,25 +6098,28 @@ public interface WindowManager extends ViewManager {
     * receive batched input event. For those events that are batched, the invocation will happen
     * once per {@link Choreographer} frame, and other input events will be delivered immediately.
     * This is different from
     * {@link #registerUnbatchedSurfaceControlInputReceiver(int, IBinder, SurfaceControl, Looper,
     * SurfaceControlInputReceiver)} in that the input events are received batched. 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.
     * { #registerUnbatchedSurfaceControlInputReceiver(int, InputTransferToken, SurfaceControl,
     * Looper, SurfaceControlInputReceiver)} in that the input events are received batched. 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 hostToken      The host token to link the InputChannel for. This is primarily for ANRs
     *                       to ensure the host receives the ANR if any issues with touch on the
     *                       InputChannel
     * @param choreographer  The Choreographer used for batching. This should match the rendering
     *                       Choreographer.
     * @param receiver       The SurfaceControlInputReceiver that will receive the input events
     * @param hostInputTransferToken The host token to link the embedded. This is used to handle
     *                               transferring touch gesture from host to embedded and for ANRs
     *                               to ensure the host receives the ANR if any issues with
     *                               touch on the embedded.
     * @param choreographer          The Choreographer used for batching. This should match the
     *                               rendering Choreographer.
     * @param receiver               The SurfaceControlInputReceiver that will receive the input
     *                               events
     */
    @FlaggedApi(Flags.FLAG_SURFACE_CONTROL_INPUT_RECEIVER)
    default void registerBatchedSurfaceControlInputReceiver(int displayId,
            @NonNull IBinder hostToken, @NonNull SurfaceControl surfaceControl,
            @NonNull InputTransferToken hostInputTransferToken,
            @NonNull SurfaceControl surfaceControl,
            @NonNull Choreographer choreographer, @NonNull SurfaceControlInputReceiver receiver) {
        throw new UnsupportedOperationException(
                "registerBatchedSurfaceControlInputReceiver is not implemented");
@@ -6123,26 +6127,30 @@ 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, IBinder, 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 hostToken      The host token to link the InputChannel for. This is primarily for ANRs
     *                       to ensure the host receives the ANR if any issues with touch on the
     *                       InputChannel
     * receive every input event. This is different than calling
     * {@link #registerBatchedSurfaceControlInputReceiver(int, 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
     *                               to ensure the host receives the ANR if any issues with
     *                               touch on the embedded.
     * @param looper                 The looper to use when invoking callbacks.
     * @param receiver       The SurfaceControlInputReceiver that will receive the input events
     **/
     * @param receiver               The SurfaceControlInputReceiver that will receive the input
     *                               events.
     */
    @FlaggedApi(Flags.FLAG_SURFACE_CONTROL_INPUT_RECEIVER)
    default void registerUnbatchedSurfaceControlInputReceiver(int displayId,
            @NonNull IBinder hostToken, @NonNull SurfaceControl surfaceControl,
            @NonNull Looper looper, @NonNull SurfaceControlInputReceiver receiver) {
            @NonNull InputTransferToken hostInputTransferToken,
            @NonNull SurfaceControl surfaceControl, @NonNull Looper looper,
            @NonNull SurfaceControlInputReceiver receiver) {
        throw new UnsupportedOperationException(
                "registerUnbatchedSurfaceControlInputReceiver is not implemented");
    }
@@ -6152,10 +6160,10 @@ 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, IBinder, SurfaceControl,
     * {@link #registerBatchedSurfaceControlInputReceiver(int, InputTransferToken, SurfaceControl,
     * Choreographer,
     * SurfaceControlInputReceiver)} or
     * {@link #registerUnbatchedSurfaceControlInputReceiver(int, IBinder, SurfaceControl, Looper,
     * {@link #registerUnbatchedSurfaceControlInputReceiver(int, InputTransferToken, SurfaceControl, Looper,
     * SurfaceControlInputReceiver)}
     *
     * @param surfaceControl The SurfaceControl to remove and unregister the input channel for.
@@ -6171,7 +6179,7 @@ public interface WindowManager extends ViewManager {
     * if the SurfaceControl was registered for input via
     * { #registerBatchedSurfaceControlInputReceiver(int, IBinder, SurfaceControl, Choreographer,
     * SurfaceControlInputReceiver)} or
     * {@link #registerUnbatchedSurfaceControlInputReceiver(int, IBinder, SurfaceControl, Looper,
     * {@link #registerUnbatchedSurfaceControlInputReceiver(int, InputTransferToken, SurfaceControl, Looper,
     * SurfaceControlInputReceiver)}.
     * <p>
     * This is helpful for testing to ensure the test waits for the layer to be registered with
Loading