Commit 6adb46a9 authored by lgcheng's avatar lgcheng Committed by Commit Bot

Fix usb_host mojom connection error.

Fix usb_host mojom connection error when OpenDeivce is rejected.

When app call OpenDevice from Android side, it can be rejected because
1. app has not requested for permission.
2. permission_broker decides the node is in use.
In these cases we return mojo::ScopedHandle() from Chrome to Android.
And case cause mojom connection error.

connection error.

Test: return mojo::ScopedHandle() to OpenDeivce and no more mojom
Bug: 922675
Change-Id: I1de5eb17cca35d57f96afc7d10de6312659253b9
Reviewed-on: https://chromium-review.googlesource.com/c/1416132Reviewed-by: default avatarHidehiko Abe <hidehiko@chromium.org>
Reviewed-by: default avatarMattias Nissler <mnissler@chromium.org>
Commit-Queue: Long Cheng <lgcheng@google.com>
Cr-Commit-Position: refs/heads/master@{#634766}
parent 6d98eb8b
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
// 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: 3 // Next MinVersion: 4
module arc.mojom; module arc.mojom;
// re-use device.mojom.UsbDeviceInfo // re-use device.mojom.UsbDeviceInfo
import "device/usb/public/mojom/device.mojom"; import "device/usb/public/mojom/device.mojom";
// Next method ID: 3 // Next method ID: 4
interface UsbHostHost { interface UsbHostHost {
// Tries to open the USB device node for the device named 'guid' for caller // Tries to open the USB device node for the device named 'guid' for caller
// 'pkg_name' and returns an open file descriptor to this node. 'pkg_name' // 'pkg_name' and returns an open file descriptor to this node. 'pkg_name'
...@@ -16,8 +16,20 @@ interface UsbHostHost { ...@@ -16,8 +16,20 @@ interface UsbHostHost {
// call will fail. Note the 'pkg_name' is informational purposes only, there // call will fail. Note the 'pkg_name' is informational purposes only, there
// is no effective way that host can restrict access to only a specific // is no effective way that host can restrict access to only a specific
// package at the security boundary formed by this Mojo interface. // package at the security boundary formed by this Mojo interface.
OpenDevice@0(string guid, // Deprecated.
[MinVersion=1] string? pkg_name) => (handle usb_fd); OpenDeviceDeprecated@0(string guid,
[MinVersion=1] string? pkg_name) => (handle usb_fd);
// Tries to open the USB device node for the device named 'guid' for caller
// 'pkg_name' and returns an open file descriptor to this node. 'pkg_name'
// needs to have previously called RequestPermission for this 'guid' else this
// call will fail. Note the 'pkg_name' is informational purposes only, there
// is no effective way that host can restrict access to only a specific
// package at the security boundary formed by this Mojo interface.
// When app tries to open a device without requesting permission, or
// permission_broker rejects the open request, empty handle will be returned.
[MinVersion=3] OpenDevice@3(string guid, 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,
......
...@@ -166,6 +166,14 @@ void ArcUsbHostBridge::OpenDevice(const std::string& guid, ...@@ -166,6 +166,14 @@ void ArcUsbHostBridge::OpenDevice(const std::string& guid,
base::Bind(&OnDeviceOpenError, repeating_callback)); base::Bind(&OnDeviceOpenError, repeating_callback));
} }
void ArcUsbHostBridge::OpenDeviceDeprecated(
const std::string& guid,
const base::Optional<std::string>& package,
OpenDeviceCallback callback) {
LOG(ERROR) << "ArcUsbHostBridge::OpenDeviceDeprecated is deprecated";
OpenDevice(guid, package, std::move(callback));
}
void ArcUsbHostBridge::GetDeviceInfo(const std::string& guid, void ArcUsbHostBridge::GetDeviceInfo(const std::string& guid,
GetDeviceInfoCallback callback) { GetDeviceInfoCallback callback) {
if (!usb_service_) { if (!usb_service_) {
......
...@@ -53,6 +53,9 @@ class ArcUsbHostBridge : public KeyedService, ...@@ -53,6 +53,9 @@ class ArcUsbHostBridge : public KeyedService,
const std::string& package, const std::string& package,
bool interactive, bool interactive,
RequestPermissionCallback callback) override; RequestPermissionCallback callback) override;
void OpenDeviceDeprecated(const std::string& guid,
const base::Optional<std::string>& package,
OpenDeviceCallback callback) override;
void OpenDevice(const std::string& guid, void OpenDevice(const std::string& guid,
const base::Optional<std::string>& package, const base::Optional<std::string>& package,
OpenDeviceCallback callback) override; OpenDeviceCallback callback) override;
......
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