diff --git a/core/java/android/view/ISurfaceControlViewHost.aidl b/core/java/android/view/ISurfaceControlViewHost.aidl new file mode 100644 index 0000000000000..fc9661a0e61a0 --- /dev/null +++ b/core/java/android/view/ISurfaceControlViewHost.aidl @@ -0,0 +1,28 @@ +/* +** Copyright 2021, The Android Open Source Project +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ + +package android.view; + +import android.content.res.Configuration; + +/** + * API from content embedder back to embedded content in SurfaceControlViewHost + * {@hide} + */ +oneway interface ISurfaceControlViewHost { + void onConfigurationChanged(in Configuration newConfig); + void onDispatchDetachedFromWindow(); +} diff --git a/core/java/android/view/OWNERS b/core/java/android/view/OWNERS index d160be59cca3e..43df294466db0 100644 --- a/core/java/android/view/OWNERS +++ b/core/java/android/view/OWNERS @@ -80,6 +80,7 @@ per-file Inset*.aidl = file:/services/core/java/com/android/server/wm/OWNERS per-file IPinnedStackListener.aidl = file:/services/core/java/com/android/server/wm/OWNERS per-file IRecents*.aidl = file:/services/core/java/com/android/server/wm/OWNERS per-file IRemote*.aidl = file:/services/core/java/com/android/server/wm/OWNERS +per-file ISurfaceControlViewHost*.aidl = file:/services/core/java/com/android/server/wm/OWNERS per-file IWindow*.aidl = file:/services/core/java/com/android/server/wm/OWNERS per-file RemoteAnimation*.java = file:/services/core/java/com/android/server/wm/OWNERS per-file RemoteAnimation*.aidl = file:/services/core/java/com/android/server/wm/OWNERS diff --git a/core/java/android/view/SurfaceControlViewHost.java b/core/java/android/view/SurfaceControlViewHost.java index a6c5042db275b..85a9dbd736edf 100644 --- a/core/java/android/view/SurfaceControlViewHost.java +++ b/core/java/android/view/SurfaceControlViewHost.java @@ -20,6 +20,7 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.TestApi; import android.content.Context; +import android.content.res.Configuration; import android.graphics.PixelFormat; import android.os.IBinder; import android.os.Parcel; @@ -45,6 +46,35 @@ public class SurfaceControlViewHost { private SurfaceControl mSurfaceControl; private IAccessibilityEmbeddedConnection mAccessibilityEmbeddedConnection; + private final class ISurfaceControlViewHostImpl extends ISurfaceControlViewHost.Stub { + @Override + public void onConfigurationChanged(Configuration configuration) { + if (mViewRoot == null) { + return; + } + mViewRoot.mHandler.post(() -> { + if (mWm != null) { + mWm.setConfiguration(configuration); + } + if (mViewRoot != null) { + mViewRoot.forceWmRelayout(); + } + }); + } + + @Override + public void onDispatchDetachedFromWindow() { + if (mViewRoot == null) { + return; + } + mViewRoot.mHandler.post(() -> { + release(); + }); + } + } + + private ISurfaceControlViewHost mRemoteInterface = new ISurfaceControlViewHostImpl(); + /** * Package encapsulating a Surface hierarchy which contains interactive view * elements. It's expected to get this object from @@ -71,12 +101,14 @@ public class SurfaceControlViewHost { private SurfaceControl mSurfaceControl; private final IAccessibilityEmbeddedConnection mAccessibilityEmbeddedConnection; private final IBinder mInputToken; + private final ISurfaceControlViewHost mRemoteInterface; SurfacePackage(SurfaceControl sc, IAccessibilityEmbeddedConnection connection, - IBinder inputToken) { + IBinder inputToken, ISurfaceControlViewHost ri) { mSurfaceControl = sc; mAccessibilityEmbeddedConnection = connection; mInputToken = inputToken; + mRemoteInterface = ri; } /** @@ -97,6 +129,7 @@ public class SurfaceControlViewHost { } mAccessibilityEmbeddedConnection = other.mAccessibilityEmbeddedConnection; mInputToken = other.mInputToken; + mRemoteInterface = other.mRemoteInterface; } private SurfacePackage(Parcel in) { @@ -105,6 +138,8 @@ public class SurfaceControlViewHost { mAccessibilityEmbeddedConnection = IAccessibilityEmbeddedConnection.Stub.asInterface( in.readStrongBinder()); mInputToken = in.readStrongBinder(); + mRemoteInterface = ISurfaceControlViewHost.Stub.asInterface( + in.readStrongBinder()); } /** @@ -126,6 +161,13 @@ public class SurfaceControlViewHost { return mAccessibilityEmbeddedConnection; } + /** + * @hide + */ + public ISurfaceControlViewHost getRemoteInterface() { + return mRemoteInterface; + } + @Override public int describeContents() { return 0; @@ -136,6 +178,7 @@ public class SurfaceControlViewHost { mSurfaceControl.writeToParcel(out, flags); out.writeStrongBinder(mAccessibilityEmbeddedConnection.asBinder()); out.writeStrongBinder(mInputToken); + out.writeStrongBinder(mRemoteInterface.asBinder()); } /** @@ -231,7 +274,7 @@ public class SurfaceControlViewHost { public @Nullable SurfacePackage getSurfacePackage() { if (mSurfaceControl != null && mAccessibilityEmbeddedConnection != null) { return new SurfacePackage(mSurfaceControl, mAccessibilityEmbeddedConnection, - mViewRoot.getInputToken()); + mViewRoot.getInputToken(), mRemoteInterface); } else { return null; } diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 77185116292e0..74129312b41b3 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -10639,4 +10639,9 @@ public final class ViewRootImpl implements ViewParent, boolean wasRelayoutRequested() { return mRelayoutRequested; } + + void forceWmRelayout() { + mForceNextWindowRelayout = true; + scheduleTraversals(); + } } diff --git a/core/java/android/view/WindowlessWindowManager.java b/core/java/android/view/WindowlessWindowManager.java index d699194dd77f0..0ec04608a7ba5 100644 --- a/core/java/android/view/WindowlessWindowManager.java +++ b/core/java/android/view/WindowlessWindowManager.java @@ -87,7 +87,7 @@ public class WindowlessWindowManager implements IWindowSession { mHostInputToken = hostInputToken; } - protected void setConfiguration(Configuration configuration) { + public void setConfiguration(Configuration configuration) { mConfiguration.setTo(configuration); }