Update BubbleExpandedView inset & height

The inset code for the IME would be too big if there was a notch. This CL
changes the displaySize to be the "real" displaySize, which makes
calculations more obvious & fixes notch issue.

Fixes an issue where the max height of the view was subtracting the
"manage" button height twice. Also subtracts the bottom inset from max
height since we're using the "real" display size.

Removes some obsolete code that was needed when bubbles were at the bottom,
this fixes a weird animation glitch with the height when expanding bubbles.

Fixes: 139002444
Test: manual - expand a bubble, make it max height, focus the IME
             - repeat above with all the different notch configurations
               in developer options
             - also toggle the different nav options (navbar & gesture)

Change-Id: I59e60864369d1bd3a15480c56b7b3fbe98b2fc16
diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java
index 18d9fe7..0ac79f5 100644
--- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java
+++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java
@@ -193,7 +193,8 @@
         mPm = context.getPackageManager();
         mDisplaySize = new Point();
         WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
-        wm.getDefaultDisplay().getSize(mDisplaySize);
+        // Get the real size -- this includes screen decorations (notches, statusbar, navbar).
+        wm.getDefaultDisplay().getRealSize(mDisplaySize);
         Resources res = getResources();
         mMinHeight = res.getDimensionPixelSize(R.dimen.bubble_expanded_default_height);
         mPointerMargin = res.getDimensionPixelSize(R.dimen.bubble_pointer_margin);
@@ -313,12 +314,10 @@
      */
     void updateInsets(WindowInsets insets) {
         if (usingActivityView()) {
-            int[] windowLocation = mActivityView.getLocationOnScreen();
-            final int windowBottom = windowLocation[1] + mActivityView.getHeight();
-            final int keyboardHeight = insets.getSystemWindowInsetBottom()
-                    - insets.getStableInsetBottom();
-            final int insetsBottom = Math.max(0,
-                    windowBottom + keyboardHeight - mDisplaySize.y);
+            int[] screenLoc = mActivityView.getLocationOnScreen();
+            final int activityViewBottom = screenLoc[1] + mActivityView.getHeight();
+            final int keyboardTop = mDisplaySize.y - insets.getSystemWindowInsetBottom();
+            final int insetsBottom = Math.max(activityViewBottom - keyboardTop, 0);
             mActivityView.setForwardedInsets(Insets.of(0, 0, 0, insetsBottom));
         }
     }
@@ -415,10 +414,8 @@
             Log.d(TAG, "updateHeight: bubble=" + getBubbleKey());
         }
         if (usingActivityView()) {
-            int max = getMaxExpandedHeight() - mSettingsIconHeight - mPointerHeight
-                    - mPointerMargin;
             float desiredHeight = Math.max(mBubble.getDesiredHeight(mContext), mMinHeight);
-            float height = Math.min(desiredHeight, max);
+            float height = Math.min(desiredHeight, getMaxExpandedHeight());
             height = Math.max(height, mMinHeight);
             LayoutParams lp = (LayoutParams) mActivityView.getLayoutParams();
             mNeedsNewHeight =  lp.height != height;
@@ -438,7 +435,11 @@
 
     private int getMaxExpandedHeight() {
         int[] windowLocation = mActivityView.getLocationOnScreen();
-        return mDisplaySize.y - windowLocation[1] - mSettingsIconHeight;
+        int bottomInset = getRootWindowInsets() != null
+                ? getRootWindowInsets().getStableInsetBottom()
+                : 0;
+        return mDisplaySize.y - windowLocation[1] - mSettingsIconHeight - mPointerHeight
+                - mPointerMargin - bottomInset;
     }
 
     /**
diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java
index c06e2d5f..e7be07c 100644
--- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java
+++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java
@@ -408,14 +408,6 @@
             if (!mIsExpanded || mIsExpansionAnimating) {
                 return view.onApplyWindowInsets(insets);
             }
-
-            float newY = getExpandedViewY();
-            if (newY < 0) {
-                // TODO: This means our expanded content is too big to fit on screen. Right now
-                // we'll let it translate off but we should be clipping it & pushing the header
-                // down so that it always remains visible.
-            }
-            mExpandedViewYAnim.animateToFinalPosition(newY);
             mExpandedAnimationController.updateYPosition(
                     // Update the insets after we're done translating otherwise position
                     // calculation for them won't be correct.