Remove Close Button From Handle Menu in Freeform

When in freeform desktop windowing mode, the close button should be removed.

Test: Manual
Bug: 296629876
Change-Id: Ic0f4c5aa7d22045c5cd7da46abd1c4beac08b6d2
diff --git a/libs/WindowManager/Shell/res/values/dimen.xml b/libs/WindowManager/Shell/res/values/dimen.xml
index 7edf2fc..cba86c8 100644
--- a/libs/WindowManager/Shell/res/values/dimen.xml
+++ b/libs/WindowManager/Shell/res/values/dimen.xml
@@ -428,9 +428,12 @@
     <!-- The height of the handle menu's "Windowing" pill in desktop mode. -->
     <dimen name="desktop_mode_handle_menu_windowing_pill_height">52dp</dimen>
 
-    <!-- The height of the handle menu's "More Actions" pill in desktop mode. -->
+    <!-- The height of the handle menu's "More Actions" pill in desktop mode, but not freeform. -->
     <dimen name="desktop_mode_handle_menu_more_actions_pill_height">156dp</dimen>
 
+    <!-- The height of the handle menu's "More Actions" pill in freeform desktop windowing mode. -->
+    <dimen name="desktop_mode_handle_menu_more_actions_pill_freeform_height">104dp</dimen>
+
     <!-- The top margin of the handle menu in desktop mode. -->
     <dimen name="desktop_mode_handle_menu_margin_top">4dp</dimen>
 
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/HandleMenu.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/HandleMenu.java
index ca7cbfd..42b1240 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/HandleMenu.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/HandleMenu.java
@@ -186,7 +186,12 @@
         // More Actions pill setup.
         final View moreActionsPillView = mMoreActionsPill.mWindowViewHost.getView();
         final Button closeBtn = moreActionsPillView.findViewById(R.id.close_button);
-        closeBtn.setOnClickListener(mOnClickListener);
+        if (mTaskInfo.getWindowingMode() == WINDOWING_MODE_FREEFORM) {
+            closeBtn.setVisibility(View.GONE);
+        } else {
+            closeBtn.setVisibility(View.VISIBLE);
+            closeBtn.setOnClickListener(mOnClickListener);
+        }
         final Button selectBtn = moreActionsPillView.findViewById(R.id.select_button);
         selectBtn.setOnClickListener(mOnClickListener);
     }
@@ -228,7 +233,6 @@
 
     /**
      * Update pill layout, in case task changes have caused positioning to change.
-     * @param t
      */
     void relayout(SurfaceControl.Transaction t) {
         if (mAppInfoPill != null) {
@@ -245,10 +249,12 @@
                     mMoreActionsPillPosition.x, mMoreActionsPillPosition.y);
         }
     }
+
     /**
      * Check a passed MotionEvent if a click has occurred on any button on this caption
      * Note this should only be called when a regular onClick is not possible
      * (i.e. the button was clicked through status bar layer)
+     *
      * @param ev the MotionEvent to compare against.
      */
     void checkClickEvent(MotionEvent ev) {
@@ -267,6 +273,7 @@
      * A valid menu input is one of the following:
      * An input that happens in the menu views.
      * Any input before the views have been laid out.
+     *
      * @param inputPoint the input to compare against.
      */
     boolean isValidMenuInput(PointF inputPoint) {
@@ -297,7 +304,6 @@
 
     /**
      * Check if the views for handle menu can be seen.
-     * @return
      */
     private boolean viewsLaidOut() {
         return mAppInfoPill.mWindowViewHost.getView().isLaidOut();
@@ -318,8 +324,7 @@
                 R.dimen.desktop_mode_handle_menu_app_info_pill_height);
         mWindowingPillHeight = loadDimensionPixelSize(resources,
                 R.dimen.desktop_mode_handle_menu_windowing_pill_height);
-        mMoreActionsPillHeight = loadDimensionPixelSize(resources,
-                R.dimen.desktop_mode_handle_menu_more_actions_pill_height);
+        mMoreActionsPillHeight = shouldShowCloseButton(resources);
         mShadowRadius = loadDimensionPixelSize(resources,
                 R.dimen.desktop_mode_handle_menu_shadow_radius);
         mCornerRadius = loadDimensionPixelSize(resources,
@@ -333,6 +338,14 @@
         return resources.getDimensionPixelSize(resourceId);
     }
 
+    private int shouldShowCloseButton(Resources resources) {
+        return (mTaskInfo.getWindowingMode() == WINDOWING_MODE_FREEFORM)
+                ? loadDimensionPixelSize(resources,
+                R.dimen.desktop_mode_handle_menu_more_actions_pill_freeform_height)
+                : loadDimensionPixelSize(resources,
+                        R.dimen.desktop_mode_handle_menu_more_actions_pill_height);
+    }
+
     void close() {
         mAppInfoPill.releaseView();
         mAppInfoPill = null;