package {
    // See: http://go/android-license-faq
    // A large-scale-change added 'default_applicable_licenses' to import
    // all of the 'license_kinds' from "hardware_interfaces_license"
    // to get the below license kinds:
    //   SPDX-license-identifier-Apache-2.0
    default_applicable_licenses: ["hardware_interfaces_license"],
}

cc_library_shared {
    name: "libbluetooth_audio_session",
    defaults: ["hidl_defaults"],
    vendor: true,
    srcs: [
        "session/BluetoothAudioSession.cpp",
        "session/BluetoothAudioSession_2_1.cpp",
        "session/BluetoothAudioSupportedCodecsDB.cpp",
        "session/BluetoothAudioSupportedCodecsDB_2_1.cpp",
    ],
    export_include_dirs: ["session/"],
    header_libs: ["libhardware_headers"],
    shared_libs: [
        "android.hardware.audio.common@5.0",
        "android.hardware.bluetooth.audio@2.0",
        "android.hardware.bluetooth.audio@2.1",
        "libbase",
        "libcutils",
        "libfmq",
        "libhidlbase",
        "liblog",
        "libutils",
        "libbluetooth_audio_session_aidl",
    ],
}

cc_library_shared {
    name: "libbluetooth_audio_session_aidl",
    vendor: true,
    host_supported: true,
    srcs: [
        "aidl_session/BluetoothAudioCodecs.cpp",
        "aidl_session/BluetoothAudioSession.cpp",
        "aidl_session/HidlToAidlMiddleware.cpp",
        "aidl_session/BluetoothLeAudioCodecsProvider.cpp",
        "aidl_session/BluetoothHfpCodecsProvider.cpp",
        "aidl_session/BluetoothLeAudioAseConfigurationSettingProvider.cpp",
    ],
    export_include_dirs: ["aidl_session/"],
    header_libs: [
        "libhardware_headers",
        "libxsdc-utils",
    ],
    defaults: [
        "latest_android_hardware_bluetooth_audio_ndk_shared",
    ],
    shared_libs: [
        "android.hardware.bluetooth.audio@2.0",
        "android.hardware.bluetooth.audio@2.1",
        "libbase",
        "libcutils",
        "libbinder_ndk",
        "libfmq",
        "liblog",
        "libhidlbase",
        "libxml2",
        "libflatbuffers-cpp",
        "server_configurable_flags",
    ],
    static_libs: [
        "btaudiohal_flags_c_lib",
    ],
    generated_sources: [
        "le_audio_codec_capabilities",
        "hfp_codec_capabilities",
    ],
    generated_headers: [
        "le_audio_codec_capabilities",
        "hfp_codec_capabilities",
        "AIDLLeAudioSetConfigSchemas_h",
    ],
    required: [
        "aidl_audio_set_configurations_bfbs",
        "aidl_audio_set_configurations_json",
        "aidl_audio_set_scenarios_bfbs",
        "aidl_audio_set_scenarios_json",
        "hfp_codec_capabilities_xml",
    ],
}

cc_test {
    name: "BluetoothLeAudioCodecsProviderTest",
    srcs: [
        "aidl_session/BluetoothLeAudioCodecsProvider.cpp",
        "aidl_session/BluetoothLeAudioCodecsProviderTest.cpp",
    ],
    header_libs: [
        "libxsdc-utils",
    ],
    shared_libs: [
        "libbase",
        "libbinder_ndk",
        "android.hardware.bluetooth.audio-V4-ndk",
        "libxml2",
    ],
    test_suites: [
        "general-tests",
    ],
    test_options: {
        unit_test: false,
    },
    generated_sources: ["le_audio_codec_capabilities"],
    generated_headers: ["le_audio_codec_capabilities"],
}

cc_test {
    name: "BluetoothHfpCodecsProviderTest",
    defaults: [
        "latest_android_hardware_audio_common_ndk_static",
        "latest_android_hardware_bluetooth_audio_ndk_static",
        "latest_android_media_audio_common_types_ndk_static",
    ],
    srcs: [
        "aidl_session/BluetoothHfpCodecsProvider.cpp",
        "aidl_session/BluetoothHfpCodecsProviderTest.cpp",
    ],
    header_libs: [
        "libxsdc-utils",
    ],
    shared_libs: [
        "libbase",
        "libbinder_ndk",
        "libxml2",
    ],
    test_suites: [
        "general-tests",
    ],
    test_options: {
        unit_test: false,
    },
    generated_sources: ["hfp_codec_capabilities"],
    generated_headers: ["hfp_codec_capabilities"],
}

xsd_config {
    name: "le_audio_codec_capabilities",
    srcs: ["le_audio_codec_capabilities/le_audio_codec_capabilities.xsd"],
    package_name: "aidl.android.hardware.bluetooth.audio.setting",
    api_dir: "le_audio_codec_capabilities/schema",
    root_elements: ["leAudioOffloadSetting"],
}

xsd_config {
    name: "hfp_codec_capabilities",
    srcs: ["hfp_codec_capabilities/hfp_codec_capabilities.xsd"],
    package_name: "aidl.android.hardware.bluetooth.audio.hfp.setting",
    api_dir: "hfp_codec_capabilities/schema",
    root_elements: ["hfpOffloadSetting"],
}

genrule {
    name: "AIDLLeAudioSetConfigSchemas_h",
    tools: [
        "flatc",
    ],
    cmd: "$(location flatc) -I hardware/interfaces/bluetooth/audio/utils/ -o $(genDir) --cpp $(in) ",
    srcs: [
        "le_audio_configuration_set/audio_set_configurations.fbs",
        "le_audio_configuration_set/audio_set_scenarios.fbs",
    ],
    out: [
        "audio_set_configurations_generated.h",
        "audio_set_scenarios_generated.h",
    ],
}

// Binary generation
genrule {
    name: "AIDLLeAudioSetScenariosSchema_bfbs",
    tools: [
        "flatc",
    ],
    cmd: "$(location flatc) -I hardware/interfaces/bluetooth/audio/utils/ -b --schema -o $(genDir) $(in) ",
    srcs: [
        "le_audio_configuration_set/audio_set_scenarios.fbs",
    ],
    out: [
        "audio_set_scenarios.bfbs",
    ],
}

genrule {
    name: "AIDLLeAudioSetConfigsSchema_bfbs",
    tools: [
        "flatc",
    ],
    cmd: "$(location flatc) -I hardware/interfaces/bluetooth/audio/utils/ -b --schema -o $(genDir) $(in) ",
    srcs: [
        "le_audio_configuration_set/audio_set_configurations.fbs",
    ],
    out: [
        "audio_set_configurations.bfbs",
    ],
}

// Add to prebuilt etc
prebuilt_etc {
    name: "aidl_audio_set_scenarios_bfbs",
    src: ":AIDLLeAudioSetScenariosSchema_bfbs",
    filename: "aidl_audio_set_scenarios.bfbs",
    sub_dir: "aidl/le_audio",
    vendor: true,
}

prebuilt_etc {
    name: "aidl_audio_set_scenarios_json",
    src: "le_audio_configuration_set/audio_set_scenarios.json",
    filename: "aidl_audio_set_scenarios.json",
    sub_dir: "aidl/le_audio",
    vendor: true,
}

prebuilt_etc {
    name: "hfp_codec_capabilities_xml",
    src: "hfp_codec_capabilities/hfp_codec_capabilities.xml",
    filename: "hfp_codec_capabilities.xml",
    sub_dir: "aidl/hfp",
    vendor: true,
}

prebuilt_etc {
    name: "aidl_audio_set_configurations_bfbs",
    src: ":AIDLLeAudioSetConfigsSchema_bfbs",
    filename: "aidl_audio_set_configurations.bfbs",
    sub_dir: "aidl/le_audio",
    vendor: true,
}

prebuilt_etc {
    name: "aidl_audio_set_configurations_json",
    src: "le_audio_configuration_set/audio_set_configurations.json",
    filename: "aidl_audio_set_configurations.json",
    sub_dir: "aidl/le_audio",
    vendor: true,
}
