Merge "Fixed incorrect rounded corner size" into rvc-dev
diff --git a/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java b/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java
index 281b566..8df3dd2 100644
--- a/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java
+++ b/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java
@@ -409,6 +409,7 @@
         // update rounded corner view rotation
         updateRoundedCornerView(pos, R.id.left);
         updateRoundedCornerView(pos, R.id.right);
+        updateRoundedCornerSize(mRoundedDefault, mRoundedDefaultTop, mRoundedDefaultBottom);
 
         // update cutout view rotation
         if (mCutoutViews != null && mCutoutViews[pos] != null) {
@@ -717,26 +718,46 @@
                     } catch (Exception e) {
                     }
                 }
-
-                if (sizeTop == 0) {
-                    sizeTop = size;
-                }
-                if (sizeBottom == 0) {
-                    sizeBottom = size;
-                }
-
-                for (int i = 0; i < BOUNDS_POSITION_LENGTH; i++) {
-                    if (mOverlays[i] == null) {
-                        continue;
-                    }
-                    setSize(mOverlays[i].findViewById(R.id.left), sizeTop);
-                    setSize(mOverlays[i].findViewById(R.id.right), sizeBottom);
-                }
+                updateRoundedCornerSize(size, sizeTop, sizeBottom);
             }
         });
     }
 
-    private void setSize(View view, int pixelSize) {
+    private void updateRoundedCornerSize(int sizeDefault, int sizeTop, int sizeBottom) {
+        if (mOverlays == null) {
+            return;
+        }
+        if (sizeTop == 0) {
+            sizeTop = sizeDefault;
+        }
+        if (sizeBottom == 0) {
+            sizeBottom = sizeDefault;
+        }
+
+        for (int i = 0; i < BOUNDS_POSITION_LENGTH; i++) {
+            if (mOverlays[i] == null) {
+                continue;
+            }
+            if (i == BOUNDS_POSITION_LEFT || i == BOUNDS_POSITION_RIGHT) {
+                if (mRotation == ROTATION_270) {
+                    setSize(mOverlays[i].findViewById(R.id.left), sizeBottom);
+                    setSize(mOverlays[i].findViewById(R.id.right), sizeTop);
+                } else {
+                    setSize(mOverlays[i].findViewById(R.id.left), sizeTop);
+                    setSize(mOverlays[i].findViewById(R.id.right), sizeBottom);
+                }
+            } else if (i == BOUNDS_POSITION_TOP) {
+                setSize(mOverlays[i].findViewById(R.id.left), sizeTop);
+                setSize(mOverlays[i].findViewById(R.id.right), sizeTop);
+            } else if (i == BOUNDS_POSITION_BOTTOM) {
+                setSize(mOverlays[i].findViewById(R.id.left), sizeBottom);
+                setSize(mOverlays[i].findViewById(R.id.right), sizeBottom);
+            }
+        }
+    }
+
+    @VisibleForTesting
+    protected void setSize(View view, int pixelSize) {
         LayoutParams params = view.getLayoutParams();
         params.width = pixelSize;
         params.height = pixelSize;
diff --git a/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java b/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java
index b6537bf..b9ddff3 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java
@@ -32,6 +32,7 @@
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyInt;
 import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.atLeastOnce;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
@@ -52,6 +53,7 @@
 import android.testing.TestableLooper.RunWithLooper;
 import android.view.Display;
 import android.view.DisplayCutout;
+import android.view.View;
 import android.view.WindowManager;
 import android.view.WindowMetrics;
 
@@ -213,6 +215,78 @@
     }
 
     @Test
+    public void testRoundingTopBottomRadius_OnTopBottomOverlay() {
+        final int testTopRadius = 1;
+        final int testBottomRadius = 5;
+        mContext.getOrCreateTestableResources().addOverride(
+                com.android.internal.R.bool.config_fillMainBuiltInDisplayCutout, false);
+        mContext.getOrCreateTestableResources().addOverride(
+                com.android.internal.R.dimen.rounded_corner_radius, testTopRadius);
+        mContext.getOrCreateTestableResources().addOverride(
+                com.android.internal.R.dimen.rounded_corner_radius_top, testTopRadius);
+        mContext.getOrCreateTestableResources().addOverride(
+                com.android.internal.R.dimen.rounded_corner_radius_bottom, testBottomRadius);
+        mContext.getOrCreateTestableResources()
+                .addOverride(R.bool.config_roundedCornerMultipleRadius, false);
+
+        // no cutout
+        doReturn(null).when(mScreenDecorations).getCutout();
+
+        mScreenDecorations.start();
+        View leftRoundedCorner =
+                mScreenDecorations.mOverlays[BOUNDS_POSITION_TOP].findViewById(R.id.left);
+        View rightRoundedCorner =
+                mScreenDecorations.mOverlays[BOUNDS_POSITION_TOP].findViewById(R.id.right);
+        verify(mScreenDecorations, atLeastOnce()).setSize(leftRoundedCorner, testTopRadius);
+        verify(mScreenDecorations, atLeastOnce()).setSize(rightRoundedCorner, testTopRadius);
+        leftRoundedCorner =
+                mScreenDecorations.mOverlays[BOUNDS_POSITION_BOTTOM].findViewById(R.id.left);
+        rightRoundedCorner =
+                mScreenDecorations.mOverlays[BOUNDS_POSITION_BOTTOM].findViewById(R.id.right);
+        verify(mScreenDecorations, atLeastOnce()).setSize(leftRoundedCorner, testBottomRadius);
+        verify(mScreenDecorations, atLeastOnce()).setSize(rightRoundedCorner, testBottomRadius);
+    }
+
+    @Test
+    public void testRoundingTopBottomRadius_OnLeftRightOverlay() {
+        final int testTopRadius = 1;
+        final int testBottomRadius = 5;
+        mContext.getOrCreateTestableResources().addOverride(
+                com.android.internal.R.bool.config_fillMainBuiltInDisplayCutout, false);
+        mContext.getOrCreateTestableResources().addOverride(
+                com.android.internal.R.dimen.rounded_corner_radius, testTopRadius);
+        mContext.getOrCreateTestableResources().addOverride(
+                com.android.internal.R.dimen.rounded_corner_radius_top, testTopRadius);
+        mContext.getOrCreateTestableResources().addOverride(
+                com.android.internal.R.dimen.rounded_corner_radius_bottom, testBottomRadius);
+        mContext.getOrCreateTestableResources()
+                .addOverride(R.bool.config_roundedCornerMultipleRadius, false);
+
+        // left cutout
+        doReturn(new DisplayCutout(
+                Insets.of(0, 10, 0, 0),
+                new Rect(0, 200, 1, 210),
+                ZERO_RECT,
+                ZERO_RECT,
+                ZERO_RECT,
+                Insets.NONE)).when(mScreenDecorations).getCutout();
+
+        mScreenDecorations.start();
+        View leftRoundedCorner =
+                mScreenDecorations.mOverlays[BOUNDS_POSITION_LEFT].findViewById(R.id.left);
+        View rightRoundedCorner =
+                mScreenDecorations.mOverlays[BOUNDS_POSITION_LEFT].findViewById(R.id.right);
+        verify(mScreenDecorations, atLeastOnce()).setSize(leftRoundedCorner, testTopRadius);
+        verify(mScreenDecorations, atLeastOnce()).setSize(rightRoundedCorner, testBottomRadius);
+        leftRoundedCorner =
+                mScreenDecorations.mOverlays[BOUNDS_POSITION_RIGHT].findViewById(R.id.left);
+        rightRoundedCorner =
+                mScreenDecorations.mOverlays[BOUNDS_POSITION_RIGHT].findViewById(R.id.right);
+        verify(mScreenDecorations, atLeastOnce()).setSize(leftRoundedCorner, testTopRadius);
+        verify(mScreenDecorations, atLeastOnce()).setSize(rightRoundedCorner, testBottomRadius);
+    }
+
+    @Test
     public void testRoundingMultipleRadius_NoCutout() {
         final VectorDrawable d = (VectorDrawable) mContext.getDrawable(R.drawable.rounded);
         final int multipleRadiusSize = Math.max(d.getIntrinsicWidth(), d.getIntrinsicHeight());