Do let IME fit invisible insets

Otherwise, the fullscreen IME won't cover the entire display while
there is a hidden system bar.

Fix: 168657591
Test: 1. Steps in the bug.
      2. Play WindowInsetsTests with combinations of system bar
         visibilities, navigation mode, screen orientation, and display
         cutout.
Merged-in: I6e7d665c55839dfbb14c8d2e5365537416f5f6c6
Change-Id: I6e7d665c55839dfbb14c8d2e5365537416f5f6c6
(cherry picked from commit 145f71182ab1c1e0be4f128683c97403c97d2696)
diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java
index 1e78153..1926ea2 100644
--- a/core/java/android/inputmethodservice/InputMethodService.java
+++ b/core/java/android/inputmethodservice/InputMethodService.java
@@ -1215,7 +1215,6 @@
                 WindowManager.LayoutParams.TYPE_INPUT_METHOD, Gravity.BOTTOM, false);
         mWindow.getWindow().getAttributes().setFitInsetsTypes(statusBars() | navigationBars());
         mWindow.getWindow().getAttributes().setFitInsetsSides(Side.all() & ~Side.BOTTOM);
-        mWindow.getWindow().getAttributes().setFitInsetsIgnoringVisibility(true);
 
         // IME layout should always be inset by navigation bar, no matter its current visibility,
         // unless automotive requests it. Automotive devices may request the navigation bar to be
diff --git a/services/core/java/com/android/server/wm/DisplayPolicy.java b/services/core/java/com/android/server/wm/DisplayPolicy.java
index daec4d7..29881cc 100644
--- a/services/core/java/com/android/server/wm/DisplayPolicy.java
+++ b/services/core/java/com/android/server/wm/DisplayPolicy.java
@@ -549,11 +549,10 @@
                         synchronized (mLock) {
                             mDisplayContent.calculateSystemGestureExclusion(
                                     excludedRegion, null /* outUnrestricted */);
-                            final boolean sideAllowed = mNavigationBarAlwaysShowOnSideGesture
-                                    || mNavigationBarPosition == NAV_BAR_RIGHT;
-                            if (mNavigationBar != null && sideAllowed
-                                    && !mSystemGestures.currentGestureStartedInRegion(
-                                            excludedRegion)) {
+                            final boolean excluded =
+                                    mSystemGestures.currentGestureStartedInRegion(excludedRegion);
+                            if (mNavigationBar != null && (mNavigationBarPosition == NAV_BAR_RIGHT
+                                    || !excluded && mNavigationBarAlwaysShowOnSideGesture)) {
                                 requestTransientBars(mNavigationBar);
                             }
                             checkAltBarSwipeForTransientBars(ALT_BAR_RIGHT);
@@ -567,11 +566,10 @@
                         synchronized (mLock) {
                             mDisplayContent.calculateSystemGestureExclusion(
                                     excludedRegion, null /* outUnrestricted */);
-                            final boolean sideAllowed = mNavigationBarAlwaysShowOnSideGesture
-                                    || mNavigationBarPosition == NAV_BAR_LEFT;
-                            if (mNavigationBar != null && sideAllowed
-                                    && !mSystemGestures.currentGestureStartedInRegion(
-                                            excludedRegion)) {
+                            final boolean excluded =
+                                    mSystemGestures.currentGestureStartedInRegion(excludedRegion);
+                            if (mNavigationBar != null && (mNavigationBarPosition == NAV_BAR_LEFT
+                                    || !excluded && mNavigationBarAlwaysShowOnSideGesture)) {
                                 requestTransientBars(mNavigationBar);
                             }
                             checkAltBarSwipeForTransientBars(ALT_BAR_LEFT);