# Copyright (c) 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("//base/update/updateservice/updateengine.gni")
import("//build/ohos.gni")
import("$updateengine_root_path/services/core/ability/log/log.gni")
import("$updateengine_root_path/services/core/ability/sqlite/sqlite.gni")
import("$updateengine_root_path/services/firmware/firmware.gni")
import("$updateengine_root_path/services/startup/startup.gni")

declare_args() {
  ability_ability_base_enable = true
  if (!defined(global_parts_info.ability_ability_base)) {
    ability_ability_base_enable = false
  }
  ability_ability_runtime_enable = true
  if (!defined(global_parts_info.ability_ability_runtime)) {
    ability_ability_runtime_enable = false
  }
  communication_netmanager_base_enable = true
  if (!defined(global_parts_info.communication_netmanager_base)) {
    communication_netmanager_base_enable = false
  }
  preference_native_preferences_enable = true
  if (!defined(global_parts_info.distributeddatamgr_preferences)) {
    preference_native_preferences_enable = false
  }
}

sa_sources = [
  "$updateengine_root_path/services/callback/src/update_callback.cpp",
  "$updateengine_root_path/services/callback/src/update_callback_proxy.cpp",
  "$updateengine_root_path/services/callback/src/update_callback_stub.cpp",
  "$updateengine_root_path/services/core/ability/adapter/src/config_parse.cpp",
  "$updateengine_root_path/services/core/ability/adapter/src/device_adapter.cpp",
  "$updateengine_root_path/services/core/ability/alarm/src/alarm_manager.cpp",
  "$updateengine_root_path/services/core/ability/alarm/src/timer_manager.cpp",
  "$updateengine_root_path/services/core/ability/status_cache/src/status_cache.cpp",
  "$updateengine_root_path/services/core/ability/utils/src/file_utils.cpp",
  "$updateengine_root_path/services/core/ability/utils/src/sha256_utils.cpp",
  "$updateengine_root_path/services/core/ability/utils/src/time_utils_proxy.cpp",
  "$updateengine_root_path/services/engine/src/message_parcel_helper.cpp",
  "$updateengine_root_path/services/engine/src/progress_thread.cpp",
  "$updateengine_root_path/services/engine/src/update_helper.cpp",
  "$updateengine_root_path/services/engine/src/update_service.cpp",
  "$updateengine_root_path/services/engine/src/update_service_cache.cpp",
  "$updateengine_root_path/services/engine/src/update_service_impl_firmware.cpp",
  "$updateengine_root_path/services/engine/src/update_service_impl_manager.cpp",
  "$updateengine_root_path/services/engine/src/update_service_local_updater.cpp",
  "$updateengine_root_path/services/engine/src/update_service_restorer.cpp",
  "$updateengine_root_path/services/engine/src/update_service_stub.cpp",
  "$updateengine_root_path/services/engine/src/update_service_util_hmos.cpp",
  "$updateengine_root_path/services/utils/src/dupdate_timer.c",
]

if (ability_ability_base_enable || ability_ability_runtime_enable) {
  sa_sources += [
    "$updateengine_root_path/services/core/ability/callback/src/base_callback_utils.cpp",
    "$updateengine_root_path/services/engine/src/update_notify.cpp",
  ]
} else {
  sa_sources += [ "$updateengine_root_path/services/core/ability/callback/src/base_callback_utils_empty.cpp" ]
}

if (communication_netmanager_base_enable) {
  sa_sources += [
    "$updateengine_root_path/services/utils/src/dupdate_net_manager.cpp",
    "$updateengine_root_path/services/utils/src/dupdate_net_observer.cpp",
  ]
} else {
  sa_sources += [
    "$updateengine_root_path/services/utils/src/dupdate_net_manager_empty.cpp",
  ]
}

if (preference_native_preferences_enable) {
  sa_sources += [ "$updateengine_root_path/services/core/ability/preference/src/preference_utils.cpp" ]
} else {
  sa_sources += [ "$updateengine_root_path/services/core/ability/preference/src/preference_utils_empty.cpp" ]
}

sa_sources += firmware_src
sa_sources += sqlite_src
sa_sources += update_log_src
sa_sources += startup_src

sa_include_dirs = [
  "$updateengine_root_path/services/auto_update/include",
  "$updateengine_root_path/services/bi_report/include",
  "$updateengine_root_path/services/callback/include",
  "$updateengine_root_path/services/core/ability/adapter/include",
  "$updateengine_root_path/services/core/ability/alarm/include",
  "$updateengine_root_path/services/core/ability/callback/include",
  "$updateengine_root_path/services/core/ability/common/include",
  "$updateengine_root_path/services/core/ability/define/include",
  "$updateengine_root_path/services/core/ability/model/include",
  "$updateengine_root_path/services/core/ability/net/include",
  "$updateengine_root_path/services/core/ability/preference/include",
  "$updateengine_root_path/services/core/ability/status_cache/include",
  "$updateengine_root_path/services/core/ability/utils/include",
  "$updateengine_root_path/services/engine/include",
  "$updateengine_root_path/services/osal/include",
  "$updateengine_root_path/services/service/include",
  "$updateengine_root_path/services/utils/include",
  "$updateengine_root_path/interfaces/inner_api/include",
  "//base/update/updater/interfaces/kits/include",  # package.h/updaterkits.h
  "//base/update/updater/services/include",  # fs_manager/mount.h
  "//commonlibrary/utils_lite/include",  # OHOS_SUCCESS
  "//third_party/curl/include",
  "//utils/native/base/include",  # sptr
  "//utils/system/safwk/native/include",
  "//third_party/libxml2/include",
  "//third_party/glib/glib",
  "//third_party/glib",
  "//third_party/openssl/include",
  "//third_party/cJSON/",
]

if (!ability_ability_base_enable || !ability_ability_runtime_enable) {
  sa_include_dirs += [
    "//foundation/ability/ability_base/interfaces/inner_api/base/include",
    "//foundation/ability/ability_base/interfaces/kits/native/uri/include",
    "//foundation/ability/ability_base/interfaces/kits/native/want/include",
    "//foundation/ability/ability_runtime/frameworks/simulator/common/include",
    "//foundation/ability/ability_runtime/interfaces/inner_api/ability_manager/include",
    "//foundation/ability/ability_runtime/interfaces/inner_api/app_manager/include/appmgr",
    "//foundation/ability/ability_runtime/interfaces/kits/native/ability/native",
    "//foundation/bundlemanager/bundle_framework/interfaces/inner_api/appexecfwk_base/include",
  ]
}

if (!preference_native_preferences_enable) {
  sa_include_dirs += [
    "//foundation/distributeddatamgr/preferences/interfaces/inner_api/include",
  ]
}

if (!communication_netmanager_base_enable) {
  sa_include_dirs += [
    "//foundation/communication/netmanager_base/interfaces/innerkits/include",
    "//foundation/communication/netmanager_base/interfaces/innerkits/netconnclient/include",
    "//foundation/communication/netmanager_base/interfaces/innerkits/netconnclient/include/proxy",
  ]
}

if (!relational_store_native_rdb_enable) {
  sa_include_dirs += [
    "//base/update/updateservice/services/core/ability/sqlite/core/include",
    "//foundation/distributeddatamgr/relational_store/interfaces/inner_api/rdb/include",
  ]
}

sa_include_dirs += firmware_include
sa_include_dirs += sqlite_include
sa_include_dirs += update_log_include
sa_include_dirs += startup_include

sa_deps = [
  "//base/update/updater/services/fs_manager:libfsmanager",  # factory_reset_GetBlockDeviceByMountPoint_"fs_manager/mount.h"
  "//third_party/cJSON:cjson",
  "//third_party/curl:curl",
  "//third_party/glib:glib_packages",
  "//third_party/jsoncpp:jsoncpp",
  "//third_party/libxml2:libxml2",
  "//third_party/mbedtls:mbedtls_shared",
  "//third_party/openssl:libcrypto_shared",
  "//third_party/openssl:libssl_shared",
]

sa_deps += firmware_deps
sa_deps += update_log_deps
sa_deps += startup_deps

sa_external_deps = [
  "access_token:libaccesstoken_sdk",
  "access_token:libtokenid_sdk",
  "c_utils:utils",  # refbase
  "hilog:libhilog",
  "hisysevent:libhisysevent",
  "init:libbegetutil",
  "ipc:ipc_core",
  "safwk:system_ability_fwk",
  "samgr:samgr_proxy",
  "updater:libpackageExt",  # "package/package.h"
  "updater:libupdaterkits",  # "updaterkits/updaterkits.h"
]

if (ability_ability_base_enable) {
  sa_external_deps += [
    "ability_base:base",
    "ability_base:want",
  ]
}
if (ability_ability_runtime_enable) {
  sa_external_deps += [ "ability_runtime:ability_manager" ]
}
if (communication_netmanager_base_enable) {
  sa_external_deps += [ "netmanager_base:net_conn_manager_if" ]
}
if (preference_native_preferences_enable) {
  sa_external_deps += [ "preferences:native_preferences" ]
}

sa_external_deps += firmware_external_deps
sa_external_deps += sqlite_external_deps
sa_external_deps += update_log_external_deps
sa_external_deps += startup_external_deps

sa_public_deps = []
sa_public_deps += startup_public_deps

sa_defines = [
  "DUAL_ADAPTER",
  "UPDATE_SERVICE",
]

if (ability_ability_base_enable) {
  sa_defines += [ "ABILITY_BASE_ENABLE" ]
}
if (ability_ability_runtime_enable) {
  sa_defines += [ "ABILITY_RUNTIME_ENABLE" ]
}
if (communication_netmanager_base_enable) {
  sa_defines += [ "NETMANAGER_BASE_ENABLE" ]
}
if (preference_native_preferences_enable) {
  sa_defines += [ "NATIVE_PREFERENCES_ENABLE" ]
}
sa_defines += sqlite_defines

sa_cflags = [
  "-fPIC",
  "-Os",
  "-Werror",
]