From 6f631db81b5b826a7497dae780b516c52a418301 Mon Sep 17 00:00:00 2001 From: Robert Carr Date: Mon, 24 Jan 2022 10:33:54 -0800 Subject: [PATCH] SurfaceControlViewHost: Expose IPC helpers Use of SurfaceControlViewHost requires the embeder and embedee to establish a side-channel in order to exchange the SurfacePackage containing the embedded hierarchy. In recent commits, SurfacePackage has grown a built in side-channel, useful for exchanging info from the host back in to the embedee. In this CL we make two of these APIs public. The general motivation for making them public is as follows: 1. onDetachedFromWindow: While public API provides a manner to tear down a SurfaceControlViewHost, it seems that almost every user will have to include an IPC method for this in their bespoke side-channel. Since it's required for every use case it seems to make sense to provide some convenience. 2. onConfigurationChanged: At the moment there would be no way to change the configuration of the remote SurfaceControlViewHosts. Client apps are instead forced to create their own configuration update side-channel and recreate the whole SurfaceControlViewHost each time. Bug: 200284683 Test: SurfaceControlViewHostTests Change-Id: I6f33f0953224d7ff60dc819560d54564250bbe3f --- core/api/current.txt | 2 ++ .../android/view/SurfaceControlViewHost.java | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/core/api/current.txt b/core/api/current.txt index eef2d4ef3943e..82977ec1dab0e 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -48968,6 +48968,8 @@ package android.view { public static final class SurfaceControlViewHost.SurfacePackage implements android.os.Parcelable { ctor public SurfaceControlViewHost.SurfacePackage(@NonNull android.view.SurfaceControlViewHost.SurfacePackage); method public int describeContents(); + method public void notifyConfigurationChanged(@NonNull android.content.res.Configuration); + method public void notifyDetachedFromWindow(); method public void release(); method public void writeToParcel(@NonNull android.os.Parcel, int); field @NonNull public static final android.os.Parcelable.Creator CREATOR; diff --git a/core/java/android/view/SurfaceControlViewHost.java b/core/java/android/view/SurfaceControlViewHost.java index 85a9dbd736edf..0eb2328373577 100644 --- a/core/java/android/view/SurfaceControlViewHost.java +++ b/core/java/android/view/SurfaceControlViewHost.java @@ -25,6 +25,7 @@ import android.graphics.PixelFormat; import android.os.IBinder; import android.os.Parcel; import android.os.Parcelable; +import android.os.RemoteException; import android.view.accessibility.IAccessibilityEmbeddedConnection; import java.util.Objects; @@ -168,6 +169,36 @@ public class SurfaceControlViewHost { return mRemoteInterface; } + /** + * Forward a configuration to the remote SurfaceControlViewHost. + * This will cause View#onConfigurationChanged to be invoked on the remote + * end. This does not automatically cause the SurfaceControlViewHost + * to be resized. The root View of a SurfaceControlViewHost + * is more akin to a PopupWindow in that the size is user specified + * independent of configuration width and height. + * + * @param c The configuration to forward + */ + public void notifyConfigurationChanged(@NonNull Configuration c) { + try { + getRemoteInterface().onConfigurationChanged(c); + } catch (RemoteException e) { + e.rethrowAsRuntimeException(); + } + } + + /** + * Tear down the remote SurfaceControlViewHost and cause + * View#onDetachedFromWindow to be invoked on the other side. + */ + public void notifyDetachedFromWindow() { + try { + getRemoteInterface().onDispatchDetachedFromWindow(); + } catch (RemoteException e) { + e.rethrowAsRuntimeException(); + } + } + @Override public int describeContents() { return 0;