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: ["frameworks_av_license"],
}

cc_defaults {
    name: "aidl_clearkey_service_defaults-use-shared-deps",

    shared_libs: [
        "android.hardware.drm-V1-ndk",
        "libbase",
        "libbinder_ndk",
        "libcrypto",
        "liblog",
        "libprotobuf-cpp-lite",
        "libutils",
    ],

    static_libs: [
        "android.hardware.common-V2-ndk",
        "libclearkeybase",
        "libjsoncpp",
    ],
}

cc_defaults {
    name: "aidl_clearkey_service_defaults-use-static-deps",

    stl: "c++_static",

    shared_libs: [
        "libbinder_ndk",
        "libcrypto",
        "liblog",
    ],

    static_libs: [
        "android.hardware.common-V2-ndk",
        "android.hardware.drm.common-V1-ndk",
        "android.hardware.drm-V1-ndk",
        "libbase",
        "libclearkeybase",
        "libjsoncpp",
        "libprotobuf-cpp-lite",
        "libutils",
    ],
}

cc_defaults {
    name: "aidl_clearkey_service_defaults",
    vendor: true,

    srcs: [
        "CreatePluginFactories.cpp",
        "CryptoPlugin.cpp",
        "DrmFactory.cpp",
        "DrmPlugin.cpp",
    ],

    relative_install_path: "hw",

    cflags: [
        "-Wall",
        "-Werror",
        "-Wthread-safety",
    ],

    include_dirs: ["frameworks/av/include"],

    local_include_dirs: ["include"],

    sanitize: {
        integer_overflow: true,
    },
}

cc_binary {
    name: "android.hardware.drm-service.clearkey",
    defaults: [
        "aidl_clearkey_service_defaults",
        "aidl_clearkey_service_defaults-use-shared-deps",
    ],
    srcs: ["Service.cpp"],
    init_rc: ["android.hardware.drm-service.clearkey.rc"],
    vintf_fragment_modules: ["android.hardware.drm-service.clearkey.xml_vintf"],
}

cc_binary {
    name: "android.hardware.drm-service-lazy.clearkey",
    defaults: [
        "aidl_clearkey_service_defaults",
        "aidl_clearkey_service_defaults-use-shared-deps",
    ],
    overrides: ["android.hardware.drm-service.clearkey"],
    srcs: ["ServiceLazy.cpp"],
    init_rc: ["android.hardware.drm-service-lazy.clearkey.rc"],
    vintf_fragment_modules: ["android.hardware.drm-service.clearkey.xml_vintf"],
}

vintf_fragment {
    name: "android.hardware.drm-service.clearkey.xml_vintf",
    src: "android.hardware.drm-service.clearkey.xml",
    vendor: true,
}

cc_binary {
    name: "android.hardware.drm-service.clearkey.apex",
    stem: "android.hardware.drm-service.clearkey",
    defaults: [
        "aidl_clearkey_service_defaults",
        "aidl_clearkey_service_defaults-use-static-deps",
    ],
    srcs: ["Service.cpp"],
    installable: false, // installed in APEX
}

cc_binary {
    name: "android.hardware.drm-service-lazy.clearkey.apex",
    stem: "android.hardware.drm-service-lazy.clearkey",
    defaults: [
        "aidl_clearkey_service_defaults",
        "aidl_clearkey_service_defaults-use-static-deps",
    ],
    srcs: ["ServiceLazy.cpp"],
    installable: false, // installed in APEX
}

phony {
    name: "android.hardware.drm@latest-service.clearkey",
    required: [
        "com.android.hardware.drm.clearkey",
    ],
    vendor: true,
}

cc_defaults {
    name: "fuzz_aidl_clearkey_service_defaults",

    srcs: [
        "CreatePluginFactories.cpp",
        "CryptoPlugin.cpp",
        "DrmFactory.cpp",
        "DrmPlugin.cpp",
    ],

    relative_install_path: "hw",

    cflags: [
        "-Wall",
        "-Werror",
        "-Wthread-safety",
    ],

    include_dirs: ["frameworks/av/include"],

    shared_libs: [
        "android.hardware.drm-V1-ndk",
        "libbase",
        "libbinder_ndk",
        "libcrypto",
        "liblog",
        "libprotobuf-cpp-lite",
        "libutils",
    ],

    static_libs: [
        "android.hardware.common-V2-ndk",
        "libclearkeybase_fuzz",
        "libjsoncpp",
    ],

    local_include_dirs: ["include"],

    sanitize: {
        integer_overflow: true,
    },
}

cc_fuzz {
    name: "android.hardware.drm-service.clearkey.aidl_fuzzer",
    defaults: [
        "fuzz_aidl_clearkey_service_defaults",
        "service_fuzzer_defaults",
    ],
    srcs: ["fuzzer.cpp"],
    fuzz_config: {
        cc: [
            "hamzeh@google.com",
        ],
    },
}

apex {
    name: "com.android.hardware.drm.clearkey",
    manifest: "manifest.json",
    file_contexts: "file_contexts",
    key: "com.android.hardware.key",
    certificate: ":com.android.hardware.certificate",
    vendor: true,
    updatable: false,

    binaries: [
        "android.hardware.drm-service.clearkey.apex",
    ],
    prebuilts: [
        "android.hardware.drm-service.clearkey.apex.rc",
        "android.hardware.drm-service.clearkey.xml",
    ],
    overrides: [
        "android.hardware.drm-service.clearkey",
    ],
}

prebuilt_etc {
    name: "android.hardware.drm-service.clearkey.apex.rc",
    src: ":gen-android.hardware.drm-service.clearkey.apex.rc",
    installable: false,
}

genrule {
    name: "gen-android.hardware.drm-service.clearkey.apex.rc",
    srcs: ["android.hardware.drm-service.clearkey.rc"],
    out: ["android.hardware.drm-service.clearkey.apex.rc"],
    cmd: "sed -E 's%/vendor/bin/%/apex/com.android.hardware.drm.clearkey/bin/%' $(in) > $(out)",
}

prebuilt_etc {
    name: "android.hardware.drm-service.clearkey.xml",
    src: "android.hardware.drm-service.clearkey.xml",
    sub_dir: "vintf",
    installable: false,
}

apex {
    name: "com.android.hardware.drm.clearkey.lazy",
    manifest: "manifest.json",
    file_contexts: "file_contexts",
    key: "com.android.hardware.key",
    certificate: ":com.android.hardware.certificate",
    vendor: true,
    updatable: false,

    binaries: [
        "android.hardware.drm-service-lazy.clearkey.apex",
    ],
    prebuilts: [
        "android.hardware.drm-service-lazy.clearkey.apex.rc",
        "android.hardware.drm-service.clearkey.xml",
    ],
    overrides: [
        "android.hardware.drm-service-lazy.clearkey",
        "android.hardware.drm-service.clearkey",
        "com.android.hardware.drm.clearkey",
    ],
}

prebuilt_etc {
    name: "android.hardware.drm-service-lazy.clearkey.apex.rc",
    src: ":gen-android.hardware.drm-service-lazy.clearkey.apex.rc",
    installable: false,
}

genrule {
    name: "gen-android.hardware.drm-service-lazy.clearkey.apex.rc",
    srcs: ["android.hardware.drm-service-lazy.clearkey.rc"],
    out: ["android.hardware.drm-service-lazy.clearkey.apex.rc"],
    cmd: "sed -E 's%/vendor/bin/%/apex/com.android.hardware.drm.clearkey/bin/%' $(in) > $(out)",
}
