# Copyright (C) 2021 Huawei Device Co., Ltd.
# 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.
SUBSYSTEM_DIR = "../.."
import("//build/ohos.gni")
import("$SUBSYSTEM_DIR/core_service/telephony_core_service.gni")

group("common_target") {
  deps = [ ":libtel_common" ]
}

config("telephony_codec_config") {
  include_dirs = [ "codec/include" ]
}

config("telephony_log_config") {
  include_dirs = [ "log/include" ]
}

config("tel_napi_config") {
  include_dirs = [
    "../frameworks/js/napi/",
    "../frameworks/js/network_search/include/",
    "../interfaces/innerkits/include/",
  ]
}

config("tel_utils_config") {
  include_dirs = [
    "common/include",
    "preferences/include",
    "log/include",
  ]
}

config("tel_contact_config") {
  include_dirs = [
    "vcard/include",
    "vcard/include/contact_data",
  ]
}

ohos_shared_library("libtel_common") {
  sanitize = {
    cfi = true
    cfi_cross_dso = true
    debug = false
  }
  branch_protector_ret = "pac_ret"
  if (core_service_support_esim) {
    version_script = "libtel_common_esim.versionscript"
  } else {
    version_script = "libtel_common.versionscript"
  }

  sources = [
    "../frameworks/js/napi/napi_util.cpp",
    "common/src/base64.cpp",
    "common/src/enum_convert.cpp",
    "common/src/str_convert.cpp",
    "common/src/tel_aes_crypto_util.cpp",
    "common/src/tel_event_handler.cpp",
    "common/src/tel_event_queue.cpp",
    "common/src/telephony_common_utils.cpp",
    "common/src/telephony_config.cpp",
    "common/src/telephony_ext_utils_wrapper.cpp",
    "common/src/telephony_permission.cpp",
    "preferences/src/tel_profile_util.cpp",
  ]

  if (core_service_support_esim) {
    sources += [
      "codec/src/asn1_builder.cpp",
      "codec/src/asn1_decoder.cpp",
      "codec/src/asn1_node.cpp",
      "codec/src/asn1_utils.cpp",
      "codec/src/request_apdu_build.cpp",
      "codec/src/reset_response.cpp",
    ]
  }

  defines = [
    "TELEPHONY_LOG_TAG = \"TelephonyCommon\"",
    "LOG_DOMAIN = 0xD001F04",
  ]

  if (is_standard_system) {
    defines += [ "STANDARD_SYSTEM_ENABLE" ]
  }

  configs = [ "../utils:telephony_log_config" ]

  if (core_service_support_esim) {
    configs += [ "../utils:telephony_codec_config" ]
  }

  public_configs = [
    ":tel_napi_config",
    ":tel_utils_config",
  ]

  if (core_service_support_esim) {
    public_configs += [ ":telephony_codec_config" ]
  }

  if (is_double_framework) {
    cflags_cc = [ "-DCONFIG_DUAL_FRAMEWORK" ]
  }

  external_deps = [
    "access_token:libaccesstoken_sdk",
    "access_token:libprivacy_sdk",
    "access_token:libtokenid_sdk",
    "bundle_framework:appexecfwk_base",
    "bundle_framework:appexecfwk_core",
    "c_utils:utils",
    "eventhandler:libeventhandler",
    "ffrt:libffrt",
    "hilog:libhilog",
    "hisysevent:libhisysevent",
    "huks:libhukssdk",
    "init:libbegetutil",
    "ipc:ipc_single",
    "napi:ace_napi",
    "openssl:libcrypto_shared",
    "preferences:native_preferences",
    "samgr:samgr_proxy",
  ]

  innerapi_tags = [ "platformsdk" ]
  part_name = "core_service"
  subsystem_name = "telephony"
}

ohos_shared_library("libtel_vcard") {
  version_script = "libtel_vcard.versionscript"
  sources = [
    "vcard/src/contact_data/vcard_anniversary_data.cpp",
    "vcard/src/contact_data/vcard_birthday_data.cpp",
    "vcard/src/contact_data/vcard_email_data.cpp",
    "vcard/src/contact_data/vcard_event_data.cpp",
    "vcard/src/contact_data/vcard_group_data.cpp",
    "vcard/src/contact_data/vcard_im_data.cpp",
    "vcard/src/contact_data/vcard_name_data.cpp",
    "vcard/src/contact_data/vcard_nickname_data.cpp",
    "vcard/src/contact_data/vcard_note_data.cpp",
    "vcard/src/contact_data/vcard_organization_data.cpp",
    "vcard/src/contact_data/vcard_phone_data.cpp",
    "vcard/src/contact_data/vcard_photo_data.cpp",
    "vcard/src/contact_data/vcard_postal_data.cpp",
    "vcard/src/contact_data/vcard_relation_data.cpp",
    "vcard/src/contact_data/vcard_sip_data.cpp",
    "vcard/src/contact_data/vcard_uid_data.cpp",
    "vcard/src/contact_data/vcard_website_data.cpp",
    "vcard/src/vcard_configuration.cpp",
    "vcard/src/vcard_constructor.cpp",
    "vcard/src/vcard_contact.cpp",
    "vcard/src/vcard_decoder.cpp",
    "vcard/src/vcard_decoder_v21.cpp",
    "vcard/src/vcard_decoder_v30.cpp",
    "vcard/src/vcard_decoder_v40.cpp",
    "vcard/src/vcard_encoder.cpp",
    "vcard/src/vcard_file_utils.cpp",
    "vcard/src/vcard_manager.cpp",
    "vcard/src/vcard_raw_data.cpp",
    "vcard/src/vcard_rdb_helper.cpp",
    "vcard/src/vcard_utils.cpp",
  ]

  branch_protector_ret = "pac_ret"

  defines = [
    "TELEPHONY_LOG_TAG = \"TelephonyVCard\"",
    "LOG_DOMAIN = 0xD001F04",
  ]

  if (is_standard_system) {
    defines += [ "STANDARD_SYSTEM_ENABLE" ]
  }

  configs = [ "../utils:telephony_log_config" ]

  public_configs = [ ":tel_contact_config" ]

  if (is_double_framework) {
    cflags_cc = [ "-DCONFIG_DUAL_FRAMEWORK" ]
  }

  cflags_cc = [
    "-Os",
    "-D_FORTIFY_SOURCE=2",
  ]

  include_dirs = [
    ":tel_contact_config",
    "../interfaces/innerkits/include/",
  ]

  deps = [ ":libtel_common" ]

  external_deps = [
    "ability_base:want",
    "ability_base:zuri",
    "ability_runtime:ability_manager",
    "ability_runtime:data_ability_helper",
    "c_utils:utils",
    "data_share:datashare_common",
    "data_share:datashare_consumer",
    "hilog:libhilog",
    "init:libbegetutil",
    "i18n:intl_util",
    "ipc:ipc_single",
  ]

  innerapi_tags = [ "platformsdk" ]
  part_name = "core_service"
  subsystem_name = "telephony"
}