diff --git a/core/java/android/view/AccessibilityEmbeddedConnection.java b/core/java/android/view/AccessibilityEmbeddedConnection.java index cc1e5010edc77..5d3466907ea20 100644 --- a/core/java/android/view/AccessibilityEmbeddedConnection.java +++ b/core/java/android/view/AccessibilityEmbeddedConnection.java @@ -33,6 +33,7 @@ import java.lang.ref.WeakReference; */ final class AccessibilityEmbeddedConnection extends IAccessibilityEmbeddedConnection.Stub { private final WeakReference mViewRootImpl; + private final Matrix mTmpScreenMatrix = new Matrix(); AccessibilityEmbeddedConnection(ViewRootImpl viewRootImpl) { mViewRootImpl = new WeakReference<>(viewRootImpl); @@ -73,9 +74,11 @@ final class AccessibilityEmbeddedConnection extends IAccessibilityEmbeddedConnec public void setScreenMatrix(float[] matrixValues) { final ViewRootImpl viewRootImpl = mViewRootImpl.get(); if (viewRootImpl != null) { - // TODO(b/148821260): Implement the rest of matrix values. - viewRootImpl.mAttachInfo.mLocationInParentDisplay.set( - (int) matrixValues[Matrix.MTRANS_X], (int) matrixValues[Matrix.MTRANS_Y]); + mTmpScreenMatrix.setValues(matrixValues); + if (viewRootImpl.mAttachInfo.mScreenMatrixInEmbeddedHierarchy == null) { + viewRootImpl.mAttachInfo.mScreenMatrixInEmbeddedHierarchy = new Matrix(); + } + viewRootImpl.mAttachInfo.mScreenMatrixInEmbeddedHierarchy.set(mTmpScreenMatrix); } } } diff --git a/core/java/android/view/AccessibilityInteractionController.java b/core/java/android/view/AccessibilityInteractionController.java index 3ca84c1eb18d0..6d4ac0ed53275 100644 --- a/core/java/android/view/AccessibilityInteractionController.java +++ b/core/java/android/view/AccessibilityInteractionController.java @@ -21,6 +21,7 @@ import static android.view.accessibility.AccessibilityNodeInfo.ACTION_ARGUMENT_A import static android.view.accessibility.AccessibilityNodeInfo.EXTRA_DATA_REQUESTED_KEY; import static android.view.accessibility.AccessibilityNodeInfo.EXTRA_DATA_TEXT_CHARACTER_LOCATION_KEY; +import android.graphics.Matrix; import android.graphics.Point; import android.graphics.Rect; import android.graphics.RectF; @@ -109,6 +110,7 @@ public final class AccessibilityInteractionController { private final Rect mTempRect = new Rect(); private final Rect mTempRect1 = new Rect(); private final Rect mTempRect2 = new Rect(); + private final RectF mTempRectF = new RectF(); private AddNodeInfosForViewId mAddNodeInfosForViewId; @@ -855,6 +857,38 @@ public final class AccessibilityInteractionController { return mViewRootImpl.mAttachInfo.mLocationInParentDisplay.equals(0, 0); } + private void applyScreenMatrixIfNeeded(List infos) { + if (infos == null || shouldBypassApplyScreenMatrix()) { + return; + } + final int infoCount = infos.size(); + for (int i = 0; i < infoCount; i++) { + final AccessibilityNodeInfo info = infos.get(i); + applyScreenMatrixIfNeeded(info); + } + } + + private void applyScreenMatrixIfNeeded(AccessibilityNodeInfo info) { + if (info == null || shouldBypassApplyScreenMatrix()) { + return; + } + final Rect boundsInScreen = mTempRect; + final RectF transformedBounds = mTempRectF; + final Matrix screenMatrix = mViewRootImpl.mAttachInfo.mScreenMatrixInEmbeddedHierarchy; + + info.getBoundsInScreen(boundsInScreen); + transformedBounds.set(boundsInScreen); + screenMatrix.mapRect(transformedBounds); + boundsInScreen.set((int) transformedBounds.left, (int) transformedBounds.top, + (int) transformedBounds.right, (int) transformedBounds.bottom); + info.setBoundsInScreen(boundsInScreen); + } + + private boolean shouldBypassApplyScreenMatrix() { + final Matrix screenMatrix = mViewRootImpl.mAttachInfo.mScreenMatrixInEmbeddedHierarchy; + return screenMatrix == null || screenMatrix.isIdentity(); + } + private void associateLeashedParentIfNeeded(List infos) { if (infos == null || shouldBypassAssociateLeashedParent()) { return; @@ -945,6 +979,7 @@ public final class AccessibilityInteractionController { try { mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = 0; associateLeashedParentIfNeeded(infos); + applyScreenMatrixIfNeeded(infos); adjustBoundsInScreenIfNeeded(infos); // To avoid applyAppScaleAndMagnificationSpecIfNeeded changing the bounds of node, // then impact the visibility result, we need to adjust visibility before apply scale. @@ -967,6 +1002,7 @@ public final class AccessibilityInteractionController { try { mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = 0; associateLeashedParentIfNeeded(info); + applyScreenMatrixIfNeeded(info); adjustBoundsInScreenIfNeeded(info); // To avoid applyAppScaleAndMagnificationSpecIfNeeded changing the bounds of node, // then impact the visibility result, we need to adjust visibility before apply scale. diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index c7f850a7eeb5a..b9be33ca0f59f 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -28819,6 +28819,12 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ final Point mLocationInParentDisplay = new Point(); + /** + * The screen matrix of this view when it's on a {@link SurfaceControlViewHost} that is + * embedded within a SurfaceView. + */ + Matrix mScreenMatrixInEmbeddedHierarchy; + /** * Global to the view hierarchy used as a temporary for dealing with * x/y points in the transparent region computations.