diff options
author | 2019-12-18 01:46:04 -0800 | |
---|---|---|
committer | 2020-01-21 22:24:54 -0800 | |
commit | 30ad618cfef9dd7fad12b14d7e0bdadb5d68cb82 (patch) | |
tree | e891d1f080b44ffc6a3bff70af67c2f5e53cc890 | |
parent | e68e6deb3e7e59994b0306064dd49c93af81d542 (diff) |
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
-rw-r--r-- | api/test-current.txt | 1 | ||||
-rw-r--r-- | core/java/android/view/SurfaceView.java | 31 | ||||
-rw-r--r-- | tests/SurfaceControlViewHostTest/src/com/android/test/viewembed/SurfaceControlViewHostTest.java | 12 |
3 files changed, 40 insertions, 4 deletions
diff --git a/api/test-current.txt b/api/test-current.txt index 06018fbd7904..f3930b850e0d 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -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 { diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java index 0de1a4f038ff..db1c1612ce72 100644 --- a/core/java/android/view/SurfaceView.java +++ b/core/java/android/view/SurfaceView.java @@ -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); @@ -1537,6 +1545,29 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall } /** + * @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. * diff --git a/tests/SurfaceControlViewHostTest/src/com/android/test/viewembed/SurfaceControlViewHostTest.java b/tests/SurfaceControlViewHostTest/src/com/android/test/viewembed/SurfaceControlViewHostTest.java index 6687f83ad0db..4c8221c813b4 100644 --- a/tests/SurfaceControlViewHostTest/src/com/android/test/viewembed/SurfaceControlViewHostTest.java +++ b/tests/SurfaceControlViewHostTest/src/com/android/test/viewembed/SurfaceControlViewHostTest.java @@ -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); @@ -70,6 +70,10 @@ public class SurfaceControlViewHostTest extends Activity implements SurfaceHolde } @Override + public void surfaceCreated(SurfaceHolder holder) { + } + + @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { Canvas canvas = holder.lockCanvas(); canvas.drawColor(Color.GREEN); |