Commit 8d5963f9 authored by lgcheng's avatar lgcheng Committed by Commit Bot

Arc USB Host USB event receivers

Pass receiver list to Android to restricted packages which can receive
the USB event.

Bug: b/78231419
Test: Manual
Change-Id: I3938fb5b105eb95017ee0e34136ad78a70fd03c6
Reviewed-on: https://chromium-review.googlesource.com/1017809Reviewed-by: default avatarLuis Hector Chavez <lhchavez@chromium.org>
Reviewed-by: default avatarMattias Nissler <mnissler@chromium.org>
Commit-Queue: Long Cheng <lgcheng@google.com>
Cr-Commit-Position: refs/heads/master@{#553842}
parent ab259835
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Next MinVersion: 2
// Next MinVersion: 3
module arc.mojom;
// re-use device.mojom.UsbDeviceInfo
......@@ -17,7 +17,7 @@ interface UsbHostHost {
// is no effective way that host can restrict access to only a specific
// package at the security boundary formed by this Mojo interface.
OpenDevice@0(string guid,
[Minversion=1] string? pkg_name) => (handle usb_fd);
[MinVersion=1] string? pkg_name) => (handle usb_fd);
// Returns the USB device descriptors for the device named 'guid'.
GetDeviceInfo@1(string guid) => (string device_name,
......@@ -40,8 +40,12 @@ interface UsbHostInstance {
Init@0(UsbHostHost host_ptr) => ();
// Notifies the instance of a new USB device.
OnDeviceAdded@1(string guid);
// Only packages in |event_receiver_packages| will receive broadcast.
OnDeviceAdded@1(string guid,
[MinVersion=2] array<string>? event_receiver_packages);
// Notifies the instance of the removal of a USB device.
OnDeviceRemoved@2(string guid);
// Only packages in |event_receiver_packages| will receive broadcast.
OnDeviceRemoved@2(string guid,
[MinVersion=2] array<string>? event_receiver_packages);
};
......@@ -215,9 +215,6 @@ void ArcUsbHostBridge::OnDeviceAdded(scoped_refptr<device::UsbDevice> device) {
void ArcUsbHostBridge::OnDeviceRemoved(
scoped_refptr<device::UsbDevice> device) {
if (ui_delegate_)
ui_delegate_->DeviceRemoved(device.get()->guid());
mojom::UsbHostInstance* usb_host_instance = ARC_GET_INSTANCE_FOR_METHOD(
arc_bridge_service_->usb_host(), OnDeviceAdded);
......@@ -226,7 +223,11 @@ void ArcUsbHostBridge::OnDeviceRemoved(
return;
}
usb_host_instance->OnDeviceRemoved(device.get()->guid());
usb_host_instance->OnDeviceRemoved(
device.get()->guid(), GetEventReceiverPackages(device.get()->guid()));
if (ui_delegate_)
ui_delegate_->DeviceRemoved(device.get()->guid());
}
// Notifies the observer that the UsbService it depends on is shutting down.
......@@ -258,6 +259,23 @@ void ArcUsbHostBridge::SetUiDelegate(ArcUsbHostUiDelegate* ui_delegate) {
ui_delegate_ = ui_delegate;
}
std::vector<std::string> ArcUsbHostBridge::GetEventReceiverPackages(
const std::string& guid) {
scoped_refptr<device::UsbDevice> device = usb_service_->GetDevice(guid);
if (!device.get()) {
LOG(WARNING) << "Unknown USB device " << guid;
return std::vector<std::string>();
}
if (!ui_delegate_)
return std::vector<std::string>();
std::unordered_set<std::string> receivers = ui_delegate_->GetEventPackageList(
guid, device->serial_number(), device->vendor_id(), device->product_id());
return std::vector<std::string>(receivers.begin(), receivers.end());
}
void ArcUsbHostBridge::OnDeviceChecked(const std::string& guid, bool allowed) {
if (!base::FeatureList::IsEnabled(arc::kUsbHostFeature)) {
VLOG(1) << "AndroidUSBHost: feature is disabled; ignoring";
......@@ -273,7 +291,7 @@ void ArcUsbHostBridge::OnDeviceChecked(const std::string& guid, bool allowed) {
if (!usb_host_instance)
return;
usb_host_instance->OnDeviceAdded(guid);
usb_host_instance->OnDeviceAdded(guid, GetEventReceiverPackages(guid));
}
void ArcUsbHostBridge::DoRequestUserAuthorization(
......
......@@ -74,6 +74,7 @@ class ArcUsbHostBridge : public KeyedService,
void SetUiDelegate(ArcUsbHostUiDelegate* ui_delegate);
private:
std::vector<std::string> GetEventReceiverPackages(const std::string& guid);
void OnDeviceChecked(const std::string& guid, bool allowed);
void DoRequestUserAuthorization(const std::string& guid,
const std::string& package,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment