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

Commit 7bdc82af authored by ryanlwlin's avatar ryanlwlin
Browse files

Change node bounds procedure based on SufaceFlinger Callback

The attachInfo from ViewRootImpl is not reliable
for DisplayArea manipulation or windowless window.

To fix this problem, we use the transform matrix of
InputWindowHandle, which could transform the bounds
from window coorindate to screen coordinate. We also
transfrom the bounds to logical display coordinates
with the associated display matrix.

Besides, we also record the magnification spec of the window,
which could get the bounds before magnification. We use
this value to decide the property 'visibleToUser'.

Bug: 200797785
Test: atest android.accessibilityservice.cts WindowInfoTest
      atest com.android.server.accessibility
Change-Id: I0917b04fe8b027fb2bd932a6f0604ba1449ebc66
parent 6fcd7dd7
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ import java.lang.ref.WeakReference;
 */
final class AccessibilityEmbeddedConnection extends IAccessibilityEmbeddedConnection.Stub {
    private final WeakReference<ViewRootImpl> mViewRootImpl;
    private final Matrix mTmpScreenMatrix = new Matrix();
    private final Matrix mTmpWindowMatrix = new Matrix();

    AccessibilityEmbeddedConnection(ViewRootImpl viewRootImpl) {
        mViewRootImpl = new WeakReference<>(viewRootImpl);
@@ -70,14 +70,14 @@ final class AccessibilityEmbeddedConnection extends IAccessibilityEmbeddedConnec
    }

    @Override
    public void setScreenMatrix(float[] matrixValues) {
    public void setWindowMatrix(float[] matrixValues) {
        final ViewRootImpl viewRootImpl = mViewRootImpl.get();
        if (viewRootImpl != null) {
            mTmpScreenMatrix.setValues(matrixValues);
            if (viewRootImpl.mAttachInfo.mScreenMatrixInEmbeddedHierarchy == null) {
                viewRootImpl.mAttachInfo.mScreenMatrixInEmbeddedHierarchy = new Matrix();
            mTmpWindowMatrix.setValues(matrixValues);
            if (viewRootImpl.mAttachInfo.mWindowMatrixInEmbeddedHierarchy == null) {
                viewRootImpl.mAttachInfo.mWindowMatrixInEmbeddedHierarchy = new Matrix();
            }
            viewRootImpl.mAttachInfo.mScreenMatrixInEmbeddedHierarchy.set(mTmpScreenMatrix);
            viewRootImpl.mAttachInfo.mWindowMatrixInEmbeddedHierarchy.set(mTmpWindowMatrix);
        }
    }
}
+116 −78

File changed.

Preview size limit exceeded, changes collapsed.

+6 −6
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ class RemoteAccessibilityController {
    private static final String TAG = "RemoteAccessibilityController";
    private int mHostId;
    private RemoteAccessibilityEmbeddedConnection mConnectionWrapper;
    private Matrix mScreenMatrixForEmbeddedHierarchy = new Matrix();
    private Matrix mWindowMatrixForEmbeddedHierarchy = new Matrix();
    private final float[] mMatrixValues = new float[9];
    private View mHostView;

@@ -140,9 +140,9 @@ class RemoteAccessibilityController {
        return mConnectionWrapper;
    }

    void setScreenMatrix(Matrix m) {
        // If the screen matrix is identity or doesn't change, do nothing.
        if (m.isIdentity() || m.equals(mScreenMatrixForEmbeddedHierarchy)) {
    void setWindowMatrix(Matrix m) {
        // If the window matrix is identity or doesn't change, do nothing.
        if (m.isIdentity() || m.equals(mWindowMatrixForEmbeddedHierarchy)) {
            return;
        }

@@ -153,8 +153,8 @@ class RemoteAccessibilityController {
                return;
            }
            m.getValues(mMatrixValues);
            wrapper.getConnection().setScreenMatrix(mMatrixValues);
            mScreenMatrixForEmbeddedHierarchy.set(m);
            wrapper.getConnection().setWindowMatrix(mMatrixValues);
            mWindowMatrixForEmbeddedHierarchy.set(m);
        } catch (RemoteException e) {
            Log.d(TAG, "Error while setScreenMatrix " + e);
        }
+6 −1
Original line number Diff line number Diff line
@@ -1781,11 +1781,16 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
            return;
        }
        getBoundsOnScreen(mTmpRect);

        // To compute the node bounds of the node on the embedded window,
        // apply this matrix to get the bounds in host window-relative coordinates,
        // then using the global transform to get the actual bounds on screen.
        mTmpRect.offset(-mAttachInfo.mWindowLeft, -mAttachInfo.mWindowTop);
        mTmpMatrix.reset();
        mTmpMatrix.setTranslate(mTmpRect.left, mTmpRect.top);
        mTmpMatrix.postScale(mScreenRect.width() / (float) mSurfaceWidth,
                mScreenRect.height() / (float) mSurfaceHeight);
        mRemoteAccessibilityController.setScreenMatrix(mTmpMatrix);
        mRemoteAccessibilityController.setWindowMatrix(mTmpMatrix);
    }

    @Override
+2 −2
Original line number Diff line number Diff line
@@ -29938,10 +29938,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        boolean mHandlingPointerEvent;
        /**
         * The screen matrix of this view when it's on a {@link SurfaceControlViewHost} that is
         * The window matrix of this view when it's on a {@link SurfaceControlViewHost} that is
         * embedded within a SurfaceView.
         */
        Matrix mScreenMatrixInEmbeddedHierarchy;
        Matrix mWindowMatrixInEmbeddedHierarchy;
        /**
         * Global to the view hierarchy used as a temporary for dealing with
Loading