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

// Whether to enable the FrameworksNetTests. Set to false in the branches that might have older
// frameworks/base since FrameworksNetTests includes the test for classes that are not in
// connectivity module.
enable_frameworks_net_tests = true
// Placeholder
// This is a placeholder comment to minimize merge conflicts, as enable_frameworks_net_tests
// may have different values depending on the branch
// Placeholder

java_defaults {
    name: "FrameworksNetTests-jni-defaults",
    jni_libs: [
        "ld-android",
        "libbase",
        "libbinder",
        "libbpf",
        "libbpf_android",
        "libc++",
        "libcgrouprc",
        "libcrypto",
        "libcutils",
        "libdl_android",
        "libhidl-gen-utils",
        "libhidlbase",
        "libjsoncpp",
        "liblog",
        "liblzma",
        "libnativehelper",
        "libnetdbpf",
        "libnetdutils",
        "libnetworkstatsfactorytestjni",
        "libpackagelistparser",
        "libpcre2",
        "libprocessgroup",
        "libselinux",
        "libtinyxml2",
        "libui",
        "libunwindstack",
        "libutils",
        "libutilscallstack",
        "libvndksupport",
        "libziparchive",
        "libz",
        "netd_aidl_interface-V5-cpp",
    ],
}

filegroup {
    name: "non-connectivity-module-test",
    srcs: [
        "java/android/app/usage/*.java",
        "java/android/net/Ikev2VpnProfileTest.java",
        "java/android/net/IpMemoryStoreTest.java",
        "java/android/net/IpSecAlgorithmTest.java",
        "java/android/net/IpSecConfigTest.java",
        "java/android/net/IpSecManagerTest.java",
        "java/android/net/IpSecTransformTest.java",
        "java/android/net/KeepalivePacketDataUtilTest.java",
        "java/android/net/NetworkIdentityTest.kt",
        "java/android/net/NetworkStatsTest.java",
        "java/android/net/NetworkStatsHistoryTest.java",
        "java/android/net/NetworkTemplateTest.kt",
        "java/android/net/TelephonyNetworkSpecifierTest.java",
        "java/android/net/VpnManagerTest.java",
        "java/android/net/ipmemorystore/*.java",
        "java/android/net/nsd/*.java",
        "java/com/android/internal/net/NetworkUtilsInternalTest.java",
        "java/com/android/internal/net/VpnProfileTest.java",
        "java/com/android/server/IpSecServiceParameterizedTest.java",
        "java/com/android/server/IpSecServiceRefcountedResourceTest.java",
        "java/com/android/server/IpSecServiceTest.java",
        "java/com/android/server/NetworkManagementServiceTest.java",
        "java/com/android/server/NsdServiceTest.java",
        "java/com/android/server/connectivity/IpConnectivityEventBuilderTest.java",
        "java/com/android/server/connectivity/IpConnectivityMetricsTest.java",
        "java/com/android/server/connectivity/MultipathPolicyTrackerTest.java",
        "java/com/android/server/connectivity/NetdEventListenerServiceTest.java",
        "java/com/android/server/connectivity/VpnTest.java",
        "java/com/android/server/net/ipmemorystore/*.java",
        "java/com/android/server/net/NetworkStats*.java",
    ]
}

// Subset of services-core used to by ConnectivityService tests to test VPN realistically.
// This is stripped by jarjar (see rules below) from other unrelated classes, so tests do not
// include most classes from services-core, which are unrelated and cause wrong code coverage
// calculations.
java_library {
    name: "services.core-vpn",
    static_libs: ["services.core"],
    jarjar_rules: "vpn-jarjar-rules.txt",
    visibility: ["//visibility:private"],
}

android_library {
    name: "FrameworksNetTestsLib",
    min_sdk_version: "30",
    defaults: [
        "framework-connectivity-test-defaults",
    ],
    srcs: [
        "java/**/*.java",
        "java/**/*.kt",
    ],
    exclude_srcs: [":non-connectivity-module-test"],
    jarjar_rules: "jarjar-rules.txt",
    static_libs: [
        "androidx.test.rules",
        "androidx.test.uiautomator",
        "bouncycastle-repackaged-unbundled",
        "core-tests-support",
        "FrameworksNetCommonTests",
        "frameworks-base-testutils",
        "frameworks-net-integration-testutils",
        "framework-protos",
        "mockito-target-minus-junit4",
        "net-tests-utils",
        "net-utils-services-common",
        "platform-compat-test-rules",
        "platform-test-annotations",
        "service-connectivity-pre-jarjar",
        "services.core-vpn",
    ],
    libs: [
        "android.net.ipsec.ike.stubs.module_lib",
        "android.test.runner",
        "android.test.base",
        "android.test.mock",
        "ServiceConnectivityResources",
    ],
    visibility: ["//packages/modules/Connectivity/tests:__subpackages__"],
}

android_test {
    name: "FrameworksNetTests",
    enabled: enable_frameworks_net_tests,
    min_sdk_version: "30",
    defaults: [
        "framework-connectivity-test-defaults",
        "FrameworksNetTests-jni-defaults",
    ],
    // this is in addition to FrameworksNetTestsLib.
    srcs: [":non-connectivity-module-test"],
    test_suites: ["device-tests"],
    static_libs: [
        "services.core",
        "services.net",
        "FrameworksNetTestsLib",
    ],
    libs: [
        "android.test.mock",
        "android.test.base",
    ],
    jni_libs: [
        "libservice-connectivity",
    ]
}
