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

Commit 30ad618c authored by Robert Carr's avatar Robert Carr
Browse files

SurfaceView: Add reparentSurfacePackage method

For use with SurfaceControlViewHost. Currently this just performs a reparent
but it's future use is to also automatically link the accessibility IDs
of the embedded content and the SurfaceView.

Test: No test, to unblock accessibility team. Builds.
Bug: 134365580
Change-Id: I990c0f29b439ed6e6f18bdfa4be2c1d46f502503
parent e68e6deb
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -4425,6 +4425,7 @@ package android.view {

  public class SurfaceView extends android.view.View {
    method @Nullable public android.os.IBinder getInputToken();
    method public void setChildSurfacePackage(@NonNull android.view.SurfaceControlViewHost.SurfacePackage);
  }

  @UiThread public class View implements android.view.accessibility.AccessibilityEventSource android.graphics.drawable.Drawable.Callback android.view.KeyEvent.Callback {
+31 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.view.WindowManagerPolicyConstants.APPLICATION_MEDIA_OVERLA
import static android.view.WindowManagerPolicyConstants.APPLICATION_MEDIA_SUBLAYER;
import static android.view.WindowManagerPolicyConstants.APPLICATION_PANEL_SUBLAYER;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.TestApi;
import android.compat.annotation.UnsupportedAppUsage;
@@ -43,6 +44,7 @@ import android.util.AttributeSet;
import android.util.Log;
import android.view.SurfaceControl.Transaction;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.SurfaceControlViewHost;

import com.android.internal.view.SurfaceCallbackHelper;

@@ -204,6 +206,7 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall

    // The token of embedded windowless view hierarchy.
    private IBinder mEmbeddedViewHierarchy;
    SurfaceControlViewHost.SurfacePackage mSurfacePackage;

    public SurfaceView(Context context) {
        this(context, null);
@@ -877,6 +880,11 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
                    } else {
                        mTmpTransaction.hide(mSurfaceControl);
                    }

                    if (mSurfacePackage != null) {
                        reparentSurfacePackage(mTmpTransaction, mSurfacePackage);
                    }

                    updateBackgroundVisibility(mTmpTransaction);
                    if (mUseAlpha) {
                        mTmpTransaction.setAlpha(mSurfaceControl, alpha);
@@ -1536,6 +1544,29 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
        viewRoot.setUseBLASTSyncTransaction();
    }

    /**
     * @hide
     */
    @TestApi
    public void setChildSurfacePackage(@NonNull SurfaceControlViewHost.SurfacePackage p) {
        final SurfaceControl sc = p != null ? p.getSurfaceControl() : null;
        final SurfaceControl lastSc = mSurfacePackage != null ?
            mSurfacePackage.getSurfaceControl() : null;
        if (mSurfaceControl != null && lastSc != null) {
            mTmpTransaction.reparent(lastSc, null).apply();
        } else if (mSurfaceControl != null) {
            reparentSurfacePackage(mTmpTransaction, p);
            mTmpTransaction.apply();
        }
        mSurfacePackage = p;
    }

    private void reparentSurfacePackage(SurfaceControl.Transaction t,
            SurfaceControlViewHost.SurfacePackage p) {
        // TODO: Link accessibility IDs here.
        t.reparent(p.getSurfaceControl(), mSurfaceControl);
    }

    /**
     * Add the token of embedded view hierarchy. Set {@code null} to clear the embedded view
     * hierarchy.
+8 −4
Original line number Diff line number Diff line
@@ -46,15 +46,15 @@ public class SurfaceControlViewHostTest extends Activity implements SurfaceHolde

        mView.setZOrderOnTop(true);
        mView.getHolder().addCallback(this);

        addEmbeddedView();
    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
    void addEmbeddedView() {
        mVr = new SurfaceControlViewHost(this, this.getDisplay(),
                mView.getInputToken());

        final SurfaceControl.Transaction t = new SurfaceControl.Transaction();
        t.reparent(mVr.getSurfacePackage().getSurfaceControl(), mView.getSurfaceControl()).apply();
        mView.setChildSurfacePackage(mVr.getSurfacePackage());

        Button v = new Button(this);
        v.setBackgroundColor(Color.BLUE);
@@ -69,6 +69,10 @@ public class SurfaceControlViewHostTest extends Activity implements SurfaceHolde
        mVr.addView(v, lp);
    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
        Canvas canvas = holder.lockCanvas();