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

Commit fa76f7af authored by Patrick Williams's avatar Patrick Williams Committed by Android (Google) Code Review
Browse files

Merge "Update SCVH InputTransferToken when available" into main

parents 125ff825 b38e97e3
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.graphics.Rect;
import android.view.InsetsState;
import android.view.ISurfaceControlViewHostParent;
import android.window.ISurfaceSyncGroup;
import android.window.InputTransferToken;

/**
 * API from content embedder back to embedded content in SurfaceControlViewHost
@@ -32,6 +33,7 @@ interface ISurfaceControlViewHost {
     * APIs that are blocking
     */
    oneway void onConfigurationChanged(in Configuration newConfig);
    oneway void onDispatchAttachedToWindow(in InputTransferToken token);
    oneway void onDispatchDetachedFromWindow();
    oneway void onInsetsChanged(in InsetsState state, in Rect insetFrame);
    ISurfaceSyncGroup getSurfaceSyncGroup();
+3 −2
Original line number Diff line number Diff line
@@ -313,8 +313,9 @@ interface IWindowSession {
    /**
     * Update the flags on an input channel associated with a particular surface.
     */
    oneway void updateInputChannel(in IBinder channelToken, int displayId,
            in SurfaceControl surface, int flags, int privateFlags, int inputFeatures,
    oneway void updateInputChannel(in IBinder channelToken,
            in @nullable InputTransferToken hostInputTransferToken,
            int displayId, in SurfaceControl surface, int flags, int privateFlags, int inputFeatures,
            in Region region);

    /**
+16 −2
Original line number Diff line number Diff line
@@ -83,6 +83,20 @@ public class SurfaceControlViewHost {
            });
        }

        @Override
        public void onDispatchAttachedToWindow(InputTransferToken hostInputTransferToken) {
            boolean hostInputTransferTokenChanged =
                    !Objects.equals(hostInputTransferToken, mWm.getHostInputTransferToken());
            if (!hostInputTransferTokenChanged) {
                return;
            }

            mWm.setHostInputTransferToken(hostInputTransferToken);
            if (mViewRoot != null && mViewRoot.mView != null) {
                mWm.updateInputChannel(getWindowToken().asBinder());
            }
        }

        @Override
        public void onDispatchDetachedFromWindow() {
            if (mViewRoot == null) {
@@ -603,11 +617,11 @@ public class SurfaceControlViewHost {
        final WindowManager wm = (WindowManager) mViewRoot.mContext.getSystemService(
                Context.WINDOW_SERVICE);
        InputTransferToken embeddedToken = getInputTransferToken();
        InputTransferToken hostToken = mWm.mHostInputTransferToken;
        InputTransferToken hostToken = mWm.getHostInputTransferToken();
        if (embeddedToken == null || hostToken == null) {
            Log.w(TAG, "Failed to transferTouchGestureToHost. Host or embedded token is null");
            return false;
        }
        return wm.transferTouchGesture(getInputTransferToken(), mWm.mHostInputTransferToken);
        return wm.transferTouchGesture(embeddedToken, hostToken);
    }
}
+30 −1
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ import android.util.Log;
import android.view.SurfaceControl.Transaction;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.IAccessibilityEmbeddedConnection;
import android.window.InputTransferToken;
import android.window.SurfaceSyncGroup;

import com.android.graphics.hwui.flags.Flags;
@@ -347,7 +348,7 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
                    sv.mSurfacePackage.getRemoteInterface().attachParentInterface(this);
                    mSurfaceView = sv;
                } catch (RemoteException e) {
                    Log.d(TAG, "Failed to attach parent interface to SCVH. Likely SCVH is alraedy "
                    Log.d(TAG, "Failed to attach parent interface to SCVH. Likely SCVH is already "
                            + "dead.");
                }
            }
@@ -492,10 +493,37 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
        mTag = "SV[" + System.identityHashCode(this) + windowName + "]";
    }

    private void dispatchScvhAttachedToHost() {
        final ViewRootImpl viewRoot = getViewRootImpl();
        if (viewRoot == null) {
            return;
        }

        IBinder inputToken = viewRoot.getInputToken();
        if (inputToken == null) {
            // We don't have an input channel so we can't transfer focus or active
            // touch gestures to embedded.
            return;
        }

        try {
            mSurfacePackage
                    .getRemoteInterface()
                    .onDispatchAttachedToWindow(new InputTransferToken(inputToken));
        } catch (RemoteException e) {
            Log.d(TAG,
                    "Failed to onDispatchAttachedToWindow to SCVH. Likely SCVH is already "
                            + "dead.");
        }
    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        setTag();
        if (mSurfacePackage != null) {
            dispatchScvhAttachedToHost();
        }
        getViewRootImpl().addSurfaceChangedCallback(this);
        mWindowStopped = false;
        mViewVisibility = getVisibility() == VISIBLE;
@@ -2189,6 +2217,7 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
            applyTransactionOnVriDraw(transaction);
        }
        mSurfacePackage = p;
        dispatchScvhAttachedToHost();
        mSurfaceControlViewHostParent.attach(this);

        if (isFocused()) {
+36 −16
Original line number Diff line number Diff line
@@ -89,7 +89,7 @@ public class WindowlessWindowManager implements IWindowSession {
    protected final SurfaceControl mRootSurface;
    private final Configuration mConfiguration;
    private final IWindowSession mRealWm;
    final InputTransferToken mHostInputTransferToken;
    private InputTransferToken mHostInputTransferToken;
    private final InputTransferToken mInputTransferToken = new InputTransferToken();
    private InsetsState mInsetsState;
    private final ClientWindowFrames mTmpFrames = new ClientWindowFrames();
@@ -128,9 +128,15 @@ public class WindowlessWindowManager implements IWindowSession {
        return null;
    }

    /**
     * Utility API.
     */
    void setHostInputTransferToken(InputTransferToken token) {
        mHostInputTransferToken = token;
    }

    InputTransferToken getHostInputTransferToken() {
        return mHostInputTransferToken;
    }

    /** Utility API. */
    void setCompletionCallback(IBinder window, ResizeCompleteCallback callback) {
        if (mResizeCompletionForWindow.get(window) != null) {
            Log.w(TAG, "Unsupported overlapping resizes");
@@ -151,11 +157,25 @@ public class WindowlessWindowManager implements IWindowSession {
                return;
            }
            state.mInputRegion = region != null ? new Region(region) : null;
            updateInputChannel(window);
        }
    }

    protected void updateInputChannel(IBinder window) {
        State state;
        synchronized (this) {
            // Do everything while locked so that we synchronize with relayout. This should be a
            // very infrequent operation.
            state = mStateForWindow.get(window);
            if (state == null) {
                return;
            }
            if (state.mInputChannelToken != null) {
                try {
                    mRealWm.updateInputChannel(state.mInputChannelToken, state.mDisplayId,
                            state.mSurfaceControl, state.mParams.flags, state.mParams.privateFlags,
                            state.mParams.inputFeatures, state.mInputRegion);
                    mRealWm.updateInputChannel(state.mInputChannelToken, mHostInputTransferToken,
                            state.mDisplayId, state.mSurfaceControl, state.mParams.flags,
                            state.mParams.privateFlags, state.mParams.inputFeatures,
                            state.mInputRegion);
                } catch (RemoteException e) {
                    Log.e(TAG, "Failed to update surface input channel: ", e);
                }
@@ -174,9 +194,7 @@ public class WindowlessWindowManager implements IWindowSession {
        }
    }

    /**
     * IWindowSession implementation.
     */
    /** IWindowSession implementation. */
    @Override
    public int addToDisplay(IWindow window, WindowManager.LayoutParams attrs,
            int viewVisibility, int displayId, @InsetsType int requestedVisibleTypes,
@@ -437,14 +455,15 @@ public class WindowlessWindowManager implements IWindowSession {
        if ((attrChanges & inputChangeMask) != 0 && state.mInputChannelToken != null) {
            try {
                if (mRealWm instanceof IWindowSession.Stub) {
                    mRealWm.updateInputChannel(state.mInputChannelToken, state.mDisplayId,
                    mRealWm.updateInputChannel(state.mInputChannelToken, mHostInputTransferToken,
                            state.mDisplayId,
                            new SurfaceControl(sc, "WindowlessWindowManager.relayout"),
                            attrs.flags, attrs.privateFlags, attrs.inputFeatures,
                            state.mInputRegion);
                } else {
                    mRealWm.updateInputChannel(state.mInputChannelToken, state.mDisplayId, sc,
                            attrs.flags, attrs.privateFlags, attrs.inputFeatures,
                            state.mInputRegion);
                    mRealWm.updateInputChannel(state.mInputChannelToken, mHostInputTransferToken,
                            state.mDisplayId, sc, attrs.flags, attrs.privateFlags,
                            attrs.inputFeatures, state.mInputRegion);
                }
            } catch (RemoteException e) {
                Log.e(TAG, "Failed to update surface input channel: ", e);
@@ -624,8 +643,9 @@ public class WindowlessWindowManager implements IWindowSession {
    }

    @Override
    public void updateInputChannel(IBinder channelToken, int displayId, SurfaceControl surface,
            int flags, int privateFlags, int inputFeatures, Region region) {
    public void updateInputChannel(IBinder channelToken, InputTransferToken hostInputToken,
            int displayId, SurfaceControl surface, int flags, int privateFlags, int inputFeatures,
            Region region) {
    }

    @Override
Loading