Commit db604224 authored by Nicholas Verne's avatar Nicholas Verne Committed by Commit Bot

Crostini USB: notify for more devices.

When a newly plugged in device reports multiple interfaces and at least
one of them is "notifiable" we notify the user. Previously, all
interfaces needed to be "notifiable".

Bug: 1082075
Change-Id: Ic203f7ebce51966b53fbe27709a4c705a33561e8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2217521
Commit-Queue: Nicholas Verne <nverne@chromium.org>
Reviewed-by: default avatarDavid Munro <davidmunro@google.com>
Reviewed-by: default avatarFergus Dall <sidereal@google.com>
Auto-Submit: Nicholas Verne <nverne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#772588}
parent 086767ed
......@@ -359,7 +359,8 @@ void CrosUsbDetector::ConnectToDeviceManager() {
}
bool CrosUsbDetector::ShouldShowNotification(
const device::mojom::UsbDeviceInfo& device_info) {
const device::mojom::UsbDeviceInfo& device_info,
uint32_t allowed_interfaces_mask) {
if (!crostini::CrostiniFeatures::Get()->IsEnabled(profile())) {
return false;
}
......@@ -368,9 +369,9 @@ bool CrosUsbDetector::ShouldShowNotification(
VLOG(1) << "Adb or fastboot device found";
return true;
}
if (!device::UsbDeviceFilterMatchesAny(guest_os_classes_without_notif_,
device_info)) {
VLOG(1) << "Only notifiable interfaces found for device";
if ((GetFilteredInterfacesMask(guest_os_classes_without_notif_, device_info) &
allowed_interfaces_mask) != 0) {
VLOG(1) << "At least one notifiable interface found for device";
return true;
}
return false;
......@@ -408,7 +409,8 @@ void CrosUsbDetector::OnDeviceChecked(
// Some devices should not trigger the notification.
if (!new_device.sharable_with_crostini || hide_notification ||
!ShouldShowNotification(*device_info)) {
!ShouldShowNotification(*device_info,
new_device.allowed_interfaces_mask)) {
VLOG(1) << "Not showing USB notification for " << new_device.label;
return;
}
......
......@@ -168,7 +168,8 @@ class CrosUsbDetector : public device::mojom::UsbDeviceManagerClient {
bool success);
// Returns true when a device should show a notification when attached.
bool ShouldShowNotification(const device::mojom::UsbDeviceInfo& device_info);
bool ShouldShowNotification(const device::mojom::UsbDeviceInfo& device_info,
uint32_t allowed_interfaces_mask);
mojo::Remote<device::mojom::UsbDeviceManager> device_manager_;
mojo::AssociatedReceiver<device::mojom::UsbDeviceManagerClient>
......
......@@ -787,6 +787,12 @@ TEST_F(CrosUsbDetectorTest, DeviceAllowedInterfacesMaskSetCorrectly) {
device_manager_.AddDevice(device);
base::RunLoop().RunUntilIdle();
// The device should notify because it has an allowed, notifiable interface.
std::string notification_id =
chromeos::CrosUsbDetector::MakeNotificationId(device->guid());
EXPECT_TRUE(display_service_->GetNotification(notification_id));
auto device_info = GetSingleDeviceInfo();
EXPECT_EQ(0x00000006U, device_info.allowed_interfaces_mask);
......
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