Commit 81e42d0d authored by lgcheng's avatar lgcheng Committed by Commit Bot

Add package name for ArcUsbHost mojom interface.

Since Chrome side never knows the identifier of requesting Android
package, pass the package name to Chrome side so that Chrome side can
respond correctly.

Bug: 776476
Bug: b:24572867
Change-Id: I14d29245d43d91bb43d83df0cfae23809d1bfd02
Reviewed-on: https://chromium-review.googlesource.com/954402Reviewed-by: default avatarMattias Nissler <mnissler@chromium.org>
Reviewed-by: default avatarLuis Hector Chavez <lhchavez@chromium.org>
Commit-Queue: Long Cheng <lgcheng@google.com>
Cr-Commit-Position: refs/heads/master@{#543412}
parent 7569414b
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// Next MinVersion: 1 // Next MinVersion: 2
module arc.mojom; module arc.mojom;
// re-use device.mojom.UsbDeviceInfo // re-use device.mojom.UsbDeviceInfo
...@@ -10,11 +10,14 @@ import "device/usb/public/mojom/device.mojom"; ...@@ -10,11 +10,14 @@ import "device/usb/public/mojom/device.mojom";
// Next method ID: 3 // Next method ID: 3
interface UsbHostHost { interface UsbHostHost {
// Tries the open the USB device node for the device named 'guid' // Tries to open the USB device node for the device named 'guid' for caller
// and returns an open file descriptor to this node. // 'pkg_name' and returns an open file descriptor to this node. 'pkg_name'
// You need to have previously called RequestPermission for this 'guid' // needs to have previously called RequestPermission for this 'guid' else this
// else this call will fail. // call will fail. Note the 'pkg_name' is informational purposes only, there
OpenDevice@0(string guid) => (handle usb_fd); // 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);
// Returns the USB device descriptors for the device named 'guid'. // Returns the USB device descriptors for the device named 'guid'.
GetDeviceInfo@1(string guid) => (string device_name, GetDeviceInfo@1(string guid) => (string device_name,
......
...@@ -120,14 +120,14 @@ void ArcUsbHostBridge::RequestPermission(const std::string& guid, ...@@ -120,14 +120,14 @@ void ArcUsbHostBridge::RequestPermission(const std::string& guid,
RequestPermissionCallback callback) { RequestPermissionCallback callback) {
VLOG(2) << "USB RequestPermission " << guid << " package " << package; VLOG(2) << "USB RequestPermission " << guid << " package " << package;
// Permission already requested. // Permission already requested.
if (HasPermissionForDevice(guid)) { if (HasPermissionForDevice(guid, package)) {
std::move(callback).Run(true); std::move(callback).Run(true);
return; return;
} }
// The other side was just checking, fail without asking the user. // The other side was just checking, fail without asking the user.
if (!interactive) { if (!interactive) {
std::move(callback).Run(false); std::move(callback).Run(HasPermissionForDevice(guid, package));
return; return;
} }
...@@ -136,8 +136,9 @@ void ArcUsbHostBridge::RequestPermission(const std::string& guid, ...@@ -136,8 +136,9 @@ void ArcUsbHostBridge::RequestPermission(const std::string& guid,
} }
void ArcUsbHostBridge::OpenDevice(const std::string& guid, void ArcUsbHostBridge::OpenDevice(const std::string& guid,
const base::Optional<std::string>& package,
OpenDeviceCallback callback) { OpenDeviceCallback callback) {
if (!usb_service_) { if (!usb_service_ || !package) {
std::move(callback).Run(mojo::ScopedHandle()); std::move(callback).Run(mojo::ScopedHandle());
return; return;
} }
...@@ -150,7 +151,7 @@ void ArcUsbHostBridge::OpenDevice(const std::string& guid, ...@@ -150,7 +151,7 @@ void ArcUsbHostBridge::OpenDevice(const std::string& guid,
} }
// The RequestPermission was never done, abort. // The RequestPermission was never done, abort.
if (!HasPermissionForDevice(guid)) { if (!HasPermissionForDevice(guid, package.value())) {
std::move(callback).Run(mojo::ScopedHandle()); std::move(callback).Run(mojo::ScopedHandle());
return; return;
} }
...@@ -297,10 +298,23 @@ void ArcUsbHostBridge::DoRequestUserAuthorization( ...@@ -297,10 +298,23 @@ void ArcUsbHostBridge::DoRequestUserAuthorization(
std::move(callback)); std::move(callback));
} }
bool ArcUsbHostBridge::HasPermissionForDevice(const std::string& guid) { bool ArcUsbHostBridge::HasPermissionForDevice(const std::string& guid,
// TODO(lgcheng): implement permission settings const std::string& package) {
// fail close for now if (!ui_delegate_)
return false;
if (!usb_service_)
return false;
scoped_refptr<device::UsbDevice> device = usb_service_->GetDevice(guid);
if (!device.get()) {
LOG(WARNING) << "Unknown USB device " << guid;
return false; return false;
}
return ui_delegate_->HasUsbAccessPermission(
package, guid, device->serial_number(), device->vendor_id(),
device->product_id());
} }
} // namespace arc } // namespace arc
...@@ -54,6 +54,7 @@ class ArcUsbHostBridge : public KeyedService, ...@@ -54,6 +54,7 @@ class ArcUsbHostBridge : public KeyedService,
bool interactive, bool interactive,
RequestPermissionCallback callback) override; RequestPermissionCallback callback) override;
void OpenDevice(const std::string& guid, void OpenDevice(const std::string& guid,
const base::Optional<std::string>& package,
OpenDeviceCallback callback) override; OpenDeviceCallback callback) override;
void GetDeviceInfo(const std::string& guid, void GetDeviceInfo(const std::string& guid,
GetDeviceInfoCallback callback) override; GetDeviceInfoCallback callback) override;
...@@ -77,7 +78,8 @@ class ArcUsbHostBridge : public KeyedService, ...@@ -77,7 +78,8 @@ class ArcUsbHostBridge : public KeyedService,
void DoRequestUserAuthorization(const std::string& guid, void DoRequestUserAuthorization(const std::string& guid,
const std::string& package, const std::string& package,
RequestPermissionCallback callback); RequestPermissionCallback callback);
bool HasPermissionForDevice(const std::string& guid); bool HasPermissionForDevice(const std::string& guid,
const std::string& package);
ArcBridgeService* const arc_bridge_service_; // Owned by ArcServiceManager. ArcBridgeService* const arc_bridge_service_; // Owned by ArcServiceManager.
mojom::UsbHostHostPtr usb_host_ptr_; mojom::UsbHostHostPtr usb_host_ptr_;
......
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