// Copyright 2020 Google Inc. All rights reserved.
//
// 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.

package {
    // See: http://go/android-license-faq
    default_applicable_licenses: ["Android-Apache-2.0"],
}

filegroup {
    name: "vndk_lib_lists",
    srcs: [
        "*.txt",
    ],
}

prebuilt_etc {
    name: "gsi_skip_mount.cfg",
    filename: "skip_mount.cfg",
    src: "gsi_skip_mount.cfg",

    system_ext_specific: true,
    relative_install_path: "init/config",

    required: ["gsi_skip_mount_compat_symlink"],
}

// Adds a symlink under /system/etc/init/config pointing to /system/system_ext/etc/init/config
// because first-stage init in Android 10.0 will read the skip_mount.cfg from /system/etc/* after
// chroot /system.
// TODO: remove this symlink when no need to support new GSI on Android 10.
// The actual file needs to be under /system/system_ext because it's GSI-specific and does not
// belong to core CSI.
install_symlink {
    name: "gsi_skip_mount_compat_symlink",
    installed_location: "etc/init/config",
    symlink_target: "/system/system_ext/etc/init/config",
}

// init.gsi.rc, GSI-specific init script.
prebuilt_etc {
    name: "init.gsi.rc",
    src: "init.gsi.rc",
    system_ext_specific: true,
    relative_install_path: "init",
}

prebuilt_etc {
    name: "init.vndk-nodef.rc",
    src: "init.vndk-nodef.rc",
    system_ext_specific: true,
    relative_install_path: "gsi",
}

gsi_symlinks = [
    {
        target: "/system/system_ext",
        name: "system_ext",
    },
    {
        target: "/system/product",
        name: "product",
    },
    {
        target: "/odm/odm_dlkm/etc",
        name: "odm_dlkm/etc",
    },
    {
        target: "/vendor/vendor_dlkm/etc",
        name: "vendor_dlkm/etc",
    },
]

android_filesystem_defaults {
    name: "android_gsi_defaults",
    defaults: [
        "system_image_defaults",
        "system_ext_image_defaults",
        "product_image_defaults",
    ],
    symlinks: gsi_symlinks,
    dirs: ["cache"],
    deps: [
        ///////////////////////////////////////////
        // gsi_system_ext
        ///////////////////////////////////////////

        // handheld packages
        "Launcher3QuickStep",
        "Provision",
        "Settings",
        "StorageManager",
        "SystemUI",

        // telephony packages
        "CarrierConfig",

        ///////////////////////////////////////////
        // 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",

        ///////////////////////////////////////////
        // gsi_product
        ///////////////////////////////////////////
        "Browser2",
        "Camera2",
        "Dialer",
        "LatinIME",
        "apns-full-conf.xml",
    ],
    multilib: {
        lib64: {
            deps: [
                ///////////////////////////////////////////
                // AVF
                ///////////////////////////////////////////
                "com.android.compos",
                "features_com.android.virt.xml",
            ],
        },
        both: {
            // PRODUCT_PACKAGES_SHIPPING_API_LEVEL_34
            deps: ["android.hidl.memory@1.0-impl"],
        },
    },
    type: "ext4",
}

// system.img for gsi_{arch} targets
android_system_image {
    name: "android_gsi",
    defaults: ["android_gsi_defaults"],
    enabled: select(soong_config_variable("ANDROID", "PRODUCT_INSTALL_DEBUG_POLICY_TO_SYSTEM_EXT"), {
        "true": true,
        default: false,
    }),
    deps: [
        // 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",
    ],
}

// system.img for aosp_{arch} targets
android_system_image {
    name: "aosp_system_image",
    defaults: ["android_gsi_defaults"],
    deps: [
        // handheld_system_ext
        "AccessibilityMenu",
        "WallpaperCropper",

        // telephony_system_ext
        "EmergencyInfo",

        // handheld_product
        "Calendar",
        "Contacts",
        "DeskClock",
        "Gallery2",
        "Music",
        "preinstalled-packages-platform-handheld-product.xml",
        "QuickSearchBox",
        "SettingsIntelligence",
        "frameworks-base-overlays",

        // telephony_product
        "ImsServiceEntitlement",
        "preinstalled-packages-platform-telephony-product.xml",

        // more AOSP packages
        "initial-package-stopped-states-aosp.xml",
        "messaging",
        "PhotoTable",
        "preinstalled-packages-platform-aosp-product.xml",
        "ThemePicker",
    ] + select(product_variable("debuggable"), {
        true: ["frameworks-base-overlays-debug"],
        default: [],
    }),
    enabled: select(soong_config_variable("gsi", "building_gsi"), {
        true: true,
        default: false,
    }),
}
