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

Commit 6a5d1002 authored by Wenhui Yang's avatar Wenhui Yang
Browse files

Introduce getChildSurfacePackage() and clearChildSurfacePackage()

Add a way to determine whether there’s embedded content inside a SurfaceView with a SurfacePackage. setChildSurfacePackage absorbs RemoteException today, and we have no way to know whether the call succeeded. Adding such APIs improves testability.

Bug: 341021569
Test: SurfaceViewTest
Flag: android.view.flags.surface_view_get_surface_package
Change-Id: I60d33cecf0c3ecb7a7595baa0e2010e78c23faca
parent f8484f60
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -52657,6 +52657,8 @@ package android.view {
    ctor public SurfaceView(android.content.Context, android.util.AttributeSet, int);
    ctor public SurfaceView(android.content.Context, android.util.AttributeSet, int, int);
    method public void applyTransactionToFrame(@NonNull android.view.SurfaceControl.Transaction);
    method @FlaggedApi("android.view.flags.surface_view_get_surface_package") public void clearChildSurfacePackage();
    method @FlaggedApi("android.view.flags.surface_view_get_surface_package") @Nullable public android.view.SurfaceControlViewHost.SurfacePackage getChildSurfacePackage();
    method @FlaggedApi("android.view.flags.surface_view_set_composition_order") public int getCompositionOrder();
    method public android.view.SurfaceHolder getHolder();
    method @Deprecated @Nullable public android.os.IBinder getHostToken();
+45 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.view;

import static android.view.flags.Flags.FLAG_SURFACE_VIEW_GET_SURFACE_PACKAGE;
import static android.view.flags.Flags.FLAG_SURFACE_VIEW_SET_COMPOSITION_ORDER;
import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
import static android.view.WindowManagerPolicyConstants.APPLICATION_MEDIA_OVERLAY_SUBLAYER;
@@ -27,6 +28,7 @@ import android.annotation.FloatRange;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SuppressLint;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.res.CompatibilityInfo.Translator;
@@ -2112,7 +2114,7 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
    }

    /**
     * Display the view-hierarchy embedded within a {@link SurfaceControlViewHost.SurfacePackage}
     * Displays the view-hierarchy embedded within a {@link SurfaceControlViewHost.SurfacePackage}
     * within this SurfaceView.
     *
     * This can be called independently of the SurfaceView lifetime callbacks. SurfaceView
@@ -2132,6 +2134,8 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
     * SurfaceView the underlying {@link SurfaceControlViewHost} remains managed by it's original
     * remote-owner.
     *
     * Users can call {@link SurfaceView#clearChildSurfacePackage} to clear the package.
     *
     * @param p The SurfacePackage to embed.
     */
    public void setChildSurfacePackage(@NonNull SurfaceControlViewHost.SurfacePackage p) {
@@ -2155,6 +2159,46 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
        invalidate();
    }

    /**
     * Returns the {@link SurfaceControlViewHost.SurfacePackage} that was set on this SurfaceView.
     *
     * Note: This method will return {@code null} if
     * {@link #setChildSurfacePackage(SurfaceControlViewHost.SurfacePackage)}
     * has not been called or if {@link #clearChildSurfacePackage()} has been called.
     *
     * @see #setChildSurfacePackage(SurfaceControlViewHost.SurfacePackage)
     */
    @SuppressLint("GetterSetterNullability")
    @FlaggedApi(FLAG_SURFACE_VIEW_GET_SURFACE_PACKAGE)
    public @Nullable SurfaceControlViewHost.SurfacePackage getChildSurfacePackage() {
        return mSurfacePackage;
    }

    /**
     * Clears the {@link SurfaceControlViewHost.SurfacePackage} that was set on this SurfaceView.
     * This hides any content rendered by the provided
     * {@link SurfaceControlViewHost.SurfacePackage}.
     *
     * @see #setChildSurfacePackage(SurfaceControlViewHost.SurfacePackage)
     */
    @FlaggedApi(FLAG_SURFACE_VIEW_GET_SURFACE_PACKAGE)
    public void clearChildSurfacePackage() {
        if (mSurfacePackage != null) {
            mSurfaceControlViewHostParent.detach();
            mEmbeddedWindowParams.clear();

            // Reparent the SurfaceControl to remove the content on screen.
            final SurfaceControl sc = mSurfacePackage.getSurfaceControl();
            final SurfaceControl.Transaction transaction = new Transaction();
            transaction.reparent(sc, null);
            mSurfacePackage.release();
            applyTransactionOnVriDraw(transaction);

            mSurfacePackage = null;
            invalidate();
        }
    }

    private void reparentSurfacePackage(SurfaceControl.Transaction t,
            SurfaceControlViewHost.SurfacePackage p) {
        final SurfaceControl sc = p.getSurfaceControl();
+8 −0
Original line number Diff line number Diff line
@@ -118,6 +118,14 @@ flag {
    is_fixed_read_only: true
}

flag {
    name: "surface_view_get_surface_package"
    namespace: "window_surfaces"
    description: "Add APIs to manage SurfacePackage of the parent SurfaceView."
    bug: "341021569"
    is_fixed_read_only: true
}

flag {
    name: "use_refactored_round_scrollbar"
    namespace: "wear_frameworks"