Define android_gsi module

android_gsi is a Soong-built GSI.

Bug: 370351758
Test: m android_gsi
Change-Id: If7ded58f3ba3c07264942c06b64f5b874395b923
diff --git a/target/product/generic/Android.bp b/target/product/generic/Android.bp
index a142f37..07e319a 100644
--- a/target/product/generic/Android.bp
+++ b/target/product/generic/Android.bp
@@ -1,4 +1,4 @@
-android_rootdirs = [
+generic_rootdirs = [
     "acct",
     "apex",
     "bootstrap-apex",
@@ -15,19 +15,22 @@
     "oem",
     "postinstall",
     "proc",
-    "product",
     "second_stage_resources",
     "storage",
     "sys",
     "system",
     "system_dlkm",
-    "system_ext",
     "tmp",
     "vendor",
     "vendor_dlkm",
 ]
 
-android_symlinks = [
+android_rootdirs = [
+    "system_ext",
+    "product",
+]
+
+generic_symlinks = [
     {
         target: "/system/bin/init",
         name: "init",
@@ -41,18 +44,10 @@
         name: "bin",
     },
     {
-        target: "/product",
-        name: "system/product",
-    },
-    {
         target: "/vendor",
         name: "system/vendor",
     },
     {
-        target: "/system_ext",
-        name: "system/system_ext",
-    },
-    {
         target: "/system_dlkm/lib/modules",
         name: "system/lib/modules",
     },
@@ -121,6 +116,17 @@
     },
 ]
 
+android_symlinks = [
+    {
+        target: "/product",
+        name: "system/product",
+    },
+    {
+        target: "/system_ext",
+        name: "system/system_ext",
+    },
+]
+
 filegroup {
     name: "generic_system_sign_key",
     srcs: [":avb_testkey_rsa4096"],
@@ -340,13 +346,17 @@
     ],
 }
 
-android_system_image {
-    name: "generic_system_image",
+filegroup {
+    name: "system_image_erofs_compress_hints.txt",
+    srcs: ["erofs_compress_hints.txt"],
+}
 
+android_filesystem_defaults {
+    name: "system_image_defaults",
     partition_name: "system",
     base_dir: "system",
-    dirs: android_rootdirs,
-    symlinks: android_symlinks,
+    dirs: generic_rootdirs,
+    symlinks: generic_symlinks,
     file_contexts: ":plat_file_contexts",
     linkerconfig: {
         gen_linker_config: true,
@@ -367,7 +377,7 @@
     type: "erofs",
     erofs: {
         compressor: "lz4hc,9",
-        compress_hints: "erofs_compress_hints.txt",
+        compress_hints: ":system_image_erofs_compress_hints.txt",
     },
     build_logtags: true,
     gen_aconfig_flags_pb: true,
@@ -873,3 +883,10 @@
         },
     },
 }
+
+android_system_image {
+    name: "generic_system_image",
+    defaults: ["system_image_defaults"],
+    dirs: android_rootdirs,
+    symlinks: android_symlinks,
+}
diff --git a/target/product/gsi/Android.bp b/target/product/gsi/Android.bp
index f18f35a..1b8f2d7 100644
--- a/target/product/gsi/Android.bp
+++ b/target/product/gsi/Android.bp
@@ -61,3 +61,139 @@
     system_ext_specific: true,
     relative_install_path: "gsi",
 }
+
+gsi_symlinks = [
+    {
+        target: "/system/system_ext",
+        name: "system_ext",
+    },
+    {
+        target: "/system/product",
+        name: "product",
+    },
+]
+
+android_system_image {
+    name: "android_gsi",
+    defaults: ["system_image_defaults"],
+    symlinks: gsi_symlinks,
+    deps: [
+        ///////////////////////////////////////////
+        // gsi_system_ext
+        ///////////////////////////////////////////
+
+        // handheld packages
+        "Launcher3QuickStep",
+        "Provision",
+        "Settings",
+        "StorageManager",
+        "SystemUI",
+
+        // telephony packages
+        "CarrierConfig",
+
+        // Install a copy of the debug policy to the system_ext partition, and allow
+        // init-second-stage to load debug policy from system_ext.
+        // This option is only meant to be set by compliance GSI targets.
+        "system_ext_userdebug_plat_sepolicy.cil",
+
+        ///////////////////////////////////////////
+        // base_system_ext
+        ///////////////////////////////////////////
+        "build_flag_system_ext",
+        "fs_config_dirs_system_ext",
+        "fs_config_files_system_ext",
+        "group_system_ext",
+        "passwd_system_ext",
+        "SatelliteClient",
+        "selinux_policy_system_ext",
+        "system_ext_manifest.xml",
+        "system_ext-build.prop",
+        // Base modules when shipping api level is less than or equal to 34
+        "hwservicemanager",
+        "android.hidl.allocator@1.0-service",
+
+        ///////////////////////////////////////////
+        // window_extensions_base
+        ///////////////////////////////////////////
+        "androidx.window.extensions",
+        "androidx.window.sidecar",
+
+        ///////////////////////////////////////////
+        // gsi_release
+        ///////////////////////////////////////////
+        "gsi_skip_mount.cfg",
+        "init.gsi.rc",
+        "init.vndk-nodef.rc",
+        // Overlay the GSI specific setting for framework and SystemUI
+        "gsi_overlay_framework",
+        "gsi_overlay_systemui",
+
+        ///////////////////////////////////////////
+        // VNDK
+        ///////////////////////////////////////////
+        "com.android.vndk.v30",
+        "com.android.vndk.v31",
+        "com.android.vndk.v32",
+        "com.android.vndk.v33",
+        "com.android.vndk.v34",
+
+        ///////////////////////////////////////////
+        // AVF
+        ///////////////////////////////////////////
+        "com.android.compos",
+        "features_com.android.virt.xml",
+
+        ///////////////////////////////////////////
+        // gsi_product
+        ///////////////////////////////////////////
+        "Browser2",
+        "Camera2",
+        "Dialer",
+        "LatinIME",
+        "apns-full-conf.xml",
+
+        ///////////////////////////////////////////
+        // media_product
+        ///////////////////////////////////////////
+        "webview",
+
+        ///////////////////////////////////////////
+        // base_product
+        ///////////////////////////////////////////
+
+        // Base modules and settings for the product partition.
+        "build_flag_product",
+        "fs_config_dirs_product",
+        "fs_config_files_product",
+        "group_product",
+        "ModuleMetadata",
+        "passwd_product",
+        "product_compatibility_matrix.xml",
+        "product_manifest.xml",
+        "selinux_policy_product",
+        "product-build.prop",
+
+        // AUDIO
+        "frameworks_sounds",
+
+        ///////////////////////////////////////////
+        // base_system
+        ///////////////////////////////////////////
+        "charger",
+    ] + select(product_variable("debuggable"), {
+        // Packages included only for eng or userdebug builds, previously debug tagged
+        true: ["adb_keys"],
+        default: [],
+    }),
+    multilib: {
+        both: {
+            // PRODUCT_PACKAGES_SHIPPING_API_LEVEL_34
+            deps: ["android.hidl.memory@1.0-impl"],
+        },
+    },
+    enabled: select(soong_config_variable("ANDROID", "PRODUCT_INSTALL_DEBUG_POLICY_TO_SYSTEM_EXT"), {
+        "true": true,
+        default: false,
+    }),
+}