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

Commit 7200d872 authored by Minche Li's avatar Minche Li Committed by Android (Google) Code Review
Browse files

Merge "Uses TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY for window magnification"

parents d0c4e4ea 7307d481
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -2610,8 +2610,6 @@
    <string name="inattentive_sleep_warning_title">Standby</string>

    <!-- Window Magnification strings -->
    <!-- Title for Magnification Overlay Window [CHAR LIMIT=NONE] -->
    <string name="magnification_overlay_title">Magnification Overlay Window</string>
    <!-- Title for Magnification Window [CHAR LIMIT=NONE] -->
    <string name="magnification_window_title">Magnification Window</string>
    <!-- Title for Magnification Controls Window [CHAR LIMIT=NONE] -->
+4 −8
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import android.content.Context;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.graphics.Rect;
import android.os.IBinder;
import android.util.Log;
import android.util.MathUtils;
import android.view.Gravity;
@@ -36,9 +35,8 @@ import com.android.systemui.R;

/**
 * Contains a movable control UI to manipulate mirrored window's position, size and scale. The
 * window type of the UI is {@link LayoutParams#TYPE_APPLICATION_SUB_PANEL} and the window type
 * of the window token should be {@link LayoutParams#TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY} to
 * ensure it is above all windows and won't be mirrored. It is not movable to the navigation bar.
 * window type of the UI is {@link LayoutParams#TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY} to
 * ensure it won't be magnified. It is not movable to the navigation bar.
 */
public abstract class MirrorWindowControl {
    private static final String TAG = "MirrorWindowControl";
@@ -86,10 +84,9 @@ public abstract class MirrorWindowControl {
    /**
     * Shows the control UI.
     *
     * @param binder the window token of the
     * {@link LayoutParams#TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY}  window.
     */
    public final void showControl(IBinder binder) {
    public final void showControl() {
        if (mControlsView != null) {
            Log.w(TAG, "control view is visible");
            return;
@@ -102,7 +99,6 @@ public abstract class MirrorWindowControl {
                R.dimen.magnification_controls_size);
        lp.width = viewSize.x <= 0 ? defaultSize : viewSize.x;
        lp.height = viewSize.y <= 0 ? defaultSize : viewSize.y;
        lp.token = binder;
        setDefaultParams(lp);
        setDefaultPosition(lp);
        mWindowManager.addView(mControlsView, lp);
@@ -113,7 +109,7 @@ public abstract class MirrorWindowControl {
        lp.gravity = Gravity.TOP | Gravity.LEFT;
        lp.flags = LayoutParams.FLAG_NOT_TOUCH_MODAL
                | LayoutParams.FLAG_NOT_FOCUSABLE;
        lp.type = LayoutParams.TYPE_APPLICATION_SUB_PANEL;
        lp.type = LayoutParams.TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY;
        lp.format = PixelFormat.RGBA_8888;
        lp.setTitle(getWindowTitle());
    }
+5 −50
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Region;
import android.os.AsyncTask;
import android.os.Binder;
import android.os.RemoteException;
import android.util.Log;
import android.view.Display;
@@ -45,7 +44,6 @@ import android.view.SurfaceControl;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.view.WindowManagerGlobal;

@@ -92,7 +90,6 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold
    private int mMirrorSurfaceMargin;
    private int mBorderDragSize;
    private int mOuterBorderSize;
    private View mOverlayView;
    // The boundary of magnification frame.
    private final Rect mMagnificationFrameBoundary = new Rect();

@@ -130,43 +127,6 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold
                R.dimen.magnification_outer_border_margin);
    }

    private void createOverlayWindow() {
        WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY,
                WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
                        | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                PixelFormat.TRANSPARENT);
        params.gravity = Gravity.TOP | Gravity.LEFT;
        params.token = new Binder();
        params.setTitle(mContext.getString(R.string.magnification_overlay_title));

        mOverlayView = new View(mContext);
        mOverlayView.getViewTreeObserver().addOnWindowAttachListener(
                new ViewTreeObserver.OnWindowAttachListener() {
                    @Override
                    public void onWindowAttached() {
                        mOverlayView.getViewTreeObserver().removeOnWindowAttachListener(this);
                        createMirrorWindow();
                        createControls();
                    }

                    @Override
                    public void onWindowDetached() {

                    }
                });

        mOverlayView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

        mWm.addView(mOverlayView, params);
    }

    /**
     * Deletes the magnification window.
     */
@@ -176,11 +136,6 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold
            mMirrorSurface = null;
        }

        if (mOverlayView != null) {
            mWm.removeView(mOverlayView);
            mOverlayView = null;
        }

        if (mMirrorView != null) {
            mWm.removeView(mMirrorView);
            mMirrorView = null;
@@ -255,12 +210,11 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold

        WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                windowWidth, windowHeight,
                WindowManager.LayoutParams.TYPE_APPLICATION_PANEL,
                WindowManager.LayoutParams.TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY,
                WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                        | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                PixelFormat.TRANSPARENT);
        params.gravity = Gravity.TOP | Gravity.LEFT;
        params.token = mOverlayView.getWindowToken();
        params.x = mMagnificationFrame.left;
        params.y = mMagnificationFrame.top;
        params.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
@@ -317,9 +271,9 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold
        return regionInsideDragBorder;
    }

    private void createControls() {
    private void showControls() {
        if (mMirrorWindowControl != null) {
            mMirrorWindowControl.showControl(mOverlayView.getWindowToken());
            mMirrorWindowControl.showControl();
        }
    }

@@ -530,7 +484,8 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold
        setMagnificationFrameBoundary();
        updateMagnificationFramePosition((int) offsetX, (int) offsetY);
        if (mMirrorView == null) {
            createOverlayWindow();
            createMirrorWindow();
            showControls();
        } else {
            modifyWindowMagnification(mTransaction);
            mTransaction.apply();
+3 −5
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ import static org.mockito.Mockito.verify;

import android.content.Context;
import android.graphics.Point;
import android.os.IBinder;
import android.testing.AndroidTestingRunner;
import android.view.LayoutInflater;
import android.view.View;
@@ -50,7 +49,6 @@ import org.mockito.MockitoAnnotations;
public class MirrorWindowControlTest extends SysuiTestCase {

    @Mock WindowManager mWindowManager;
    @Mock IBinder mIBinder;
    View mView;
    int mViewWidth;
    int mViewHeight;
@@ -77,7 +75,7 @@ public class MirrorWindowControlTest extends SysuiTestCase {

    @Test
    public void showControl_createViewAndAddView() {
        mStubMirrorWindowControl.showControl(mIBinder);
        mStubMirrorWindowControl.showControl();

        assertTrue(mStubMirrorWindowControl.mInvokeOnCreateView);
        ArgumentCaptor<ViewGroup.LayoutParams> lpCaptor = ArgumentCaptor.forClass(
@@ -89,7 +87,7 @@ public class MirrorWindowControlTest extends SysuiTestCase {

    @Test
    public void destroyControl_removeView() {
        mStubMirrorWindowControl.showControl(mIBinder);
        mStubMirrorWindowControl.showControl();
        ArgumentCaptor<View> captor = ArgumentCaptor.forClass(View.class);
        verify(mWindowManager).addView(captor.capture(), any(LayoutParams.class));

@@ -102,7 +100,7 @@ public class MirrorWindowControlTest extends SysuiTestCase {
    public void move_offsetIsCorrect() {
        ArgumentCaptor<ViewGroup.LayoutParams> lpCaptor = ArgumentCaptor.forClass(
                ViewGroup.LayoutParams.class);
        mStubMirrorWindowControl.showControl(mIBinder);
        mStubMirrorWindowControl.showControl();
        verify(mWindowManager).addView(any(), lpCaptor.capture());
        LayoutParams lp = (LayoutParams) lpCaptor.getValue();
        Point startPosition = new Point(lp.x, lp.y);
+1 −2
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;

import android.app.Instrumentation;
import android.os.IBinder;
import android.testing.AndroidTestingRunner;

import androidx.test.InstrumentationRegistry;
@@ -72,7 +71,7 @@ public class WindowMagnificationControllerTest extends SysuiTestCase {
                    Float.NaN);
        });
        mInstrumentation.waitForIdleSync();
        verify(mMirrorWindowControl).showControl(any(IBinder.class));
        verify(mMirrorWindowControl).showControl();
    }

    @Test