Updating consumed insets when dispatching to child views

Bug: 134963243
Change-Id: I4fa072128398cfd22b906037c6c444495781c9d0
diff --git a/src/com/android/launcher3/LauncherRootView.java b/src/com/android/launcher3/LauncherRootView.java
index 49b380b..f964b8d 100644
--- a/src/com/android/launcher3/LauncherRootView.java
+++ b/src/com/android/launcher3/LauncherRootView.java
@@ -8,18 +8,22 @@
 import android.content.Context;
 import android.graphics.Canvas;
 import android.graphics.Color;
+import android.graphics.Insets;
 import android.graphics.Paint;
 import android.graphics.Rect;
 import android.os.Build;
 import android.util.AttributeSet;
 import android.view.View;
 import android.view.ViewDebug;
+import android.view.WindowInsets;
 
 import java.util.Collections;
 import java.util.List;
 
 public class LauncherRootView extends InsettableFrameLayout {
 
+    private final Rect mTempRect = new Rect();
+
     private final Launcher mLauncher;
 
     private final Paint mOpaquePaint;
@@ -56,9 +60,7 @@
         super.onFinishInflate();
     }
 
-    @TargetApi(23)
-    @Override
-    protected boolean fitSystemWindows(Rect insets) {
+    private void handleSystemWindowInsets(Rect insets) {
         mConsumedInsets.setEmpty();
         boolean drawInsetBar = false;
         if (mLauncher.isInMultiWindowMode()
@@ -66,13 +68,13 @@
             mConsumedInsets.left = insets.left;
             mConsumedInsets.right = insets.right;
             mConsumedInsets.bottom = insets.bottom;
-            insets = new Rect(0, insets.top, 0, 0);
+            insets.set(0, insets.top, 0, 0);
             drawInsetBar = true;
         } else  if ((insets.right > 0 || insets.left > 0) &&
                 getContext().getSystemService(ActivityManager.class).isLowRamDevice()) {
             mConsumedInsets.left = insets.left;
             mConsumedInsets.right = insets.right;
-            insets = new Rect(0, insets.top, 0, insets.bottom);
+            insets.set(0, insets.top, 0, insets.bottom);
             drawInsetBar = true;
         }
 
@@ -99,8 +101,19 @@
         if (resetState) {
             mLauncher.getStateManager().reapplyState(true /* cancelCurrentAnimation */);
         }
+    }
 
-        return false; // Let children get the full insets
+    @Override
+    public WindowInsets onApplyWindowInsets(WindowInsets insets) {
+        mTempRect.set(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(),
+                insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom());
+        handleSystemWindowInsets(mTempRect);
+        if (Utilities.ATLEAST_Q) {
+            return insets.inset(mConsumedInsets.left, mConsumedInsets.top,
+                    mConsumedInsets.right, mConsumedInsets.bottom);
+        } else {
+            return insets.replaceSystemWindowInsets(mTempRect);
+        }
     }
 
     @Override