diff options
7 files changed, 20 insertions, 9 deletions
diff --git a/api/current.txt b/api/current.txt index a85d632e0f31..bdb62c2a8137 100644 --- a/api/current.txt +++ b/api/current.txt @@ -53603,10 +53603,11 @@ package android.view { public class SurfaceControlViewHost { ctor public SurfaceControlViewHost(@NonNull android.content.Context, @NonNull android.view.Display, @Nullable android.os.IBinder); - method public void addView(@NonNull android.view.View, int, int); method @Nullable public android.view.SurfaceControlViewHost.SurfacePackage getSurfacePackage(); + method @Nullable public android.view.View getView(); method public void relayout(int, int); method public void release(); + method public void setView(@NonNull android.view.View, int, int); } public static final class SurfaceControlViewHost.SurfacePackage implements android.os.Parcelable { diff --git a/api/test-current.txt b/api/test-current.txt index 4f4c82b43e70..e8b1754e9f9f 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -4953,8 +4953,8 @@ package android.view { } public class SurfaceControlViewHost { - method public void addView(@NonNull android.view.View, android.view.WindowManager.LayoutParams); method public void relayout(android.view.WindowManager.LayoutParams); + method public void setView(@NonNull android.view.View, @NonNull android.view.WindowManager.LayoutParams); } @UiThread public class View implements android.view.accessibility.AccessibilityEventSource android.graphics.drawable.Drawable.Callback android.view.KeyEvent.Callback { diff --git a/core/java/android/service/autofill/InlineSuggestionRenderService.java b/core/java/android/service/autofill/InlineSuggestionRenderService.java index ee15283715ff..0c813321bfad 100644 --- a/core/java/android/service/autofill/InlineSuggestionRenderService.java +++ b/core/java/android/service/autofill/InlineSuggestionRenderService.java @@ -94,7 +94,7 @@ public abstract class InlineSuggestionRenderService extends Service { final SurfaceControlViewHost host = new SurfaceControlViewHost(this, getDisplay(), hostInputToken); - host.addView(suggestionRoot, lp); + host.setView(suggestionRoot, lp); suggestionRoot.setOnClickListener((v) -> { try { callback.onAutofill(); diff --git a/core/java/android/view/SurfaceControlViewHost.java b/core/java/android/view/SurfaceControlViewHost.java index a3b3f1f72310..41a384797521 100644 --- a/core/java/android/view/SurfaceControlViewHost.java +++ b/core/java/android/view/SurfaceControlViewHost.java @@ -26,6 +26,8 @@ import android.os.Parcel; import android.os.Parcelable; import android.view.accessibility.IAccessibilityEmbeddedConnection; +import java.util.Objects; + /** * Utility class for adding a View hierarchy to a {@link SurfaceControl}. The View hierarchy * will render in to a root SurfaceControl, and receive input based on the SurfaceControl's @@ -159,7 +161,8 @@ public class SurfaceControlViewHost { * @hide */ @TestApi - public void addView(@NonNull View view, WindowManager.LayoutParams attrs) { + public void setView(@NonNull View view, @NonNull WindowManager.LayoutParams attrs) { + Objects.requireNonNull(view); mViewRoot.setView(view, attrs, null); } @@ -172,11 +175,18 @@ public class SurfaceControlViewHost { * @param width The width to layout the View within, in pixels. * @param height The height to layout the View within, in pixels. */ - public void addView(@NonNull View view, int width, int height) { + public void setView(@NonNull View view, int width, int height) { final WindowManager.LayoutParams lp = new WindowManager.LayoutParams(width, height, WindowManager.LayoutParams.TYPE_APPLICATION, 0, PixelFormat.TRANSPARENT); - addView(view, lp); + setView(view, lp); + } + + /** + * @return The view passed to setView, or null if none has been passed. + */ + public @Nullable View getView() { + return mViewRoot.getView(); } /** diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/SurfaceViewRequestReceiver.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/SurfaceViewRequestReceiver.java index d33c653f2cb7..29100ef8f70f 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/SurfaceViewRequestReceiver.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/SurfaceViewRequestReceiver.java @@ -90,7 +90,7 @@ public class SurfaceViewRequestReceiver { view.setTranslationX((surfaceControl.getWidth() - scale * viewSize.getWidth()) / 2); view.setTranslationY((surfaceControl.getHeight() - scale * viewSize.getHeight()) / 2); - mSurfaceControlViewHost.addView(view, layoutParams); + mSurfaceControlViewHost.setView(view, layoutParams); } } } diff --git a/packages/SystemUI/src/com/android/systemui/wm/SystemWindows.java b/packages/SystemUI/src/com/android/systemui/wm/SystemWindows.java index ccb86999674c..381ccdb50386 100644 --- a/packages/SystemUI/src/com/android/systemui/wm/SystemWindows.java +++ b/packages/SystemUI/src/com/android/systemui/wm/SystemWindows.java @@ -196,7 +196,7 @@ public class SystemWindows { final Display display = mDisplayController.getDisplay(mDisplayId); SurfaceControlViewHost viewRoot = new SurfaceControlViewHost(mContext, display, wwm); attrs.flags |= FLAG_HARDWARE_ACCELERATED; - viewRoot.addView(view, attrs); + viewRoot.setView(view, attrs); mViewRoots.put(view, viewRoot); } diff --git a/tests/SurfaceControlViewHostTest/src/com/android/test/viewembed/SurfaceControlViewHostTest.java b/tests/SurfaceControlViewHostTest/src/com/android/test/viewembed/SurfaceControlViewHostTest.java index 61696718c76e..3bc530975580 100644 --- a/tests/SurfaceControlViewHostTest/src/com/android/test/viewembed/SurfaceControlViewHostTest.java +++ b/tests/SurfaceControlViewHostTest/src/com/android/test/viewembed/SurfaceControlViewHostTest.java @@ -66,7 +66,7 @@ public class SurfaceControlViewHostTest extends Activity implements SurfaceHolde WindowManager.LayoutParams lp = new WindowManager.LayoutParams(500, 500, WindowManager.LayoutParams.TYPE_APPLICATION, 0, PixelFormat.OPAQUE); - mVr.addView(v, lp); + mVr.setView(v, lp); } @Override |