forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Filtering bluetooth devices in the chrome os UI.
Add utility method FilterDeviceList in device/bluetooth/chromeos to filter the devices before updating in bluetooth UI. Extension change is in a separate CL: https://chromium-review.googlesource.com/c/chromium/src/+/1004414/ Design doc: http://go/cros-bluetooth-filtering Bug: 817599 Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation Change-Id: I2a5cfb2ecdacbbe633770bb0c59b2e914b4e4b1f Reviewed-on: https://chromium-review.googlesource.com/999014 Commit-Queue: Xiaoyin Hu <xiaoyinh@chromium.org> Reviewed-by: Steven Bennetts <stevenjb@chromium.org> Reviewed-by: Miao-chen Chou <mcchou@chromium.org> Reviewed-by: Rahul Chaturvedi <rkc@chromium.org> Cr-Commit-Position: refs/heads/master@{#550046}
- Loading branch information
Sarah Hu
authored and
Commit Bot
committed
Apr 12, 2018
1 parent
64a3223
commit ad95e80
Showing
4 changed files
with
107 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2018 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "device/bluetooth/chromeos/bluetooth_utils.h" | ||
|
||
namespace device { | ||
|
||
namespace { | ||
|
||
// Get limited number of devices from |devices| and | ||
// prioritize paired/connecting devices over other devices. | ||
BluetoothAdapter::DeviceList GetLimitedNumDevices( | ||
size_t max_device_num, | ||
const BluetoothAdapter::DeviceList& devices) { | ||
// If |max_device_num| is 0, it means there's no limit. | ||
if (max_device_num == 0) | ||
return devices; | ||
|
||
BluetoothAdapter::DeviceList result; | ||
for (BluetoothDevice* device : devices) { | ||
if (result.size() == max_device_num) | ||
break; | ||
|
||
if (device->IsPaired() || device->IsConnecting()) | ||
result.push_back(device); | ||
} | ||
|
||
for (BluetoothDevice* device : devices) { | ||
if (result.size() == max_device_num) | ||
break; | ||
|
||
if (!device->IsPaired() && !device->IsConnecting()) | ||
result.push_back(device); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
// Filter out unknown devices from the list. | ||
BluetoothAdapter::DeviceList FilterUnknownDevices( | ||
const BluetoothAdapter::DeviceList& devices) { | ||
BluetoothAdapter::DeviceList result; | ||
for (BluetoothDevice* device : devices) { | ||
if (device->GetDeviceType() != device::BluetoothDeviceType::UNKNOWN) | ||
result.push_back(device); | ||
} | ||
return result; | ||
} | ||
|
||
} // namespace | ||
|
||
device::BluetoothAdapter::DeviceList FilterBluetoothDeviceList( | ||
const BluetoothAdapter::DeviceList& devices, | ||
BluetoothFilterType filter_type, | ||
int max_devices) { | ||
BluetoothAdapter::DeviceList filtered_devices = | ||
filter_type == BluetoothFilterType::KNOWN ? FilterUnknownDevices(devices) | ||
: devices; | ||
return GetLimitedNumDevices(max_devices, filtered_devices); | ||
} | ||
|
||
} // namespace device |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2018 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef DEVICE_BLUETOOTH_CHROMEOS_BLUETOOTH_UTILS_H_ | ||
#define DEVICE_BLUETOOTH_CHROMEOS_BLUETOOTH_UTILS_H_ | ||
|
||
#include "device/bluetooth/bluetooth_adapter.h" | ||
#include "device/bluetooth/bluetooth_export.h" | ||
|
||
// This file contains common utilities for filtering the bluetooth devices | ||
// based on the filter criteria. | ||
namespace device { | ||
|
||
enum class BluetoothFilterType { | ||
// No filtering, all bluetooth devices will be returned. | ||
ALL = 0, | ||
// Return bluetooth devices that are known to the UI. | ||
// I.e. bluetooth device type != UNKNOWN | ||
KNOWN, | ||
}; | ||
|
||
// Return filtered devices based on the filter type and max number of devices. | ||
device::BluetoothAdapter::DeviceList DEVICE_BLUETOOTH_EXPORT | ||
FilterBluetoothDeviceList(const BluetoothAdapter::DeviceList& devices, | ||
BluetoothFilterType filter_type, | ||
int max_devices); | ||
|
||
} // namespace device | ||
|
||
#endif // DEVICE_BLUETOOTH_CHROMEOS_BLUETOOTH_UTILS_H_ |