Create a new-installs-only uniformity trial.
[chromium-blink-merge.git] / device / bluetooth / bluetooth_device.cc
blob378c6cedae797f0c8bc1c147007172cab3780f48
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"
11 namespace device {
13 BluetoothDevice::BluetoothDevice()
14 : bluetooth_class_(0),
15 visible_(false),
16 bonded_(false),
17 connected_(false) {
20 BluetoothDevice::~BluetoothDevice() {
23 const std::string& BluetoothDevice::address() const {
24 return address_;
27 string16 BluetoothDevice::GetName() const {
28 if (!name_.empty()) {
29 return UTF8ToUTF16(name_);
30 } else {
31 return GetAddressWithLocalizedDeviceTypeName();
35 string16 BluetoothDevice::GetAddressWithLocalizedDeviceTypeName() const {
36 string16 address = UTF8ToUTF16(address_);
37 BluetoothDevice::DeviceType device_type = GetDeviceType();
38 switch (device_type) {
39 case DEVICE_COMPUTER:
40 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_COMPUTER,
41 address);
42 case DEVICE_PHONE:
43 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_PHONE,
44 address);
45 case DEVICE_MODEM:
46 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_MODEM,
47 address);
48 case DEVICE_AUDIO:
49 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_AUDIO,
50 address);
51 case DEVICE_CAR_AUDIO:
52 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_CAR_AUDIO,
53 address);
54 case DEVICE_VIDEO:
55 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_VIDEO,
56 address);
57 case DEVICE_JOYSTICK:
58 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_JOYSTICK,
59 address);
60 case DEVICE_GAMEPAD:
61 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_GAMEPAD,
62 address);
63 case DEVICE_KEYBOARD:
64 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_KEYBOARD,
65 address);
66 case DEVICE_MOUSE:
67 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_MOUSE,
68 address);
69 case DEVICE_TABLET:
70 return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_TABLET,
71 address);
72 case DEVICE_KEYBOARD_MOUSE_COMBO:
73 return l10n_util::GetStringFUTF16(
74 IDS_BLUETOOTH_DEVICE_KEYBOARD_MOUSE_COMBO, address);
75 default:
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) {
83 case 0x01:
84 // Computer major device class.
85 return DEVICE_COMPUTER;
86 case 0x02:
87 // Phone major device class.
88 switch ((bluetooth_class_ & 0xfc) >> 2) {
89 case 0x01:
90 case 0x02:
91 case 0x03:
92 // Cellular, cordless and smart phones.
93 return DEVICE_PHONE;
94 case 0x04:
95 case 0x05:
96 // Modems: wired or voice gateway and common ISDN access.
97 return DEVICE_MODEM;
99 break;
100 case 0x04:
101 // Audio major device class.
102 switch ((bluetooth_class_ & 0xfc) >> 2) {
103 case 0x08:
104 // Car audio.
105 return DEVICE_CAR_AUDIO;
106 case 0x0b:
107 case 0x0c:
108 case 0x0d:
109 case 0x0e:
110 case 0x0f:
111 case 0x010:
112 // Video devices.
113 return DEVICE_VIDEO;
114 default:
115 return DEVICE_AUDIO;
117 break;
118 case 0x05:
119 // Peripheral major device class.
120 switch ((bluetooth_class_ & 0xc0) >> 6) {
121 case 0x00:
122 // "Not a keyboard or pointing device."
123 switch ((bluetooth_class_ & 0x01e) >> 2) {
124 case 0x01:
125 // Joystick.
126 return DEVICE_JOYSTICK;
127 case 0x02:
128 // Gamepad.
129 return DEVICE_GAMEPAD;
130 default:
131 return DEVICE_PERIPHERAL;
133 break;
134 case 0x01:
135 // Keyboard.
136 return DEVICE_KEYBOARD;
137 case 0x02:
138 // Pointing device.
139 switch ((bluetooth_class_ & 0x01e) >> 2) {
140 case 0x05:
141 // Digitizer tablet.
142 return DEVICE_TABLET;
143 default:
144 // Mouse.
145 return DEVICE_MOUSE;
147 break;
148 case 0x03:
149 // Combo device.
150 return DEVICE_KEYBOARD_MOUSE_COMBO;
152 break;
155 return DEVICE_UNKNOWN;
158 bool BluetoothDevice::IsVisible() const {
159 return visible_;
162 bool BluetoothDevice::IsBonded() const {
163 return bonded_;
166 bool BluetoothDevice::IsConnected() const {
167 return connected_;
170 } // namespace device