Commit 791ce9ad authored by Giovanni Ortuño Urquidi's avatar Giovanni Ortuño Urquidi Committed by Commit Bot

bluetooth: Introduce device::mojom::BluetoothDeviceInfo

Replace ash::BluetoothDeviceInfo with device::mojom::BluetoothDeviceInfo.
The new struct will be returned by the BT System interface and used
instead of ash::BluetoothDeviceInfo.

Bug: 882346

Change-Id: I01830955e5caef35b430d69e48ae129df47eac8c
Reviewed-on: https://chromium-review.googlesource.com/c/1328624Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarTetsui Ohkubo <tetsui@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarOvidio Henriquez <odejesush@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Commit-Queue: Giovanni Ortuño Urquidi <ortuno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610527}
parent 24d7413c
......@@ -1285,6 +1285,7 @@ component("ash") {
"//ash/wayland",
"//components/discardable_memory/public/interfaces",
"//mojo/public/cpp/system",
"//services/device/public/cpp/bluetooth",
"//services/device/public/mojom",
"//services/media_session/public/mojom",
"//services/service_manager/public/cpp",
......
......@@ -12,6 +12,8 @@
#include "ash/system/tray/tray_info_label.h"
#include "ash/system/tray/tray_popup_item_style.h"
#include "ash/system/tray/tray_popup_utils.h"
#include "base/strings/utf_string_conversions.h"
#include "services/device/public/cpp/bluetooth/bluetooth_utils.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/controls/button/toggle_button.h"
......@@ -20,6 +22,7 @@
#include "ui/views/layout/box_layout.h"
using device::mojom::BluetoothSystem;
using device::mojom::BluetoothDeviceInfo;
namespace ash {
namespace tray {
......@@ -30,34 +33,36 @@ const int kDisabledPanelLabelBaselineY = 20;
// Returns corresponding device type icons for given Bluetooth device types and
// connection states.
const gfx::VectorIcon& GetBluetoothDeviceIcon(
device::BluetoothDeviceType device_type,
bool connected) {
BluetoothDeviceInfo::DeviceType device_type,
BluetoothDeviceInfo::ConnectionState connection_state) {
switch (device_type) {
case device::BluetoothDeviceType::COMPUTER:
case BluetoothDeviceInfo::DeviceType::kComputer:
return ash::kSystemMenuComputerIcon;
case device::BluetoothDeviceType::PHONE:
case BluetoothDeviceInfo::DeviceType::kPhone:
return ash::kSystemMenuPhoneIcon;
case device::BluetoothDeviceType::AUDIO:
case device::BluetoothDeviceType::CAR_AUDIO:
case BluetoothDeviceInfo::DeviceType::kAudio:
case BluetoothDeviceInfo::DeviceType::kCarAudio:
return ash::kSystemMenuHeadsetIcon;
case device::BluetoothDeviceType::VIDEO:
case BluetoothDeviceInfo::DeviceType::kVideo:
return ash::kSystemMenuVideocamIcon;
case device::BluetoothDeviceType::JOYSTICK:
case device::BluetoothDeviceType::GAMEPAD:
case BluetoothDeviceInfo::DeviceType::kJoystick:
case BluetoothDeviceInfo::DeviceType::kGamepad:
return ash::kSystemMenuGamepadIcon;
case device::BluetoothDeviceType::KEYBOARD:
case device::BluetoothDeviceType::KEYBOARD_MOUSE_COMBO:
case BluetoothDeviceInfo::DeviceType::kKeyboard:
case BluetoothDeviceInfo::DeviceType::kKeyboardMouseCombo:
return ash::kSystemMenuKeyboardIcon;
case device::BluetoothDeviceType::TABLET:
case BluetoothDeviceInfo::DeviceType::kTablet:
return ash::kSystemMenuTabletIcon;
case device::BluetoothDeviceType::MOUSE:
case BluetoothDeviceInfo::DeviceType::kMouse:
return ash::kSystemMenuMouseIcon;
case device::BluetoothDeviceType::MODEM:
case device::BluetoothDeviceType::PERIPHERAL:
case BluetoothDeviceInfo::DeviceType::kModem:
case BluetoothDeviceInfo::DeviceType::kPeripheral:
return ash::kSystemMenuBluetoothIcon;
default:
return connected ? ash::kSystemMenuBluetoothConnectedIcon
: ash::kSystemMenuBluetoothIcon;
return connection_state ==
BluetoothDeviceInfo::ConnectionState::kConnected
? ash::kSystemMenuBluetoothConnectedIcon
: ash::kSystemMenuBluetoothIcon;
}
}
......@@ -154,8 +159,13 @@ void BluetoothDetailedView::UpdateDeviceScrollList(
const BluetoothDeviceList& connecting_devices,
const BluetoothDeviceList& paired_not_connected_devices,
const BluetoothDeviceList& discovered_not_paired_devices) {
connecting_devices_ = connecting_devices;
paired_not_connected_devices_ = paired_not_connected_devices;
connecting_devices_.clear();
for (const auto& device : connecting_devices)
connecting_devices_.push_back(device->Clone());
paired_not_connected_devices_.clear();
for (const auto& device : paired_not_connected_devices)
paired_not_connected_devices_.push_back(device->Clone());
std::string focused_device_address = GetFocusedDeviceAddress();
......@@ -214,14 +224,20 @@ void BluetoothDetailedView::AppendSameTypeDevicesToScrollList(
bool checked) {
for (const auto& device : list) {
const gfx::VectorIcon& icon =
GetBluetoothDeviceIcon(device.device_type, device.connected);
HoverHighlightView* container =
AddScrollListItem(icon, device.display_name);
if (device.connected)
SetupConnectedScrollListItem(container);
else if (device.connecting)
SetupConnectingScrollListItem(container);
device_map_[container] = device.address;
GetBluetoothDeviceIcon(device->device_type, device->connection_state);
HoverHighlightView* container = AddScrollListItem(
icon, device::GetBluetoothDeviceNameForDisplay(device));
switch (device->connection_state) {
case BluetoothDeviceInfo::ConnectionState::kNotConnected:
break;
case BluetoothDeviceInfo::ConnectionState::kConnecting:
SetupConnectingScrollListItem(container);
break;
case BluetoothDeviceInfo::ConnectionState::kConnected:
SetupConnectedScrollListItem(container);
break;
}
device_map_[container] = device->address;
}
}
......@@ -229,7 +245,7 @@ bool BluetoothDetailedView::FoundDevice(
const std::string& device_address,
const BluetoothDeviceList& device_list) const {
for (const auto& device : device_list) {
if (device.address == device_address)
if (device->address == device_address)
return true;
}
return false;
......
......@@ -4,6 +4,8 @@
#include "ash/system/bluetooth/bluetooth_feature_pod_controller.h"
#include <utility>
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/session/session_controller.h"
#include "ash/shell.h"
......@@ -12,9 +14,11 @@
#include "ash/system/unified/feature_pod_button.h"
#include "ash/system/unified/unified_system_tray_controller.h"
#include "base/i18n/number_formatting.h"
#include "services/device/public/cpp/bluetooth/bluetooth_utils.h"
#include "ui/base/l10n/l10n_util.h"
using device::mojom::BluetoothSystem;
using device::mojom::BluetoothDeviceInfo;
namespace ash {
......@@ -91,10 +95,12 @@ void BluetoothFeaturePodController::UpdateButton() {
}
BluetoothDeviceList connected_devices;
for (const auto& device :
for (auto& device :
Shell::Get()->tray_bluetooth_helper()->GetAvailableBluetoothDevices()) {
if (device.connected)
connected_devices.push_back(device);
if (device->connection_state ==
BluetoothDeviceInfo::ConnectionState::kConnected) {
connected_devices.push_back(std::move(device));
}
}
if (connected_devices.size() > 1) {
......@@ -107,7 +113,8 @@ void BluetoothFeaturePodController::UpdateButton() {
IDS_ASH_STATUS_TRAY_BLUETOOTH_MULTIPLE_DEVICES_CONNECTED_TOOLTIP,
device_count));
} else if (connected_devices.size() == 1) {
const base::string16& device_name = connected_devices.back().display_name;
const base::string16 device_name =
device::GetBluetoothDeviceNameForDisplay(connected_devices.back());
button_->SetVectorIcon(kUnifiedMenuBluetoothConnectedIcon);
button_->SetLabel(device_name);
button_->SetSubLabel(l10n_util::GetStringUTF16(
......
......@@ -8,13 +8,6 @@ using device::mojom::BluetoothSystem;
namespace ash {
BluetoothDeviceInfo::BluetoothDeviceInfo() = default;
BluetoothDeviceInfo::BluetoothDeviceInfo(const BluetoothDeviceInfo& other) =
default;
BluetoothDeviceInfo::~BluetoothDeviceInfo() = default;
TrayBluetoothHelper::TrayBluetoothHelper() = default;
TrayBluetoothHelper::~TrayBluetoothHelper() = default;
......
......@@ -15,23 +15,7 @@
namespace ash {
// Cached info from device::BluetoothDevice used for display in the UI.
// Exists because it is not safe to cache pointers to device::BluetoothDevice
// instances.
struct ASH_EXPORT BluetoothDeviceInfo {
BluetoothDeviceInfo();
BluetoothDeviceInfo(const BluetoothDeviceInfo& other);
~BluetoothDeviceInfo();
std::string address;
base::string16 display_name;
bool connected = false;
bool connecting = false;
bool paired = false;
device::BluetoothDeviceType device_type;
};
using BluetoothDeviceList = std::vector<BluetoothDeviceInfo>;
using BluetoothDeviceList = std::vector<device::mojom::BluetoothDeviceInfoPtr>;
// Maps UI concepts from the Bluetooth system tray (e.g. "Bluetooth is on") into
// device concepts ("Bluetooth adapter enabled"). Note that most Bluetooth
......
......@@ -20,6 +20,8 @@
#include "device/bluetooth/chromeos/bluetooth_utils.h"
using device::mojom::BluetoothSystem;
using device::mojom::BluetoothDeviceInfo;
using device::mojom::BluetoothDeviceInfoPtr;
namespace ash {
namespace {
......@@ -34,14 +36,66 @@ void BluetoothSetDiscoveringError() {
void BluetoothDeviceConnectError(
device::BluetoothDevice::ConnectErrorCode error_code) {}
BluetoothDeviceInfo GetBluetoothDeviceInfo(device::BluetoothDevice* device) {
BluetoothDeviceInfo info;
info.address = device->GetAddress();
info.display_name = device->GetNameForDisplay();
info.connected = device->IsConnected();
info.connecting = device->IsConnecting();
info.paired = device->IsPaired();
info.device_type = device->GetDeviceType();
BluetoothDeviceInfoPtr GetBluetoothDeviceInfo(device::BluetoothDevice* device) {
BluetoothDeviceInfoPtr info = BluetoothDeviceInfo::New();
info->address = device->GetAddress();
info->name = device->GetName();
info->is_paired = device->IsPaired();
switch (device->GetDeviceType()) {
case device::BluetoothDeviceType::UNKNOWN:
info->device_type = BluetoothDeviceInfo::DeviceType::kUnknown;
break;
case device::BluetoothDeviceType::COMPUTER:
info->device_type = BluetoothDeviceInfo::DeviceType::kComputer;
break;
case device::BluetoothDeviceType::PHONE:
info->device_type = BluetoothDeviceInfo::DeviceType::kPhone;
break;
case device::BluetoothDeviceType::MODEM:
info->device_type = BluetoothDeviceInfo::DeviceType::kModem;
break;
case device::BluetoothDeviceType::AUDIO:
info->device_type = BluetoothDeviceInfo::DeviceType::kAudio;
break;
case device::BluetoothDeviceType::CAR_AUDIO:
info->device_type = BluetoothDeviceInfo::DeviceType::kCarAudio;
break;
case device::BluetoothDeviceType::VIDEO:
info->device_type = BluetoothDeviceInfo::DeviceType::kVideo;
break;
case device::BluetoothDeviceType::PERIPHERAL:
info->device_type = BluetoothDeviceInfo::DeviceType::kPeripheral;
break;
case device::BluetoothDeviceType::JOYSTICK:
info->device_type = BluetoothDeviceInfo::DeviceType::kJoystick;
break;
case device::BluetoothDeviceType::GAMEPAD:
info->device_type = BluetoothDeviceInfo::DeviceType::kGamepad;
break;
case device::BluetoothDeviceType::KEYBOARD:
info->device_type = BluetoothDeviceInfo::DeviceType::kKeyboard;
break;
case device::BluetoothDeviceType::MOUSE:
info->device_type = BluetoothDeviceInfo::DeviceType::kMouse;
break;
case device::BluetoothDeviceType::TABLET:
info->device_type = BluetoothDeviceInfo::DeviceType::kTablet;
break;
case device::BluetoothDeviceType::KEYBOARD_MOUSE_COMBO:
info->device_type = BluetoothDeviceInfo::DeviceType::kKeyboardMouseCombo;
break;
}
if (device->IsConnecting()) {
info->connection_state = BluetoothDeviceInfo::ConnectionState::kConnecting;
} else if (device->IsConnected()) {
info->connection_state = BluetoothDeviceInfo::ConnectionState::kConnected;
} else {
info->connection_state =
BluetoothDeviceInfo::ConnectionState::kNotConnected;
}
return info;
}
......@@ -70,11 +124,12 @@ void TrayBluetoothHelperLegacy::Initialize() {
BluetoothDeviceList TrayBluetoothHelperLegacy::GetAvailableBluetoothDevices()
const {
BluetoothDeviceList device_list;
device::BluetoothAdapter::DeviceList devices =
device::FilterBluetoothDeviceList(adapter_->GetDevices(),
device::BluetoothFilterType::KNOWN,
kMaximumDevicesShown);
BluetoothDeviceList device_list;
for (device::BluetoothDevice* device : devices)
device_list.push_back(GetBluetoothDeviceInfo(device));
......
......@@ -25,9 +25,9 @@ namespace {
// Returns true if device with |address| exists in the filtered device list.
// Returns false otherwise.
bool ExistInFilteredDevices(const std::string& address,
BluetoothDeviceList filtered_devices) {
const BluetoothDeviceList& filtered_devices) {
for (const auto& device : filtered_devices) {
if (device.address == address)
if (device->address == address)
return true;
}
return false;
......
......@@ -6,6 +6,7 @@
#include <set>
#include <string>
#include <utility>
#include "ash/session/session_controller.h"
#include "ash/shell.h"
......@@ -16,6 +17,8 @@
#include "base/stl_util.h"
using device::mojom::BluetoothSystem;
using device::mojom::BluetoothDeviceInfo;
using device::mojom::BluetoothDeviceInfoPtr;
namespace ash {
......@@ -27,16 +30,15 @@ namespace {
// end of the |list|; otherwise, keep it at the same place, but update the data
// with new device info provided by |device|.
void UpdateBluetoothDeviceListHelper(BluetoothDeviceList* list,
const BluetoothDeviceInfo& device) {
for (BluetoothDeviceList::iterator it = list->begin(); it != list->end();
++it) {
if ((*it).address == device.address) {
*it = device;
BluetoothDeviceInfoPtr new_device) {
for (auto& device : *list) {
if (device->address == new_device->address) {
device.Swap(&new_device);
return;
}
}
list->push_back(device);
list->push_back(std::move(new_device));
}
// Removes the obsolete BluetoothDevices from |list|, if they are not in the
......@@ -45,8 +47,8 @@ void RemoveObsoleteBluetoothDevicesFromList(
BluetoothDeviceList* device_list,
const std::set<std::string>& new_device_address_list) {
base::EraseIf(*device_list, [&new_device_address_list](
const BluetoothDeviceInfo& info) {
return !base::ContainsKey(new_device_address_list, info.address);
const BluetoothDeviceInfoPtr& info) {
return !base::ContainsKey(new_device_address_list, info->address);
});
}
......@@ -149,21 +151,25 @@ void UnifiedBluetoothDetailedViewController::UpdateBluetoothDeviceList() {
std::set<std::string> new_paired_not_connected_devices;
std::set<std::string> new_discovered_not_paired_devices;
BluetoothDeviceList list =
Shell::Get()->tray_bluetooth_helper()->GetAvailableBluetoothDevices();
for (const auto& device : list) {
if (device.connecting) {
new_connecting_devices.insert(device.address);
UpdateBluetoothDeviceListHelper(&connecting_devices_, device);
} else if (device.connected && device.paired) {
new_connected_devices.insert(device.address);
UpdateBluetoothDeviceListHelper(&connected_devices_, device);
} else if (device.paired) {
new_paired_not_connected_devices.insert(device.address);
UpdateBluetoothDeviceListHelper(&paired_not_connected_devices_, device);
for (auto& device :
Shell::Get()->tray_bluetooth_helper()->GetAvailableBluetoothDevices()) {
if (device->connection_state ==
BluetoothDeviceInfo::ConnectionState::kConnecting) {
new_connecting_devices.insert(device->address);
UpdateBluetoothDeviceListHelper(&connecting_devices_, std::move(device));
} else if (device->connection_state ==
BluetoothDeviceInfo::ConnectionState::kConnected &&
device->is_paired) {
new_connected_devices.insert(device->address);
UpdateBluetoothDeviceListHelper(&connected_devices_, std::move(device));
} else if (device->is_paired) {
new_paired_not_connected_devices.insert(device->address);
UpdateBluetoothDeviceListHelper(&paired_not_connected_devices_,
std::move(device));
} else {
new_discovered_not_paired_devices.insert(device.address);
UpdateBluetoothDeviceListHelper(&discovered_not_paired_devices_, device);
new_discovered_not_paired_devices.insert(device->address);
UpdateBluetoothDeviceListHelper(&discovered_not_paired_devices_,
std::move(device));
}
}
RemoveObsoleteBluetoothDevicesFromList(&connecting_devices_,
......
......@@ -3,6 +3,7 @@
# found in the LICENSE file.
import("//tools/grit/grit_rule.gni")
import("//tools/grit/repack.gni")
grit("strings") {
source = "../bluetooth_strings.grd"
......@@ -64,3 +65,13 @@ grit("strings") {
"bluetooth_strings_zh-TW.pak",
]
}
repack("bluetooth_test_strings") {
sources = [
"$root_gen_dir/device/bluetooth/strings/bluetooth_strings_en-US.pak",
]
output = "$root_out_dir/bluetooth_test_strings.pak"
deps = [
":strings",
]
}
......@@ -121,6 +121,7 @@ source_set("tests") {
"//services/device/geolocation:test_support",
"//services/device/power_monitor",
"//services/device/public/cpp:device_features",
"//services/device/public/cpp/bluetooth:bluetooth_tests",
"//services/device/public/cpp/power_monitor",
"//services/device/public/mojom",
"//services/device/wake_lock",
......
# 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.
source_set("bluetooth") {
sources = [
"bluetooth_utils.cc",
"bluetooth_utils.h",
]
deps = [
"//base",
"//device/bluetooth",
"//device/bluetooth/strings",
"//services/device/public/mojom",
"//ui/base",
]
}
source_set("bluetooth_tests") {
testonly = true
sources = [
"bluetooth_utils_unittest.cc",
]
deps = [
":bluetooth",
"//base",
"//services/device/public/mojom",
"//testing/gtest",
"//ui/base",
]
}
include_rules = [
"+ui/base/l10n",
]
// 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 "services/device/public/cpp/bluetooth/bluetooth_utils.h"
#include "base/optional.h"
#include "base/strings/utf_string_conversions.h"
#include "device/bluetooth/string_util_icu.h"
#include "device/bluetooth/strings/grit/bluetooth_strings.h"
#include "ui/base/l10n/l10n_util.h"
namespace device {
using DeviceType = mojom::BluetoothDeviceInfo::DeviceType;
base::string16 GetBluetoothDeviceNameForDisplay(
const mojom::BluetoothDeviceInfoPtr& device_info) {
if (device_info->name) {
const std::string& device_name = device_info->name.value();
if (HasGraphicCharacter(device_name))
return base::UTF8ToUTF16(device_name);
}
auto address_utf16 = base::UTF8ToUTF16(device_info->address);
auto device_type = device_info->device_type;
switch (device_type) {
case DeviceType::kUnknown:
case DeviceType::kPeripheral:
return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_UNKNOWN,
address_utf16);
case DeviceType::kComputer:
return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_COMPUTER,
address_utf16);
case DeviceType::kPhone:
return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_PHONE,
address_utf16);
case DeviceType::kModem:
return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_MODEM,
address_utf16);
case DeviceType::kAudio:
return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_AUDIO,
address_utf16);
case DeviceType::kCarAudio:
return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_CAR_AUDIO,
address_utf16);
case DeviceType::kVideo:
return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_VIDEO,
address_utf16);
case DeviceType::kJoystick:
return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_JOYSTICK,
address_utf16);
case DeviceType::kGamepad:
return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_GAMEPAD,
address_utf16);
case DeviceType::kKeyboard:
return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_KEYBOARD,
address_utf16);
case DeviceType::kMouse:
return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_MOUSE,
address_utf16);
case DeviceType::kTablet:
return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_TABLET,
address_utf16);
case DeviceType::kKeyboardMouseCombo:
return l10n_util::GetStringFUTF16(
IDS_BLUETOOTH_DEVICE_KEYBOARD_MOUSE_COMBO, address_utf16);
}
NOTREACHED();
}
} // namespace device
// 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 SERVICES_DEVICE_PUBLIC_CPP_BLUETOOTH_BLUETOOTH_UTILS_H_
#define SERVICES_DEVICE_PUBLIC_CPP_BLUETOOTH_BLUETOOTH_UTILS_H_
#include "base/strings/string16.h"
#include "services/device/public/mojom/bluetooth_system.mojom.h"
namespace device {
// Returns the name of the device suitable for displaying, this may
// be a synthesized string containing the address and localized type name
// if the device has no obtained name.
base::string16 GetBluetoothDeviceNameForDisplay(
const mojom::BluetoothDeviceInfoPtr& device_info);
}; // namespace device
#endif // SERVICES_DEVICE_PUBLIC_CPP_BLUETOOTH_BLUETOOTH_UTILS_H_
// 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 "services/device/public/cpp/bluetooth/bluetooth_utils.h"
#include "base/files/file_path.h"
#include "base/optional.h"
#include "base/path_service.h"
#include "base/strings/utf_string_conversions.h"
#include "services/device/public/mojom/bluetooth_system.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace device {
using mojom::BluetoothDeviceInfo;
using mojom::BluetoothDeviceInfoPtr;
constexpr char kAddress[] = "00:00:00:00:00:00";
constexpr char kName[] = "Foo Bar";
constexpr char kUnicodeName[] = "❤❤❤❤";
constexpr char kEmptyName[] = "";
constexpr char kWhitespaceName[] = " ";
constexpr char kUnicodeWhitespaceName[] = "    ";
TEST(BluetoothUtilsTest, NoNameAndNoUnknownDeviceType) {
BluetoothDeviceInfoPtr info = BluetoothDeviceInfo::New();
info->address = kAddress;
info->name = base::nullopt;
info->device_type = BluetoothDeviceInfo::DeviceType::kUnknown;
EXPECT_EQ(
base::UTF8ToUTF16("Unknown or Unsupported Device (00:00:00:00:00:00)"),
GetBluetoothDeviceNameForDisplay(info));
}
TEST(BluetoothUtilsTest, NoNameAndComputerDeviceType) {
BluetoothDeviceInfoPtr info = BluetoothDeviceInfo::New();
info->address = kAddress;
info->name = base::nullopt;
info->device_type = BluetoothDeviceInfo::DeviceType::kComputer;
EXPECT_EQ(base::UTF8ToUTF16("Computer (00:00:00:00:00:00)"),
GetBluetoothDeviceNameForDisplay(info));
}
TEST(BluetoothUtilsTest, NameAndUnknownDeviceType) {
BluetoothDeviceInfoPtr info = BluetoothDeviceInfo::New();
info->address = kAddress;
info->name = kName;
info->device_type = BluetoothDeviceInfo::DeviceType::kUnknown;
EXPECT_EQ(base::UTF8ToUTF16(kName), GetBluetoothDeviceNameForDisplay(info));
}
TEST(BluetoothUtilsTest, NameAndComputerDeviceType) {
BluetoothDeviceInfoPtr info = BluetoothDeviceInfo::New();
info->address = kAddress;
info->name = kName;
info->device_type = BluetoothDeviceInfo::DeviceType::kComputer;
EXPECT_EQ(base::UTF8ToUTF16(kName), GetBluetoothDeviceNameForDisplay(info));
}
TEST(BluetoothUtilsTests, UnicodeName) {
BluetoothDeviceInfoPtr info = BluetoothDeviceInfo::New();
info->address = kAddress;
info->name = kUnicodeName;
info->device_type = BluetoothDeviceInfo::DeviceType::kComputer;
EXPECT_EQ(base::UTF8ToUTF16(kUnicodeName),
GetBluetoothDeviceNameForDisplay(info));
}
TEST(BluetoothUtilsTests, EmptyName) {
BluetoothDeviceInfoPtr info = BluetoothDeviceInfo::New();
info->address = kAddress;
info->name = kEmptyName;
info->device_type = BluetoothDeviceInfo::DeviceType::kComputer;
EXPECT_EQ(base::UTF8ToUTF16("Computer (00:00:00:00:00:00)"),
GetBluetoothDeviceNameForDisplay(info));
}
TEST(BluetoothUtilsTests, WhitespaceName) {
BluetoothDeviceInfoPtr info = BluetoothDeviceInfo::New();
info->address = kAddress;
info->name = kWhitespaceName;
info->device_type = BluetoothDeviceInfo::DeviceType::kComputer;
EXPECT_EQ(base::UTF8ToUTF16("Computer (00:00:00:00:00:00)"),
GetBluetoothDeviceNameForDisplay(info));
}
TEST(BluetoothUtilsTests, UnicodeWhitespaceName) {
BluetoothDeviceInfoPtr info = BluetoothDeviceInfo::New();
info->address = kAddress;
info->name = kUnicodeWhitespaceName;
info->device_type = BluetoothDeviceInfo::DeviceType::kComputer;
EXPECT_EQ(base::UTF8ToUTF16("Computer (00:00:00:00:00:00)"),
GetBluetoothDeviceNameForDisplay(info));
}
} // namespace device
......@@ -4,6 +4,58 @@
module device.mojom;
// Holds information about a Bluetooth Device.
struct BluetoothDeviceInfo {
enum ConnectionState {
kNotConnected,
kConnecting,
kConnected,
};
// Represent the different types of Bluetooth devices that we support
// or are aware of. Based on the Device Classes specified by the Bluetooth SIG
// https://www.bluetooth.com/specifications/assigned-numbers/baseband.
enum DeviceType {
kUnknown,
kComputer,
kPhone,
kModem,
kAudio,
kCarAudio,
kVideo,
kPeripheral,
kJoystick,
kGamepad,
kKeyboard,
kMouse,
kTablet,
kKeyboardMouseCombo,
};
// The MAC Address of the device e.g. AA:BB:CC:00:11:22.
// TODO(ortuno): Validate address.
string address;
// Name of the device. Retrieved during the inquiry response for Classic
// devices, from the Advertisement from LE devices, or from the devices itself
// after connecting to it.
string? name;
// Indicates whether the device is not connected, connecting, or already
// connected.
ConnectionState connection_state;
// Indicates whether the device is paired to the system.
bool is_paired;
// Retrieved from the the Bluetooth class[1] for Classic and Dual devices and
// from the appearance characteristic[2] for LE devices.
//
// [1] https://www.bluetooth.com/specifications/assigned-numbers/baseband
// [2] https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.gap.appearance.xml
DeviceType device_type;
};
// Factory to get an instance of the BluetoothSystem interface.
interface BluetoothSystemFactory {
Create(BluetoothSystem& system, BluetoothSystemClient system_client);
......
......@@ -31,6 +31,7 @@ source_set("run_all_service_tests") {
}
data_deps = [
"//device/bluetooth/strings:bluetooth_test_strings",
"//ui/resources:ui_test_pak_data",
]
......
......@@ -3,13 +3,16 @@
// found in the LICENSE file.
#include "base/bind.h"
#include "base/files/file.h"
#include "base/i18n/icu_util.h"
#include "base/macros.h"
#include "base/path_service.h"
#include "base/test/launcher/unit_test_launcher.h"
#include "base/test/test_suite.h"
#include "build/build_config.h"
#include "services/service_manager/public/cpp/test/common_initialization.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/resource/scale_factor.h"
#include "ui/base/ui_base_paths.h"
namespace {
......@@ -28,6 +31,17 @@ class ServiceTestSuite : public base::TestSuite {
ASSERT_TRUE(base::PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path));
ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path);
base::FilePath path;
#if defined(OS_ANDROID)
ASSERT_TRUE(base::PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &path));
#else
ASSERT_TRUE(base::PathService::Get(base::DIR_MODULE, &path));
#endif
base::FilePath bluetooth_test_strings =
path.Append(FILE_PATH_LITERAL("bluetooth_test_strings.pak"));
ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath(
bluetooth_test_strings, ui::SCALE_FACTOR_NONE);
// base::TestSuite and ViewsInit both try to load icu. That's ok for tests.
base::i18n::AllowMultipleInitializeCallsForTesting();
}
......
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