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

Commit be92d69e authored by Rishabh Singh's avatar Rishabh Singh Committed by Android (Google) Code Review
Browse files

Merge "Add getHostToken API in AttachedSurfaceControl" into main

parents c1e2c53c 2df2633b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -49803,6 +49803,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 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);
+19 −0
Original line number Diff line number Diff line
@@ -15,14 +15,18 @@
 */
package android.view;

import android.annotation.FlaggedApi;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UiThread;
import android.graphics.Rect;
import android.graphics.Region;
import android.hardware.HardwareBuffer;
import android.os.IBinder;
import android.window.SurfaceSyncGroup;

import com.android.window.flags.Flags;

import java.util.concurrent.Executor;
import java.util.function.Consumer;

@@ -177,6 +181,21 @@ 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.
     *
     * @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.");
    }

    /**
     * Add a trusted presentation listener on the SurfaceControl associated with this window.
     *
+13 −0
Original line number Diff line number Diff line
@@ -93,6 +93,7 @@ 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;
@@ -227,6 +228,7 @@ import com.android.internal.policy.PhoneFallbackEventHandler;
import com.android.internal.view.BaseSurfaceHolder;
import com.android.internal.view.RootViewSurfaceTaker;
import com.android.internal.view.SurfaceCallbackHelper;
import com.android.window.flags.Flags;

import java.io.IOException;
import java.io.OutputStream;
@@ -10858,6 +10860,17 @@ 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();
    }

    @NonNull
    public IBinder getWindowToken() {
        return mAttachInfo.mWindowToken;
+8 −0
Original line number Diff line number Diff line
@@ -17,3 +17,11 @@ flag {
    is_fixed_read_only: true
    bug: "300019131"
}

flag {
    namespace: "window_surfaces"
    name: "get_host_token_api"
    description: "Feature flag to associate the host and embedded windows"
    is_fixed_read_only: true
    bug: "304508760"
}
+20 −0
Original line number Diff line number Diff line
@@ -48,6 +48,9 @@ import android.hardware.display.DisplayManagerGlobal;
import android.os.Binder;
import android.os.SystemProperties;
import android.platform.test.annotations.Presubmit;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;
import android.util.Log;
@@ -60,6 +63,7 @@ import androidx.test.filters.SmallTest;
import androidx.test.platform.app.InstrumentationRegistry;

import com.android.compatibility.common.util.ShellIdentityUtils;
import com.android.window.flags.Flags;

import org.junit.After;
import org.junit.AfterClass;
@@ -97,6 +101,9 @@ public class ViewRootImplTest {
    // state after the test completes.
    private static boolean sOriginalTouchMode;

    @Rule
    public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();

    @BeforeClass
    public static void setUpClass() {
        sContext = sInstrumentation.getTargetContext();
@@ -338,6 +345,19 @@ public class ViewRootImplTest {
        assertThat(view.hasWindowFocus()).isFalse();
    }

    @Test
    @RequiresFlagsEnabled(Flags.FLAG_GET_HOST_TOKEN_API)
    public void whenViewIsAttachedToWindow_getHostToken() {
        View view = new View(sContext);
        attachViewToWindow(view);

        mViewRootImpl = view.getViewRootImpl();

        assertThat(mViewRootImpl.getHostToken()).isNotEqualTo(null);
        assertThat(mViewRootImpl.getHostToken())
                .isEqualTo(mViewRootImpl.getInputToken());
    }

    /**
     * When window doesn't have focus, keys should be dropped.
     */