From 0f4db1b1e24c49eac4dfc2a6c79ff66737ee18ca Mon Sep 17 00:00:00 2001 From: Evan Rosky Date: Tue, 28 Apr 2020 16:20:00 -0700 Subject: [PATCH] Set DividerView accessibility embedded matrix to surface position Even though it isn't technically embedded, pretend like it is embedded into the display. We need to do this because the surface is moving, but the view content is always drawn at 0,0. For utilities like View.getBoundsOnScreen to work, this matrix needs to be updated to offset things properly. Bug: 151632128 Test: Enter split-screen and dump accessibility nodes if possible. UiAutomator-based tests using divider should work again Change-Id: Icc42e1236f3863dcafbe7f14512082f6f92b76c3 --- .../systemui/stackdivider/DividerView.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/packages/SystemUI/src/com/android/systemui/stackdivider/DividerView.java b/packages/SystemUI/src/com/android/systemui/stackdivider/DividerView.java index 2df450604d3b7..6f2eede5b1200 100644 --- a/packages/SystemUI/src/com/android/systemui/stackdivider/DividerView.java +++ b/packages/SystemUI/src/com/android/systemui/stackdivider/DividerView.java @@ -28,11 +28,13 @@ import android.animation.ValueAnimator; import android.annotation.Nullable; import android.content.Context; import android.content.res.Configuration; +import android.graphics.Matrix; import android.graphics.Rect; import android.graphics.Region.Op; import android.hardware.display.DisplayManager; import android.os.Bundle; import android.os.Handler; +import android.os.RemoteException; import android.util.AttributeSet; import android.util.Slog; import android.view.Display; @@ -163,6 +165,9 @@ public class DividerView extends FrameLayout implements OnTouchListener, int mDividerPositionX; int mDividerPositionY; + private final Matrix mTmpMatrix = new Matrix(); + private final float[] mTmpValues = new float[9]; + // The view is removed or in the process of been removed from the system. private boolean mRemoved; @@ -248,6 +253,22 @@ public class DividerView extends FrameLayout implements OnTouchListener, } }; + private Runnable mUpdateEmbeddedMatrix = () -> { + if (getViewRootImpl() == null) { + return; + } + if (isHorizontalDivision()) { + mTmpMatrix.setTranslate(0, mDividerPositionY - mDividerInsets); + } else { + mTmpMatrix.setTranslate(mDividerPositionX - mDividerInsets, 0); + } + mTmpMatrix.getValues(mTmpValues); + try { + getViewRootImpl().getAccessibilityEmbeddedConnection().setScreenMatrix(mTmpValues); + } catch (RemoteException e) { + } + }; + public DividerView(Context context) { this(context, null); } @@ -1069,6 +1090,10 @@ public class DividerView extends FrameLayout implements OnTouchListener, t.setPosition(dividerCtrl, mDividerPositionX - mDividerInsets, 0); } } + if (getViewRootImpl() != null) { + mHandler.removeCallbacks(mUpdateEmbeddedMatrix); + mHandler.post(mUpdateEmbeddedMatrix); + } } void setResizeDimLayer(Transaction t, boolean primary, float alpha) {