Merge "Set a maximum expanded view width for large screens" into main
diff --git a/libs/WindowManager/Shell/multivalentTests/src/com/android/wm/shell/bubbles/BubblePositionerTest.kt b/libs/WindowManager/Shell/multivalentTests/src/com/android/wm/shell/bubbles/BubblePositionerTest.kt
index b38d00da..1d0c505 100644
--- a/libs/WindowManager/Shell/multivalentTests/src/com/android/wm/shell/bubbles/BubblePositionerTest.kt
+++ b/libs/WindowManager/Shell/multivalentTests/src/com/android/wm/shell/bubbles/BubblePositionerTest.kt
@@ -602,8 +602,72 @@
         testGetBubbleBarExpandedViewBounds(onLeft = false, isOverflow = true)
     }
 
+    @Test
+    fun getExpandedViewContainerPadding_largeScreen_fitsMaxViewWidth() {
+        val expandedViewWidth = context.resources.getDimensionPixelSize(
+            R.dimen.bubble_expanded_view_largescreen_width
+        )
+        // set the screen size so that it is wide enough to fit the maximum width size
+        val screenWidth = expandedViewWidth * 2
+        positioner.update(
+            defaultDeviceConfig.copy(
+                windowBounds = Rect(0, 0, screenWidth, 2000),
+                isLargeScreen = true,
+                isLandscape = false
+            )
+        )
+        val paddings =
+            positioner.getExpandedViewContainerPadding(/* onLeft= */ true, /* isOverflow= */ false)
+
+        val padding = context.resources.getDimensionPixelSize(
+            R.dimen.bubble_expanded_view_largescreen_landscape_padding
+        )
+        val right = screenWidth - expandedViewWidth - padding
+        assertThat(paddings).isEqualTo(intArrayOf(padding - positioner.pointerSize, 0, right, 0))
+    }
+
+    @Test
+    fun getExpandedViewContainerPadding_largeScreen_doesNotFitMaxViewWidth() {
+        positioner.update(
+            defaultDeviceConfig.copy(
+                windowBounds = Rect(0, 0, 600, 2000),
+                isLargeScreen = true,
+                isLandscape = false
+            )
+        )
+        val paddings =
+            positioner.getExpandedViewContainerPadding(/* onLeft= */ true, /* isOverflow= */ false)
+
+        val padding = context.resources.getDimensionPixelSize(
+            R.dimen.bubble_expanded_view_largescreen_landscape_padding
+        )
+        // the screen is not wide enough to fit the maximum width size, so the view fills the screen
+        // minus left and right padding
+        assertThat(paddings).isEqualTo(intArrayOf(padding - positioner.pointerSize, 0, padding, 0))
+    }
+
+    @Test
+    fun getExpandedViewContainerPadding_smallTablet() {
+        val screenWidth = 500
+        positioner.update(
+            defaultDeviceConfig.copy(
+                windowBounds = Rect(0, 0, screenWidth, 2000),
+                isLargeScreen = true,
+                isSmallTablet = true,
+                isLandscape = false
+            )
+        )
+        val paddings =
+            positioner.getExpandedViewContainerPadding(/* onLeft= */ true, /* isOverflow= */ false)
+
+        // for small tablets, the view width is set to be 0.72 * screen width
+        val viewWidth = (screenWidth * 0.72).toInt()
+        val padding = (screenWidth - viewWidth) / 2
+        assertThat(paddings).isEqualTo(intArrayOf(padding - positioner.pointerSize, 0, padding, 0))
+    }
+
     private fun testGetBubbleBarExpandedViewBounds(onLeft: Boolean, isOverflow: Boolean) {
-        positioner.setShowingInBubbleBar(true)
+        positioner.isShowingInBubbleBar = true
         val windowBounds = Rect(0, 0, 2000, 2600)
         val insets = Insets.of(10, 20, 5, 15)
         val deviceConfig =
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubblePositioner.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubblePositioner.java
index 0fd4206..de85d9a 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubblePositioner.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubblePositioner.java
@@ -163,8 +163,11 @@
             mExpandedViewLargeScreenWidth = (int) (bounds.width()
                     * EXPANDED_VIEW_SMALL_TABLET_WIDTH_PERCENT);
         } else {
-            mExpandedViewLargeScreenWidth =
-                    res.getDimensionPixelSize(R.dimen.bubble_expanded_view_largescreen_width);
+            int expandedViewLargeScreenSpacing = res.getDimensionPixelSize(
+                    R.dimen.bubble_expanded_view_largescreen_landscape_padding);
+            mExpandedViewLargeScreenWidth = Math.min(
+                    res.getDimensionPixelSize(R.dimen.bubble_expanded_view_largescreen_width),
+                    bounds.width() - expandedViewLargeScreenSpacing * 2);
         }
         if (mDeviceConfig.isLargeScreen()) {
             if (mDeviceConfig.isSmallTablet()) {