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

tidy_errors = [
    // https://clang.llvm.org/extra/clang-tidy/checks/list.html
    // For many categories, the checks are too many to specify individually.
    // Feel free to disable as needed - as warnings are generally ignored,
    // we treat warnings as errors.
    "android-*",
    "bugprone-*",
    "cert-*",
    "clang-analyzer-security*",
    "google-*",
    "misc-*",
    //"modernize-*",  // explicitly list the modernize as they can be subjective.
    "modernize-avoid-bind",
    //"modernize-avoid-c-arrays", // std::array<> can be verbose
    "modernize-concat-nested-namespaces",
    //"modernize-deprecated-headers", // C headers still ok even if there is C++ equivalent.
    "modernize-deprecated-ios-base-aliases",
    "modernize-loop-convert",
    "modernize-make-shared",
    "modernize-make-unique",
    "modernize-pass-by-value",
    "modernize-raw-string-literal",
    "modernize-redundant-void-arg",
    "modernize-replace-auto-ptr",
    "modernize-replace-random-shuffle",
    "modernize-return-braced-init-list",
    "modernize-shrink-to-fit",
    "modernize-unary-static-assert",
    // "modernize-use-auto", // found in AAudioAudio.cpp
    "modernize-use-bool-literals",
    "modernize-use-default-member-init",
    "modernize-use-emplace",
    "modernize-use-equals-default",
    "modernize-use-equals-delete",
    "modernize-use-nodiscard",
    "modernize-use-noexcept",
    "modernize-use-nullptr",
    "modernize-use-override",
    // "modernize-use-trailing-return-type", // not necessarily more readable
    "modernize-use-transparent-functors",
    "modernize-use-uncaught-exceptions",
    // "modernize-use-using", // found typedef in several files
    "performance-*",

    // Remove some pedantic stylistic requirements.
    "-android-cloexec-dup", // found in SharedMemoryParcelable.cpp
    "-bugprone-macro-parentheses", // found in SharedMemoryParcelable.h
    "-bugprone-narrowing-conversions", // found in several interface from size_t to int32_t

    "-google-build-using-namespace", // Reenable and fix later.
    "-google-global-names-in-headers", // found in several files
    "-google-readability-casting", // C++ casts not always necessary and may be verbose
    "-google-readability-todo", // do not require TODO(info)

    "-misc-non-private-member-variables-in-classes", // found in aidl generated files

    "-performance-no-int-to-ptr", // found in SharedMemoryParcelable.h
]

cc_library {
    name: "libaaudio",

    local_include_dirs: [
        "binding",
        "client",
        "core",
        "fifo",
        "flowgraph",
        "legacy",
        "utility",
    ],
    header_libs: [
        "libaaudio_headers",
    ],
    export_header_lib_headers: ["libaaudio_headers"],
    version_script: "libaaudio.map.txt",

    srcs: [
        "core/AAudioAudio.cpp",
    ],

    cflags: [
        "-Wall",
        "-Werror",
        "-Wno-unused-parameter",
        "-Wthread-safety",

        // AAUDIO_API is used to explicitly export a function or a variable as a visible symbol.
        "-DAAUDIO_API=__attribute__((visibility(\"default\")))",
    ],

    shared_libs: [
        "framework-permission-aidl-cpp",
        "libaaudio_internal",
        "libaudioclient",
        "libaudiofoundation",
        "libaudioutils",
        "libbinder",
        "libcutils",
        "liblog",
        "libmedia_helper",
        "libmediametrics",
        "libmediautils",
        "libutils",
    ],

    sanitize: {
        integer_overflow: true,
        misc_undefined: ["bounds"],
    },

    stubs: {
        symbol_file: "libaaudio.map.txt",
        versions: ["28"],
    },

    tidy: true,
    tidy_checks: tidy_errors,
    tidy_checks_as_errors: tidy_errors,
    tidy_flags: [
        "-format-style=file",
    ],
}

cc_library {
    name: "libaaudio_internal",

    defaults: [
        "latest_android_media_audio_common_types_cpp_shared",
    ],

    local_include_dirs: [
        "binding",
        "client",
        "core",
        "fifo",
        "legacy",
        "utility",
    ],

    export_include_dirs: ["."],
    header_libs: [
        "libaaudio_headers",
        "libmedia_headers",
        "libmediametrics_headers",
    ],
    export_header_lib_headers: ["libaaudio_headers"],

    export_shared_lib_headers: [
        "framework-permission-aidl-cpp",
    ],

    shared_libs: [
        "aaudio-aidl-cpp",
        "audioclient-types-aidl-cpp",
        "com.android.media.aaudio-aconfig-cc",
        "framework-permission-aidl-cpp",
        "libaudioclient",
        "libaudioclient_aidl_conversion",
        "libaudiofoundation",
        "libaudioutils",
        "libbinder",
        "libcutils",
        "liblog",
        "libmedia_helper",
        "libmediametrics",
        "libmediautils",
        "libutils",
    ],

    cflags: [
        "-Wall",
        "-Werror",
        "-Wno-unused-parameter",
    ],

    srcs: [
        "binding/AAudioBinderAdapter.cpp",
        "binding/AAudioBinderClient.cpp",
        "binding/AAudioStreamConfiguration.cpp",
        "binding/AAudioStreamRequest.cpp",
        "binding/AudioEndpointParcelable.cpp",
        "binding/RingBufferParcelable.cpp",
        "binding/SharedMemoryParcelable.cpp",
        "binding/SharedRegionParcelable.cpp",
        "client/AAudioFlowGraph.cpp",
        "client/AudioEndpoint.cpp",
        "client/AudioStreamInternal.cpp",
        "client/AudioStreamInternalCapture.cpp",
        "client/AudioStreamInternalPlay.cpp",
        "client/IsochronousClockModel.cpp",
        "core/AAudioStreamParameters.cpp",
        "core/AudioGlobal.cpp",
        "core/AudioStream.cpp",
        "core/AudioStreamBuilder.cpp",
        "fifo/FifoBuffer.cpp",
        "fifo/FifoControllerBase.cpp",
        "flowgraph/ChannelCountConverter.cpp",
        "flowgraph/ClipToRange.cpp",
        "flowgraph/FlowGraphNode.cpp",
        "flowgraph/Limiter.cpp",
        "flowgraph/ManyToMultiConverter.cpp",
        "flowgraph/MonoBlend.cpp",
        "flowgraph/MonoToMultiConverter.cpp",
        "flowgraph/MultiToManyConverter.cpp",
        "flowgraph/MultiToMonoConverter.cpp",
        "flowgraph/RampLinear.cpp",
        "flowgraph/SampleRateConverter.cpp",
        "flowgraph/SinkFloat.cpp",
        "flowgraph/SinkI8_24.cpp",
        "flowgraph/SinkI16.cpp",
        "flowgraph/SinkI24.cpp",
        "flowgraph/SinkI32.cpp",
        "flowgraph/SourceFloat.cpp",
        "flowgraph/SourceI8_24.cpp",
        "flowgraph/SourceI16.cpp",
        "flowgraph/SourceI24.cpp",
        "flowgraph/SourceI32.cpp",
        "flowgraph/resampler/IntegerRatio.cpp",
        "flowgraph/resampler/LinearResampler.cpp",
        "flowgraph/resampler/MultiChannelResampler.cpp",
        "flowgraph/resampler/PolyphaseResampler.cpp",
        "flowgraph/resampler/PolyphaseResamplerMono.cpp",
        "flowgraph/resampler/PolyphaseResamplerStereo.cpp",
        "flowgraph/resampler/SincResampler.cpp",
        "flowgraph/resampler/SincResamplerStereo.cpp",
        "legacy/AudioStreamLegacy.cpp",
        "legacy/AudioStreamRecord.cpp",
        "legacy/AudioStreamTrack.cpp",
        "utility/AAudioUtilities.cpp",
        "utility/FixedBlockAdapter.cpp",
        "utility/FixedBlockReader.cpp",
        "utility/FixedBlockWriter.cpp",
    ],
    sanitize: {
        integer_overflow: true,
        misc_undefined: ["bounds"],
    },

    tidy: true,
    tidy_checks: tidy_errors,
    tidy_checks_as_errors: tidy_errors,
    tidy_flags: [
        "-format-style=file",
    ],
}

aidl_interface {
    name: "aaudio-aidl",
    unstable: true,
    local_include_dir: "binding/aidl",
    defaults: [
        "latest_android_media_audio_common_types_import_interface",
    ],
    srcs: [
        "binding/aidl/aaudio/Endpoint.aidl",
        "binding/aidl/aaudio/IAAudioClient.aidl",
        "binding/aidl/aaudio/IAAudioService.aidl",
        "binding/aidl/aaudio/RingBuffer.aidl",
        "binding/aidl/aaudio/SharedRegion.aidl",
        "binding/aidl/aaudio/StreamParameters.aidl",
        "binding/aidl/aaudio/StreamRequest.aidl",
    ],
    imports: [
        "audioclient-types-aidl",
        "framework-permission-aidl",
        "shared-file-region-aidl",
    ],
    backend: {
        java: {
            sdk_version: "module_current",
        },
    },
}
