# 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.

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

config("appmgr_config") {
  include_dirs = [
    "include",
    "//base/startup/appspawn_standard/interfaces/innerkits/include",
    "//utils/system/safwk/native/include",
    "//base/account/os_account/interfaces/innerkits/osaccount/native/include",
    "//base/notification/ces_standard/frameworks/core/include",
    "//base/notification/ces_standard/interfaces/innerkits/native/include",
    "//base/security/permission/interfaces/innerkits/permission_standard/permissionsdk/main/cpp/include",
    "//base/global/i18n_standard/frameworks/intl/include",
  ]
}

group("ams_target") {
  deps = [
    ":libams",
    ":lmks",
    ":lmks.rc",
    "examples:appmgrserviceregtest",
    "examples:appspawnclienttest",
  ]
}

ohos_executable("lmks") {
  include_dirs = [
    "include/lmks",
    "//utils/native/base/include",
  ]

  sources = [
    "src/lmks/lmks_main.cpp",
    "src/lmks/lmks_server.cpp",
    "src/lmks/lmks_utils.cpp",
  ]

  cflags = []
  if (target_cpu == "arm") {
    cflags += [ "-DBINDER_IPC_32BIT" ]
  }

  deps = [ "//utils/native/base:utils" ]

  external_deps = [ "hiviewdfx_hilog_native:libhilog" ]

  install_enable = true
  subsystem_name = "aafwk"
  part_name = "ability_runtime"
}

ohos_prebuilt_etc("lmks.rc") {
  source = "lmks.cfg"
  relative_install_dir = "init"
  subsystem_name = "aafwk"
  part_name = "ability_runtime"
}

ohos_shared_library("libams") {
  sources = [
    "src/ability_running_record.cpp",
    "src/ams_mgr_scheduler.cpp",
    "src/app_death_recipient.cpp",
    "src/app_lifecycle_deal.cpp",
    "src/app_mgr_service.cpp",
    "src/app_mgr_service_event_handler.cpp",
    "src/app_mgr_service_inner.cpp",
    "src/app_process_manager.cpp",
    "src/app_running_manager.cpp",
    "src/app_running_record.cpp",
    "src/app_spawn_client.cpp",
    "src/app_spawn_msg_wrapper.cpp",
    "src/app_spawn_socket.cpp",
    "src/cgroup_manager.cpp",
    "src/lmks_client.cpp",
    "src/module_running_record.cpp",
    "src/process_optimizer.cpp",
    "src/process_optimizer_uba.cpp",
    "src/remote_client_manager.cpp",
    "src/system_environment_information.cpp",
  ]

  defines = [
    "APP_LOG_TAG = \"AppMgrService\"",
    "LOG_DOMAIN = 0xD001110",
  ]

  configs = [
    ":appmgr_config",
    "${appexecfwk_path}/libs/libeventhandler:libeventhandler_config",
    "${aafwk_path}/interfaces/innerkits/app_manager:appmgr_sdk_config",
  ]
  cflags = []
  if (target_cpu == "arm") {
    cflags += [ "-DBINDER_IPC_32BIT" ]
  }
  deps = [
    "${aafwk_path}/interfaces/innerkits/app_manager:app_manager",
    "${appexecfwk_path}/common:libappexecfwk_common",
    "${appexecfwk_path}/interfaces/innerkits/appexecfwk_base:appexecfwk_base",
    "${appexecfwk_path}/interfaces/innerkits/appexecfwk_core:appexecfwk_core",
    "${appexecfwk_path}/libs/libeventhandler:libeventhandler_target",
    "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits",
    "//base/global/i18n_standard/frameworks/intl:intl_util",
    "//base/security/permission/interfaces/innerkits/permission_standard/permissionsdk:libpermissionsdk_standard",
    "//foundation/aafwk/standard/interfaces/innerkits/base:base",
    "//foundation/aafwk/standard/interfaces/innerkits/want:want",
    "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk",
    "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
    "//utils/native/base:utils",
  ]

  external_deps = [
    "appspawn:appspawn_socket_client",
    "bytrace_standard:bytrace_core",
    "ces_standard:cesfwk_core",
    "ces_standard:cesfwk_innerkits",
    "hiviewdfx_hilog_native:libhilog",
    "ipc:ipc_core",
  ]

  subsystem_name = "aafwk"
  part_name = "ability_runtime"
}
