// Copyright (C) 2019 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.

package {
    // 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",
    "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",
    "performance-*",

    // Remove some pedantic stylistic requirements.
    "-android-cloexec-dup", // found in AAudioServiceEndpointMMAP.cpp
    "-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

]

cc_defaults {
    name: "libaaudioservice_dependencies",

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

    static_libs: [
        "libaudioflinger",
    ],
}

cc_library_static {

    name: "libaaudioservice",

    defaults: [
        "latest_android_media_audio_common_types_cpp_shared",
        "libaaudioservice_dependencies",
    ],

    srcs: [
        "AAudioClientTracker.cpp",
        "AAudioCommandQueue.cpp",
        "AAudioEndpointManager.cpp",
        "AAudioMixer.cpp",
        "AAudioService.cpp",
        "AAudioServiceEndpoint.cpp",
        "AAudioServiceEndpointCapture.cpp",
        "AAudioServiceEndpointMMAP.cpp",
        "AAudioServiceEndpointPlay.cpp",
        "AAudioServiceEndpointShared.cpp",
        "AAudioServiceStreamBase.cpp",
        "AAudioServiceStreamMMAP.cpp",
        "AAudioServiceStreamShared.cpp",
        "AAudioStreamTracker.cpp",
        "AAudioThread.cpp",
        "SharedMemoryProxy.cpp",
        "SharedMemoryWrapper.cpp",
        "SharedRingBuffer.cpp",
        "TimestampScheduler.cpp",
    ],

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

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

    header_libs: [
        "libaudiohal_headers",
    ],

    include_dirs: [
        "frameworks/av/media/libnbaio/include",
        "frameworks/av/media/libnbaio/include_mono",
    ],

    export_include_dirs: ["."],

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