Merge "IME always provides bottom insets, if any"
diff --git a/core/java/android/view/InsetsAnimationControlImpl.java b/core/java/android/view/InsetsAnimationControlImpl.java
index e863aa0..5c24047 100644
--- a/core/java/android/view/InsetsAnimationControlImpl.java
+++ b/core/java/android/view/InsetsAnimationControlImpl.java
@@ -272,8 +272,8 @@
             if (leash != null) {
                 // TODO: use a better interpolation for fade.
                 alpha = mFade ? ((float) maxInset / inset * 0.3f + 0.7f) : alpha;
-                surfaceParams.add(new SurfaceParams(leash, alpha, mTmpMatrix,
-                        null /* windowCrop */, 0 /* layer */, 0f /* cornerRadius*/,
+                surfaceParams.add(new SurfaceParams(leash, side == ISIDE_FLOATING ? 1 : alpha,
+                        mTmpMatrix, null /* windowCrop */, 0 /* layer */, 0f /* cornerRadius*/,
                         side == ISIDE_FLOATING ? state.getSource(source.getType()).isVisible()
                                 : inset != 0 /* visible */));
             }
diff --git a/core/java/android/view/InsetsSource.java b/core/java/android/view/InsetsSource.java
index 67ccfd6..37034ee 100644
--- a/core/java/android/view/InsetsSource.java
+++ b/core/java/android/view/InsetsSource.java
@@ -16,6 +16,8 @@
 
 package android.view;
 
+import static android.view.InsetsState.ITYPE_IME;
+
 import android.annotation.Nullable;
 import android.graphics.Insets;
 import android.graphics.Rect;
@@ -109,6 +111,12 @@
             return Insets.NONE;
         }
 
+        // TODO: Currently, non-floating IME always intersects at bottom due to issues with cutout.
+        // However, we should let the policy decide from the server.
+        if (getType() == ITYPE_IME) {
+            return Insets.of(0, 0, 0, mTmpFrame.height());
+        }
+
         // Intersecting at top/bottom
         if (mTmpFrame.width() == relativeFrame.width()) {
             if (mTmpFrame.top == relativeFrame.top) {
diff --git a/core/tests/coretests/src/android/view/InsetsSourceTest.java b/core/tests/coretests/src/android/view/InsetsSourceTest.java
index e3b08bb..756d63d 100644
--- a/core/tests/coretests/src/android/view/InsetsSourceTest.java
+++ b/core/tests/coretests/src/android/view/InsetsSourceTest.java
@@ -16,6 +16,7 @@
 
 package android.view;
 
+import static android.view.InsetsState.ITYPE_IME;
 import static android.view.InsetsState.ITYPE_NAVIGATION_BAR;
 
 import static org.junit.Assert.assertEquals;
@@ -44,10 +45,12 @@
 public class InsetsSourceTest {
 
     private InsetsSource mSource = new InsetsSource(ITYPE_NAVIGATION_BAR);
+    private InsetsSource mImeSource = new InsetsSource(ITYPE_IME);
 
     @Before
     public void setUp() {
         mSource.setVisible(true);
+        mImeSource.setVisible(true);
     }
 
     @Test
@@ -91,6 +94,14 @@
     }
 
     @Test
+    public void testCalculateInsets_ime_leftCutout() {
+        mImeSource.setFrame(new Rect(100, 400, 500, 500));
+        Insets insets = mImeSource.calculateInsets(new Rect(0, 0, 500, 500),
+                false /* ignoreVisibility */);
+        assertEquals(Insets.of(0, 0, 0, 100), insets);
+    }
+
+    @Test
     public void testCalculateInsets_invisible() {
         mSource.setFrame(new Rect(0, 0, 500, 100));
         mSource.setVisible(false);