Allowing Launcher to draw behind cutouts

> Launcher uses realSize, availableSize and insets to calculate
various layout values. Without drawing behind cutouts, these values
are not consistent (insets + availableSize != realSize) leading to
jumps in layouts.
> Removing fake black bars in low-ram devices to avoid inconsistent
insets.
> Fixing various layouts not taking lert/right insets into account.

Bug: 156268804
Change-Id: I8441db8a468b08a65b57b932050b5b4b37313966
diff --git a/src/com/android/launcher3/LauncherRootView.java b/src/com/android/launcher3/LauncherRootView.java
index 9ac370f..6951ff2 100644
--- a/src/com/android/launcher3/LauncherRootView.java
+++ b/src/com/android/launcher3/LauncherRootView.java
@@ -1,19 +1,12 @@
 package com.android.launcher3;
 
 import static com.android.launcher3.config.FeatureFlags.SEPARATE_RECENTS_ACTIVITY;
-import static com.android.launcher3.util.SystemUiController.FLAG_DARK_NAV;
-import static com.android.launcher3.util.SystemUiController.UI_STATE_ROOT_VIEW;
 
 import android.annotation.TargetApi;
-import android.app.ActivityManager;
 import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Color;
-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;
 
@@ -26,16 +19,10 @@
 
     private final Launcher mLauncher;
 
-    private final Paint mOpaquePaint;
-
-    @ViewDebug.ExportedProperty(category = "launcher")
-    private final Rect mConsumedInsets = new Rect();
-
     @ViewDebug.ExportedProperty(category = "launcher")
     private static final List<Rect> SYSTEM_GESTURE_EXCLUSION_RECT =
             Collections.singletonList(new Rect());
 
-    private View mAlignedView;
     private WindowStateListener mWindowStateListener;
     @ViewDebug.ExportedProperty(category = "launcher")
     private boolean mDisallowBackGesture;
@@ -44,55 +31,15 @@
 
     public LauncherRootView(Context context, AttributeSet attrs) {
         super(context, attrs);
-
-        mOpaquePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
-        mOpaquePaint.setColor(Color.BLACK);
-        mOpaquePaint.setStyle(Paint.Style.FILL);
-
         mLauncher = Launcher.getLauncher(context);
     }
 
-    @Override
-    protected void onFinishInflate() {
-        if (getChildCount() > 0) {
-            // LauncherRootView contains only one child, which should be aligned
-            // based on the horizontal insets.
-            mAlignedView = getChildAt(0);
-        }
-        super.onFinishInflate();
-    }
-
     private void handleSystemWindowInsets(Rect insets) {
-        mConsumedInsets.setEmpty();
-        boolean drawInsetBar = false;
-        if ((insets.right > 0 || insets.left > 0)
-                && getContext().getSystemService(ActivityManager.class).isLowRamDevice()) {
-            mConsumedInsets.left = insets.left;
-            mConsumedInsets.right = insets.right;
-            insets.set(0, insets.top, 0, insets.bottom);
-            drawInsetBar = true;
-        }
-
-        mLauncher.getSystemUiController().updateUiState(
-                UI_STATE_ROOT_VIEW, drawInsetBar ? FLAG_DARK_NAV : 0);
-
         // Update device profile before notifying th children.
         mLauncher.getDeviceProfile().updateInsets(insets);
         boolean resetState = !insets.equals(mInsets);
         setInsets(insets);
 
-        if (mAlignedView != null) {
-            // Apply margins on aligned view to handle consumed insets.
-            MarginLayoutParams lp = (MarginLayoutParams) mAlignedView.getLayoutParams();
-            if (lp.leftMargin != mConsumedInsets.left || lp.rightMargin != mConsumedInsets.right ||
-                    lp.bottomMargin != mConsumedInsets.bottom) {
-                lp.leftMargin = mConsumedInsets.left;
-                lp.rightMargin = mConsumedInsets.right;
-                lp.topMargin = mConsumedInsets.top;
-                lp.bottomMargin = mConsumedInsets.bottom;
-                mAlignedView.setLayoutParams(lp);
-            }
-        }
         if (resetState) {
             mLauncher.getStateManager().reapplyState(true /* cancelCurrentAnimation */);
         }
@@ -103,12 +50,7 @@
         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);
-        }
+        return insets;
     }
 
     @Override
@@ -125,24 +67,6 @@
         super.setInsets(mInsets);
     }
 
-    @Override
-    protected void dispatchDraw(Canvas canvas) {
-        super.dispatchDraw(canvas);
-
-        // If the right inset is opaque, draw a black rectangle to ensure that is stays opaque.
-        if (mConsumedInsets.right > 0) {
-            int width = getWidth();
-            canvas.drawRect(width - mConsumedInsets.right, 0, width, getHeight(), mOpaquePaint);
-        }
-        if (mConsumedInsets.left > 0) {
-            canvas.drawRect(0, 0, mConsumedInsets.left, getHeight(), mOpaquePaint);
-        }
-        if (mConsumedInsets.bottom > 0) {
-            int height = getHeight();
-            canvas.drawRect(0, height - mConsumedInsets.bottom, getWidth(), height, mOpaquePaint);
-        }
-    }
-
     public void setWindowStateListener(WindowStateListener listener) {
         mWindowStateListener = listener;
     }