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

Commit 2fd50048 authored by Robert Carr's avatar Robert Carr Committed by Rob Carr
Browse files

SurfaceControlViewHost: Allow updating of WindowContext used for SCVH

Our initial attempt to allow updating the configuration of
SurfaceControlViewHost was insufficient when the SurfaceControlViewHost
is using a service context. This service context will always be
on the global configuration, and ViewRoot won't be able to override it.
We add some documentation suggesting the user use a window context,
and wire up SurfaceControlViewHost VRI so that they are the authority
on configuration (and propagate the change in to the context).

Bug: 215204813
Test: SurfaceControlViewHostTests. Manual in game overlay+split-screen
Change-Id: I24c0309593b7fddaeab8db355f63a5f6bd763562
parent c98cb446
Loading
Loading
Loading
Loading
+23 −0
Original line number Original line Diff line number Diff line
@@ -28,6 +28,7 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable;
import android.os.RemoteException;
import android.os.RemoteException;
import android.util.Log;
import android.util.Log;
import android.window.WindowTokenClient;
import android.view.InsetsState;
import android.view.InsetsState;
import android.view.WindowManagerGlobal;
import android.view.WindowManagerGlobal;
import android.view.accessibility.IAccessibilityEmbeddedConnection;
import android.view.accessibility.IAccessibilityEmbeddedConnection;
@@ -193,6 +194,14 @@ public class SurfaceControlViewHost {
         * is more akin to a PopupWindow in that the size is user specified
         * is more akin to a PopupWindow in that the size is user specified
         * independent of configuration width and height.
         * independent of configuration width and height.
         *
         *
         * In order to receive the configuration change via 
         * {@link View#onConfigurationChanged}, the context used with the
         * SurfaceControlViewHost and it's embedded view hierarchy must
         * be a WindowContext obtained from {@link Context#createWindowContext}.
         *
         * If a regular service context is used, then your embedded view hierarchy
         * will always perceive the global configuration.
         *
         * @param c The configuration to forward
         * @param c The configuration to forward
         */
         */
        public void notifyConfigurationChanged(@NonNull Configuration c) {
        public void notifyConfigurationChanged(@NonNull Configuration c) {
@@ -266,6 +275,8 @@ public class SurfaceControlViewHost {
            @NonNull WindowlessWindowManager wwm) {
            @NonNull WindowlessWindowManager wwm) {
        mWm = wwm;
        mWm = wwm;
        mViewRoot = new ViewRootImpl(c, d, mWm);
        mViewRoot = new ViewRootImpl(c, d, mWm);
        addConfigCallback(c, d);

        WindowManagerGlobal.getInstance().addWindowlessRoot(mViewRoot);
        WindowManagerGlobal.getInstance().addWindowlessRoot(mViewRoot);


        mAccessibilityEmbeddedConnection = mViewRoot.getAccessibilityEmbeddedConnection();
        mAccessibilityEmbeddedConnection = mViewRoot.getAccessibilityEmbeddedConnection();
@@ -294,11 +305,23 @@ public class SurfaceControlViewHost {
                mSurfaceControl, hostToken);
                mSurfaceControl, hostToken);


        mViewRoot = new ViewRootImpl(context, display, mWm);
        mViewRoot = new ViewRootImpl(context, display, mWm);
        addConfigCallback(context, display);

        WindowManagerGlobal.getInstance().addWindowlessRoot(mViewRoot);
        WindowManagerGlobal.getInstance().addWindowlessRoot(mViewRoot);


        mAccessibilityEmbeddedConnection = mViewRoot.getAccessibilityEmbeddedConnection();
        mAccessibilityEmbeddedConnection = mViewRoot.getAccessibilityEmbeddedConnection();
    }
    }


    private void addConfigCallback(Context c, Display d) {
        final IBinder token = c.getWindowContextToken();
        mViewRoot.addConfigCallback((conf) -> {
            if (token instanceof WindowTokenClient) {
                final WindowTokenClient w = (WindowTokenClient)  token;
                w.onConfigurationChanged(conf, d.getDisplayId(), true);
            }
        });
    }

    /**
    /**
     * @hide
     * @hide
     */
     */