// Copyright (C) 2023 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/licensNew.javaues/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.

license {
    name: "stable_cronet_license",
    license_kinds: [
        "SPDX-license-identifier-Apache-2.0",
        "SPDX-license-identifier-BSD",
        "SPDX-license-identifier-BSD-3-Clause",
        "SPDX-license-identifier-BSD-Source-Code",
        "SPDX-license-identifier-BSD-2-Clause",
        "SPDX-license-identifier-BSD-4-Clause",
        "SPDX-license-identifier-BSL-1.0",
        "SPDX-license-identifier-ICU",
        "SPDX-license-identifier-ISC",
        "SPDX-license-identifier-MIT",
        "SPDX-license-identifier-MPL",
        "SPDX-license-identifier-MPL-1.1",
        "SPDX-license-identifier-MPL-2.0",
        "SPDX-license-identifier-NCSA",
        "SPDX-license-identifier-Zlib",
        // "SPDX-license-identifier-GPL-2.0-with-autoconf-exception", // ICU TODO(aymanm): Reapply those once aosp/2470343 is merged
        // "SPDX-license-identifier-GPL-3.0-with-autoconf-exception", // ICU TODO(aymanm): Reapply those once aosp/2470343 is merged
        "SPDX-license-identifier-OpenSSL",
        "SPDX-license-identifier-Unicode-DFS-2016",
        "legacy_unencumbered",
    ],
    license_text: [
        "LICENSE",
    ],
}

java_library {
    name: "stable_cronet_api_java",
    static_libs: [
        "stable_cronet_components_cronet_android_cronet_api_java",
    ],
    sdk_version: "module_current",
    min_sdk_version: "30",
    visibility: [
        "//packages/modules/Connectivity:__subpackages__",
        "//external/cronet:__subpackages__",
    ],
    apex_available: [
        "com.android.tethering",
    ],
}

java_library {
    name: "stable_cronet_java",
    static_libs: [
        "stable_cronet_components_cronet_android_cronet_impl_native_java",
        "stable_cronet_components_cronet_android_cronet_build_config_and_jni_registration_java",
    ],
    sdk_version: "module_current",
    min_sdk_version: "30",
    visibility: [
        "//packages/modules/Connectivity:__subpackages__",
        "//external/cronet/android:__subpackages__",
    ],
    apex_available: [
        "com.android.tethering",
    ],
}

java_library {
    name: "stable_cronet_java__testing",
    static_libs: [
        "stable_cronet_components_cronet_android_cronet_impl_native_java__testing",
        "stable_cronet_components_cronet_android_cronet_build_config_and_jni_registration_java__testing",
        "stable_cronet_components_cronet_android_cronet_tests_jni_registration_java__testing",
    ],
    sdk_version: "module_current",
    min_sdk_version: "30",
    visibility: [
        "//external/cronet:__subpackages__",
    ],
    apex_available: [
        "com.android.tethering",
    ],
}

// ------------------------------ NATIVE TEST TARGETS --------------------------------------------

java_library {
    name: "stable_cronet_for_testing_net_java",
    static_libs: [
        "stable_cronet_net_android_net_test_support_provider_java__testing",
        "stable_cronet_net_android_net_java_test_support__testing",
        "stable_cronet_net_android_net_tests_java__testing",
        "stable_cronet_net_android_dummy_spnego_authenticator_java__testing",
    ],
}

filegroup {
    name: "stable_cronet_net_unittests_data",
    srcs: [
        "net/data/**/*",
        "net/third_party/quiche/src/quiche/common/platform/api/testdir/**/*",
        "third_party/anonymous_tokens/src/anonymous_tokens/testdata/**/*",
    ],
}

filegroup {
    name: "stable_cronet_javatests_resources",
    srcs: [
        "net/data/ssl/certificates/**/*",
        "components/cronet/android/test/test_server/data/**/*",
    ],
    visibility: [
        "//external/cronet:__subpackages__",
    ],
}

android_library {
    name: "stable_cronet_java_tests",
    manifest: "components/cronet/android/test/src/org/chromium/net/AndroidManifest.xml",
    sdk_version: "module_current",
    min_sdk_version: "30",
    static_libs: [
        "stable_cronet_components_cronet_android_cronet_javatests__testing",
        "androidx.test.ext.junit",
        "androidx.test.rules",
        "stable_cronet_java__testing",
        "guava",
        "hamcrest-library",
        "junit",
        "net-tests-utils",
        "truth",
    ],
    libs: [
        "android.test.base.stubs.system",
        "stable_cronet_api_java",
        "framework-connectivity.stubs.module_lib",
        "framework-connectivity-pre-jarjar",
        // android.net.TrafficStats apis
        "framework-connectivity-t.stubs.module_lib",
        "guava",
    ],
    lint: {
        test: true,
    },
    visibility: [
        "//external/cronet:__subpackages__",
    ],
}

java_defaults {
    name: "stable_cronet_java_framework_defaults",
    sdk_version: "module_current",
    libs: [
        "framework-connectivity-pre-jarjar-without-cronet",
        "framework-connectivity.stubs.module_lib",
        "framework-connectivity-t.stubs.module_lib",
        "framework-location.stubs.module_lib",
        "framework-mediaprovider.stubs.module_lib",
        "framework-statsd.stubs.module_lib",
        "framework-wifi.stubs.module_lib",
        "framework-sdkextensions.stubs.module_lib",
    ],
    visibility: [
        "//external/cronet:__subpackages__",
    ],
}

// rust_bindgen modules do not have an `include_dirs` attribute. Due to that,
// C++ headers generated from rust_bindgen can't reference other headers
// through paths relative to the repository root. This is what Chromium does
// so, to circumvent this issue, create this module that adds the root of the
// repository to `include_dirs`. This will be added to all modules depending
// on a rust_bindgen module.
cc_library_headers {
    name: "stable_cronet_repository_root_include_dirs_anchor",
    host_supported: true,
    apex_available: [
        "com.android.tethering",
    ],
    min_sdk_version: "30",
    export_include_dirs: ["."],
    visibility: [
        "//external/cronet:__subpackages__",
    ],
}

java_defaults {
    name: "stable_cronet_api_defaults",
    static_libs: [
        "stable_cronet_components_cronet_android_cronet_api_java",
    ],
}

java_library {
    name: "stable_cronet_aml_api_java",
    defaults: [
        "stable_cronet_api_defaults",
    ],
    sdk_version: "module_current",
    min_sdk_version: "30",
    visibility: [
        "//packages/modules/Connectivity:__subpackages__",
        "//external/cronet/android:__subpackages__",
    ],
    apex_available: [
        "com.android.tethering",
    ],
}


java_defaults {
    name: "stable_cronet_java_tests_defaults",
    static_libs: [
        "stable_cronet_java_tests",
    ],
    jni_libs: [
        "stable_cronet_components_cronet_android_cronet_tests__testing",
        "stable_cronet_components_cronet_android_cronet__testing",
        "stable_cronet_third_party_netty_tcnative_netty_tcnative_so__testing",
    ],
    data: [":stable_cronet_javatests_resources"],
    manifest: "components/cronet/android/test/javatests/AndroidManifest.xml",
    resource_dirs: ["components/cronet/android/test/res"],
}

java_defaults {
    name: "stable_cronet_testing",
    static_libs: [
        "stable_cronet_components_cronet_android_cronet_impl_native_java__testing",
        "stable_cronet_components_cronet_android_cronet_build_config_and_jni_registration_java__testing",
        "stable_cronet_components_cronet_android_cronet_tests_jni_registration_java__testing",
    ],
}

java_library {
    name: "stable_cronet_aml_java__testing",
    defaults: [
        "stable_cronet_testing",
    ],
    sdk_version: "module_current",
    min_sdk_version: "30",
    visibility: [
        "//external/cronet/android:__subpackages__",
    ],
    apex_available: [
        "com.android.tethering",
    ],
}

android_test {
    name: "stable_cronet_NetHttpCoverageTests",
    enforce_default_target_sdk_version: true,
    min_sdk_version: "30",
    test_suites: [
        "general-tests",
        "mts-tethering",
    ],
    defaults: [
        "stable_cronet_java_tests_defaults",
    ],
    static_libs: [
        "modules-utils-native-coverage-listener",
        "CtsNetHttpTestsLib",
        "stable_cronet_aml_api_java",
        "stable_cronet_aml_java__testing",
    ],
    compile_multilib: "both", // Include both the 32 and 64 bit versions
    jni_libs: [
        "libnativecoverage",
    ],
    test_config: "AndroidTest.xml",
}
