# Copyright (c) 2021-2025 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/ability/ability_runtime/ability_runtime.gni")

config("appmgr_sdk_config") {
  include_dirs = [
    "include/appmgr",
    "${ability_runtime_path}/interfaces/kits/native/ability/native",
    "${ability_runtime_innerkits_path}/ability_manager/include",
  ]
  defines = []
  if (ability_command_for_test) {
    defines += [ "ABILITY_COMMAND_FOR_TEST" ]
  }
  if (ability_runtime_child_process) {
    defines += [ "SUPPORT_CHILD_PROCESS" ]
  }
}

config("appmgr_core_config") {
  include_dirs = [ "include" ]
  defines = []
  if (ability_command_for_test) {
    defines += [ "ABILITY_COMMAND_FOR_TEST" ]
  }
  if (ability_runtime_child_process) {
    defines += [ "SUPPORT_CHILD_PROCESS" ]
  }
}

ohos_shared_library("app_manager") {
  branch_protector_ret = "pac_ret"
  sanitize = {
    integer_overflow = true
    ubsan = true
    boundary_sanitize = true
    cfi = true
    cfi_cross_dso = true
    cfi_vcall_icall_only = true
    cfi_policy = "adaptive"
    debug = false
  }

  include_dirs = [
    "${ability_runtime_path}/interfaces/kits/native/appkit/dfr",
    "${ability_runtime_path}/utils/global/common/include",
    "${ability_runtime_path}/utils/global/time/include",
    "${ability_runtime_services_path}/appdfr/include",
    "${ability_runtime_services_path}/appmgr/include",
    "${ability_runtime_services_path}/common/include",
    "${ability_runtime_utils_path}/global/constant",
  ]

  sources = [
    "${ability_runtime_services_path}/appdfr/src/appfreeze_cpu_freq_manager.cpp",
    "${ability_runtime_services_path}/appdfr/src/appfreeze_event_report.cpp",
    "${ability_runtime_services_path}/appdfr/src/appfreeze_manager.cpp",
    "${ability_runtime_services_path}/appdfr/src/app_recovery_mgr.cpp",
    "${ability_runtime_services_path}/appdfr/src/appfreeze_util.cpp",
    "${ability_runtime_services_path}/appdfr/src/cpu_data_processor.cpp",
    "${ability_runtime_services_path}/appdfr/src/cpu_sys_config.cpp",
    "src/appmgr/ability_controller_proxy.cpp",
    "src/appmgr/ability_controller_stub.cpp",
    "src/appmgr/ability_debug_response_proxy.cpp",
    "src/appmgr/ability_debug_response_stub.cpp",
    "src/appmgr/ability_foreground_state_observer_proxy.cpp",
    "src/appmgr/ability_foreground_state_observer_stub.cpp",
    "src/appmgr/ability_info_callback_proxy.cpp",
    "src/appmgr/ability_info_callback_stub.cpp",
    "src/appmgr/ability_state_data.cpp",
    "src/appmgr/ams_mgr_proxy.cpp",
    "src/appmgr/ams_mgr_stub.cpp",
    "src/appmgr/app_cjheap_mem_info.cpp",
    "src/appmgr/app_debug_info.cpp",
    "src/appmgr/app_debug_listener_proxy.cpp",
    "src/appmgr/app_debug_listener_stub.cpp",
    "src/appmgr/app_foreground_state_observer_proxy.cpp",
    "src/appmgr/app_foreground_state_observer_stub.cpp",
    "src/appmgr/app_mem_dump_info.cpp",
    "src/appmgr/app_jsheap_mem_info.cpp",
    "src/appmgr/app_jshandle_map_info.cpp",
    "src/appmgr/app_launch_data.cpp",
    "src/appmgr/app_malloc_info.cpp",
    "src/appmgr/app_mgr_client.cpp",
    "src/appmgr/app_mgr_proxy.cpp",
    "src/appmgr/app_mgr_stub.cpp",
    "src/appmgr/app_process_data.cpp",
    "src/appmgr/app_record_id.cpp",
    "src/appmgr/app_running_status_proxy.cpp",
    "src/appmgr/app_running_status_stub.cpp",
    "src/appmgr/app_scheduler_host.cpp",
    "src/appmgr/app_scheduler_proxy.cpp",
    "src/appmgr/app_service_manager.cpp",
    "src/appmgr/app_state_callback_host.cpp",
    "src/appmgr/app_state_callback_proxy.cpp",
    "src/appmgr/app_state_data.cpp",
    "src/appmgr/application_state_filter.cpp",
    "src/appmgr/application_state_observer_proxy.cpp",
    "src/appmgr/application_state_observer_stub.cpp",
    "src/appmgr/background_app_info.cpp",
    "src/appmgr/child_process_info.cpp",
    "src/appmgr/child_scheduler_proxy.cpp",
    "src/appmgr/child_scheduler_stub.cpp",
    "src/appmgr/configuration_observer_proxy.cpp",
    "src/appmgr/configuration_observer_stub.cpp",
    "src/appmgr/configuration_policy.cpp",
    "src/appmgr/fault_data.cpp",
    "src/appmgr/image_process_state_data.cpp",
    "src/appmgr/image_error_handler_proxy.cpp",
    "src/appmgr/image_error_handler_stub.cpp",
    "src/appmgr/image_process_state_observer_proxy.cpp",
    "src/appmgr/image_process_state_observer_stub.cpp",
    "src/appmgr/kia_interceptor_proxy.cpp",
    "src/appmgr/kia_interceptor_stub.cpp",
    "src/appmgr/load_ability_callback_manager.cpp",
    "src/appmgr/load_ability_callback_proxy.cpp",
    "src/appmgr/load_ability_callback_stub.cpp",
    "src/appmgr/memory_level_info.cpp",
    "src/appmgr/mem_dump_callback_proxy.cpp",
    "src/appmgr/mem_dump_callback_stub.cpp",
    "src/appmgr/native_child_notify_proxy.cpp",
    "src/appmgr/native_child_notify_stub.cpp",
    "src/appmgr/page_state_data.cpp",
    "src/appmgr/preload_process_data.cpp",
    "src/appmgr/priority_object.cpp",
    "src/appmgr/process_bind_data.cpp",
    "src/appmgr/process_data.cpp",
    "src/appmgr/process_info.cpp",
    "src/appmgr/process_memory_state.cpp",
    "src/appmgr/profile.cpp",
    "src/appmgr/quick_fix_callback_proxy.cpp",
    "src/appmgr/quick_fix_callback_stub.cpp",
    "src/appmgr/render_process_info.cpp",
    "src/appmgr/render_scheduler_host.cpp",
    "src/appmgr/render_scheduler_proxy.cpp",
    "src/appmgr/render_state_data.cpp",
    "src/appmgr/render_state_observer_proxy.cpp",
    "src/appmgr/render_state_observer_stub.cpp",
    "src/appmgr/running_multi_info.cpp",
    "src/appmgr/running_process_info.cpp",
    "src/appmgr/start_specified_ability_response_proxy.cpp",
    "src/appmgr/start_specified_ability_response_stub.cpp",
    "src/appmgr/system_memory_attr.cpp",
  ]

  public_configs = [
    ":appmgr_core_config",
    ":appmgr_sdk_config",
  ]

  configs = [ "${ability_runtime_services_path}/common:optimize_config" ]

  defines = [ "AMS_LOG_TAG = \"AppexecfwkCore\"" ]
  defines += [ "AMS_LOG_DOMAIN = 0xD001306" ]
  cflags = []
  if (target_cpu == "arm") {
    cflags += [ "-DBINDER_IPC_32BIT" ]
  }
  deps = [
    "${ability_runtime_path}/utils/global/common:runtime_utils",
    "${ability_runtime_path}/utils/global/freeze:freeze_util",
    "${ability_runtime_path}/utils/server/startup:startup_util",
    "${ability_runtime_services_path}/common:app_util",
    "${ability_runtime_services_path}/common:hisysevent_report",
  ]

  external_deps = [
    "c_utils:utils",
    "faultloggerd:libdfx_dumpcatcher",
    "faultloggerd:libfaultloggerd",
    "ffrt:libffrt",
    "hicollie:libhicollie",
    "hilog:libhilog",
    "hisysevent:libhisysevent",
    "eventhandler:libeventhandler",
    "ability_base:session_info",
    "hitrace:hitrace_meter",
    "hitrace:libhitracechain",
    "init:libbegetutil",
    "ipc:ipc_core",
    "json:nlohmann_json_static",
    "samgr:samgr_proxy",
  ]
  public_external_deps = [
    "ability_base:configuration",
    "ability_base:session_info",
    "ability_base:want",
    "bundle_framework:appexecfwk_base",
    # used in push service
    "image_framework:image_native",
    "relational_store:native_rdb",
  ]
  if (ability_runtime_child_process) {
    defines += [ "SUPPORT_CHILD_PROCESS" ]
    sources += [
      "src/appmgr/child_process_args.cpp",
      "src/appmgr/child_process_options.cpp",
      "src/appmgr/child_process_request.cpp",
    ]
  }

  if (background_task_mgr_continuous_task_enable) {
    defines += [ "BGTASKMGR_CONTINUOUS_TASK_ENABLE" ]
  }

  if (ability_runtime_hitrace_enable) {
    external_deps += [ "hitrace:libhitracechain" ]
    defines += [ "ABILITY_RUNTIME_HITRACE_ENABLE" ]
  }

  if (ability_runtime_app_no_response_dialog) {
    defines += [ "APP_NO_RESPONSE_DIALOG" ]
  }

  innerapi_tags = [ "platformsdk" ]
  subsystem_name = "ability"
  part_name = "ability_runtime"
}

ohos_shared_library("app_state_data") {
  sanitize = {
    integer_overflow = true
    ubsan = true
    boundary_sanitize = true
    cfi = true
    cfi_cross_dso = true
    cfi_vcall_icall_only = true
    cfi_policy = "adaptive"
    debug = false
  }
  branch_protector_ret = "pac_ret"

  include_dirs = [
    "include/appmgr",
    "${ability_runtime_path}/utils/global/common/include",
    "${ability_runtime_services_path}/common/include",
  ]

  sources = [ 
    "src/appmgr/app_state_data.cpp",
    "${ability_runtime_path}/utils/global/common/src/ui_extension_wrapper.cpp"
  ]

  defines = [ "AMS_LOG_TAG = \"AppexecfwkCore\"" ]
  defines += [ "AMS_LOG_DOMAIN = 0xD001306" ]
  cflags = []
  if (target_cpu == "arm") {
    cflags += [ "-DBINDER_IPC_32BIT" ]
  }

  external_deps = [
    "bundle_framework:appexecfwk_base",
    "c_utils:utils",
    "hilog:libhilog",
    "ipc:ipc_single",
  ]

  innerapi_tags = [ "platformsdk" ]
  subsystem_name = "ability"
  part_name = "ability_runtime"
}