// Copyright (C) 2020 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 {
    default_applicable_licenses: [
        "external_libese_ready_se_google_keymint_KM300_HAL_license",
    ],
}

// Added automatically by a large-scale-change
// See: http://go/android-license-faq
license {
    name: "external_libese_ready_se_google_keymint_KM300_HAL_license",
    visibility: [":__subpackages__"],
    license_kinds: [
        "SPDX-license-identifier-Apache-2.0",
    ],
    license_text: [
        "LICENSE",
    ],
}

cc_binary {
    name: "android.hardware.security.keymint3-service.strongbox",
    defaults: [
        "jc_keymint_defaults",
        "libjc_keymint_defaults",
    ],
    init_rc: ["android.hardware.security.keymint3-service.strongbox.rc"],
    vintf_fragment_modules: [
        "android.hardware.security.keymint3-service.strongbox.xml",
        "android.hardware.security.sharedsecret-service.strongbox3.xml",
    ],
    shared_libs: [
        "android.hardware.security.keymint-V3-ndk",
        "lib_android_keymaster_keymint_utils_V3",
    ],
    srcs: [
        "KeyMint3Service.cpp",
    ],
    required: [
        "android.hardware.hardware_keystore.jc-strongbox-keymint3.xml",
    ],
}

cc_binary {
    name: "android.hardware.security.keymint4-service.strongbox",
    init_rc: ["android.hardware.security.keymint4-service.strongbox.rc"],
    vintf_fragment_modules: [
        "android.hardware.security.keymint4-service.strongbox.xml",
        "android.hardware.security.sharedsecret-service.strongbox4.xml",
    ],
    defaults: [
        "jc_keymint_defaults",
        "libjc_keymint_defaults",
    ],
    shared_libs: [
        "android.hardware.security.keymint-V4-ndk",
        "lib_android_keymaster_keymint_utils",
    ],
    srcs: [
        "JavacardKeyMint4Device.cpp",
        "KeyMint4Service.cpp",
    ],
    required: [
        "android.hardware.hardware_keystore.jc-strongbox-keymint4.xml",
    ],
}

cc_defaults {
    name: "libjc_keymint_defaults",
    srcs: [
        "CborConverter.cpp",
        "JavacardKeyMintDevice.cpp",
        "JavacardKeyMintOperation.cpp",
        "JavacardRemotelyProvisionedComponentDevice.cpp",
        "JavacardSecureElement.cpp",
        "JavacardSharedSecret.cpp",
        "keymint_utils.cpp",
    ],
    cflags: ["-O0"],
    shared_libs: [
        "android.hardware.security.rkp-V3-ndk",
        "android.hardware.security.secureclock-V1-ndk",
        "android.hardware.security.sharedsecret-V1-ndk",
        "libbase",
        "libbinder_ndk",
        "libcppbor",
        "libcrypto",
        "libcutils",
        "libjc_keymint_transport",
        "libkeymaster_messages",
        "libkeymaster_portable",
        "liblog",
        "libsoft_attestation_cert",
    ],
    export_shared_lib_headers: ["libjc_keymint_transport"],
    export_include_dirs: ["."],
}

cc_defaults {
    name: "jc_keymint_defaults",
    relative_install_path: "hw",
    vendor: true,
    cflags: [
        "-Wall",
        "-Wextra",
    ],
    shared_libs: [
        "android.se.omapi-V1-ndk",
        "libbase",
        "libbinder_ndk",
        "libcppbor",
        "libcrypto",
        "libjc_keymint_transport",
        "libkeymaster_portable",
        "liblog",
        "libutils",
    ],
}

// The following targets (and underlying XML files) declare specific
// versions of KeyMint.  Vendors should use the version that matches the
// version of the KeyMint HAL that the device implements.

vintf_fragment {
    name: "android.hardware.security.keymint4-service.strongbox.xml",
    src: "android.hardware.security.keymint4-service.strongbox.xml",
    vendor: true,
}

vintf_fragment {
    name: "android.hardware.security.sharedsecret-service.strongbox4.xml",
    src: "android.hardware.security.sharedsecret-service.strongbox4.xml",
    vendor: true,
}

vintf_fragment {
    name: "android.hardware.security.keymint3-service.strongbox.xml",
    src: "android.hardware.security.keymint3-service.strongbox.xml",
    vendor: true,
}

vintf_fragment {
    name: "android.hardware.security.sharedsecret-service.strongbox3.xml",
    src: "android.hardware.security.sharedsecret-service.strongbox3.xml",
    vendor: true,
}

prebuilt_etc {
    name: "android.hardware.hardware_keystore.jc-strongbox-keymint3.xml",
    sub_dir: "permissions",
    vendor: true,
    src: "android.hardware.hardware_keystore.jc-strongbox-keymint3.xml",
}

prebuilt_etc {
    name: "android.hardware.hardware_keystore.jc-strongbox-keymint4.xml",
    sub_dir: "permissions",
    vendor: true,
    src: "android.hardware.hardware_keystore.jc-strongbox-keymint4.xml",
}
