chromium/services/device/BUILD.gn

# Copyright 2016 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/chromeos/ui_mode.gni")
import("//build/config/chromeos/ui_mode.gni")
import("//build/config/features.gni")
import("//services/device/public/cpp/compute_pressure/buildflags.gni")
import("//services/device/public/cpp/geolocation/buildflags.gni")
import("//testing/test.gni")

if (is_android) {
  import("//build/config/android/rules.gni")
  import("//third_party/jni_zero/jni_zero.gni")
}

is_serial_enabled_platform =
    is_win || ((is_linux || is_chromeos) && use_udev) || is_mac

source_set("lib") {
  # This should be visible only to embedders of the Device Service, and the
  # dependence should only be for the purpose of embedding the Device Service.
  visibility = [
    ":test_support",
    ":tests",
    "//content/browser",
    "//content/test:test_support",
    "//services/device/public/cpp:test_support",
  ]
  sources = [
    "device_service.cc",
    "device_service.h",
  ]

  configs += [ "//build/config/compiler:wexit_time_destructors" ]

  deps = [
    ":binder_overrides",
    "//build:chromeos_buildflags",
    "//services/device/fingerprint",
    "//services/device/generic_sensor",
    "//services/device/geolocation",
    "//services/device/power_monitor",
    "//services/device/public/cpp:device_features",
    "//services/device/public/cpp/compute_pressure:buildflags",
    "//services/device/public/mojom:geolocation_internals",
    "//services/device/public/mojom:usb",
    "//services/device/public/mojom:usb_test",
    "//services/device/screen_orientation",
    "//services/device/time_zone_monitor",
    "//services/device/usb/mojo",
    "//services/device/vibration",
    "//services/device/wake_lock",
    "//services/service_manager/public/cpp",
    "//ui/gfx",
  ]

  public_deps = [
    "//base",
    "//mojo/public/cpp/bindings",
    "//services/device/public/mojom",
    "//services/device/public/mojom:device_service",
  ]

  if (is_android) {
    deps += [ ":device_service_jni_headers" ]
  } else {
    deps += [
      "//services/device/battery",
      "//services/device/hid",
    ]
  }

  if (enable_compute_pressure) {
    deps += [ "//services/device/compute_pressure" ]
  }

  if (is_chromeos_ash && use_dbus) {
    deps += [ "//services/device/media_transfer_protocol" ]
  }

  if (is_serial_enabled_platform) {
    deps += [ "//services/device/serial" ]
  }

  if (is_chromeos_lacros) {
    deps += [
      "//chromeos/crosapi/mojom",
      "//chromeos/lacros",
    ]
  }

  if (is_serial_enabled_platform) {
    defines = [ "IS_SERIAL_ENABLED_PLATFORM" ]
  }
}

# NOTE: We use a separate component target to support global binder overrides,
# since the service implementation itself may be linked into multiple
# simultaneously loaded binary targets in a component build. The ":lib" target
# cannot be a component target itself because it depends on generated JNI
# headers that do not currently support component exports.
component("binder_overrides") {
  visibility = [ ":lib" ]
  output_name = "device_service_binder_overrides"
  sources = [
    "binder_overrides.cc",
    "binder_overrides.h",
  ]
  configs += [ "//build/config/compiler:wexit_time_destructors" ]
  public_deps = [
    "//base",
    "//mojo/public/cpp/bindings",
    "//services/device/public/mojom",
  ]
  defines = [ "IS_DEVICE_SERVICE_BINDER_OVERRIDES_IMPL" ]
}

source_set("perftests") {
  testonly = true

  sources = [ "geolocation/position_cache_impl_perftest.cc" ]

  deps = [
    ":test_support",
    "//base",
    "//base/test:test_support",
    "//services/device/geolocation",
    "//services/device/geolocation:test_support",
    "//testing/gtest",
    "//testing/perf",
  ]
}

source_set("tests") {
  testonly = true

  sources = [
    "battery/battery_status_service_unittest.cc",
    "generic_sensor/absolute_orientation_euler_angles_fusion_algorithm_using_accelerometer_and_magnetometer_unittest.cc",
    "generic_sensor/fake_platform_sensor_and_provider.cc",
    "generic_sensor/fake_platform_sensor_and_provider.h",
    "generic_sensor/fake_platform_sensor_fusion.cc",
    "generic_sensor/fake_platform_sensor_fusion.h",
    "generic_sensor/generic_sensor_service_unittest.cc",
    "generic_sensor/gravity_fusion_algorithm_using_accelerometer_unittest.cc",
    "generic_sensor/linear_acceleration_fusion_algorithm_using_accelerometer_unittest.cc",
    "generic_sensor/orientation_euler_angles_fusion_algorithm_using_quaternion_unittest.cc",
    "generic_sensor/orientation_quaternion_fusion_algorithm_using_euler_angles_unittest.cc",
    "generic_sensor/orientation_test_data.h",
    "generic_sensor/platform_sensor_and_provider_unittest.cc",
    "generic_sensor/platform_sensor_fusion_unittest.cc",
    "generic_sensor/platform_sensor_util_unittest.cc",
    "generic_sensor/relative_orientation_euler_angles_fusion_algorithm_using_accelerometer_and_gyroscope_unittest.cc",
    "generic_sensor/relative_orientation_euler_angles_fusion_algorithm_using_accelerometer_unittest.cc",
    "generic_sensor/sensor_fusion_algorithm_using_accelerometer_unittest.cc",
    "geolocation/geolocation_impl_unittest.cc",
    "geolocation/geolocation_provider_impl_unittest.cc",
    "geolocation/geolocation_service_unittest.cc",
    "geolocation/location_provider_manager_unittest.cc",
    "geolocation/network_location_provider_unittest.cc",
    "geolocation/position_cache_impl_unittest.cc",
    "geolocation/public_ip_address_geolocator_unittest.cc",
    "geolocation/public_ip_address_location_notifier_unittest.cc",
    "geolocation/wifi_data_provider_common_unittest.cc",
    "geolocation/wifi_polling_policy_unittest.cc",
    "power_monitor/power_monitor_message_broadcaster_unittest.cc",
    "public/cpp/power_monitor/power_monitor_broadcast_source_unittest.cc",
    "vibration/vibration_manager_impl_unittest.cc",
    "wake_lock/wake_lock_unittest.cc",
  ]

  deps = [
    ":lib",
    ":test_support",
    "//base",
    "//base/test:test_support",
    "//build:chromeos_buildflags",
    "//components/system_cpu:test_support",
    "//components/variations",
    "//device/base/synchronization",
    "//mojo/public/cpp/bindings",
    "//net",
    "//net:test_support",
    "//services/device/generic_sensor",
    "//services/device/geolocation",
    "//services/device/geolocation:test_support",
    "//services/device/power_monitor",
    "//services/device/public/cpp:device_features",
    "//services/device/public/cpp/power_monitor",
    "//services/device/public/mojom",
    "//services/device/public/mojom:geolocation_internals",
    "//services/device/vibration",
    "//services/device/wake_lock",
    "//services/network:test_support",
    "//testing/gmock",
    "//testing/gtest",
  ]

  if (enable_compute_pressure) {
    sources += [
      "compute_pressure/cpu_probe_manager_unittest.cc",
      "compute_pressure/pressure_manager_impl_unittest.cc",
    ]
    deps += [ "//services/device/compute_pressure" ]
  }

  if (is_android) {
    sources += [ "generic_sensor/platform_sensor_provider_unittest_android.cc" ]
  }

  if (is_win) {
    sources += [
      "battery/battery_status_manager_win_unittest.cc",
      "generic_sensor/platform_sensor_and_provider_unittest_win.cc",
      "geolocation/wifi_data_provider_win_unittest.cc",
    ]
  }

  if (os_level_geolocation_permission_supported) {
    sources += [ "public/cpp/geolocation/geolocation_system_permission_manager_unittest.cc" ]
  }

  if (is_chromeos) {
    sources += [
      "generic_sensor/platform_sensor_chromeos_unittest.cc",
      "generic_sensor/platform_sensor_provider_chromeos_unittest.cc",
    ]
    deps += [
      "//chromeos/components/sensors:sensors",
      "//chromeos/components/sensors:test_support",
    ]
  } else if (is_linux && use_udev) {
    sources +=
        [ "generic_sensor/platform_sensor_and_provider_unittest_linux.cc" ]
  }

  if (is_linux && use_dbus) {
    sources += [ "battery/battery_status_manager_linux_unittest.cc" ]
    deps += [ "//dbus:test_support" ]

    if (is_linux) {
      sources += [ "geolocation/wifi_data_provider_linux_unittest.cc" ]
    }
  }

  if (is_chromeos_ash) {
    sources += [
      "fingerprint/fingerprint_chromeos_unittest.cc",
      "geolocation/wifi_data_provider_chromeos_unittest.cc",
    ]
    deps += [
      "//chromeos/ash/components/dbus/biod:test_support",
      "//chromeos/ash/components/dbus/shill",
      "//chromeos/ash/components/network:test_support",
      "//services/device/fingerprint",
      "//third_party/protobuf:protobuf_lite",
    ]
  }

  if (is_chromeos_lacros) {
    sources += [ "geolocation/wifi_data_provider_lacros_unittest.cc" ]
    deps += [ "//chromeos/lacros:test_support" ]
  }

  if (is_android) {
    sources -= [
      "battery/battery_status_service_unittest.cc",
      "geolocation/network_location_provider_unittest.cc",
      "geolocation/wifi_data_provider_common_unittest.cc",
    ]
    deps += [ ":device_service_jni_headers" ]
  } else {
    sources += [
      "battery/battery_monitor_impl_unittest.cc",
      "hid/hid_device_info_unittest.cc",
      "hid/hid_manager_unittest.cc",
      "public/cpp/hid/hid_blocklist_unittest.cc",
    ]
    deps += [
      "//components/variations:test_support",
      "//services/device/battery",
      "//services/device/hid",
    ]

    if ((!is_linux && !is_chromeos) || use_udev) {
      sources += [
        "hid/hid_connection_impl_unittest.cc",
        "public/cpp/hid/hid_device_filter_unittest.cc",
        "public/cpp/hid/hid_report_descriptor_unittest.cc",
      ]
      if (is_linux || is_chromeos) {
        sources += [
          "hid/hid_service_linux_unittest.cc",
          "hid/input_service_linux_unittest.cc",
        ]
      }
      if (!is_fuchsia && !is_ios) {
        # Fuchsia and iOS do not currently implement HidService.
        sources += [ "hid/hid_service_unittest.cc" ]
      }
      if (!is_ios) {
        sources += [ "hid/hid_connection_unittest.cc" ]
        deps += [
          ":usb_test_gadget",
          "//net:test_support",
          "//services/device/usb",
        ]
      }
    }
  }

  if (is_serial_enabled_platform) {
    sources += [
      "serial/bluetooth_serial_device_enumerator_unittests.cc",
      "serial/bluetooth_serial_port_impl_unittest.cc",
      "serial/serial_device_enumerator_unittest.cc",
      "serial/serial_port_impl_unittest.cc",
      "serial/serial_port_manager_impl_unittest.cc",
    ]

    if (is_linux || is_chromeos) {
      sources += [ "serial/serial_device_enumerator_linux_unittest.cc" ]
    }

    if (is_posix) {
      sources += [ "serial/serial_io_handler_posix_unittest.cc" ]
    }

    if (is_linux || is_chromeos) {
      deps += [ "//device/udev_linux:test_support" ]
    }

    deps += [
      "//device/bluetooth:mocks",
      "//services/device/public/cpp/bluetooth:bluetooth",
      "//services/device/serial",
      "//services/device/serial:test_support",
    ]
  }

  # USB does not compile on Chromium without blink.
  if (use_blink) {
    sources += [
      "public/cpp/usb/usb_utils_unittest.cc",
      "usb/mojo/device_impl_unittest.cc",
      "usb/mojo/device_manager_impl_unittest.cc",
      "usb/usb_descriptors_unittest.cc",
      "usb/usb_device_handle_unittest.cc",
      "usb/usb_service_unittest.cc",
      "usb/webusb_descriptors_unittest.cc",
    ]
    deps += [
      ":usb_test_gadget",
      "//device/base",
      "//mojo/public/cpp/test_support:test_utils",
      "//net:test_support",
      "//services/device/public/cpp:test_support",
      "//services/device/public/cpp/usb",
      "//services/device/public/mojom",
      "//services/device/usb",
      "//services/device/usb:test_support",
      "//services/device/usb/mojo",
    ]

    if (!is_android) {
      sources += [ "public/cpp/usb/usb_ids_unittest.cc" ]
    }
  }

  if (is_apple) {
    sources += [ "geolocation/core_location_provider_unittest.cc" ]
  }

  # UsbContext is a libusb-specific object.
  # TODO(crbug.com/40136337) Remove these tests.
  if (is_mac) {
    sources += [ "usb/usb_context_unittest.cc" ]
    deps += [ "//third_party/libusb" ]
  }

  if (is_win) {
    sources += [
      "generic_sensor/platform_sensor_provider_winrt_unittest.cc",
      "generic_sensor/platform_sensor_reader_winrt_unittests.cc",
      "geolocation/win/fake_geocoordinate_winrt.cc",
      "geolocation/win/fake_geocoordinate_winrt.h",
      "geolocation/win/fake_geolocator_winrt.cc",
      "geolocation/win/fake_geolocator_winrt.h",
      "geolocation/win/fake_geoposition_winrt.cc",
      "geolocation/win/fake_geoposition_winrt.h",
      "geolocation/win/fake_position_changed_event_args_winrt.cc",
      "geolocation/win/fake_position_changed_event_args_winrt.h",
      "geolocation/win/fake_status_changed_event_args_winrt.cc",
      "geolocation/win/fake_status_changed_event_args_winrt.h",
      "geolocation/win/location_provider_winrt_unittest.cc",
      "hid/hid_preparsed_data_unittest.cc",
    ]

    # Needed for "generic_sensor/platform_sensor_and_provider_unittest_win.cc"
    libs = [
      "propsys.lib",
      "sensorsapi.lib",
    ]
  }
}

source_set("test_support") {
  testonly = true

  sources = [
    "device_service_test_base.cc",
    "device_service_test_base.h",
  ]

  deps = [
    ":lib",
    "//base",
    "//base/test:test_support",
    "//mojo/public/cpp/bindings",
    "//net",
    "//net:test_support",
    "//services/device/public/cpp:test_support",
    "//services/device/public/cpp/geolocation",
    "//services/device/public/mojom:device_service",
    "//services/network:test_support",
    "//services/service_manager/public/cpp",
    "//services/service_manager/public/cpp/test:test_support",
    "//testing/gtest",
  ]
}

if (is_android) {
  generate_jni("device_service_jni_headers") {
    sources = [
      "android/java/src/org/chromium/services/device/InterfaceRegistrar.java",
    ]
  }

  android_library("java") {
    # This should be visible only to embedders of the Device Service, and the
    # dependence should only be for the purpose of embedding the Device Service.
    # //content/public/android:* here actually wants to identify the
    # //content/public/android:content_java target and all of its generated
    # targets which also need to see this target as well.
    # //services:* identifies //services:service_unittests and all of its
    # generated targets.
    visibility = [
      "//content/public/android:*",
      "//services:*",
    ]
    sources = [
      "android/java/src/org/chromium/services/device/InterfaceRegistrar.java",
    ]
    srcjar_deps = [ ":device_service_jni_headers" ]
    deps = [
      "//mojo/public/java:bindings_java",
      "//mojo/public/java:system_java",
      "//mojo/public/java/system:system_impl_java",
      "//services/device/battery/android:battery_monitor_java",
      "//services/device/generic_sensor:java",
      "//services/device/geolocation:geolocation_java",
      "//services/device/nfc/android:java",
      "//services/device/public/java:nfc_java",
      "//services/device/public/mojom:mojom_java",
      "//services/device/screen_orientation:java",
      "//services/device/time_zone_monitor:java",
      "//services/device/usb:java",
      "//services/device/vibration/android:vibration_manager_java",
      "//services/device/wake_lock/power_save_blocker:java",
      "//services/service_manager/public/java:service_manager_java",
      "//services/service_manager/public/mojom:mojom_java",
      "//third_party/jni_zero:jni_zero_java",
    ]
  }
}

source_set("usb_test_gadget") {
  testonly = true

  sources = [
    "test/usb_test_gadget.h",
    "test/usb_test_gadget_impl.cc",
  ]

  deps = [
    "//device/base",
    "//net:test_support",
    "//services/device/usb",
    "//tools/usb_gadget",
  ]
}

source_set("utility") {
  sources = []

  if (is_mac) {
    sources += [
      "utils/mac_utils.cc",
      "utils/mac_utils.h",
    ]
  }
  deps = [ "//base" ]
}