DO NOT MERGE Fix StatusIconPanelController#attachPanel to account for gravity

Bug: 203701201
Test: Manual
Change-Id: Ie86569242ce986a651c1ffa25530d657236edc2a
diff --git a/src/com/android/systemui/car/statusicon/StatusIconPanelController.java b/src/com/android/systemui/car/statusicon/StatusIconPanelController.java
index e30837f..82c2118 100644
--- a/src/com/android/systemui/car/statusicon/StatusIconPanelController.java
+++ b/src/com/android/systemui/car/statusicon/StatusIconPanelController.java
@@ -157,13 +157,32 @@
 
     /**
      * Attaches a panel to a root view that toggles the panel visibility when clicked.
+     *
+     * Variant of {@link #attachPanel(View, int, int, int, int, int)} with
+     * xOffset={@code 0}, yOffset={@link #mYOffsetPixel} &
+     * gravity={@link #DEFAULT_POPUP_WINDOW_ANCHOR_GRAVITY}.
      */
     public void attachPanel(View view, @LayoutRes int layoutRes, @DimenRes int widthRes) {
-        attachPanel(view, layoutRes, widthRes, /* xOffset= */ 0,  /* yOffset= */0);
+        attachPanel(view, layoutRes, widthRes, DEFAULT_POPUP_WINDOW_ANCHOR_GRAVITY);
     }
 
     /**
      * Attaches a panel to a root view that toggles the panel visibility when clicked.
+     *
+     * Variant of {@link #attachPanel(View, int, int, int, int, int)} with
+     * xOffset={@code 0} & yOffset={@link #mYOffsetPixel}.
+     */
+    public void attachPanel(View view, @LayoutRes int layoutRes, @DimenRes int widthRes,
+            int gravity) {
+        attachPanel(view, layoutRes, widthRes, /* xOffset= */ 0, mYOffsetPixel,
+                gravity);
+    }
+
+    /**
+     * Attaches a panel to a root view that toggles the panel visibility when clicked.
+     *
+     * Variant of {@link #attachPanel(View, int, int, int, int, int)} with
+     * gravity={@link #DEFAULT_POPUP_WINDOW_ANCHOR_GRAVITY}.
      */
     public void attachPanel(View view, @LayoutRes int layoutRes, @DimenRes int widthRes,
             int xOffset, int yOffset) {
@@ -205,7 +224,7 @@
             registerFocusListener(true);
 
             // TODO(b/202563671): remove yOffsetPixel when the PopupWindow API is updated.
-            mPanel.showAsDropDown(mAnchorView, /* xoff= */ 0, mYOffsetPixel);
+            mPanel.showAsDropDown(mAnchorView, xOffset, yOffset, gravity);
             mAnchorView.setSelected(true);
             highlightStatusIcon(true);
 
diff --git a/src/com/android/systemui/car/systembar/CarSystemBarController.java b/src/com/android/systemui/car/systembar/CarSystemBarController.java
index e9c3fbf..ba95492 100644
--- a/src/com/android/systemui/car/systembar/CarSystemBarController.java
+++ b/src/com/android/systemui/car/systembar/CarSystemBarController.java
@@ -270,9 +270,10 @@
             }
         }));
 
-        mMicPanelController.attachPanel(mTopView.requireViewById(R.id.privacy_chip),
-                R.layout.qc_mic_panel, R.dimen.car_mic_qc_panel_width,
-                /* xOffset= */ 0, /* yOffset= */ 0, Gravity.TOP | Gravity.END);
+        View micPrivacyChipFocusView =
+                mTopView.requireViewById(R.id.privacy_chip).requireViewById(R.id.focus_view);
+        mMicPanelController.attachPanel(micPrivacyChipFocusView, R.layout.qc_mic_panel,
+                R.dimen.car_mic_qc_panel_width, Gravity.TOP | Gravity.END);
     }
 
     /** Sets a touch listener for the top navigation bar. */