# Copyright (C) 2009 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.
#
LOCAL_PATH := $(call my-dir)
ifeq ($(PRODUCT_TRUSTZONE_ENABLED), true)

LOCAL_TARGET_SOC := $(TARGET_SOC)
ifneq ($(filter $(TARGET_SOC), exynos7884 exynos7884A exynos7884B exynos7904 exynos7905),)
    LOCAL_TARGET_SOC := exynos7885
endif # End of TARGET_SOC
ifneq ($(filter $(TARGET_SOC), MT6762),)
    LOCAL_TARGET_SOC := MT6765
endif # End of TARGET_SOC

#===================================================================
#
# pre-configuation.
#
#===================================================================
ifeq ($(call math_gt_or_eq,$(PRODUCT_SHIPPING_API_LEVEL),28),true)
    SYSTEM_HIDL_ENABLED :=true
endif

$(warning [DeviceRootKey][TA] target soc is $(LOCAL_TARGET_SOC))
#===================================================================
#
# Exynos series trustlet.
#
#===================================================================
ifeq ($(USE_MOBICORE), true)
include $(CLEAR_VARS)

    #Default.
    LOCAL_MODULE := ffffffff00000000000000000000000c.tlbin
    PROV_TA_FILE := $(LOCAL_MODULE)

    ifeq (false,$(call spf_check,SEC_PRODUCT_FEATURE_COMMON_CONFIG_DEVICE_MANUFACTURING_TYPE,jdm))
        ifneq ($(filter haechiy19%, $(TARGET_PRODUCT)),)
            LOCAL_SRC_FILES := output/$(LOCAL_TARGET_SOC)/$(LOCAL_MODULE)_treble
        else 
            #From R OS, TA is located on new path (trustedapps/standalone).
            LOCAL_SRC_FILES := ../../../kinibi_source/prov/Locals/Code/Out/Bin/$(LOCAL_MODULE)_enc
        endif # End of LOCAL_TARGET_SOC
    else
        LOCAL_SRC_FILES := output/$(LOCAL_TARGET_SOC)/$(LOCAL_MODULE)_treble
    endif
    $(warning [DeviceRootKey][TA] PROV_TA_SRC is $(LOCAL_SRC_FILES))

    LOCAL_MODULE_CLASS := ETC
    LOCAL_MODULE_TAGS := optional
    ifeq ($(call math_gt_or_eq,$(PRODUCT_SHIPPING_API_LEVEL),28),true)
        LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/app/mcRegistry
    else
        ifeq ($(PRODUCT_FULL_TREBLE_OVERRIDE),true)
            LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/app/mcRegistry
        else
            LOCAL_MODULE_PATH := $(TARGET_OUT_APPS)/mcRegistry
        endif # End of PRODUCT_FULL_TREBLE_OVERRIDE
    endif

    include $(BUILD_PREBUILT)
endif   # End of USE_MOBICORE

#===================================================================
#
# Teegris series trustlet.
#
#===================================================================
ifeq ($(call math_lt,$(PRODUCT_SHIPPING_API_LEVEL),31),true)
ifeq ($(USE_BLOWFISH), true)
include $(CLEAR_VARS)

PROV_TA := 00000000-0000-0000-0000-505256544545

#Default. TEEGRIS 3.0~ TA runtype : ss_teegris_ta_rp
    #From R OS, TA is located on new path (trustedapps/standalone).
    PROV_TA_SRC := ./vendor/samsung/system/security/trustedapps/teegris_source/prov/bin/swd/encrypted/$(PROV_TA)

# in prebuilt case, please add target_sac here.
#ifneq ($(filter $(LOCAL_TARGET_SOC), exynos0000),)
#        PROV_TA_SRC := ./vendor/samsung/system/security/DeviceRootKey/provTee/output/teegris/$(LOCAL_TARGET_SOC)/$(PROV_TA)
#endif # End of LOCAL_TARGET_SOC

$(warning [DeviceRootKey][TA] PROV_TA_SRC is $(PROV_TA_SRC))

ifneq ("$(wildcard $(PROV_TA_SRC))","")
    LOCAL_MODULE        := $(PROV_TA)
    LOCAL_MODULE_TAGS   := optional
    LOCAL_MODULE_CLASS  := ETC
    LOCAL_SRC_FILES     := ../../../../../../../../$(PROV_TA_SRC)

    ifeq ($(call math_gt_or_eq,$(PRODUCT_SHIPPING_API_LEVEL),28),true)
        LOCAL_MODULE_PATH   := $(TARGET_OUT_VENDOR)/tee
    else
        ifeq ($(PRODUCT_FULL_TREBLE_OVERRIDE), true)
            LOCAL_MODULE_PATH   := $(TARGET_OUT_VENDOR)/tee
        else
            LOCAL_MODULE_PATH   := $(PRODUCT_OUT)/system/tee
        endif
    endif
    include $(BUILD_PREBUILT)
endif   # End of wildcard(PROV_TA_SRC)

endif   # End of USE_BLOWFISH
endif   # End of math_gt_or_eq PRODUCT_SHIPPING_API_LEVEL < 31

endif   # End of PRODUCT_TRUSTZONE_ENABLE

