Removed the experimental code for gestural mode

Removing the experimental code that separated the navigation bar window
height/width and the visual height/width. Also added a gesture inset
to calculate the difference between navigation bar window and the
gesture size.

Bug: 113952590
Test: manual
Change-Id: I925bd1a4a412786f5fe1fc48ed756e3699cbaf65
diff --git a/core/res/res/values/dimens.xml b/core/res/res/values/dimens.xml
index b81db15..e5bf088 100644
--- a/core/res/res/values/dimens.xml
+++ b/core/res/res/values/dimens.xml
@@ -51,18 +51,23 @@
          that just start below the notch. -->
     <dimen name="display_cutout_touchable_region_size">12dp</dimen>
 
-    <!-- EXPERIMENT BEGIN -->
     <!-- Height of the bottom navigation bar frame; this is different than navigation_bar_height
          where that is the height reported to all the other windows to resize themselves around the
          navigation bar window but navigation_bar_frame_height is reported to SystemUI navigation
          bar view's window -->
     <dimen name="navigation_bar_frame_height">@dimen/navigation_bar_height</dimen>
+    <!-- Height of the bottom navigation bar frame in landscape -->
+    <dimen name="navigation_bar_frame_height_landscape">@dimen/navigation_bar_frame_height</dimen>
     <!-- Width of the left/right navigation bar frame; this is different than navigation_bar_width
          where that is the width reported to all the other windows to resize themselves around the
          navigation bar window but navigation_bar_frame_width is reported to SystemUI navigation
          bar view's window -->
     <dimen name="navigation_bar_frame_width">@dimen/navigation_bar_width</dimen>
-    <!-- EXPERIMENT END-->
+
+    <!-- The height of the navigation gesture area; if the size is larger than the navigation bar
+        frame width/height, then the difference is the spacing from the navigation bar window to
+        the area that detects gestures. -->
+    <dimen name="navigation_bar_gesture_height">@dimen/navigation_bar_frame_height</dimen>
 
     <!-- Height of the bottom navigation / system bar in car mode. -->
     <dimen name="navigation_bar_height_car_mode">96dp</dimen>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index a6a0c6e..196e205 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -1746,6 +1746,8 @@
   <java-symbol type="dimen" name="navigation_bar_height_landscape" />
   <java-symbol type="dimen" name="navigation_bar_width" />
   <java-symbol type="dimen" name="navigation_bar_frame_height" />
+  <java-symbol type="dimen" name="navigation_bar_frame_height_landscape" />
+  <java-symbol type="dimen" name="navigation_bar_gesture_height" />
   <java-symbol type="dimen" name="navigation_bar_frame_width" />
   <java-symbol type="dimen" name="navigation_bar_height_car_mode" />
   <java-symbol type="dimen" name="navigation_bar_height_landscape_car_mode" />
diff --git a/services/core/java/com/android/server/wm/DisplayPolicy.java b/services/core/java/com/android/server/wm/DisplayPolicy.java
index bd874ba..6f3dee4 100644
--- a/services/core/java/com/android/server/wm/DisplayPolicy.java
+++ b/services/core/java/com/android/server/wm/DisplayPolicy.java
@@ -268,6 +268,9 @@
     private int[] mNavigationBarHeightForRotationInCarMode = new int[4];
     private int[] mNavigationBarWidthForRotationInCarMode = new int[4];
 
+    /** See {@link #getNavigationBarFrameHeight} */
+    private int[] mNavigationBarFrameHeightForRotationDefault = new int[4];
+
     /** Cached value of {@link ScreenShapeHelper#getWindowOutsetBottomPx} */
     @Px private int mWindowOutsetBottom;
 
@@ -286,10 +289,6 @@
                 }
             };
 
-    // EXPERIMENT TODO(b/113952590): Remove once experiment in bug is completed
-    private NavigationBarExperiments mExperiments = new NavigationBarExperiments();
-    // EXPERIMENT END
-
     @GuardedBy("mHandler")
     private SleepToken mDreamingSleepToken;
 
@@ -1607,11 +1606,9 @@
             // It's a system nav bar or a portrait screen; nav bar goes on bottom.
             final int top = cutoutSafeUnrestricted.bottom
                     - getNavigationBarHeight(rotation, uiMode);
-            // EXPERIMENT TODO(b/113952590): Remove once experiment in bug is completed
             final int topNavBar = cutoutSafeUnrestricted.bottom
-                    - mExperiments.getNavigationBarFrameHeight();
+                    - getNavigationBarFrameHeight(rotation, uiMode);
             navigationFrame.set(0, topNavBar, displayWidth, displayFrames.mUnrestricted.bottom);
-            // EXPERIMENT END
             displayFrames.mStable.bottom = displayFrames.mStableFullscreen.bottom = top;
             if (transientNavBarShowing) {
                 mNavigationBarController.setBarShowingLw(true);
@@ -1634,11 +1631,7 @@
             // Landscape screen; nav bar goes to the right.
             final int left = cutoutSafeUnrestricted.right
                     - getNavigationBarWidth(rotation, uiMode);
-            // EXPERIMENT TODO(b/113952590): Remove once experiment in bug is completed
-            final int leftNavBar = cutoutSafeUnrestricted.right
-                    - mExperiments.getNavigationBarFrameWidth();
-            navigationFrame.set(leftNavBar, 0, displayFrames.mUnrestricted.right, displayHeight);
-            // EXPERIMENT END
+            navigationFrame.set(left, 0, displayFrames.mUnrestricted.right, displayHeight);
             displayFrames.mStable.right = displayFrames.mStableFullscreen.right = left;
             if (transientNavBarShowing) {
                 mNavigationBarController.setBarShowingLw(true);
@@ -1661,11 +1654,7 @@
             // Seascape screen; nav bar goes to the left.
             final int right = cutoutSafeUnrestricted.left
                     + getNavigationBarWidth(rotation, uiMode);
-            // EXPERIMENT TODO(b/113952590): Remove once experiment in bug is completed
-            final int rightNavBar = cutoutSafeUnrestricted.left
-                    + mExperiments.getNavigationBarFrameWidth();
-            navigationFrame.set(displayFrames.mUnrestricted.left, 0, rightNavBar, displayHeight);
-            // EXPERIMENT END
+            navigationFrame.set(displayFrames.mUnrestricted.left, 0, right, displayHeight);
             displayFrames.mStable.left = displayFrames.mStableFullscreen.left = right;
             if (transientNavBarShowing) {
                 mNavigationBarController.setBarShowingLw(true);
@@ -1873,10 +1862,21 @@
                 }
             }
 
-            // EXPERIMENT TODO(b/113952590): Remove once experiment in bug is completed
-            // Offset the ime to avoid overlapping with the nav bar
-            mExperiments.offsetWindowFramesForNavBar(mNavigationBarPosition, win);
-            // EXPERIMENT END
+            // In case the navigation bar is on the bottom, we use the frame height instead of the
+            // regular height for the insets we send to the IME as we need some space to show
+            // additional buttons in SystemUI when the IME is up.
+            if (mNavigationBarPosition == NAV_BAR_BOTTOM) {
+                final int rotation = displayFrames.mRotation;
+                final int uimode = mService.mPolicy.getUiMode();
+                final int navHeightOffset = getNavigationBarFrameHeight(rotation, uimode)
+                        - getNavigationBarHeight(rotation, uimode);
+                if (navHeightOffset > 0) {
+                    cf.bottom -= navHeightOffset;
+                    sf.bottom -= navHeightOffset;
+                    vf.bottom -= navHeightOffset;
+                    dcf.bottom -= navHeightOffset;
+                }
+            }
 
             // IM dock windows always go to the bottom of the screen.
             attrs.gravity = Gravity.BOTTOM;
@@ -2609,6 +2609,7 @@
         final int upsideDownRotation = displayRotation.getUpsideDownRotation();
         final int landscapeRotation = displayRotation.getLandscapeRotation();
         final int seascapeRotation = displayRotation.getSeascapeRotation();
+        final int uiMode = mService.mPolicy.getUiMode();
 
         if (hasStatusBar()) {
             mStatusBarHeightForRotation[portraitRotation] =
@@ -2632,6 +2633,14 @@
         mNavigationBarHeightForRotationDefault[seascapeRotation] =
                 res.getDimensionPixelSize(R.dimen.navigation_bar_height_landscape);
 
+        // Height of the navigation bar frame when presented horizontally at bottom
+        mNavigationBarFrameHeightForRotationDefault[portraitRotation] =
+        mNavigationBarFrameHeightForRotationDefault[upsideDownRotation] =
+                res.getDimensionPixelSize(R.dimen.navigation_bar_frame_height);
+        mNavigationBarFrameHeightForRotationDefault[landscapeRotation] =
+        mNavigationBarFrameHeightForRotationDefault[seascapeRotation] =
+                res.getDimensionPixelSize(R.dimen.navigation_bar_frame_height_landscape);
+
         // Width of the navigation bar when presented vertically along one side
         mNavigationBarWidthForRotationDefault[portraitRotation] =
         mNavigationBarWidthForRotationDefault[upsideDownRotation] =
@@ -2660,16 +2669,10 @@
         mSideGestureInset = res.getDimensionPixelSize(R.dimen.config_backGestureInset);
         mNavigationBarLetsThroughTaps = res.getBoolean(R.bool.config_navBarTapThrough);
 
-        // EXPERIMENT TODO(b/113952590): Remove once experiment in bug is completed
-        mExperiments.onConfigurationChanged(uiContext);
-        // EXPERIMENT END
-
-        // EXPERIMENT: TODO(b/113952590): Replace with real code after experiment.
-        // This should calculate how much above the frame we accept gestures. Currently,
-        // we extend the frame to capture the gestures, so this is 0.
-        mBottomGestureAdditionalInset = mExperiments.getNavigationBarFrameHeight()
-                - mExperiments.getNavigationBarFrameHeight();
-        // EXPERIMENT END
+        // This should calculate how much above the frame we accept gestures.
+        mBottomGestureAdditionalInset = Math.max(0,
+                res.getDimensionPixelSize(R.dimen.navigation_bar_gesture_height)
+                        - getNavigationBarFrameHeight(portraitRotation, uiMode));
 
         updateConfigurationAndScreenSizeDependentBehaviors();
         mWindowOutsetBottom = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
@@ -2735,6 +2738,26 @@
     }
 
     /**
+     * Get the Navigation Bar Frame height. This dimension is the height of the navigation bar that
+     * is used for spacing to show additional buttons on the navigation bar (such as the ime
+     * switcher when ime is visible) while {@link #getNavigationBarHeight} is used for the visible
+     * height that we send to the app as content insets that can be smaller.
+     * <p>
+     * In car mode it will return the same height as {@link #getNavigationBarHeight}
+     *
+     * @param rotation specifies rotation to return dimension from
+     * @param uiMode to determine if in car mode
+     * @return navigation bar frame height
+     */
+    private int getNavigationBarFrameHeight(int rotation, int uiMode) {
+        if (ALTERNATE_CAR_MODE_NAV_SIZE && (uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
+            return mNavigationBarHeightForRotationInCarMode[rotation];
+        } else {
+            return mNavigationBarFrameHeightForRotationDefault[rotation];
+        }
+    }
+
+    /**
      * Return the display height available after excluding any screen
      * decorations that could never be removed in Honeycomb. That is, system bar or
      * button bar.
diff --git a/services/core/java/com/android/server/wm/NavigationBarExperiments.java b/services/core/java/com/android/server/wm/NavigationBarExperiments.java
deleted file mode 100644
index bb3ff5e..0000000
--- a/services/core/java/com/android/server/wm/NavigationBarExperiments.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.server.wm;
-
-import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
-import static android.view.WindowManagerPolicyConstants.NAV_BAR_BOTTOM;
-import static android.view.WindowManagerPolicyConstants.NAV_BAR_LEFT;
-import static android.view.WindowManagerPolicyConstants.NAV_BAR_RIGHT;
-
-import android.content.Context;
-import android.graphics.Rect;
-
-/**
- * This class acts as a proxy for Navigation Bar experiments enabled with custom overlays
- * {@see OverlayManagerService}. By default with no overlays, this class will essentially do nothing
- * and pass the original resource data back. By default the navigation bar height/width is the same
- * as the frame height/width and therefore any offsets calculated will cancel out and do nothing.
- * TODO(b/113952590): Remove class once experiment in bug is completed
- */
-public class NavigationBarExperiments {
-
-    private int mNavigationBarHeight;
-    private int mNavigationBarWidth;
-
-    /**
-     * This represents the height of the navigation bar buttons. With no experiments or overlays
-     * enabled, the frame height is the same as the normal navigation bar height.
-     */
-    private int mNavigationBarFrameHeight;
-
-    /**
-     * This represents the width of the navigation bar buttons. With no experiments or overlays
-     * enabled, the frame width is the same as the normal navigation bar width.
-     */
-    private int mNavigationBarFrameWidth;
-
-    /**
-     * Call when configuration change to refresh resource dimensions
-     * @param systemUiContext to get the resource values
-     */
-    public void onConfigurationChanged(Context systemUiContext) {
-        // Cache all the values again
-        mNavigationBarHeight = systemUiContext.getResources().getDimensionPixelSize(
-                com.android.internal.R.dimen.navigation_bar_height);
-        mNavigationBarWidth = systemUiContext.getResources().getDimensionPixelSize(
-                com.android.internal.R.dimen.navigation_bar_width);
-        mNavigationBarFrameHeight = systemUiContext.getResources().getDimensionPixelSize(
-                com.android.internal.R.dimen.navigation_bar_frame_height);
-        mNavigationBarFrameWidth = systemUiContext.getResources().getDimensionPixelSize(
-                com.android.internal.R.dimen.navigation_bar_frame_width);
-    }
-
-    public int getNavigationBarHeight() {
-        return mNavigationBarHeight;
-    }
-
-    public int getNavigationBarWidth() {
-        return mNavigationBarWidth;
-    }
-
-    public int getNavigationBarFrameHeight() {
-        return mNavigationBarFrameHeight;
-    }
-
-    public int getNavigationBarFrameWidth() {
-        return mNavigationBarFrameWidth;
-    }
-
-    /**
-     * If navigation frame width/height is different than navigation bar width/height then only
-     * offset the ime's and home activity's window rects depending on the navigation bar position to
-     * add a gap where the navigation bar would have been drawn. With no experiments or overlays
-     * enabled, the height/width is the same as the frame height/width and the offsets calculated
-     * will be 0 and this function will do nothing.
-     * @param navPosition position of navigation bar (left, right or bottom)
-     * @param w the window that is being offset by experiment
-     */
-    public void offsetWindowFramesForNavBar(int navPosition, WindowState w) {
-        if (w.getAttrs().type != TYPE_INPUT_METHOD) {
-            return;
-        }
-
-        final WindowFrames windowFrames = w.getWindowFrames();
-        final Rect cf = windowFrames.mContentFrame;
-        switch (navPosition) {
-            case NAV_BAR_BOTTOM:
-                int navHeight = getNavigationBarFrameHeight() - getNavigationBarHeight();
-                if (navHeight > 0) {
-                    cf.bottom -= navHeight;
-                    windowFrames.mStableFrame.bottom -= navHeight;
-                }
-                break;
-            case NAV_BAR_LEFT:
-            case NAV_BAR_RIGHT:
-                int navWidth = getNavigationBarFrameWidth() - getNavigationBarWidth();
-                if (navWidth > 0) {
-                    if (navPosition == NAV_BAR_LEFT) {
-                        cf.left += navWidth;
-                    } else {
-                        cf.right -= navWidth;
-                    }
-                }
-                break;
-        }
-    }
-}