Skip to content
This repository has been archived by the owner on Jul 18, 2018. It is now read-only.

Commit

Permalink
Remove HID from the device service on Android
Browse files Browse the repository at this point in the history
HID is not supported on Android so there's no reason to include all this
code. To prevent this from regressing an assert() is added to
device/hid/BUILD.gn which requires some updates to MockDeviceClient to
completely remove the dependency when building tests.

Bug: 765671
Change-Id: Ieaab1f28594a7e0cdd177389d1bdb91159e868c9
Reviewed-on: https://chromium-review.googlesource.com/674050
Reviewed-by: Ken Rockot <rockot@chromium.org>
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#503303}
  • Loading branch information
reillyeon authored and Commit Bot committed Sep 21, 2017
1 parent 877167b commit 7211fa2
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 16 deletions.
5 changes: 4 additions & 1 deletion device/base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ source_set("mocks") {

deps = [
":base",
"//device/hid:mocks",
"//device/usb:test_support",
]

if (!is_android) {
deps += [ "//device/hid:mocks" ]
}
}
16 changes: 15 additions & 1 deletion device/base/mock_device_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,41 @@

#include "device/base/mock_device_client.h"

#include "device/hid/mock_hid_service.h"
#include "base/logging.h"
#include "device/usb/mock_usb_service.h"

#if !defined(OS_ANDROID)
#include "device/hid/mock_hid_service.h"
#endif

namespace device {

MockDeviceClient::MockDeviceClient() {}

MockDeviceClient::~MockDeviceClient() {}

HidService* MockDeviceClient::GetHidService() {
#if defined(OS_ANDROID)
NOTREACHED();
return nullptr;
#else
return hid_service();
#endif
}

UsbService* MockDeviceClient::GetUsbService() {
return usb_service();
}

MockHidService* MockDeviceClient::hid_service() {
#if defined(OS_ANDROID)
NOTREACHED();
return nullptr;
#else
if (!hid_service_)
hid_service_.reset(new MockHidService());
return hid_service_.get();
#endif
}

MockUsbService* MockDeviceClient::usb_service() {
Expand Down
3 changes: 3 additions & 0 deletions device/base/mock_device_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <memory>

#include "build/build_config.h"
#include "device/base/device_client.h"

namespace device {
Expand All @@ -30,7 +31,9 @@ class MockDeviceClient : device::DeviceClient {
MockUsbService* usb_service();

private:
#if !defined(OS_ANDROID)
std::unique_ptr<MockHidService> hid_service_;
#endif
std::unique_ptr<MockUsbService> usb_service_;
};

Expand Down
3 changes: 3 additions & 0 deletions device/hid/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import("//build/config/features.gni")
import("//testing/libfuzzer/fuzzer_test.gni")

source_set("hid") {
# HID support is not implemented on Android.
assert(!is_android)

sources = [
"hid_collection_info.cc",
"hid_collection_info.h",
Expand Down
2 changes: 1 addition & 1 deletion services/device/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ source_set("lib") {

deps = [
"//base",
"//device/hid",
"//device/sensors",
"//device/sensors/public/interfaces",
"//services/device/fingerprint",
Expand All @@ -46,6 +45,7 @@ source_set("lib") {
deps += [ ":device_service_jni_headers" ]
} else {
deps += [
"//device/hid",
"//services/device/battery",
"//services/device/vibration",
]
Expand Down
18 changes: 9 additions & 9 deletions services/device/device_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "base/single_thread_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
#include "device/hid/hid_manager_impl.h"
#include "device/sensors/device_sensor_host.h"
#include "mojo/public/cpp/system/message_pipe.h"
#include "services/device/fingerprint/fingerprint.h"
Expand All @@ -30,6 +29,7 @@
#include "jni/InterfaceRegistrar_jni.h"
#include "services/device/screen_orientation/screen_orientation_listener_android.h"
#else
#include "device/hid/hid_manager_impl.h" // nogncheck
#include "services/device/battery/battery_monitor_impl.h"
#include "services/device/battery/battery_status_service.h"
#include "services/device/vibration/vibration_manager_impl.h"
Expand Down Expand Up @@ -85,8 +85,6 @@ DeviceService::~DeviceService() {
void DeviceService::OnStart() {
registry_.AddInterface<mojom::Fingerprint>(base::Bind(
&DeviceService::BindFingerprintRequest, base::Unretained(this)));
registry_.AddInterface<mojom::HidManager>(base::Bind(
&DeviceService::BindHidManagerRequest, base::Unretained(this)));
registry_.AddInterface<mojom::OrientationSensor>(base::Bind(
&DeviceService::BindOrientationSensorRequest, base::Unretained(this)));
registry_.AddInterface<mojom::OrientationAbsoluteSensor>(
Expand Down Expand Up @@ -120,6 +118,8 @@ void DeviceService::OnStart() {
#else
registry_.AddInterface<mojom::BatteryMonitor>(base::Bind(
&DeviceService::BindBatteryMonitorRequest, base::Unretained(this)));
registry_.AddInterface<mojom::HidManager>(base::Bind(
&DeviceService::BindHidManagerRequest, base::Unretained(this)));
registry_.AddInterface<mojom::NFCProvider>(base::Bind(
&DeviceService::BindNFCProviderRequest, base::Unretained(this)));
registry_.AddInterface<mojom::VibrationManager>(base::Bind(
Expand All @@ -140,6 +140,12 @@ void DeviceService::BindBatteryMonitorRequest(
BatteryMonitorImpl::Create(std::move(request));
}

void DeviceService::BindHidManagerRequest(mojom::HidManagerRequest request) {
if (!hid_manager_)
hid_manager_ = base::MakeUnique<HidManagerImpl>();
hid_manager_->AddBinding(std::move(request));
}

void DeviceService::BindNFCProviderRequest(mojom::NFCProviderRequest request) {
LOG(ERROR) << "NFC is only supported on Android";
NOTREACHED();
Expand All @@ -151,12 +157,6 @@ void DeviceService::BindVibrationManagerRequest(
}
#endif

void DeviceService::BindHidManagerRequest(mojom::HidManagerRequest request) {
if (!hid_manager_)
hid_manager_ = base::MakeUnique<HidManagerImpl>();
hid_manager_->AddBinding(std::move(request));
}

void DeviceService::BindFingerprintRequest(mojom::FingerprintRequest request) {
Fingerprint::Create(std::move(request));
}
Expand Down
9 changes: 5 additions & 4 deletions services/device/device_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#define SERVICES_DEVICE_DEVICE_SERVICE_H_

#include "base/memory/ref_counted.h"
#include "device/hid/public/interfaces/hid.mojom.h"
#include "device/screen_orientation/public/interfaces/screen_orientation.mojom.h"
#include "device/sensors/public/interfaces/orientation.mojom.h"
#include "mojo/public/cpp/bindings/binding_set.h"
Expand All @@ -26,6 +25,8 @@

#if defined(OS_ANDROID)
#include "base/android/scoped_java_ref.h"
#else
#include "device/hid/public/interfaces/hid.mojom.h" // nogncheck
#endif

namespace base {
Expand Down Expand Up @@ -75,15 +76,14 @@ class DeviceService : public service_manager::Service {

void BindFingerprintRequest(mojom::FingerprintRequest request);

void BindHidManagerRequest(mojom::HidManagerRequest request);

void BindOrientationSensorRequest(mojom::OrientationSensorRequest request);

void BindOrientationAbsoluteSensorRequest(
mojom::OrientationAbsoluteSensorRequest request);

#if !defined(OS_ANDROID)
void BindBatteryMonitorRequest(mojom::BatteryMonitorRequest request);
void BindHidManagerRequest(mojom::HidManagerRequest request);
void BindNFCProviderRequest(mojom::NFCProviderRequest request);
void BindVibrationManagerRequest(mojom::VibrationManagerRequest request);
#endif
Expand All @@ -104,7 +104,6 @@ class DeviceService : public service_manager::Service {

void BindSerialIoHandlerRequest(mojom::SerialIoHandlerRequest request);

std::unique_ptr<HidManagerImpl> hid_manager_;
std::unique_ptr<PowerMonitorMessageBroadcaster>
power_monitor_message_broadcaster_;
std::unique_ptr<TimeZoneMonitor> time_zone_monitor_;
Expand All @@ -124,6 +123,8 @@ class DeviceService : public service_manager::Service {
bool java_interface_provider_initialized_;

base::android::ScopedJavaGlobalRef<jobject> java_nfc_delegate_;
#else
std::unique_ptr<HidManagerImpl> hid_manager_;
#endif

service_manager::BinderRegistry registry_;
Expand Down

0 comments on commit 7211fa2

Please sign in to comment.