# Copyright (c) 2021-2022 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.

import("//build/ohos.gni")
import("//foundation/aafwk/standard/aafwk.gni")

config("ability_config") {
  visibility = [ ":*" ]
  include_dirs = [
    "include",
    "include/continuation/distributed",
    "include/continuation/kits",
    "include/continuation/remote_register_service",
    "include/distributed_ability_runtime",
    "${kits_path}/appkit/native/app/include",
    "${innerkits_path}/app_manager/include/appmgr",
    "${innerkits_path}/uri/include",
    "${services_path}/abilitymgr/include",
    "${kits_path}/appkit/native/ability_runtime/app",
    "${kits_path}/appkit/native/app/include",
    "${form_runtime_path}/interfaces/kits/native/include",
    "${kits_path}/app/native/app/include",
    "${services_path}/common/include",
    "//third_party/node/src",
    "${innerkits_path}/ability_manager/include/continuation",
    "${kits_path}/appkit/native/app/include/task",
    "${aafwk_path}/interfaces/kits/napi/aafwk/inner/napi_common",
    "${aafwk_path}/interfaces/kits/napi/aafwk/featureAbility",
  ]

  cflags = []
  if (target_cpu == "arm") {
    cflags += [ "-DBINDER_IPC_32BIT" ]
  }
  defines = [
    "AMS_LOG_TAG = \"Ability\"",
    "AMS_LOG_DOMAIN = 0xD002200",
  ]
  if (target_cpu == "arm64") {
    defines += [ "_ARM64_" ]
  }

  if (ability_runtime_graphics) {
    include_dirs += [ "${form_runtime_path}/interfaces/inner_api/include" ]
    defines += [ "SUPPORT_GRAPHICS" ]
  }
}

config("ability_public_config") {
  visibility = [ ":*" ]
  include_dirs = [
    "include",
    "include/continuation/distributed",
    "include/continuation/kits",
    "include/continuation/remote_register_service",
    "include/distributed_ability_runtime",
    "${kits_path}/appkit/native",
    "${kits_path}/appkit/native/ability_runtime/app",
    "${kits_path}/appkit/native/app/include",
    "${kits_path}/appkit/native/ability_runtime",
    "//third_party/libuv/include",
    "${kits_path}/appkit/native/ability_runtime/context",
    "${innerkits_path}/ability_manager/include/continuation",
    "${global_path}/resource_management/interfaces/inner_api/include",
    "//third_party/jsoncpp/include",
    "//third_party/json/include",
  ]

  if (ability_runtime_graphics) {
    include_dirs += [
      "${form_runtime_path}/interfaces/kits/native/include",
      "${form_runtime_path}/interfaces/inner_api/include",
      "${windowmanager_path}/interfaces/innerkits/wm",
      "${windowmanager_path}/interfaces/kits/napi/window_runtime/window_stage_napi",
    ]
    defines = [ "SUPPORT_GRAPHICS" ]
  }
}

ohos_shared_library("static_subscriber_ipc") {
  include_dirs = [ "include" ]

  sources = [
    "src/static_subscriber_proxy.cpp",
    "src/static_subscriber_stub.cpp",
  ]

  deps = []

  external_deps = [
    "ability_base:want",
    "common_event_service:cesfwk_innerkits",
    "ipc:ipc_core",
    "samgr_standard:samgr_proxy",
    "utils_base:utils",
  ]

  subsystem_name = "aafwk"
  part_name = "ability_runtime"
}

ohos_shared_library("abilitykit_native") {
  include_dirs = [
    "${distributeddatamgr_path}/appdatamgr/frameworks/js/napi/rdb/include",
    "${distributeddatamgr_path}/appdatamgr/frameworks/js/napi//common/include",
    "${distributeddatamgr_path}/appdatamgr/frameworks/js/napi/dataability/include",
    "${distributeddatamgr_path}/objectstore/interfaces/innerkits/",
  ]

  sources = [
    "${aafwk_path}/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_ability.cpp",
    "${aafwk_path}/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_configuration.cpp",
    "${aafwk_path}/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_start_options.cpp",
    "${aafwk_path}/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_util.cpp",
    "${aafwk_path}/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_want.cpp",
    "${distributeddatamgr_path}/appdatamgr/frameworks/js/napi/common/src/js_utils.cpp",
    "${distributeddatamgr_path}/appdatamgr/frameworks/js/napi/dataability/src/napi_data_ability_predicates.cpp",
    "${distributeddatamgr_path}/appdatamgr/frameworks/js/napi/rdb/src/napi_result_set.cpp",
    "${innerkits_path}/app_manager/src/appmgr/process_info.cpp",
    "${kits_path}/appkit/native/ability_runtime/context/context_impl.cpp",
    "${kits_path}/appkit/native/ability_runtime/extension_context.cpp",
    "${kits_path}/appkit/native/ability_runtime/service_extension_context.cpp",
    "${kits_path}/appkit/native/ability_runtime/static_subscriber_extension_context.cpp",
    "${kits_path}/appkit/native/app/src/application_context.cpp",
    "${kits_path}/appkit/native/app/src/context_container.cpp",
    "${kits_path}/appkit/native/app/src/context_deal.cpp",
    "${kits_path}/appkit/native/app/src/sys_mgr_client.cpp",
    "${services_path}/abilitymgr/src/ability_start_setting.cpp",
    "${services_path}/abilitymgr/src/launch_param.cpp",
    "src/ability.cpp",
    "src/ability_context.cpp",
    "src/ability_handler.cpp",
    "src/ability_impl.cpp",
    "src/ability_impl_factory.cpp",
    "src/ability_lifecycle.cpp",
    "src/ability_lifecycle_executor.cpp",
    "src/ability_loader.cpp",
    "src/ability_local_record.cpp",
    "src/ability_post_event_timeout.cpp",
    "src/ability_process.cpp",
    "src/ability_runtime/js_ability.cpp",
    "src/ability_runtime/js_ability_context.cpp",
    "src/ability_runtime/js_caller_complex.cpp",
    "src/ability_thread.cpp",
    "src/continuation/distributed/continuation_handler.cpp",
    "src/continuation/distributed/continuation_manager.cpp",
    "src/continuation/distributed/reverse_continuation_scheduler_primary.cpp",
    "src/continuation/distributed/reverse_continuation_scheduler_primary_proxy.cpp",
    "src/continuation/distributed/reverse_continuation_scheduler_primary_stub.cpp",
    "src/continuation/distributed/reverse_continuation_scheduler_recipient.cpp",
    "src/continuation/distributed/reverse_continuation_scheduler_replica.cpp",
    "src/continuation/distributed/reverse_continuation_scheduler_replica_proxy.cpp",
    "src/continuation/distributed/reverse_continuation_scheduler_replica_stub.cpp",
    "src/continuation/remote_register_service/connect_callback_proxy.cpp",
    "src/continuation/remote_register_service/connect_callback_stub.cpp",
    "src/continuation/remote_register_service/continuation_connector.cpp",
    "src/continuation/remote_register_service/continuation_device_callback_proxy.cpp",
    "src/continuation/remote_register_service/continuation_register_manager.cpp",
    "src/continuation/remote_register_service/continuation_register_manager_proxy.cpp",
    "src/continuation/remote_register_service/remote_register_service_proxy.cpp",
    "src/continuation/remote_register_service/remote_register_service_stub.cpp",
    "src/data_ability_helper.cpp",
    "src/data_ability_impl.cpp",
    "src/data_ability_operation.cpp",
    "src/data_ability_operation_builder.cpp",
    "src/data_ability_result.cpp",
    "src/data_uri_utils.cpp",
    "src/distributed_ability_runtime/distributed_client.cpp",
    "src/extension.cpp",
    "src/extension_impl.cpp",
    "src/extension_module_loader.cpp",
    "src/js_service_extension.cpp",
    "src/js_service_extension_context.cpp",
    "src/js_static_subscriber_extension.cpp",
    "src/js_static_subscriber_extension_context.cpp",
    "src/mission_information.cpp",
    "src/new_ability_impl.cpp",
    "src/service_ability_impl.cpp",
    "src/service_extension.cpp",
    "src/static_subscriber_extension.cpp",
    "src/static_subscriber_stub_imp.cpp",
  ]
  configs = [ ":ability_config" ]
  public_configs = [
    ":ability_public_config",
    "${kits_path}/ability/ability_runtime:ability_context_public_config",
    "${kits_path}/wantagent:wantagent_innerkits_public_config",
  ]

  deps = [
    ":static_subscriber_ipc",
    "${innerkits_path}/dataobs_manager:dataobs_manager",
    "${kits_path}/appkit:app_context",
    "${kits_path}/appkit:appkit_delegator",
  ]

  external_deps = [
    "ability_base:base",
    "ability_base:configuration",
    "ability_base:want",
    "ability_base:zuri",
    "ability_runtime:ability_context_native",
    "ability_runtime:ability_manager",
    "ability_runtime:app_manager",
    "ability_runtime:napi_base_context",
    "ability_runtime:runtime",
    "ability_runtime:wantagent_innerkits",
    "access_token:libaccesstoken_sdk",
    "bundle_framework:appexecfwk_base",
    "bundle_framework:appexecfwk_core",
    "common_event_service:cesfwk_innerkits",
    "dataability:native_dataability",
    "hitrace_native:hitrace_meter",
    "ipc:ipc_core",
    "ipc_js:rpc",
    "relational_store:native_appdatafwk",
    "relational_store:native_rdb",
    "resource_management:global_resmgr",
    "samgr_standard:samgr_proxy",
    "utils_base:utils",
  ]

  defines = []
  if (os_account_part_enabled) {
    defines += [ "OS_ACCOUNT_PART_ENABLED" ]
    external_deps += [ "os_account:os_account_innerkits" ]
  }

  if (background_task_mgr_continuous_task_enable) {
    external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ]
    defines += [ "BGTASKMGR_CONTINUOUS_TASK_ENABLE" ]
  }

  if (distributed_data_object_enable) {
    external_deps += [ "distributeddataobject:distributeddataobject_impl" ]
    defines += [ "DISTRIBUTED_DATA_OBJECT_ENABLE" ]
  }

  public_deps = [
    "${bundlefwk_innerkits_path}/libeventhandler:libeventhandler",
    "${global_path}/resource_management/frameworks/resmgr:global_resmgr",
    "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
    "//foundation/arkui/napi:ace_napi",
  ]

  if (ability_runtime_graphics) {
    include_dirs += []
    sources += [
      "${kits_path}/appkit/native/ability_runtime/form_extension_context.cpp",
      "src/ability_window.cpp",
      "src/form_extension.cpp",
      "src/form_js_event_handler.cpp",
      "src/form_provider_client.cpp",
      "src/form_runtime/form_extension_provider_client.cpp",
      "src/form_runtime/js_form_extension.cpp",
      "src/form_runtime/js_form_extension_context.cpp",
      "src/form_runtime/js_form_extension_util.cpp",
      "src/page_ability_impl.cpp",
    ]
    deps += [
      "${multimodalinput_path}/frameworks/proxy:libmmi-common",
      "//third_party/icu/icu4c:shared_icuuc",
    ]

    external_deps += [
      "form_runtime:fmskit_native",
      "form_runtime:form_manager",
      "input:libmmi-client",
      "multimedia_image_standard:image",
    ]

    public_deps += [
      "${global_path}/i18n/frameworks/intl:intl_util",
      "${graphic_path}:libwmclient",
      "${multimedia_path}/interfaces/innerkits:image_native",
      "${windowmanager_path}/dm:libdm",
      "${windowmanager_path}/interfaces/kits/napi/window_runtime:windowstage_kit",
      "${windowmanager_path}/wm:libwm",
    ]
  }
  subsystem_name = "aafwk"
  part_name = "ability_runtime"
}

ohos_shared_library("service_extension_module") {
  include_dirs = [ "include" ]

  sources = [ "src/service_extension_module_loader.cpp" ]

  configs = [ ":ability_config" ]
  public_configs = [ ":ability_public_config" ]

  deps = [ ":abilitykit_native" ]

  external_deps = [
    "ability_base:want",
    "ability_runtime:runtime",
    "hiviewdfx_hilog_native:libhilog",
    "ipc:ipc_core",
    "utils_base:utils",
  ]

  relative_install_dir = "extensionability/"
  subsystem_name = "aafwk"
  part_name = "ability_runtime"
}
