Merge 24Q3 (ab/11976889) to aosp-main-future

Bug: 347831320
Merged-In: I9cb155e852cab0965550cfb45815c89d96745e30
Change-Id: I5795e535b5a06e569cf9d3e64d07d28c989b8b79
diff --git a/Android.bp b/Android.bp
index 39b80a1..24f41b1 100644
--- a/Android.bp
+++ b/Android.bp
@@ -8,6 +8,7 @@
     manifest: "AndroidManifest.xml",
     srcs: ["**/*.java"],
     exclude_srcs: ["src/com/android/htmlviewer/CarHTMLViewerActivity.java"],
+    static_libs: ["androidx.core_core"],
     sdk_version: "current",
 }
 
@@ -17,6 +18,9 @@
     overrides: ["HTMLViewer"],
     srcs: ["**/*.java"],
     libs: ["android.car-stubs"],
-    static_libs: ["car-ui-lib"],
+    static_libs: [
+        "androidx.core_core",
+        "car-ui-lib",
+    ],
     sdk_version: "current",
 }
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index f6b8db3..90dcf3e 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -26,7 +26,7 @@
          android:supportsRtl="true">
         <activity android:name="HTMLViewerActivity"
              android:label="@string/app_label"
-             android:theme="@android:style/Theme.DeviceDefault.Settings"
+             android:theme="@style/Theme.HTMLViewer"
              android:exported="true">
             <intent-filter>
                 <category android:name="android.intent.category.DEFAULT"/>
diff --git a/res/values/themes.xml b/res/values/themes.xml
new file mode 100644
index 0000000..d1ce102
--- /dev/null
+++ b/res/values/themes.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Copyright (C) 2024 The Android Open Source Project
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+  -->
+
+<resources>
+    <style name="Theme.HTMLViewer" parent="@android:style/Theme.DeviceDefault.Settings">
+        <item name="android:windowOptOutEdgeToEdgeEnforcement">true</item>
+    </style>
+</resources>
\ No newline at end of file
diff --git a/src/com/android/htmlviewer/HTMLViewerActivity.java b/src/com/android/htmlviewer/HTMLViewerActivity.java
index 233a87d..ded052c 100644
--- a/src/com/android/htmlviewer/HTMLViewerActivity.java
+++ b/src/com/android/htmlviewer/HTMLViewerActivity.java
@@ -34,6 +34,11 @@
 import android.webkit.WebViewClient;
 import android.widget.Toast;
 
+import androidx.core.graphics.Insets;
+import androidx.core.view.ViewCompat;
+import androidx.core.view.WindowCompat;
+import androidx.core.view.WindowInsetsCompat;
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URISyntaxException;
@@ -84,6 +89,7 @@
     }
 
     protected void setContentView() {
+        setupEdgeToEdge();
         setContentView(R.layout.main);
     }
 
@@ -187,4 +193,20 @@
             return null;
         }
     }
+
+    private void setupEdgeToEdge() {
+        // Shamelessly copied from SettingsHomepageActivity
+        // https://cs.android.com/android/platform/superproject/main/+/main:packages/apps/Settings/src/com/android/settings/homepage/SettingsHomepageActivity.java;l=355;drc=6b4b7336bc0bdbbdbd144429b8dfb006503d6a7b
+        WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
+        ViewCompat.setOnApplyWindowInsetsListener(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;
+                });
+    }
 }