# Copyright (c) 2023 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("../../windowmanager_aafwk.gni")

config("session_public_config") {
  include_dirs = [
    "host/include",
    "${window_base_path}/window_scene",
    "${window_base_path}/window_scene/screen_session_manager_client/include",
    "${window_base_path}/window_scene/intention_event/service/anr_manager/include",
    "${window_base_path}/window_scene/intention_event/framework/anr_handler/include",
    "${window_base_path}/window_scene/intention_event/utils/include",
    "${window_base_path}/interfaces/innerkits/dm",
    "${window_base_path}/wm/include/zidl",

    # for window_manager_hilog
    "${window_base_path}/utils/include",
    "${window_base_path}/window_scene/common/include",

    # for WMError Code
    "${window_base_path}/interfaces/innerkits/wm",
  ]

  cflags = []
  defines = []
  if (window_manager_feature_asbng_path_enable) {
    defines += [ "WINDOW_ATOMIC_SERVICE_ATTRIBUTION_ENABLE" ]
    cflags +=
        [ "-DACE_ENGINE_PLUGIN_PATH=\"${window_manager_feature_asbng_path}\"" ]
  }
}

config("ui_effect_public_config") {
  include_dirs = [ "${window_base_path}/window_scene/session/host/include" ]
}

ohos_source_set("ui_effect_controller_client") {
  branch_protector_ret = "pac_ret"
  sanitize = {
    cfi = true
    cfi_cross_dso = true
    cfi_vcall_icall_only = true
    debug = false
    cfi_policy = "adaptive"
  }
  sources = [
    "host/src/ui_effect_controller_client.cpp",
    "host/src/ui_effect_controller_client_stub.cpp",
    "host/src/ui_effect_controller_proxy.cpp",
  ]
  external_deps = [
    "ability_runtime:runtime",
    "c_utils:utils",
    "graphic_2d:librender_service_client",
    "hilog:libhilog",
    "napi:ace_napi",
    "node:node_header_notice",
    "libuv:uv",
    ]
  public_configs = [ ":ui_effect_public_config" ]
  deps = [ "${window_base_path}/utils:ui_effect_controller_common" ]
  part_name = "window_manager"
  subsystem_name = "window"
}

ohos_source_set("ui_effect_controller") {
  branch_protector_ret = "pac_ret"
  sanitize = {
    cfi = true
    cfi_cross_dso = true
    cfi_vcall_icall_only = true
    debug = false
    cfi_policy = "adaptive"
  }
  sources = [
    "host/src/ui_effect_controller.cpp",
    "host/src/ui_effect_controller_client_proxy.cpp",
    "host/src/ui_effect_controller_stub.cpp",
  ]
  public_configs = [ ":ui_effect_public_config" ]
  external_deps = [
    "ability_runtime:runtime",
    "c_utils:utils",
    "graphic_2d:librender_service_client",
    "hilog:libhilog",
    "napi:ace_napi",
    "node:node_header_notice",
    "libuv:uv",
    ]
  deps = [
    "${window_base_path}/utils:ui_effect_controller_common",
    "${window_base_path}/window_scene/common:window_scene_common",

    ]
  part_name = "window_manager"
  subsystem_name = "window"
}

ohos_static_library("scene_session_static") {
    branch_protector_ret = "pac_ret"
  sanitize = {
    cfi = true
    cfi_cross_dso = true
    cfi_vcall_icall_only = true
    debug = false
  }
  sources = [
    "container/src/window_event_channel.cpp",
    "container/src/zidl/session_stage_proxy.cpp",
    "container/src/zidl/session_stage_stub.cpp",
    "container/src/zidl/window_event_channel_proxy.cpp",
    "container/src/zidl/window_event_channel_stub.cpp",
    "host/src/ability_info_manager.cpp",
    "host/src/extension_session.cpp",
    "host/src/keyboard_session.cpp",
    "host/src/layout_controller.cpp",
    "host/src/main_session.cpp",
    "host/src/move_drag_bounds_applier.cpp",
    "host/src/move_drag_controller.cpp",
    "host/src/move_resampler.cpp",
    "host/src/multi_instance_manager.cpp",
    "host/src/pc_fold_screen_controller.cpp",
    "host/src/pc_fold_screen_manager.cpp",
    "host/src/root_scene_session.cpp",
    "host/src/scb_system_session.cpp",
    "host/src/scene_node_count_callback.cpp",
    "host/src/scene_persistence.cpp",
    "host/src/scene_persistent_storage.cpp",
    "host/src/scene_session.cpp",
    "host/src/session.cpp",
    "host/src/session_change_recorder.cpp",
    "host/src/session_coordinate_helper.cpp",
    "host/src/session_utils.cpp",
    "host/src/sub_session.cpp",
    "host/src/system_session.cpp",
    "host/src/ui_extension/host_data_handler.cpp",
    "host/src/ws_ffrt_helper.cpp",
    "host/src/ws_snapshot_helper.cpp",
    "host/src/zidl/session_proxy.cpp",
    "host/src/zidl/session_stub.cpp",
    "host/src/zidl/scene_node_count_callback_proxy.cpp",
    "host/src/zidl/scene_node_count_callback_stub.cpp",
  ]

  if (window_manager_feature_asbng_path_enable) {
    sources += [ "host/src/atomicservice_basic_engine_plugin.cpp" ]
  }

  public_configs = [ ":session_public_config" ]

  deps = [
    "${window_base_path}/dm:libdm",
    "${window_base_path}/utils:libwmutil",
    "${window_base_path}/utils:libwmutil_base",
    "${window_base_path}/window_scene/common:window_scene_common",
    "${window_base_path}/window_scene/intention_event/service:intention_event_anr_manager",
    "${window_base_path}/window_scene/interfaces/innerkits:libwsutils",
    "${window_base_path}/window_scene/screen_session_manager_client:screen_session_manager_client",
    "${window_base_path}/window_scene/session:screen_session",
  ]

  external_deps = [
    "ability_base:base",
    "ability_base:session_info",
    "ability_base:want",
    "accessibility:accessibility_common",
    "accessibility:accessibility_interface",
    "ability_base:configuration",
    "ability_runtime:ability_manager",
    "ability_runtime:ability_start_setting",
    "ability_runtime:app_context",
    "ability_runtime:app_manager",
    "ability_runtime:process_options",
    "ability_runtime:start_window_option",
    "bundle_framework:appexecfwk_base",
    "bundle_framework:appexecfwk_core",
    "bundle_framework:libappexecfwk_common",
    "c_utils:utils",
    "eventhandler:libeventhandler",
    "ffrt:libffrt",
    "graphic_2d:librender_service_base",
    "graphic_2d:librender_service_client",
    "graphic_2d:window_animation",
    "hilog:libhilog",
    "hisysevent:libhisysevent",
    "hitrace:hitrace_meter",
    "hitrace:libhitracechain",
    "image_framework:image_native",
    "init:libbegetutil",
    "input:libmmi-client",
    "input:libmmi-napi",
    "ipc:ipc_single",
    "samgr:samgr_proxy",
    "zlib:shared_libz",
  ]
  if (!(host_os == "linux" && host_cpu == "arm64")) {
    external_deps += [ "preferences:native_preferences" ]
  }

  defines = []

  if (defined(global_parts_info) &&
      defined(global_parts_info.barrierfree_accessibility)) {
    external_deps += [ "accessibility:accessibility_common" ]
  }

  if (defined(global_parts_info) &&
      defined(global_parts_info.powermgr_power_manager)) {
    external_deps += [ "power_manager:powermgr_client" ]
    defines += [ "POWER_MANAGER_ENABLE" ]
  }

  if (defined(global_parts_info) &&
      defined(global_parts_info.resourceschedule_resource_schedule_service)) {
    external_deps += [ "resource_schedule_service:ressched_client" ]
    defines += [ "RES_SCHED_ENABLE" ]
  }

  if (device_status_enable) {
    external_deps += [ "device_status:devicestatus_client" ]
    defines += [ "DEVICE_STATUS_ENABLE" ]
  }

  if (!defined(global_parts_info) ||
      defined(global_parts_info.inputmethod_imf)) {
    imf_enable = true
  } else {
    imf_enable = false
  }
  print("imf_enable: ", imf_enable)
  if (imf_enable == true) {
    external_deps += [ "imf:inputmethod_client" ]
    defines += [ "IMF_ENABLE" ]
  }

  if (build_variant == "root") {
    defines += [ "ACCESSIBILITY_DUMP_FOR_TEST" ]
  }

  part_name = "window_manager"
  subsystem_name = "window"

  if (build_variant == "user") {
    defines += [ "IS_RELEASE_VERSION" ]
  }
}

ohos_shared_library("scene_session") {
  branch_protector_ret = "pac_ret"
  sanitize = {
    cfi = true
    cfi_cross_dso = true
    cfi_vcall_icall_only = true
    debug = false
    cfi_policy = "adaptive"
  }
  sources = [
    "container/src/window_event_channel.cpp",
    "container/src/zidl/session_stage_proxy.cpp",
    "container/src/zidl/session_stage_stub.cpp",
    "container/src/zidl/window_event_channel_proxy.cpp",
    "container/src/zidl/window_event_channel_stub.cpp",
    "host/src/ability_info_manager.cpp",
    "host/src/extension_session.cpp",
    "host/src/keyboard_session.cpp",
    "host/src/layout_controller.cpp",
    "host/src/main_session.cpp",
    "host/src/move_drag_bounds_applier.cpp",
    "host/src/move_drag_controller.cpp",
    "host/src/move_resampler.cpp",
    "host/src/multi_instance_manager.cpp",
    "host/src/pc_fold_screen_controller.cpp",
    "host/src/pc_fold_screen_manager.cpp",
    "host/src/root_scene_session.cpp",
    "host/src/scb_system_session.cpp",
    "host/src/scene_node_count_callback.cpp",
    "host/src/scene_persistence.cpp",
    "host/src/scene_persistent_storage.cpp",
    "host/src/scene_session.cpp",
    "host/src/session.cpp",
    "host/src/session_change_recorder.cpp",
    "host/src/session_coordinate_helper.cpp",
    "host/src/session_utils.cpp",
    "host/src/sub_session.cpp",
    "host/src/system_session.cpp",
    "host/src/ui_extension/host_data_handler.cpp",
    "host/src/ws_ffrt_helper.cpp",
    "host/src/ws_snapshot_helper.cpp",
    "host/src/zidl/session_proxy.cpp",
    "host/src/zidl/session_stub.cpp",
    "host/src/zidl/scene_node_count_callback_proxy.cpp",
    "host/src/zidl/scene_node_count_callback_stub.cpp",
  ]

  if (window_manager_feature_asbng_path_enable) {
    sources += [ "host/src/atomicservice_basic_engine_plugin.cpp" ]
  }

  version_script = "libscene_session.map"

  public_configs = [ ":session_public_config" ]

  deps = [
    "${window_base_path}/dm:libdm",
    "${window_base_path}/utils:libwmutil",
    "${window_base_path}/utils:libwmutil_base",
    "${window_base_path}/window_scene/common:window_scene_common",
    "${window_base_path}/window_scene/intention_event/service:intention_event_anr_manager",
    "${window_base_path}/window_scene/interfaces/innerkits:libwsutils",
    "${window_base_path}/window_scene/screen_session_manager_client:screen_session_manager_client",
    "${window_base_path}/window_scene/session:screen_session",
  ]

  external_deps = [
    "ability_base:base",
    "ability_base:configuration",
    "ability_base:session_info",
    "ability_base:want",
    "ability_runtime:ability_manager",
    "ability_runtime:ability_start_setting",
    "ability_runtime:app_context",
    "ability_runtime:app_manager",
    "ability_runtime:process_options",
    "ability_runtime:start_window_option",
    "accessibility:accessibility_common",
    "accessibility:accessibility_interface",
    "bundle_framework:appexecfwk_base",
    "bundle_framework:appexecfwk_core",
    "bundle_framework:libappexecfwk_common",
    "c_utils:utils",
    "eventhandler:libeventhandler",
    "ffrt:libffrt",
    "graphic_2d:librender_service_base",
    "graphic_2d:librender_service_client",
    "graphic_2d:window_animation",
    "hilog:libhilog",
    "hisysevent:libhisysevent",
    "hitrace:hitrace_meter",
    "image_framework:image_native",
    "init:libbegetutil",
    "input:libmmi-client",
    "input:libmmi-napi",
    "ipc:ipc_single",
    "samgr:samgr_proxy",
    "zlib:shared_libz",
    "egl:libEGL",
    "opengles:libGLES",
  ]

  if (!(host_os == "linux" && host_cpu == "arm64")) {
    external_deps += [ "preferences:native_preferences" ]
  }
  
  defines = []

  if (defined(global_parts_info) &&
      defined(global_parts_info.barrierfree_accessibility)) {
    external_deps += [ "accessibility:accessibility_common" ]
  }

  if (defined(global_parts_info) &&
      defined(global_parts_info.powermgr_power_manager)) {
    external_deps += [ "power_manager:powermgr_client" ]
    defines += [ "POWER_MANAGER_ENABLE" ]
  }

  if (defined(global_parts_info) &&
      defined(global_parts_info.resourceschedule_resource_schedule_service)) {
    external_deps += [ "resource_schedule_service:ressched_client" ]
    defines += [ "RES_SCHED_ENABLE" ]
  }

  if (device_status_enable) {
    external_deps += [ "device_status:devicestatus_client" ]
    defines += [ "DEVICE_STATUS_ENABLE" ]
  }

  if (!defined(global_parts_info) ||
      defined(global_parts_info.inputmethod_imf)) {
    imf_enable = true
  } else {
    imf_enable = false
  }
  print("imf_enable: ", imf_enable)
  if (imf_enable == true) {
    external_deps += [ "imf:inputmethod_client" ]
    defines += [ "IMF_ENABLE" ]
  }

  if (build_variant == "root") {
    defines += [ "ACCESSIBILITY_DUMP_FOR_TEST" ]
  }

  innerapi_tags = [ "platformsdk" ]
  part_name = "window_manager"
  subsystem_name = "window"

  if (build_variant == "user") {
    defines += [ "IS_RELEASE_VERSION" ]
  }
  ldflags = [ "-Wl,-Bsymbolic-functions" ]
}

screen_session_sources = [
  "screen/src/screen_property.cpp",
  "screen/src/screen_session.cpp",
]

screen_session_deps = [
  "${window_base_path}/utils:libwmutil",
  "${window_base_path}/utils:libwmutil_base",
]

screen_session_external_deps = [
  "ability_base:base",
  "ability_base:want",
  "accessibility:accessibility_common",
  "bundle_framework:appexecfwk_core",
  "c_utils:utils",
  "graphic_2d:librender_service_base",
  "graphic_2d:librender_service_client",
  "hicollie:libhicollie",
  "hilog:libhilog",
  "hisysevent:libhisysevent",
  "hitrace:hitrace_meter",
  "init:libbegetutil",
  "input:libmmi-napi",
  "ipc:ipc_single",
]

## Build libscreen_session_static.a
ohos_static_library("screen_session_static") {
  branch_protector_ret = "pac_ret"
  sanitize = {
    cfi = true
    cfi_cross_dso = true
    cfi_vcall_icall_only = true
    debug = false
    cfi_policy = "adaptive"
  }

  public_configs = [ ":session_public_config" ]
  sources = screen_session_sources
  deps = screen_session_deps
  external_deps = screen_session_external_deps

  defines = []
  if (window_manager_feature_screen_color_gamut) {
    defines += [ "WM_SCREEN_COLOR_GAMUT_ENABLE" ]
  }

  if (window_manager_feature_screen_hdr_format) {
    defines += [ "WM_SCREEN_HDR_FORMAT_ENABLE" ]
  }

  if (window_manager_feature_screen_color_space) {
    defines += [ "WM_SCREEN_COLOR_SPACE_ENABLE" ]
  }

  part_name = "window_manager"
  subsystem_name = "window"
}

## Build libscreen_session.z.so
ohos_shared_library("screen_session") {
  branch_protector_ret = "pac_ret"
  sanitize = {
    cfi = true
    cfi_cross_dso = true
    cfi_vcall_icall_only = true
    debug = false
    cfi_policy = "adaptive"
  }

  public_configs = [ ":session_public_config" ]
  sources = screen_session_sources
  deps = screen_session_deps
  external_deps = screen_session_external_deps

  defines = []
  if (window_manager_feature_screen_color_gamut) {
    defines += [ "WM_SCREEN_COLOR_GAMUT_ENABLE" ]
  }

  if (window_manager_feature_screen_hdr_format) {
    defines += [ "WM_SCREEN_HDR_FORMAT_ENABLE" ]
  }

  if (window_manager_feature_screen_color_space) {
    defines += [ "WM_SCREEN_COLOR_SPACE_ENABLE" ]
  }

  version_script = "libscreen_session.map"

  innerapi_tags = [ "platformsdk" ]
  part_name = "window_manager"
  subsystem_name = "window"
}