Support circular magnification frame on circular devices

The magnification viewport expects its boundary to be a rectangular region,
and always draws it as such.  This change causes the indicator to draw as a
circle on devices with circular displays.  This also refactors the width of
the indicator's frame to use a proper dimension resource and updates the
width to 4dip.

Bug:18242438
Change-Id: I1d86647b6d1ef84f5dd506f4141223ec050a79b5
diff --git a/services/core/java/com/android/server/wm/AccessibilityController.java b/services/core/java/com/android/server/wm/AccessibilityController.java
index 08754f9..37ca0db 100644
--- a/services/core/java/com/android/server/wm/AccessibilityController.java
+++ b/services/core/java/com/android/server/wm/AccessibilityController.java
@@ -397,8 +397,6 @@
 
         private final class MagnifiedViewport {
 
-            private static final int DEFAUTLT_BORDER_WIDTH_DIP = 5;
-
             private final SparseArray<WindowState> mTempWindowStates =
                     new SparseArray<WindowState>();
 
@@ -411,6 +409,8 @@
             private final Region mMagnifiedBounds = new Region();
             private final Region mOldMagnifiedBounds = new Region();
 
+            private final Path mCircularPath;
+
             private final MagnificationSpec mMagnificationSpec = MagnificationSpec.obtain();
 
             private final WindowManager mWindowManager;
@@ -425,12 +425,22 @@
 
             public MagnifiedViewport() {
                 mWindowManager = (WindowManager) mContext.getSystemService(Service.WINDOW_SERVICE);
-                mBorderWidth = TypedValue.applyDimension(
-                        TypedValue.COMPLEX_UNIT_DIP, DEFAUTLT_BORDER_WIDTH_DIP,
-                                mContext.getResources().getDisplayMetrics());
+                mBorderWidth = mContext.getResources().getDimension(
+                        com.android.internal.R.dimen.accessibility_magnification_indicator_width);
                 mHalfBorderWidth = (int) Math.ceil(mBorderWidth / 2);
                 mDrawBorderInset = (int) mBorderWidth / 2;
                 mWindow = new ViewportWindow(mContext);
+
+                if (mContext.getResources().getBoolean(
+                            com.android.internal.R.bool.config_windowIsRound)) {
+                    mCircularPath = new Path();
+                    mWindowManager.getDefaultDisplay().getRealSize(mTempPoint);
+                    final int centerXY = mTempPoint.x / 2;
+                    mCircularPath.addCircle(centerXY, centerXY, centerXY, Path.Direction.CW);
+                } else {
+                    mCircularPath = null;
+                }
+
                 recomputeBoundsLocked();
             }
 
@@ -459,6 +469,10 @@
                 Region availableBounds = mTempRegion1;
                 availableBounds.set(0, 0, screenWidth, screenHeight);
 
+                if (mCircularPath != null) {
+                    availableBounds.setPath(mCircularPath, availableBounds);
+                }
+
                 Region nonMagnifiedBounds = mTempRegion4;
                 nonMagnifiedBounds.set(0, 0, 0, 0);