Handle the Edge to Edge problem

- Fix the navigation bar overlapped problem in sub-pages.
- Use a workaround solution to handle Homepage statusbar problem.

Bug: 328622648
Fixes: 330217912
Test: manual test
Change-Id: I67a65e2af10def84bf743d4d3cd0047098423ffe
diff --git a/res/values/themes.xml b/res/values/themes.xml
index b149bb8..73a7d67 100644
--- a/res/values/themes.xml
+++ b/res/values/themes.xml
@@ -192,6 +192,9 @@
 
         <!-- Define this color for material design -->
         <item name="colorPrimaryVariant">@android:color/white</item>
+        <!-- Workaround for E2E modification. -->
+        <!-- TODO (b/328622648) waiting for new method instead of this attribute. -->
+        <item name="android:windowOptOutEdgeToEdgeEnforcement">true</item>
     </style>
 
     <style name="Theme.Settings.Home" parent="Theme.Settings.HomeBase">
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index c4b0014..7d1e02d 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -103,10 +103,14 @@
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 import androidx.annotation.VisibleForTesting;
+import androidx.core.graphics.Insets;
 import androidx.core.graphics.drawable.IconCompat;
 import androidx.core.graphics.drawable.RoundedBitmapDrawable;
 import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory;
+import androidx.core.view.ViewCompat;
+import androidx.core.view.WindowInsetsCompat;
 import androidx.fragment.app.Fragment;
+import androidx.fragment.app.FragmentActivity;
 import androidx.lifecycle.Lifecycle;
 
 import com.android.internal.app.UnlaunchableAppActivity;
@@ -1375,6 +1379,27 @@
                 && userManager.isQuietModeEnabled(userHandle);
     }
 
+    /**
+     * Enable new edge to edge feature.
+     *
+     * @param activity the Activity need to setup the edge to edge feature.
+     */
+    public static void setupEdgeToEdge(@NonNull FragmentActivity activity) {
+        if (com.android.window.flags.Flags.edgeToEdgeByDefault()) {
+            ViewCompat.setOnApplyWindowInsetsListener(activity.findViewById(android.R.id.content),
+                    (v, windowInsets) -> {
+                        Insets insets = windowInsets.getInsets(
+                                WindowInsetsCompat.Type.systemBars());
+                        // Apply the insets paddings to the view.
+                        v.setPadding(insets.left, insets.top, insets.right, insets.bottom);
+
+                        // Return CONSUMED if you don't want the window insets to keep being
+                        // passed down to descendant views.
+                        return WindowInsetsCompat.CONSUMED;
+                    });
+        }
+    }
+
     private static FaceManager.RemovalCallback faceManagerRemovalCallback(int userId) {
         return new FaceManager.RemovalCallback() {
             @Override
diff --git a/src/com/android/settings/core/SettingsBaseActivity.java b/src/com/android/settings/core/SettingsBaseActivity.java
index e43772e..c282498 100644
--- a/src/com/android/settings/core/SettingsBaseActivity.java
+++ b/src/com/android/settings/core/SettingsBaseActivity.java
@@ -42,6 +42,7 @@
 import com.android.settings.R;
 import com.android.settings.SetupWizardUtils;
 import com.android.settings.SubSettings;
+import com.android.settings.Utils;
 import com.android.settings.core.CategoryMixin.CategoryHandler;
 import com.android.settingslib.core.lifecycle.HideNonSystemOverlayMixin;
 import com.android.settingslib.transition.SettingsTransitionHelper.TransitionType;
@@ -91,6 +92,7 @@
             Log.w(TAG, "Devices lock task mode pinned.");
             finish();
         }
+        Utils.setupEdgeToEdge(this);
         final long startTime = System.currentTimeMillis();
         getLifecycle().addObserver(new HideNonSystemOverlayMixin(this));
         TextAppearanceConfig.setShouldLoadFontSynchronously(true);