The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.bluetooth; |
| 18 | |
Ralph Nathan | 29335fd | 2018-07-23 09:35:18 -0700 | [diff] [blame] | 19 | import android.annotation.TestApi; |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 20 | import android.annotation.UnsupportedAppUsage; |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 21 | import android.os.Parcel; |
| 22 | import android.os.Parcelable; |
| 23 | |
Pulkit Bhuwalka | 66d6123 | 2017-08-16 21:52:04 -0700 | [diff] [blame] | 24 | import java.nio.ByteBuffer; |
| 25 | import java.nio.ByteOrder; |
| 26 | import java.util.Arrays; |
| 27 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | /** |
Scott Main | 9fab0ae | 2009-11-03 18:17:59 -0800 | [diff] [blame] | 29 | * Represents a Bluetooth class, which describes general characteristics |
| 30 | * and capabilities of a device. For example, a Bluetooth class will |
| 31 | * specify the general device type such as a phone, a computer, or |
| 32 | * headset, and whether it's capable of services such as audio or telephony. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | * |
Scott Main | 9fab0ae | 2009-11-03 18:17:59 -0800 | [diff] [blame] | 34 | * <p>Every Bluetooth class is composed of zero or more service classes, and |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 35 | * exactly one device class. The device class is further broken down into major |
| 36 | * and minor device class components. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | * |
Scott Main | 9fab0ae | 2009-11-03 18:17:59 -0800 | [diff] [blame] | 38 | * <p>{@link BluetoothClass} is useful as a hint to roughly describe a device |
| 39 | * (for example to show an icon in the UI), but does not reliably describe which |
| 40 | * Bluetooth profiles or services are actually supported by a device. Accurate |
| 41 | * service discovery is done through SDP requests, which are automatically |
| 42 | * performed when creating an RFCOMM socket with {@link |
Jake Hamby | f51eada | 2010-09-21 13:39:53 -0700 | [diff] [blame] | 43 | * BluetoothDevice#createRfcommSocketToServiceRecord} and {@link |
| 44 | * BluetoothAdapter#listenUsingRfcommWithServiceRecord}</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | * |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 46 | * <p>Use {@link BluetoothDevice#getBluetoothClass} to retrieve the class for |
| 47 | * a remote device. |
Scott Main | 9fab0ae | 2009-11-03 18:17:59 -0800 | [diff] [blame] | 48 | * |
| 49 | * <!-- |
| 50 | * The Bluetooth class is a 32 bit field. The format of these bits is defined at |
| 51 | * http://www.bluetooth.org/Technical/AssignedNumbers/baseband.htm |
| 52 | * (login required). This class contains that 32 bit field, and provides |
| 53 | * constants and methods to determine which Service Class(es) and Device Class |
| 54 | * are encoded in that field. |
| 55 | * --> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | */ |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 57 | public final class BluetoothClass implements Parcelable { |
| 58 | /** |
| 59 | * Legacy error value. Applications should use null instead. |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 60 | * |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 61 | * @hide |
| 62 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | public static final int ERROR = 0xFF000000; |
| 64 | |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 65 | private final int mClass; |
Yue Lixin | a4433af | 2009-07-09 16:56:43 +0800 | [diff] [blame] | 66 | |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 67 | /** @hide */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 68 | @UnsupportedAppUsage |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 69 | public BluetoothClass(int classInt) { |
| 70 | mClass = classInt; |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public boolean equals(Object o) { |
| 75 | if (o instanceof BluetoothClass) { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 76 | return mClass == ((BluetoothClass) o).mClass; |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 77 | } |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public int hashCode() { |
| 83 | return mClass; |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public String toString() { |
| 88 | return Integer.toHexString(mClass); |
| 89 | } |
| 90 | |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 91 | @Override |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 92 | public int describeContents() { |
| 93 | return 0; |
| 94 | } |
| 95 | |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 96 | public static final Parcelable.Creator<BluetoothClass> CREATOR = |
| 97 | new Parcelable.Creator<BluetoothClass>() { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 98 | public BluetoothClass createFromParcel(Parcel in) { |
| 99 | return new BluetoothClass(in.readInt()); |
| 100 | } |
| 101 | |
| 102 | public BluetoothClass[] newArray(int size) { |
| 103 | return new BluetoothClass[size]; |
| 104 | } |
| 105 | }; |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 106 | |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 107 | @Override |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 108 | public void writeToParcel(Parcel out, int flags) { |
| 109 | out.writeInt(mClass); |
| 110 | } |
| 111 | |
| 112 | /** |
Scott Main | 9fab0ae | 2009-11-03 18:17:59 -0800 | [diff] [blame] | 113 | * Defines all service class constants. |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 114 | * <p>Each {@link BluetoothClass} encodes zero or more service classes. |
| 115 | */ |
| 116 | public static final class Service { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 117 | private static final int BITMASK = 0xFFE000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | |
| 119 | public static final int LIMITED_DISCOVERABILITY = 0x002000; |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 120 | public static final int POSITIONING = 0x010000; |
| 121 | public static final int NETWORKING = 0x020000; |
| 122 | public static final int RENDER = 0x040000; |
| 123 | public static final int CAPTURE = 0x080000; |
| 124 | public static final int OBJECT_TRANSFER = 0x100000; |
| 125 | public static final int AUDIO = 0x200000; |
| 126 | public static final int TELEPHONY = 0x400000; |
| 127 | public static final int INFORMATION = 0x800000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 128 | } |
| 129 | |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 130 | /** |
Scott Main | 9fab0ae | 2009-11-03 18:17:59 -0800 | [diff] [blame] | 131 | * Return true if the specified service class is supported by this |
| 132 | * {@link BluetoothClass}. |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 133 | * <p>Valid service classes are the public constants in |
| 134 | * {@link BluetoothClass.Service}. For example, {@link |
| 135 | * BluetoothClass.Service#AUDIO}. |
| 136 | * |
| 137 | * @param service valid service class |
| 138 | * @return true if the service class is supported |
| 139 | */ |
| 140 | public boolean hasService(int service) { |
| 141 | return ((mClass & Service.BITMASK & service) != 0); |
| 142 | } |
| 143 | |
| 144 | /** |
Scott Main | 9fab0ae | 2009-11-03 18:17:59 -0800 | [diff] [blame] | 145 | * Defines all device class constants. |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 146 | * <p>Each {@link BluetoothClass} encodes exactly one device class, with |
| 147 | * major and minor components. |
| 148 | * <p>The constants in {@link |
| 149 | * BluetoothClass.Device} represent a combination of major and minor |
Scott Main | 9fab0ae | 2009-11-03 18:17:59 -0800 | [diff] [blame] | 150 | * device components (the complete device class). The constants in {@link |
| 151 | * BluetoothClass.Device.Major} represent only major device classes. |
| 152 | * <p>See {@link BluetoothClass.Service} for service class constants. |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 153 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 154 | public static class Device { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 155 | private static final int BITMASK = 0x1FFC; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | |
Scott Main | 9fab0ae | 2009-11-03 18:17:59 -0800 | [diff] [blame] | 157 | /** |
| 158 | * Defines all major device class constants. |
| 159 | * <p>See {@link BluetoothClass.Device} for minor classes. |
| 160 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 161 | public static class Major { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 162 | private static final int BITMASK = 0x1F00; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 164 | public static final int MISC = 0x0000; |
| 165 | public static final int COMPUTER = 0x0100; |
| 166 | public static final int PHONE = 0x0200; |
| 167 | public static final int NETWORKING = 0x0300; |
| 168 | public static final int AUDIO_VIDEO = 0x0400; |
| 169 | public static final int PERIPHERAL = 0x0500; |
| 170 | public static final int IMAGING = 0x0600; |
| 171 | public static final int WEARABLE = 0x0700; |
| 172 | public static final int TOY = 0x0800; |
| 173 | public static final int HEALTH = 0x0900; |
| 174 | public static final int UNCATEGORIZED = 0x1F00; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | // Devices in the COMPUTER major class |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 178 | public static final int COMPUTER_UNCATEGORIZED = 0x0100; |
| 179 | public static final int COMPUTER_DESKTOP = 0x0104; |
| 180 | public static final int COMPUTER_SERVER = 0x0108; |
| 181 | public static final int COMPUTER_LAPTOP = 0x010C; |
| 182 | public static final int COMPUTER_HANDHELD_PC_PDA = 0x0110; |
| 183 | public static final int COMPUTER_PALM_SIZE_PC_PDA = 0x0114; |
| 184 | public static final int COMPUTER_WEARABLE = 0x0118; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 185 | |
| 186 | // Devices in the PHONE major class |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 187 | public static final int PHONE_UNCATEGORIZED = 0x0200; |
| 188 | public static final int PHONE_CELLULAR = 0x0204; |
| 189 | public static final int PHONE_CORDLESS = 0x0208; |
| 190 | public static final int PHONE_SMART = 0x020C; |
| 191 | public static final int PHONE_MODEM_OR_GATEWAY = 0x0210; |
| 192 | public static final int PHONE_ISDN = 0x0214; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | |
| 194 | // Minor classes for the AUDIO_VIDEO major class |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 195 | public static final int AUDIO_VIDEO_UNCATEGORIZED = 0x0400; |
| 196 | public static final int AUDIO_VIDEO_WEARABLE_HEADSET = 0x0404; |
| 197 | public static final int AUDIO_VIDEO_HANDSFREE = 0x0408; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 198 | //public static final int AUDIO_VIDEO_RESERVED = 0x040C; |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 199 | public static final int AUDIO_VIDEO_MICROPHONE = 0x0410; |
| 200 | public static final int AUDIO_VIDEO_LOUDSPEAKER = 0x0414; |
| 201 | public static final int AUDIO_VIDEO_HEADPHONES = 0x0418; |
| 202 | public static final int AUDIO_VIDEO_PORTABLE_AUDIO = 0x041C; |
| 203 | public static final int AUDIO_VIDEO_CAR_AUDIO = 0x0420; |
| 204 | public static final int AUDIO_VIDEO_SET_TOP_BOX = 0x0424; |
| 205 | public static final int AUDIO_VIDEO_HIFI_AUDIO = 0x0428; |
| 206 | public static final int AUDIO_VIDEO_VCR = 0x042C; |
| 207 | public static final int AUDIO_VIDEO_VIDEO_CAMERA = 0x0430; |
| 208 | public static final int AUDIO_VIDEO_CAMCORDER = 0x0434; |
| 209 | public static final int AUDIO_VIDEO_VIDEO_MONITOR = 0x0438; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 210 | public static final int AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER = 0x043C; |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 211 | public static final int AUDIO_VIDEO_VIDEO_CONFERENCING = 0x0440; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | //public static final int AUDIO_VIDEO_RESERVED = 0x0444; |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 213 | public static final int AUDIO_VIDEO_VIDEO_GAMING_TOY = 0x0448; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 214 | |
| 215 | // Devices in the WEARABLE major class |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 216 | public static final int WEARABLE_UNCATEGORIZED = 0x0700; |
| 217 | public static final int WEARABLE_WRIST_WATCH = 0x0704; |
| 218 | public static final int WEARABLE_PAGER = 0x0708; |
| 219 | public static final int WEARABLE_JACKET = 0x070C; |
| 220 | public static final int WEARABLE_HELMET = 0x0710; |
| 221 | public static final int WEARABLE_GLASSES = 0x0714; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | |
| 223 | // Devices in the TOY major class |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 224 | public static final int TOY_UNCATEGORIZED = 0x0800; |
| 225 | public static final int TOY_ROBOT = 0x0804; |
| 226 | public static final int TOY_VEHICLE = 0x0808; |
| 227 | public static final int TOY_DOLL_ACTION_FIGURE = 0x080C; |
| 228 | public static final int TOY_CONTROLLER = 0x0810; |
| 229 | public static final int TOY_GAME = 0x0814; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 230 | |
| 231 | // Devices in the HEALTH major class |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 232 | public static final int HEALTH_UNCATEGORIZED = 0x0900; |
| 233 | public static final int HEALTH_BLOOD_PRESSURE = 0x0904; |
| 234 | public static final int HEALTH_THERMOMETER = 0x0908; |
| 235 | public static final int HEALTH_WEIGHING = 0x090C; |
| 236 | public static final int HEALTH_GLUCOSE = 0x0910; |
| 237 | public static final int HEALTH_PULSE_OXIMETER = 0x0914; |
| 238 | public static final int HEALTH_PULSE_RATE = 0x0918; |
| 239 | public static final int HEALTH_DATA_DISPLAY = 0x091C; |
Jaikumar Ganesh | c88b0c6 | 2011-01-05 13:49:00 -0800 | [diff] [blame] | 240 | |
| 241 | // Devices in PERIPHERAL major class |
| 242 | /** |
| 243 | * @hide |
| 244 | */ |
| 245 | public static final int PERIPHERAL_NON_KEYBOARD_NON_POINTING = 0x0500; |
| 246 | /** |
| 247 | * @hide |
| 248 | */ |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 249 | public static final int PERIPHERAL_KEYBOARD = 0x0540; |
Jaikumar Ganesh | c88b0c6 | 2011-01-05 13:49:00 -0800 | [diff] [blame] | 250 | /** |
| 251 | * @hide |
| 252 | */ |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 253 | public static final int PERIPHERAL_POINTING = 0x0580; |
Jaikumar Ganesh | c88b0c6 | 2011-01-05 13:49:00 -0800 | [diff] [blame] | 254 | /** |
| 255 | * @hide |
| 256 | */ |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 257 | public static final int PERIPHERAL_KEYBOARD_POINTING = 0x05C0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 258 | } |
Yue Lixin | a4433af | 2009-07-09 16:56:43 +0800 | [diff] [blame] | 259 | |
| 260 | /** |
Scott Main | 9fab0ae | 2009-11-03 18:17:59 -0800 | [diff] [blame] | 261 | * Return the major device class component of this {@link BluetoothClass}. |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 262 | * <p>Values returned from this function can be compared with the |
| 263 | * public constants in {@link BluetoothClass.Device.Major} to determine |
| 264 | * which major class is encoded in this Bluetooth class. |
| 265 | * |
| 266 | * @return major device class component |
| 267 | */ |
| 268 | public int getMajorDeviceClass() { |
| 269 | return (mClass & Device.Major.BITMASK); |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * Return the (major and minor) device class component of this |
| 274 | * {@link BluetoothClass}. |
| 275 | * <p>Values returned from this function can be compared with the |
| 276 | * public constants in {@link BluetoothClass.Device} to determine which |
| 277 | * device class is encoded in this Bluetooth class. |
| 278 | * |
| 279 | * @return device class component |
| 280 | */ |
| 281 | public int getDeviceClass() { |
| 282 | return (mClass & Device.BITMASK); |
| 283 | } |
| 284 | |
Pulkit Bhuwalka | 66d6123 | 2017-08-16 21:52:04 -0700 | [diff] [blame] | 285 | /** |
| 286 | * Return the Bluetooth Class of Device (CoD) value including the |
| 287 | * {@link BluetoothClass.Service}, {@link BluetoothClass.Device.Major} and |
| 288 | * minor device fields. |
| 289 | * |
| 290 | * <p>This value is an integer representation of Bluetooth CoD as in |
| 291 | * Bluetooth specification. |
| 292 | * |
| 293 | * @see <a href="Bluetooth CoD">https://www.bluetooth.com/specifications/assigned-numbers/baseband</a> |
| 294 | * |
| 295 | * @hide |
| 296 | */ |
Ralph Nathan | 29335fd | 2018-07-23 09:35:18 -0700 | [diff] [blame] | 297 | @TestApi |
Pulkit Bhuwalka | 66d6123 | 2017-08-16 21:52:04 -0700 | [diff] [blame] | 298 | public int getClassOfDevice() { |
| 299 | return mClass; |
| 300 | } |
| 301 | |
| 302 | /** |
| 303 | * Return the Bluetooth Class of Device (CoD) value including the |
| 304 | * {@link BluetoothClass.Service}, {@link BluetoothClass.Device.Major} and |
| 305 | * minor device fields. |
| 306 | * |
| 307 | * <p>This value is a byte array representation of Bluetooth CoD as in |
| 308 | * Bluetooth specification. |
| 309 | * |
| 310 | * <p>Bluetooth COD information is 3 bytes, but stored as an int. Hence the |
| 311 | * MSB is useless and needs to be thrown away. The lower 3 bytes are |
| 312 | * converted into a byte array MSB to LSB. Hence, using BIG_ENDIAN. |
| 313 | * |
| 314 | * @see <a href="Bluetooth CoD">https://www.bluetooth.com/specifications/assigned-numbers/baseband</a> |
| 315 | * |
| 316 | * @hide |
| 317 | */ |
| 318 | public byte[] getClassOfDeviceBytes() { |
| 319 | byte[] bytes = ByteBuffer.allocate(4) |
| 320 | .order(ByteOrder.BIG_ENDIAN) |
| 321 | .putInt(mClass) |
| 322 | .array(); |
| 323 | |
| 324 | // Discard the top byte |
| 325 | return Arrays.copyOfRange(bytes, 1, bytes.length); |
| 326 | } |
| 327 | |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 328 | /** @hide */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 329 | @UnsupportedAppUsage |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 330 | public static final int PROFILE_HEADSET = 0; |
| 331 | /** @hide */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 332 | @UnsupportedAppUsage |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 333 | public static final int PROFILE_A2DP = 1; |
| 334 | /** @hide */ |
| 335 | public static final int PROFILE_OPP = 2; |
Adam Powell | df7627d | 2010-06-21 16:23:42 -0700 | [diff] [blame] | 336 | /** @hide */ |
| 337 | public static final int PROFILE_HID = 3; |
Jaikumar Ganesh | 3320580 | 2010-08-23 11:49:36 -0700 | [diff] [blame] | 338 | /** @hide */ |
| 339 | public static final int PROFILE_PANU = 4; |
| 340 | /** @hide */ |
| 341 | public static final int PROFILE_NAP = 5; |
Sanket Agarwal | 1bec6a5 | 2015-10-21 18:23:27 -0700 | [diff] [blame] | 342 | /** @hide */ |
| 343 | public static final int PROFILE_A2DP_SINK = 6; |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 344 | |
| 345 | /** |
Yue Lixin | a4433af | 2009-07-09 16:56:43 +0800 | [diff] [blame] | 346 | * Check class bits for possible bluetooth profile support. |
| 347 | * This is a simple heuristic that tries to guess if a device with the |
| 348 | * given class bits might support specified profile. It is not accurate for all |
| 349 | * devices. It tries to err on the side of false positives. |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 350 | * |
Yue Lixin | a4433af | 2009-07-09 16:56:43 +0800 | [diff] [blame] | 351 | * @param profile The profile to be checked |
| 352 | * @return True if this device might support specified profile. |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 353 | * @hide |
Yue Lixin | a4433af | 2009-07-09 16:56:43 +0800 | [diff] [blame] | 354 | */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 355 | @UnsupportedAppUsage |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 356 | public boolean doesClassMatch(int profile) { |
Yue Lixin | a4433af | 2009-07-09 16:56:43 +0800 | [diff] [blame] | 357 | if (profile == PROFILE_A2DP) { |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 358 | if (hasService(Service.RENDER)) { |
Yue Lixin | a4433af | 2009-07-09 16:56:43 +0800 | [diff] [blame] | 359 | return true; |
| 360 | } |
| 361 | // By the A2DP spec, sinks must indicate the RENDER service. |
| 362 | // However we found some that do not (Chordette). So lets also |
| 363 | // match on some other class bits. |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 364 | switch (getDeviceClass()) { |
| 365 | case Device.AUDIO_VIDEO_HIFI_AUDIO: |
| 366 | case Device.AUDIO_VIDEO_HEADPHONES: |
| 367 | case Device.AUDIO_VIDEO_LOUDSPEAKER: |
| 368 | case Device.AUDIO_VIDEO_CAR_AUDIO: |
Yue Lixin | a4433af | 2009-07-09 16:56:43 +0800 | [diff] [blame] | 369 | return true; |
| 370 | default: |
| 371 | return false; |
| 372 | } |
Sanket Agarwal | 1bec6a5 | 2015-10-21 18:23:27 -0700 | [diff] [blame] | 373 | } else if (profile == PROFILE_A2DP_SINK) { |
| 374 | if (hasService(Service.CAPTURE)) { |
| 375 | return true; |
| 376 | } |
| 377 | // By the A2DP spec, srcs must indicate the CAPTURE service. |
| 378 | // However if some device that do not, we try to |
| 379 | // match on some other class bits. |
| 380 | switch (getDeviceClass()) { |
| 381 | case Device.AUDIO_VIDEO_HIFI_AUDIO: |
| 382 | case Device.AUDIO_VIDEO_SET_TOP_BOX: |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 383 | case Device.AUDIO_VIDEO_VCR: |
Sanket Agarwal | 1bec6a5 | 2015-10-21 18:23:27 -0700 | [diff] [blame] | 384 | return true; |
| 385 | default: |
| 386 | return false; |
| 387 | } |
Yue Lixin | a4433af | 2009-07-09 16:56:43 +0800 | [diff] [blame] | 388 | } else if (profile == PROFILE_HEADSET) { |
| 389 | // The render service class is required by the spec for HFP, so is a |
| 390 | // pretty good signal |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 391 | if (hasService(Service.RENDER)) { |
Yue Lixin | a4433af | 2009-07-09 16:56:43 +0800 | [diff] [blame] | 392 | return true; |
| 393 | } |
| 394 | // Just in case they forgot the render service class |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 395 | switch (getDeviceClass()) { |
| 396 | case Device.AUDIO_VIDEO_HANDSFREE: |
| 397 | case Device.AUDIO_VIDEO_WEARABLE_HEADSET: |
| 398 | case Device.AUDIO_VIDEO_CAR_AUDIO: |
Yue Lixin | a4433af | 2009-07-09 16:56:43 +0800 | [diff] [blame] | 399 | return true; |
| 400 | default: |
| 401 | return false; |
| 402 | } |
| 403 | } else if (profile == PROFILE_OPP) { |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 404 | if (hasService(Service.OBJECT_TRANSFER)) { |
Yue Lixin | a4433af | 2009-07-09 16:56:43 +0800 | [diff] [blame] | 405 | return true; |
| 406 | } |
| 407 | |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 408 | switch (getDeviceClass()) { |
| 409 | case Device.COMPUTER_UNCATEGORIZED: |
| 410 | case Device.COMPUTER_DESKTOP: |
| 411 | case Device.COMPUTER_SERVER: |
| 412 | case Device.COMPUTER_LAPTOP: |
| 413 | case Device.COMPUTER_HANDHELD_PC_PDA: |
| 414 | case Device.COMPUTER_PALM_SIZE_PC_PDA: |
| 415 | case Device.COMPUTER_WEARABLE: |
| 416 | case Device.PHONE_UNCATEGORIZED: |
| 417 | case Device.PHONE_CELLULAR: |
| 418 | case Device.PHONE_CORDLESS: |
| 419 | case Device.PHONE_SMART: |
| 420 | case Device.PHONE_MODEM_OR_GATEWAY: |
| 421 | case Device.PHONE_ISDN: |
Yue Lixin | a4433af | 2009-07-09 16:56:43 +0800 | [diff] [blame] | 422 | return true; |
| 423 | default: |
| 424 | return false; |
| 425 | } |
Adam Powell | df7627d | 2010-06-21 16:23:42 -0700 | [diff] [blame] | 426 | } else if (profile == PROFILE_HID) { |
| 427 | return (getDeviceClass() & Device.Major.PERIPHERAL) == Device.Major.PERIPHERAL; |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 428 | } else if (profile == PROFILE_PANU || profile == PROFILE_NAP) { |
Jaikumar Ganesh | 3320580 | 2010-08-23 11:49:36 -0700 | [diff] [blame] | 429 | // No good way to distinguish between the two, based on class bits. |
| 430 | if (hasService(Service.NETWORKING)) { |
| 431 | return true; |
| 432 | } |
| 433 | return (getDeviceClass() & Device.Major.NETWORKING) == Device.Major.NETWORKING; |
Yue Lixin | a4433af | 2009-07-09 16:56:43 +0800 | [diff] [blame] | 434 | } else { |
| 435 | return false; |
| 436 | } |
| 437 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 438 | } |