1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "device/bluetooth/bluetooth_device.h"
7 #include "base/utf_string_conversions.h"
8 #include "grit/generated_resources.h"
9 #include "ui/base/l10n/l10n_util.h"
13 BluetoothDevice::BluetoothDevice()
14 : bluetooth_class_(0),
20 BluetoothDevice::~BluetoothDevice() {
23 const std::string
& BluetoothDevice::address() const {
27 string16
BluetoothDevice::GetName() const {
29 return UTF8ToUTF16(name_
);
31 return GetAddressWithLocalizedDeviceTypeName();
35 string16
BluetoothDevice::GetAddressWithLocalizedDeviceTypeName() const {
36 string16 address
= UTF8ToUTF16(address_
);
37 BluetoothDevice::DeviceType device_type
= GetDeviceType();
38 switch (device_type
) {
40 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_COMPUTER
,
43 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_PHONE
,
46 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_MODEM
,
49 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_AUDIO
,
51 case DEVICE_CAR_AUDIO
:
52 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_CAR_AUDIO
,
55 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_VIDEO
,
58 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_JOYSTICK
,
61 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_GAMEPAD
,
64 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_KEYBOARD
,
67 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_MOUSE
,
70 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_TABLET
,
72 case DEVICE_KEYBOARD_MOUSE_COMBO
:
73 return l10n_util::GetStringFUTF16(
74 IDS_BLUETOOTH_DEVICE_KEYBOARD_MOUSE_COMBO
, address
);
76 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_UNKNOWN
, address
);
80 BluetoothDevice::DeviceType
BluetoothDevice::GetDeviceType() const {
81 // https://www.bluetooth.org/Technical/AssignedNumbers/baseband.htm
82 switch ((bluetooth_class_
& 0x1f00) >> 8) {
84 // Computer major device class.
85 return DEVICE_COMPUTER
;
87 // Phone major device class.
88 switch ((bluetooth_class_
& 0xfc) >> 2) {
92 // Cellular, cordless and smart phones.
96 // Modems: wired or voice gateway and common ISDN access.
101 // Audio major device class.
102 switch ((bluetooth_class_
& 0xfc) >> 2) {
105 return DEVICE_CAR_AUDIO
;
119 // Peripheral major device class.
120 switch ((bluetooth_class_
& 0xc0) >> 6) {
122 // "Not a keyboard or pointing device."
123 switch ((bluetooth_class_
& 0x01e) >> 2) {
126 return DEVICE_JOYSTICK
;
129 return DEVICE_GAMEPAD
;
131 return DEVICE_PERIPHERAL
;
136 return DEVICE_KEYBOARD
;
139 switch ((bluetooth_class_
& 0x01e) >> 2) {
142 return DEVICE_TABLET
;
150 return DEVICE_KEYBOARD_MOUSE_COMBO
;
155 return DEVICE_UNKNOWN
;
158 bool BluetoothDevice::IsVisible() const {
162 bool BluetoothDevice::IsBonded() const {
166 bool BluetoothDevice::IsConnected() const {
170 } // namespace device