Loading core/java/android/view/accessibility/IWindowMagnificationConnectionCallback.aidl +11 −2 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ package android.view.accessibility; import android.graphics.Rect; /** * interface to notify the change of the window magnifier bounds and request to change * interface to notify the changes of the window magnification and request to change * the magnification mode. * * @hide Loading @@ -27,12 +27,13 @@ import android.graphics.Rect; oneway interface IWindowMagnificationConnectionCallback { /** * Called when the bounds of the window magnifier is changed. * Called when the bounds of the mirrow window is changed. * * @param displayId The logical display id. * @param bounds The window magnifier bounds in screen coordinates. */ void onWindowMagnifierBoundsChanged(int displayId, in Rect bounds); /** * Changes the magnification mode on specified display. It is invoked by System UI when the * switch button is toggled. Loading @@ -41,4 +42,12 @@ import android.graphics.Rect; * @param magnificationMode new magnification mode. */ void onChangeMagnificationMode(int displayId, int magnificationMode); /** * Called when the magnified bounds is changed. * * @param displayId The logical display id. * @param sourceBounds The magnified bounds in screen coordinates. */ void onSourceBoundsChanged(int displayId, in Rect sourceBounds); } packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnification.java +19 −1 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.graphics.Rect; import android.os.Handler; import android.os.RemoteException; import android.util.Log; import android.view.SurfaceControl; import android.view.accessibility.AccessibilityManager; import android.view.accessibility.IWindowMagnificationConnection; import android.view.accessibility.IWindowMagnificationConnectionCallback; Loading Loading @@ -97,7 +98,7 @@ public class WindowMagnification extends SystemUI implements WindowMagnifierCall mWindowMagnificationController = new WindowMagnificationController(mContext, mHandler, new SfVsyncFrameCallbackProvider(), null, null, new SurfaceControl.Transaction(), this); } mWindowMagnificationController.enableWindowMagnification(scale, centerX, centerY); Loading Loading @@ -135,6 +136,13 @@ public class WindowMagnification extends SystemUI implements WindowMagnifierCall } } @Override public void onSourceBoundsChanged(int displayId, Rect sourceBounds) { if (mWindowMagnificationConnectionImpl != null) { mWindowMagnificationConnectionImpl.onSourceBoundsChanged(displayId, sourceBounds); } } @Override public void requestWindowMagnificationConnection(boolean connect) { if (connect) { Loading Loading @@ -225,5 +233,15 @@ public class WindowMagnification extends SystemUI implements WindowMagnifierCall } } } void onSourceBoundsChanged(int displayId, Rect sourceBounds) { if (mConnectionCallback != null) { try { mConnectionCallback.onSourceBoundsChanged(displayId, sourceBounds); } catch (RemoteException e) { Log.e(TAG, "Failed to inform source bounds changed", e); } } } } } packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationController.java +23 −19 Original line number Diff line number Diff line Loading @@ -67,7 +67,7 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold @Surface.Rotation private int mRotation; private final Rect mMagnificationFrame = new Rect(); private final SurfaceControl.Transaction mTransaction = new SurfaceControl.Transaction(); private final SurfaceControl.Transaction mTransaction; private final WindowManager mWm; Loading @@ -75,6 +75,7 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold private final Rect mTmpRect = new Rect(); private final Rect mMirrorViewBounds = new Rect(); private final Rect mSourceBounds = new Rect(); // The root of the mirrored content private SurfaceControl mMirrorSurface; Loading @@ -101,22 +102,14 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold private final Rect mMagnificationFrameBoundary = new Rect(); private final SfVsyncFrameCallbackProvider mSfVsyncFrameProvider; private final Choreographer.FrameCallback mMirrorViewGeometryVsyncCallback = l -> { if (mMirrorView != null) { final Rect sourceBounds = getSourceBounds(mMagnificationFrame, mScale); mTransaction.setGeometry(mMirrorSurface, sourceBounds, mTmpRect, Surface.ROTATION_0).apply(); } }; private Choreographer.FrameCallback mMirrorViewGeometryVsyncCallback; @Nullable private MirrorWindowControl mMirrorWindowControl; WindowMagnificationController(Context context, @NonNull Handler handler, WindowMagnificationController(Context context, @NonNull Handler handler, SfVsyncFrameCallbackProvider sfVsyncFrameProvider, MirrorWindowControl mirrorWindowControl, MirrorWindowControl mirrorWindowControl, SurfaceControl.Transaction transaction, @NonNull WindowMagnifierCallback callback) { mContext = context; mHandler = handler; Loading @@ -137,6 +130,7 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold if (mMirrorWindowControl != null) { mMirrorWindowControl.setWindowDelegate(this); } mTransaction = transaction; setInitialStartBounds(); // Initialize listeners. Loading @@ -153,6 +147,20 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold mMirrorSurfaceViewLayoutChangeListener = (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> applyTapExcludeRegion(); mMirrorViewGeometryVsyncCallback = l -> { if (mMirrorView != null && mMirrorSurface != null) { calculateSourceBounds(mMagnificationFrame, mScale); // The final destination for the magnification surface should be at 0,0 // since the ViewRootImpl's position will change mTmpRect.set(0, 0, mMagnificationFrame.width(), mMagnificationFrame.height()); mTransaction.setGeometry(mMirrorSurface, mSourceBounds, mTmpRect, Surface.ROTATION_0).apply(); mWindowMagnifierCallback.onSourceBoundsChanged(mDisplayId, mSourceBounds); } }; } private void updateDimensions() { Loading Loading @@ -350,13 +358,9 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold * Modifies the placement of the mirrored content when the position of mMirrorView is updated. */ private void modifyWindowMagnification(SurfaceControl.Transaction t) { // The final destination for the magnification surface should be at 0,0 since the // ViewRootImpl's position will change mTmpRect.set(0, 0, mMagnificationFrame.width(), mMagnificationFrame.height()); mSfVsyncFrameProvider.postFrameCallback(mMirrorViewGeometryVsyncCallback); updateMirrorViewLayout(); mSfVsyncFrameProvider.postFrameCallback(mMirrorViewGeometryVsyncCallback); } /** Loading Loading @@ -420,14 +424,14 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold * Calculates the desired source bounds. This will be the area under from the center of the * displayFrame, factoring in scale. */ private Rect getSourceBounds(Rect displayFrame, float scale) { private void calculateSourceBounds(Rect displayFrame, float scale) { int halfWidth = displayFrame.width() / 2; int halfHeight = displayFrame.height() / 2; int left = displayFrame.left + (halfWidth - (int) (halfWidth / scale)); int right = displayFrame.right - (halfWidth - (int) (halfWidth / scale)); int top = displayFrame.top + (halfHeight - (int) (halfHeight / scale)); int bottom = displayFrame.bottom - (halfHeight - (int) (halfHeight / scale)); return new Rect(left, top, right, bottom); mSourceBounds.set(left, top, right, bottom); } private void setMagnificationFrameBoundary() { Loading packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnifierCallback.java +8 −0 Original line number Diff line number Diff line Loading @@ -29,4 +29,12 @@ interface WindowMagnifierCallback { * @param bounds The bounds of window magnifier on the screen. */ void onWindowMagnifierBoundsChanged(int displayId, Rect bounds); /** * Called when the magnified bounds is changed. * * @param displayId The logical display id. * @param sourceBounds The magnified bounds in screen coordinates. */ void onSourceBoundsChanged(int displayId, Rect sourceBounds); } packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationControllerTest.java +20 −2 Original line number Diff line number Diff line Loading @@ -16,13 +16,19 @@ package com.android.systemui.accessibility; import static android.view.Choreographer.FrameCallback; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.app.Instrumentation; import android.os.Handler; import android.testing.AndroidTestingRunner; import android.view.SurfaceControl; import androidx.test.InstrumentationRegistry; import androidx.test.filters.SmallTest; Loading @@ -49,6 +55,8 @@ public class WindowMagnificationControllerTest extends SysuiTestCase { MirrorWindowControl mMirrorWindowControl; @Mock WindowMagnifierCallback mWindowMagnifierCallback; @Mock SurfaceControl.Transaction mTransaction; private WindowMagnificationController mWindowMagnificationController; private Instrumentation mInstrumentation; Loading @@ -56,9 +64,19 @@ public class WindowMagnificationControllerTest extends SysuiTestCase { public void setUp() { MockitoAnnotations.initMocks(this); mInstrumentation = InstrumentationRegistry.getInstrumentation(); doAnswer(invocation -> { FrameCallback callback = invocation.getArgument(0); callback.doFrame(0); return null; }).when(mSfVsyncFrameProvider).postFrameCallback( any(FrameCallback.class)); when(mTransaction.remove(any())).thenReturn(mTransaction); when(mTransaction.setGeometry(any(), any(), any(), anyInt())).thenReturn(mTransaction); mWindowMagnificationController = new WindowMagnificationController(getContext(), mHandler, mSfVsyncFrameProvider, mMirrorWindowControl, mWindowMagnifierCallback); mMirrorWindowControl, mTransaction, mWindowMagnifierCallback); verify(mMirrorWindowControl).setWindowDelegate( any(MirrorWindowControl.MirrorWindowDelegate.class)); } Loading @@ -71,7 +89,7 @@ public class WindowMagnificationControllerTest extends SysuiTestCase { } @Test public void createWindowMagnification_showControl() { public void enableWindowMagnification_showControl() { mInstrumentation.runOnMainSync(() -> { mWindowMagnificationController.enableWindowMagnification(Float.NaN, Float.NaN, Float.NaN); Loading Loading
core/java/android/view/accessibility/IWindowMagnificationConnectionCallback.aidl +11 −2 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ package android.view.accessibility; import android.graphics.Rect; /** * interface to notify the change of the window magnifier bounds and request to change * interface to notify the changes of the window magnification and request to change * the magnification mode. * * @hide Loading @@ -27,12 +27,13 @@ import android.graphics.Rect; oneway interface IWindowMagnificationConnectionCallback { /** * Called when the bounds of the window magnifier is changed. * Called when the bounds of the mirrow window is changed. * * @param displayId The logical display id. * @param bounds The window magnifier bounds in screen coordinates. */ void onWindowMagnifierBoundsChanged(int displayId, in Rect bounds); /** * Changes the magnification mode on specified display. It is invoked by System UI when the * switch button is toggled. Loading @@ -41,4 +42,12 @@ import android.graphics.Rect; * @param magnificationMode new magnification mode. */ void onChangeMagnificationMode(int displayId, int magnificationMode); /** * Called when the magnified bounds is changed. * * @param displayId The logical display id. * @param sourceBounds The magnified bounds in screen coordinates. */ void onSourceBoundsChanged(int displayId, in Rect sourceBounds); }
packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnification.java +19 −1 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.graphics.Rect; import android.os.Handler; import android.os.RemoteException; import android.util.Log; import android.view.SurfaceControl; import android.view.accessibility.AccessibilityManager; import android.view.accessibility.IWindowMagnificationConnection; import android.view.accessibility.IWindowMagnificationConnectionCallback; Loading Loading @@ -97,7 +98,7 @@ public class WindowMagnification extends SystemUI implements WindowMagnifierCall mWindowMagnificationController = new WindowMagnificationController(mContext, mHandler, new SfVsyncFrameCallbackProvider(), null, null, new SurfaceControl.Transaction(), this); } mWindowMagnificationController.enableWindowMagnification(scale, centerX, centerY); Loading Loading @@ -135,6 +136,13 @@ public class WindowMagnification extends SystemUI implements WindowMagnifierCall } } @Override public void onSourceBoundsChanged(int displayId, Rect sourceBounds) { if (mWindowMagnificationConnectionImpl != null) { mWindowMagnificationConnectionImpl.onSourceBoundsChanged(displayId, sourceBounds); } } @Override public void requestWindowMagnificationConnection(boolean connect) { if (connect) { Loading Loading @@ -225,5 +233,15 @@ public class WindowMagnification extends SystemUI implements WindowMagnifierCall } } } void onSourceBoundsChanged(int displayId, Rect sourceBounds) { if (mConnectionCallback != null) { try { mConnectionCallback.onSourceBoundsChanged(displayId, sourceBounds); } catch (RemoteException e) { Log.e(TAG, "Failed to inform source bounds changed", e); } } } } }
packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationController.java +23 −19 Original line number Diff line number Diff line Loading @@ -67,7 +67,7 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold @Surface.Rotation private int mRotation; private final Rect mMagnificationFrame = new Rect(); private final SurfaceControl.Transaction mTransaction = new SurfaceControl.Transaction(); private final SurfaceControl.Transaction mTransaction; private final WindowManager mWm; Loading @@ -75,6 +75,7 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold private final Rect mTmpRect = new Rect(); private final Rect mMirrorViewBounds = new Rect(); private final Rect mSourceBounds = new Rect(); // The root of the mirrored content private SurfaceControl mMirrorSurface; Loading @@ -101,22 +102,14 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold private final Rect mMagnificationFrameBoundary = new Rect(); private final SfVsyncFrameCallbackProvider mSfVsyncFrameProvider; private final Choreographer.FrameCallback mMirrorViewGeometryVsyncCallback = l -> { if (mMirrorView != null) { final Rect sourceBounds = getSourceBounds(mMagnificationFrame, mScale); mTransaction.setGeometry(mMirrorSurface, sourceBounds, mTmpRect, Surface.ROTATION_0).apply(); } }; private Choreographer.FrameCallback mMirrorViewGeometryVsyncCallback; @Nullable private MirrorWindowControl mMirrorWindowControl; WindowMagnificationController(Context context, @NonNull Handler handler, WindowMagnificationController(Context context, @NonNull Handler handler, SfVsyncFrameCallbackProvider sfVsyncFrameProvider, MirrorWindowControl mirrorWindowControl, MirrorWindowControl mirrorWindowControl, SurfaceControl.Transaction transaction, @NonNull WindowMagnifierCallback callback) { mContext = context; mHandler = handler; Loading @@ -137,6 +130,7 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold if (mMirrorWindowControl != null) { mMirrorWindowControl.setWindowDelegate(this); } mTransaction = transaction; setInitialStartBounds(); // Initialize listeners. Loading @@ -153,6 +147,20 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold mMirrorSurfaceViewLayoutChangeListener = (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> applyTapExcludeRegion(); mMirrorViewGeometryVsyncCallback = l -> { if (mMirrorView != null && mMirrorSurface != null) { calculateSourceBounds(mMagnificationFrame, mScale); // The final destination for the magnification surface should be at 0,0 // since the ViewRootImpl's position will change mTmpRect.set(0, 0, mMagnificationFrame.width(), mMagnificationFrame.height()); mTransaction.setGeometry(mMirrorSurface, mSourceBounds, mTmpRect, Surface.ROTATION_0).apply(); mWindowMagnifierCallback.onSourceBoundsChanged(mDisplayId, mSourceBounds); } }; } private void updateDimensions() { Loading Loading @@ -350,13 +358,9 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold * Modifies the placement of the mirrored content when the position of mMirrorView is updated. */ private void modifyWindowMagnification(SurfaceControl.Transaction t) { // The final destination for the magnification surface should be at 0,0 since the // ViewRootImpl's position will change mTmpRect.set(0, 0, mMagnificationFrame.width(), mMagnificationFrame.height()); mSfVsyncFrameProvider.postFrameCallback(mMirrorViewGeometryVsyncCallback); updateMirrorViewLayout(); mSfVsyncFrameProvider.postFrameCallback(mMirrorViewGeometryVsyncCallback); } /** Loading Loading @@ -420,14 +424,14 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold * Calculates the desired source bounds. This will be the area under from the center of the * displayFrame, factoring in scale. */ private Rect getSourceBounds(Rect displayFrame, float scale) { private void calculateSourceBounds(Rect displayFrame, float scale) { int halfWidth = displayFrame.width() / 2; int halfHeight = displayFrame.height() / 2; int left = displayFrame.left + (halfWidth - (int) (halfWidth / scale)); int right = displayFrame.right - (halfWidth - (int) (halfWidth / scale)); int top = displayFrame.top + (halfHeight - (int) (halfHeight / scale)); int bottom = displayFrame.bottom - (halfHeight - (int) (halfHeight / scale)); return new Rect(left, top, right, bottom); mSourceBounds.set(left, top, right, bottom); } private void setMagnificationFrameBoundary() { Loading
packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnifierCallback.java +8 −0 Original line number Diff line number Diff line Loading @@ -29,4 +29,12 @@ interface WindowMagnifierCallback { * @param bounds The bounds of window magnifier on the screen. */ void onWindowMagnifierBoundsChanged(int displayId, Rect bounds); /** * Called when the magnified bounds is changed. * * @param displayId The logical display id. * @param sourceBounds The magnified bounds in screen coordinates. */ void onSourceBoundsChanged(int displayId, Rect sourceBounds); }
packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationControllerTest.java +20 −2 Original line number Diff line number Diff line Loading @@ -16,13 +16,19 @@ package com.android.systemui.accessibility; import static android.view.Choreographer.FrameCallback; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.app.Instrumentation; import android.os.Handler; import android.testing.AndroidTestingRunner; import android.view.SurfaceControl; import androidx.test.InstrumentationRegistry; import androidx.test.filters.SmallTest; Loading @@ -49,6 +55,8 @@ public class WindowMagnificationControllerTest extends SysuiTestCase { MirrorWindowControl mMirrorWindowControl; @Mock WindowMagnifierCallback mWindowMagnifierCallback; @Mock SurfaceControl.Transaction mTransaction; private WindowMagnificationController mWindowMagnificationController; private Instrumentation mInstrumentation; Loading @@ -56,9 +64,19 @@ public class WindowMagnificationControllerTest extends SysuiTestCase { public void setUp() { MockitoAnnotations.initMocks(this); mInstrumentation = InstrumentationRegistry.getInstrumentation(); doAnswer(invocation -> { FrameCallback callback = invocation.getArgument(0); callback.doFrame(0); return null; }).when(mSfVsyncFrameProvider).postFrameCallback( any(FrameCallback.class)); when(mTransaction.remove(any())).thenReturn(mTransaction); when(mTransaction.setGeometry(any(), any(), any(), anyInt())).thenReturn(mTransaction); mWindowMagnificationController = new WindowMagnificationController(getContext(), mHandler, mSfVsyncFrameProvider, mMirrorWindowControl, mWindowMagnifierCallback); mMirrorWindowControl, mTransaction, mWindowMagnifierCallback); verify(mMirrorWindowControl).setWindowDelegate( any(MirrorWindowControl.MirrorWindowDelegate.class)); } Loading @@ -71,7 +89,7 @@ public class WindowMagnificationControllerTest extends SysuiTestCase { } @Test public void createWindowMagnification_showControl() { public void enableWindowMagnification_showControl() { mInstrumentation.runOnMainSync(() -> { mWindowMagnificationController.enableWindowMagnification(Float.NaN, Float.NaN, Float.NaN); Loading