# Copyright (c) 2024-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("//build/test.gni")
import("../../../multimodalinput_mini.gni")

module_output_path = "input/input"

config("oh_input_manager_config") {
  visibility = [ ":*" ]
  include_dirs = [ "../../../interfaces/kits/c/input" ]
}

ohos_shared_library("oh_input_manager") {
  branch_protector_ret = "pac_ret"
  sanitize = {
    integer_overflow = true
    ubsan = true
    boundary_sanitize = true
    cfi = true
    cfi_cross_dso = true
    debug = false
  }

  configs = [
    "${mmi_path}/service/filter:mmi_event_filter_config",
    "${mmi_path}/common/anco/comm:mmi_anco_channel_config",
  ]

  public_configs = [ ":oh_input_manager_config" ]

  include_dirs = [
    "${mmi_path}/common/anco/comm/include",
    "${mmi_path}/frameworks/native/input/",
    "${mmi_path}/frameworks/native/input/include",
    "${mmi_path}/interfaces/kits/c/input/",
    "${mmi_path}/interfaces/native/innerkits/",
    "${mmi_path}/service/connect_manager/include",
    "${mmi_path}/service/filter/include",
    "${mmi_path}/service/module_loader/include",
    "${mmi_path}/service/nap_process/include",
    "${mmi_path}/service/permission_helper/include",
    "${mmi_path}/util/common/include",
    "${mmi_path}/util/socket/include",
    "${mmi_path}/util/network/include",
    "${mmi_path}/frameworks/proxy/event_handler/include",
    "${mmi_path}/frameworks/proxy/module_loader/include",
    "${mmi_path}/frameworks/proxy/events/include",
  ]

  sources = [
    "${mmi_path}/frameworks/native/input/oh_input_device_listener.cpp",
    "${mmi_path}/frameworks/native/input/oh_input_interceptor.cpp",
    "${mmi_path}/frameworks/native/input/oh_input_manager.cpp",
    "${mmi_path}/service/permission_helper/src/permission_helper.cpp",
  ]

  cflags = [
    "-Werror",
    "-Oz",
  ]

  deps = [
    "${mmi_path}/frameworks/proxy:libmmi-client",
    "${mmi_path}/util:libmmi-util",
  ]

  external_deps = [
    "access_token:libaccesstoken_sdk",
    "access_token:libtokenid_sdk",
    "access_token:libprivacy_sdk",
    "c_utils:utils",
    "eventhandler:libeventhandler",
    "hilog:libhilog",
    "init:libbegetutil",
    "image_framework:image_native",
    "image_framework:pixelmap",
  ]

  if (enable_player_framework) {
    external_deps += [
      "ipc:ipc_single",
      "player_framework:media_client",
    ]
  }

  if (input_feature_api_metrics_histogram) {
    external_deps += [ "api_metrics:histogrammanager" ]
  }

  innerapi_tags = [ "ndk" ]

  output_name = "ohinput"
  output_extension = "so"
  subsystem_name = "multimodalinput"
  part_name = "input"

  relative_install_dir = "ndk"
}

ohos_unittest("OHInputManagerTest") {
  module_out_path = module_output_path
  include_dirs = [
    "${mmi_path}/frameworks/native/input/include",
    "${mmi_path}/interfaces/kits/c/input",
    "${mmi_path}/service/connect_manager/include",
    "${mmi_path}/service/filter/include",
    "${mmi_path}/service/module_loader/include",
    "${mmi_path}/service/nap_process/include",
    "${mmi_path}/service/permission_helper/include",
    "${mmi_path}/frameworks/native/input/test/",
  ]
  sources = [
    "${mmi_path}/frameworks/native/input/oh_input_device_listener.cpp",
    "${mmi_path}/frameworks/native/input/oh_input_interceptor.cpp",
    "${mmi_path}/frameworks/native/input/oh_input_manager.cpp",
    "${mmi_path}/frameworks/native/input/test/oh_input_manager_test.cpp",
    "${mmi_path}/service/permission_helper/src/permission_helper.cpp",
  ]

  configs = [
    "${mmi_path}:coverage_flags",
    "${mmi_path}/frameworks/proxy:libmmi_test_util",
    "${mmi_path}/service/filter:mmi_event_filter_config",
    "${mmi_path}/common/anco/comm:mmi_anco_channel_config",
  ]

  branch_protector_ret = "pac_ret"
  sanitize = {
    cfi = true
    cfi_cross_dso = true
    debug = false
    blocklist = "./ipc_blocklist.txt"
  }

  deps = [
    "${mmi_path}/frameworks/proxy:libmmi-client",
    "${mmi_path}/util:libmmi-util",
    "${mmi_path}/frameworks/proxy:libmmi-common",
  ]

  external_deps = [
    "access_token:libaccesstoken_sdk",
    "access_token:libtokenid_sdk",
    "access_token:libprivacy_sdk",
    "c_utils:utils",
    "eventhandler:libeventhandler",
    "googletest:gmock_main",
    "googletest:gtest_main",
    "hilog:libhilog",
    "init:libbegetutil",
    "ipc:ipc_single",
    "image_framework:image_native",
    "image_framework:pixelmap",
    "napi:ace_napi",
    "node:node_header_notice",
  ]

  if (enable_player_framework) {
    external_deps += [ "player_framework:media_client" ]
  }

  if (input_feature_api_metrics_histogram) {
    external_deps += [ "api_metrics:histogrammanager" ]
  }
}

ohos_unittest("OHInputManagerEXTest") {
  module_out_path = module_output_path
  include_dirs = [
    "${mmi_path}/frameworks/native/input/include",
    "${mmi_path}/interfaces/kits/c/input",
    "${mmi_path}/service/connect_manager/include",
    "${mmi_path}/service/filter/include",
    "${mmi_path}/service/module_loader/include",
    "${mmi_path}/service/nap_process/include",
    "${mmi_path}/service/permission_helper/include",
  ]
  sources = [
    "${mmi_path}/frameworks/native/input/oh_input_device_listener.cpp",
    "${mmi_path}/frameworks/native/input/oh_input_interceptor.cpp",
    "${mmi_path}/frameworks/native/input/oh_input_manager.cpp",
    "${mmi_path}/frameworks/native/input/test/mock.cpp",
    "${mmi_path}/frameworks/native/input/test/oh_input_manager_ex_test.cpp",
    "${mmi_path}/service/permission_helper/src/permission_helper.cpp",
  ]

  configs = [
    "${mmi_path}:coverage_flags",
    "${mmi_path}/frameworks/proxy:libmmi_test_util",
    "${mmi_path}/service/filter:mmi_event_filter_config",
    "${mmi_path}/common/anco/comm:mmi_anco_channel_config",
  ]

  deps = [
    "${mmi_path}/frameworks/proxy:libmmi-client",
    "${mmi_path}/util:libmmi-util",
    "${mmi_path}/frameworks/proxy:libmmi-common",
  ]

  external_deps = [
    "access_token:libaccesstoken_sdk",
    "access_token:libtokenid_sdk",
    "access_token:libprivacy_sdk",
    "c_utils:utils",
    "eventhandler:libeventhandler",
    "googletest:gmock_main",
    "googletest:gtest_main",
    "hilog:libhilog",
    "init:libbegetutil",
    "ipc:ipc_single",
    "image_framework:image_native",
    "image_framework:pixelmap",
    "napi:ace_napi",
    "node:node_header_notice",
  ]

  if (enable_player_framework) {
    external_deps += [ "player_framework:media_client" ]
  }

  if (input_feature_api_metrics_histogram) {
    external_deps += [ "api_metrics:histogrammanager" ]
  }
}

ohos_unittest("GetPointerLocationTest") {
  module_out_path = module_output_path
  include_dirs = [
    "${mmi_path}/frameworks/native/input/include",
    "${mmi_path}/interfaces/kits/c/input",
    "${mmi_path}/service/connect_manager/include",
    "${mmi_path}/service/filter/include",
    "${mmi_path}/service/module_loader/include",
    "${mmi_path}/service/nap_process/include",
    "${mmi_path}/service/permission_helper/include",
    "${mmi_path}/frameworks/native/input/test/",
  ]

  sources = [
    "${mmi_path}/frameworks/native/input/oh_input_device_listener.cpp",
    "${mmi_path}/frameworks/native/input/oh_input_interceptor.cpp",
    "${mmi_path}/frameworks/native/input/oh_input_manager.cpp",
    "${mmi_path}/frameworks/native/input/test/oh_input_get_pointer_location_test.cpp",
    "${mmi_path}/service/permission_helper/src/permission_helper.cpp",
  ]

  configs = [
    "${mmi_path}:coverage_flags",
    "${mmi_path}/frameworks/proxy:libmmi_test_util",
    "${mmi_path}/service/filter:mmi_event_filter_config",
    "${mmi_path}/common/anco/comm:mmi_anco_channel_config",
  ]

  branch_protector_ret = "pac_ret"
  sanitize = {
    cfi = true
    cfi_cross_dso = true
    debug = false
    blocklist = "./ipc_blocklist.txt"
  }

  deps = [
    "${mmi_path}/frameworks/proxy:libmmi-client",
    "${mmi_path}/util:libmmi-util",
    "${mmi_path}/frameworks/proxy:libmmi-common",
  ]

  external_deps = [
    "access_token:libaccesstoken_sdk",
    "access_token:libtokenid_sdk",
    "access_token:libprivacy_sdk",
    "c_utils:utils",
    "eventhandler:libeventhandler",
    "googletest:gmock_main",
    "googletest:gtest_main",
    "hilog:libhilog",
    "init:libbegetutil",
    "ipc:ipc_single",
    "image_framework:image_native",
    "image_framework:pixelmap",
    "napi:ace_napi",
    "node:node_header_notice",
  ]

  if (enable_player_framework) {
    external_deps += [ "player_framework:media_client" ]
  }
}

ohos_unittest("SetDisplayBindTest") {
  module_out_path = module_output_path
  include_dirs = [
    "${mmi_path}/frameworks/native/input/include",
    "${mmi_path}/interfaces/kits/c/input",
    "${mmi_path}/service/connect_manager/include",
    "${mmi_path}/service/filter/include",
    "${mmi_path}/service/module_loader/include",
    "${mmi_path}/service/nap_process/include",
    "${mmi_path}/service/permission_helper/include",
    "${mmi_path}/frameworks/native/input/test/",
  ]

   sources = [
    "${mmi_path}/frameworks/native/input/oh_input_device_listener.cpp",
    "${mmi_path}/frameworks/native/input/oh_input_interceptor.cpp",
    "${mmi_path}/frameworks/native/input/oh_input_manager.cpp",
    "${mmi_path}/frameworks/native/input/test/oh_input_set_display_bind_test.cpp",
    "${mmi_path}/service/permission_helper/src/permission_helper.cpp",
  ]

  configs = [
    "${mmi_path}:coverage_flags",
    "${mmi_path}/frameworks/proxy:libmmi_test_util",
    "${mmi_path}/service/filter:mmi_event_filter_config",
    "${mmi_path}/common/anco/comm:mmi_anco_channel_config",
  ]

  branch_protector_ret = "pac_ret"
  sanitize = {
    cfi = true
    cfi_cross_dso = true
    debug = false
    blocklist = "./ipc_blocklist.txt"
  }

  deps = [
    "${mmi_path}/frameworks/proxy:libmmi-client",
    "${mmi_path}/util:libmmi-util",
    "${mmi_path}/frameworks/proxy:libmmi-common",
  ]

  external_deps = [
    "access_token:libaccesstoken_sdk",
    "access_token:libtokenid_sdk",
    "access_token:libprivacy_sdk",
    "c_utils:utils",
    "eventhandler:libeventhandler",
    "googletest:gmock_main",
    "googletest:gtest_main",
    "hilog:libhilog",
    "init:libbegetutil",
    "ipc:ipc_single",
    "image_framework:image_native",
    "image_framework:pixelmap",
    "napi:ace_napi",
    "node:node_header_notice",
  ]

  if (enable_player_framework) {
    external_deps += [ "player_framework:media_client" ]
  }
}