# Copyright (c) 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("//base/notification/distributed_notification_service/notification.gni")
import("//build/config/components/ets_frontend/ets2abc_config.gni")
import("//build/ohos.gni")

# ROM-004: ANI shared_library extraction
# Extracts shared sts_*.cpp (11,322 lines, redundant 15,732 lines) from 4 ANI targets
# into a single shared library to eliminate duplicate compilation. [PR#4766 借鉴]
# NOTE: 公共库不加 -fvisibility=hidden,让依赖模块可链接公共库符号
ohos_shared_library("notification_ani_common") {
  branch_protector_ret = "pac_ret"
  sanitize = {
    cfi = true
    cfi_cross_dso = true
    cfi_vcall_icall_only = true
    debug = false
  }

  include_dirs = [
    "./include",
    "./include/manager",
    "./include/subscribe",
    "${core_path}/common/include",
    "${inner_api_path}",
  ]

  configs = []

  sources = [
    "./src/sts_common.cpp",
    "./src/sts_throw_erro.cpp",
    "./src/sts_bundle_option.cpp",
    "./src/sts_callback_promise.cpp",
    "./src/sts_notification_flag.cpp",
    "./src/sts_sorting.cpp",
    "./src/sts_sorting_map.cpp",
    "./src/sts_template.cpp",
    "./src/sts_user_input.cpp",
    "./src/sts_subscribe_info.cpp",
    "./src/sts_disturb_mode.cpp",
    "./src/sts_ringtone_info.cpp",
    "./src/sts_notification_manager.cpp",
    "./src/sts_notification_content.cpp",
    "./src/sts_request.cpp",
    "./src/sts_subscribe.cpp",
    "./src/sts_subscriber.cpp",
    "./src/sts_trigger.cpp",
    "./src/sts_convert_other.cpp",
    "./src/sts_slot.cpp",
    "./src/sts_action_button.cpp",
    "${core_path}/src/image_pixelmap_helper.cpp",
    "${core_path}/src/pixelmap_cache_manager.cpp",
    "${core_path}/src/subscriber_image_util.cpp",
  ]

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

  ldflags = notification_size_opt_ldflags

  version_script = "libnotification_ani_common.map"

  deps = [ "${frameworks_module_ans_path}:ans_innerkits" ]

  external_deps = [
    "ability_base:want",
    "ability_base:zuri",
    "ability_runtime:ani_common",
    "ability_runtime:ani_wantagent_common",
    "ability_runtime:app_context",
    "ability_runtime:runtime",
    "ability_runtime:wantagent_innerkits",
    "c_utils:utils",
    "hilog:libhilog",
    "image_framework:image",
    "image_framework:image_native",
    "image_framework:image_source",
    "image_framework:image_taihe",
    "image_framework:pixelmap",
    "ipc:ipc_core",
    "napi:ace_napi",
    "node:node_header_notice",
    "os_account:os_account_innerkits",
    "resource_management:global_resmgr",
    "resource_management:librawfile",
    "runtime_core:ani",
    "runtime_core:ani_helpers",
  ]

  innerapi_tags = [ "platformsdk" ]
  subsystem_name = "${subsystem_name}"
  part_name = "${component_name}"
}

ohos_shared_library("notification_manager_ani") {
  shlib_type = "ani"
  branch_protector_ret = "pac_ret"
  sanitize = {
    cfi = true
    cfi_cross_dso = true
    cfi_vcall_icall_only = true
    debug = false
  }

  include_dirs = [
    "./include",
    "./include/manager",
    "${core_path}/common/include",
    "${inner_api_path}",
    "${frameworks_path}/cj/ffi/include",
  ]

  sources = [
    "./src/manager/ani_ans_dialog_callback.cpp",
    "./src/manager/ani_cance.cpp",
    "./src/manager/ani_display_badge.cpp",
    "./src/manager/ani_distributed_enable.cpp",
    "./src/manager/ani_do_not_disturb_date.cpp",
    "./src/manager/ani_do_not_disturb_profile.cpp",
    "./src/manager/ani_geofence_enabled.cpp",
    "./src/manager/ani_get_active.cpp",
    "./src/manager/ani_get_notification_parameters.cpp",
    "./src/manager/ani_local_live_view.cpp",
    "./src/manager/ani_manager.cpp",
    "./src/manager/ani_notification_enable.cpp",
    "./src/manager/ani_notification_switch.cpp",
    "./src/manager/ani_on.cpp",
    "./src/manager/ani_open_settings.cpp",
    "./src/manager/ani_priority.cpp",
    "./src/manager/ani_publish.cpp",
    "./src/manager/ani_push_callback.cpp",
    "./src/manager/ani_reminder_info.cpp",
    "./src/manager/ani_remove_group.cpp",
    "./src/manager/ani_request_enable.cpp",
    "./src/manager/ani_ringtone_info_by_bundle.cpp",
    "./src/manager/ani_silent_reminder_enable.cpp",
    "./src/manager/ani_slot.cpp",
    "./src/manager/ani_snooze_notification.cpp",
    "./src/manager/ani_statistics.cpp",
    "./src/manager/ani_support_template.cpp",
    "./src/manager/ani_sync_config.cpp",
    "./src/sts_badge_query_callback.cpp",
    "./src/sts_notification_statistics.cpp",
    "./src/sts_reminder_info.cpp",
  ]

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

  ldflags = notification_size_opt_ldflags

  version_script = "libnotification_manager_ani.map"

  deps = [
    ":notification_ani_common",
    "${frameworks_module_ans_path}:ans_innerkits",
    "${frameworks_path}/cj/ffi:cj_notification_manager_ffi",
  ]

  defines = []

  if (distributed_notification_service_disable_control) {
    defines += [ "DISABLE_NOTIFICATION_FEATURE_ENABLE" ]
  }

  if (distributed_notification_service_feature_badge_manager) {
    defines += [ "ANS_FEATURE_BADGE_MANAGER" ]
  }

  if (distributed_notification_service_feature_local_liveview) {
    defines += [ "ANS_FEATURE_LIVEVIEW_LOCAL_LIVEVIEW" ]
  }

  if (distributed_notification_service_feature_distributed_supported) {
    defines += [ "ANS_FEATURE_DISTRIBUTED_SUPPORTED" ]
  }

  if (distributed_notification_service_feature_original_distributed) {
    defines += [ "ANS_FEATURE_ORIGINAL_DISTRIBUTED" ]
  }
  if (distributed_notification_service_feature_disturb_manager) {
    defines += [ "ANS_FEATURE_DISTURB_MANAGER" ]
  }

  if (distributed_notification_service_feature_slot_manager) {
    defines += [ "ANS_FEATURE_SLOT_MANAGER" ]
  }

  if (distributed_notification_service_feature_additional_config) {
    defines += [ "ANS_FEATURE_ADDITIONAL_CONFIG" ]
  }

  if (distributed_notification_service_feature_open_notification_settings) {
    defines += [ "ANS_FEATURE_OPEN_NOTIFICATION_SETTINGS" ]
  }

  if (distributed_notification_service_feature_priority_notification) {
    defines += [ "ANS_FEATURE_PRIORITY_NOTIFICATION" ]
  }

  if (distributed_notification_service_feature_notification_statistics) {
    defines += [ "ANS_FEATURE_NOTIFICATION_STATISTICS" ]
  }

  external_deps = [
    "ability_base:zuri",
    "ability_runtime:ability_context_native",
    "ability_runtime:abilitykit_native",
    "ability_runtime:ani_base_context",
    "ability_runtime:ani_common",
    "ability_runtime:ani_wantagent_common",
    "ability_runtime:app_context",
    "ability_runtime:runtime",
    "ability_runtime:wantagent_innerkits",
    "access_token:libtokenid_sdk",
    "ace_engine:ace_uicontent",
    "c_utils:utils",
    "ffrt:libffrt",
    "hilog:libhilog",
    "image_framework:image",
    "image_framework:image_native",
    "image_framework:image_source",
    "image_framework:image_taihe",
    "image_framework:pixelmap",
    "ipc:ipc_core",
    "napi:ace_napi",
    "node:node_header_notice",
    "os_account:os_account_innerkits",
    "resource_management:global_resmgr",
    "resource_management:librawfile",
    "runtime_core:ani",
    "runtime_core:ani_helpers",
    "window_manager:libwmutil",
  ]

  if (distributed_notification_service_feature_api_metrics) {
    external_deps += [ "api_metrics:histogrammanager" ]
    defines += [ "ANS_FEATURE_API_METRICS_HISTOGRAM" ]
  }

  innerapi_tags = [ "platformsdk" ]
  subsystem_name = "${subsystem_name}"
  part_name = "${component_name}"
}

ohos_shared_library("notification_subscribe_ani") {
  shlib_type = "ani"
  branch_protector_ret = "pac_ret"
  sanitize = {
    cfi = true
    cfi_cross_dso = true
    cfi_vcall_icall_only = true
    debug = false
  }

  include_dirs = [
    "./include",
    "./include/subscribe",
    "${core_path}/common/include",
    "${inner_api_path}",
    "${frameworks_path}/cj/ffi/include",
  ]

  configs = [ "${frameworks_module_ans_path}:ans_innerkits_public_config" ]

  sources = [
    "./src/subscribe/ani_remove.cpp",
    "./src/subscribe/ani_subscribe.cpp",
  ]

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

  ldflags = notification_size_opt_ldflags

  version_script = "libnotification_subscribe_ani.map"

  deps = [
    ":notification_ani_common",
    "${frameworks_module_ans_path}:ans_innerkits",
    "${frameworks_path}/cj/ffi:cj_notification_manager_ffi",
  ]

  external_deps = [
    "ability_base:configuration",
    "ability_base:want",
    "ability_base:zuri",
    "ability_runtime:ani_common",
    "ability_runtime:ani_wantagent_common",
    "ability_runtime:app_context",
    "ability_runtime:runtime",
    "ability_runtime:wantagent_innerkits",
    "c_utils:utils",
    "hilog:libhilog",
    "image_framework:image",
    "image_framework:image_native",
    "image_framework:image_source",
    "image_framework:image_taihe",
    "image_framework:pixelmap",
    "ipc:ipc_core",
    "napi:ace_napi",
    "node:node_header_notice",
    "os_account:os_account_innerkits",
    "resource_management:global_resmgr",
    "resource_management:librawfile",
    "runtime_core:ani",
    "runtime_core:ani_helpers",
  ]

  innerapi_tags = [ "platformsdk" ]
  subsystem_name = "${subsystem_name}"
  part_name = "${component_name}"
}

ohos_shared_library("notificationextensionsubscription_ani") {
  branch_protector_ret = "pac_ret"
  sanitize = {
    cfi = true
    cfi_cross_dso = true
    cfi_vcall_icall_only = true
    debug = false
  }

  include_dirs = [
    "./include",
    "./include/extension_subscription",
    "./include/manager",
    "${core_path}/common/include",
    "${inner_api_path}",
  ]

  configs = []

  sources = [
    "./src/extension_subscription/ani_extension_subscription.cpp",
    "./src/extension_subscription/ani_notification_extension_subscription_info.cpp",
    "./src/extension_subscription/ani_notification_subscriber_extension.cpp",
    "./src/extension_subscription/ani_open_subscribe_settings.cpp",
  ]

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

  ldflags = notification_size_opt_ldflags

  version_script = "libnotificationextensionsubscription_ani.map"

  deps = [
    ":notification_ani_common",
    "${frameworks_module_ans_path}:ans_innerkits",
  ]

  external_deps = [
    "ability_base:want",
    "ability_runtime:ability_context_native",
    "ability_runtime:ability_manager",
    "ability_runtime:abilitykit_native",
    "ability_runtime:ani_base_context",
    "ability_runtime:ani_common",
    "ability_runtime:app_context",
    "ability_runtime:extensionkit_native",
    "ability_runtime:napi_common",
    "ability_runtime:runtime",
    "ace_engine:ace_uicontent",
    "c_utils:utils",
    "hilog:libhilog",
    "ipc:ipc_core",
    "ipc:ipc_napi",
    "napi:ace_napi",
    "node:node_header_notice",
    "os_account:os_account_innerkits",
    "resource_management:global_resmgr",
    "runtime_core:ani",
    "runtime_core:ani_helpers",
    "window_manager:libwmutil",
  ]

  defines = []

  if (distributed_notification_service_feature_api_metrics) {
    external_deps += [ "api_metrics:histogrammanager" ]
    defines += [ "ANS_FEATURE_API_METRICS_HISTOGRAM" ]
  }

  innerapi_tags = [ "platformsdk" ]
  subsystem_name = "${subsystem_name}"
  part_name = "${component_name}"
}

ohos_shared_library("notification_subscriber_extension_ani") {
  branch_protector_ret = "pac_ret"
  sanitize = {
    cfi = true
    cfi_cross_dso = true
    cfi_vcall_icall_only = true
    debug = false
  }

  include_dirs = [
    "./include",
    "./include/extension",
    "${core_path}/common/include",
    "${frameworks_module_extension_path}/include",
    "${inner_api_path}",
  ]

  configs = []

  sources = [
    "./src/extension/sts_notification_extension_content.cpp",
    "./src/extension/sts_notification_info.cpp",
    "./src/extension/sts_notification_subscriber_extension.cpp",
    "./src/extension/sts_notification_subscriber_extension_context.cpp",
  ]

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

  ldflags = notification_size_opt_ldflags

  version_script = "libnotification_subscriber_extension_ani.map"

  deps = [
    ":notification_ani_common",
    "${frameworks_module_ans_path}:ans_innerkits",
    "${frameworks_module_extension_path}:notification_subscriber_extension_common",
    "${frameworks_module_extension_path}:notification_subscriber_ipc",
  ]

  external_deps = [
    "ability_base:want",
    "ability_runtime:ability_context_native",
    "ability_runtime:ability_manager",
    "ability_runtime:ani_common",
    "ability_runtime:app_context",
    "ability_runtime:extensionkit_native",
    "ability_runtime:napi_common",
    "ability_runtime:runtime",
    "c_utils:utils",
    "hilog:libhilog",
    "ipc:ipc_core",
    "ipc:ipc_napi",
    "libuv:uv",
    "napi:ace_napi",
    "node:node_header_notice",
    "os_account:os_account_innerkits",
    "resource_management:global_resmgr",
    "runtime_core:ani",
    "runtime_core:ani_helpers",
  ]

  innerapi_tags = [ "platformsdk" ]
  subsystem_name = "${subsystem_name}"
  part_name = "${component_name}"
}