19066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/* 29066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Copyright (C) 2008 The Android Open Source Project 39066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 49066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License"); 59066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * you may not use this file except in compliance with the License. 69066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * You may obtain a copy of the License at 79066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 89066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * http://www.apache.org/licenses/LICENSE-2.0 99066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Unless required by applicable law or agreed to in writing, software 119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS, 129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * See the License for the specific language governing permissions and 149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * limitations under the License. 159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpackage android.bluetooth; 189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 19005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pellyimport android.os.Parcel; 20005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pellyimport android.os.Parcelable; 21005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/** 239fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * Represents a Bluetooth class, which describes general characteristics 249fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * and capabilities of a device. For example, a Bluetooth class will 259fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * specify the general device type such as a phone, a computer, or 269fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * headset, and whether it's capable of services such as audio or telephony. 279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 289fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * <p>Every Bluetooth class is composed of zero or more service classes, and 29005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * exactly one device class. The device class is further broken down into major 30005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * and minor device class components. 319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 329fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * <p>{@link BluetoothClass} is useful as a hint to roughly describe a device 339fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * (for example to show an icon in the UI), but does not reliably describe which 349fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * Bluetooth profiles or services are actually supported by a device. Accurate 359fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * service discovery is done through SDP requests, which are automatically 369fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * performed when creating an RFCOMM socket with {@link 37f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * BluetoothDevice#createRfcommSocketToServiceRecord} and {@link 38f51eadaf1f83abfe16a609a4ded6d789494689b2Jake Hamby * BluetoothAdapter#listenUsingRfcommWithServiceRecord}</p> 399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 40005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Use {@link BluetoothDevice#getBluetoothClass} to retrieve the class for 41005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * a remote device. 429fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * 439fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * <!-- 449fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * The Bluetooth class is a 32 bit field. The format of these bits is defined at 459fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * http://www.bluetooth.org/Technical/AssignedNumbers/baseband.htm 469fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * (login required). This class contains that 32 bit field, and provides 479fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * constants and methods to determine which Service Class(es) and Device Class 489fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * are encoded in that field. 499fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * --> 509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 51005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pellypublic final class BluetoothClass implements Parcelable { 52005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 53005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Legacy error value. Applications should use null instead. 54005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * @hide 55005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int ERROR = 0xFF000000; 579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 58005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly private final int mClass; 59005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 60005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** @hide */ 61005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public BluetoothClass(int classInt) { 62005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly mClass = classInt; 63005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly } 64a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin 65005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @Override 66005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public boolean equals(Object o) { 67005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly if (o instanceof BluetoothClass) { 68005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly return mClass == ((BluetoothClass)o).mClass; 69005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly } 70005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly return false; 71005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly } 72005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 73005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @Override 74005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public int hashCode() { 75005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly return mClass; 76005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly } 77005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 78005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly @Override 79005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public String toString() { 80005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly return Integer.toHexString(mClass); 81005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly } 82005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 83005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public int describeContents() { 84005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly return 0; 85005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly } 86005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 87005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final Parcelable.Creator<BluetoothClass> CREATOR = 88005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly new Parcelable.Creator<BluetoothClass>() { 89005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public BluetoothClass createFromParcel(Parcel in) { 90005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly return new BluetoothClass(in.readInt()); 91005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly } 92005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public BluetoothClass[] newArray(int size) { 93005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly return new BluetoothClass[size]; 94005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly } 95005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly }; 96005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 97005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public void writeToParcel(Parcel out, int flags) { 98005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly out.writeInt(mClass); 99005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly } 100005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 101005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 1029fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * Defines all service class constants. 103005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Each {@link BluetoothClass} encodes zero or more service classes. 104005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 105005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final class Service { 106005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly private static final int BITMASK = 0xFFE000; 1079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int LIMITED_DISCOVERABILITY = 0x002000; 1099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int POSITIONING = 0x010000; 1109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int NETWORKING = 0x020000; 1119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int RENDER = 0x040000; 1129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int CAPTURE = 0x080000; 1139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int OBJECT_TRANSFER = 0x100000; 1149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int AUDIO = 0x200000; 1159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int TELEPHONY = 0x400000; 1169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int INFORMATION = 0x800000; 117005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly } 1189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 119005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 1209fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * Return true if the specified service class is supported by this 1219fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * {@link BluetoothClass}. 122005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Valid service classes are the public constants in 123005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * {@link BluetoothClass.Service}. For example, {@link 124005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * BluetoothClass.Service#AUDIO}. 125005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * 126005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * @param service valid service class 127005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * @return true if the service class is supported 128005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 129005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public boolean hasService(int service) { 130005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly return ((mClass & Service.BITMASK & service) != 0); 1319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 1329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 133005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 1349fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * Defines all device class constants. 135005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Each {@link BluetoothClass} encodes exactly one device class, with 136005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * major and minor components. 137005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>The constants in {@link 138005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * BluetoothClass.Device} represent a combination of major and minor 1399fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * device components (the complete device class). The constants in {@link 1409fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * BluetoothClass.Device.Major} represent only major device classes. 1419fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * <p>See {@link BluetoothClass.Service} for service class constants. 142005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 1439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static class Device { 144005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly private static final int BITMASK = 0x1FFC; 1459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1469fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main /** 1479fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * Defines all major device class constants. 1489fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * <p>See {@link BluetoothClass.Device} for minor classes. 1499fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main */ 1509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static class Major { 151005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly private static final int BITMASK = 0x1F00; 1529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int MISC = 0x0000; 1549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int COMPUTER = 0x0100; 1559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int PHONE = 0x0200; 1569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int NETWORKING = 0x0300; 1579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int AUDIO_VIDEO = 0x0400; 1589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int PERIPHERAL = 0x0500; 1599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int IMAGING = 0x0600; 1609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int WEARABLE = 0x0700; 1619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int TOY = 0x0800; 1629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int HEALTH = 0x0900; 1639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int UNCATEGORIZED = 0x1F00; 1649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 1659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project // Devices in the COMPUTER major class 1679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int COMPUTER_UNCATEGORIZED = 0x0100; 1689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int COMPUTER_DESKTOP = 0x0104; 1699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int COMPUTER_SERVER = 0x0108; 1709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int COMPUTER_LAPTOP = 0x010C; 1719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int COMPUTER_HANDHELD_PC_PDA = 0x0110; 1729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int COMPUTER_PALM_SIZE_PC_PDA = 0x0114; 1739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int COMPUTER_WEARABLE = 0x0118; 1749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project // Devices in the PHONE major class 1769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int PHONE_UNCATEGORIZED = 0x0200; 1779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int PHONE_CELLULAR = 0x0204; 1789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int PHONE_CORDLESS = 0x0208; 1799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int PHONE_SMART = 0x020C; 1809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int PHONE_MODEM_OR_GATEWAY = 0x0210; 1819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int PHONE_ISDN = 0x0214; 1829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project // Minor classes for the AUDIO_VIDEO major class 1849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int AUDIO_VIDEO_UNCATEGORIZED = 0x0400; 1859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int AUDIO_VIDEO_WEARABLE_HEADSET = 0x0404; 1869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int AUDIO_VIDEO_HANDSFREE = 0x0408; 1879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project //public static final int AUDIO_VIDEO_RESERVED = 0x040C; 1889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int AUDIO_VIDEO_MICROPHONE = 0x0410; 1899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int AUDIO_VIDEO_LOUDSPEAKER = 0x0414; 1909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int AUDIO_VIDEO_HEADPHONES = 0x0418; 1919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int AUDIO_VIDEO_PORTABLE_AUDIO = 0x041C; 1929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int AUDIO_VIDEO_CAR_AUDIO = 0x0420; 1939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int AUDIO_VIDEO_SET_TOP_BOX = 0x0424; 1949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int AUDIO_VIDEO_HIFI_AUDIO = 0x0428; 1959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int AUDIO_VIDEO_VCR = 0x042C; 1969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int AUDIO_VIDEO_VIDEO_CAMERA = 0x0430; 1979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int AUDIO_VIDEO_CAMCORDER = 0x0434; 1989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int AUDIO_VIDEO_VIDEO_MONITOR = 0x0438; 1999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER = 0x043C; 2009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int AUDIO_VIDEO_VIDEO_CONFERENCING = 0x0440; 2019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project //public static final int AUDIO_VIDEO_RESERVED = 0x0444; 2029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int AUDIO_VIDEO_VIDEO_GAMING_TOY = 0x0448; 2039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 2049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project // Devices in the WEARABLE major class 2059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int WEARABLE_UNCATEGORIZED = 0x0700; 2069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int WEARABLE_WRIST_WATCH = 0x0704; 2079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int WEARABLE_PAGER = 0x0708; 2089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int WEARABLE_JACKET = 0x070C; 2099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int WEARABLE_HELMET = 0x0710; 2109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int WEARABLE_GLASSES = 0x0714; 2119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 2129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project // Devices in the TOY major class 2139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int TOY_UNCATEGORIZED = 0x0800; 2149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int TOY_ROBOT = 0x0804; 2159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int TOY_VEHICLE = 0x0808; 2169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int TOY_DOLL_ACTION_FIGURE = 0x080C; 2179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int TOY_CONTROLLER = 0x0810; 2189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int TOY_GAME = 0x0814; 2199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 2209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project // Devices in the HEALTH major class 2219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int HEALTH_UNCATEGORIZED = 0x0900; 2229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int HEALTH_BLOOD_PRESSURE = 0x0904; 2239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int HEALTH_THERMOMETER = 0x0908; 2249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int HEALTH_WEIGHING = 0x090C; 2259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int HEALTH_GLUCOSE = 0x0910; 2269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int HEALTH_PULSE_OXIMETER = 0x0914; 2279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int HEALTH_PULSE_RATE = 0x0918; 2289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int HEALTH_DATA_DISPLAY = 0x091C; 229c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh 230c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh // Devices in PERIPHERAL major class 231c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 232c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 233c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 234c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh public static final int PERIPHERAL_NON_KEYBOARD_NON_POINTING = 0x0500; 235c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 236c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 237c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 238c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh public static final int PERIPHERAL_KEYBOARD = 0x0540; 239c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 240c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 241c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 242c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh public static final int PERIPHERAL_POINTING = 0x0580; 243c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh /** 244c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh * @hide 245c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh */ 246c88b0c62c52ab76f1277f3c999d795d8ba527028Jaikumar Ganesh public static final int PERIPHERAL_KEYBOARD_POINTING = 0x05C0; 247005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly } 2489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 249005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 2509fab0aef19a4633d2e4670564e5d7ae9e52fe11fScott Main * Return the major device class component of this {@link BluetoothClass}. 251005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Values returned from this function can be compared with the 252005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * public constants in {@link BluetoothClass.Device.Major} to determine 253005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * which major class is encoded in this Bluetooth class. 254005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * 255005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * @return major device class component 256005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 257005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public int getMajorDeviceClass() { 258005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly return (mClass & Device.Major.BITMASK); 259005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly } 260005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 261005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** 262005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * Return the (major and minor) device class component of this 263005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * {@link BluetoothClass}. 264005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * <p>Values returned from this function can be compared with the 265005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * public constants in {@link BluetoothClass.Device} to determine which 266005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * device class is encoded in this Bluetooth class. 267005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * 268005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * @return device class component 269005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly */ 270005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public int getDeviceClass() { 271005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly return (mClass & Device.BITMASK); 2729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 273a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin 274005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** @hide */ 275005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final int PROFILE_HEADSET = 0; 276005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** @hide */ 277005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final int PROFILE_A2DP = 1; 278005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly /** @hide */ 279005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public static final int PROFILE_OPP = 2; 280df7627db715a7a2e7f646f02a07caf2347bb90b8Adam Powell /** @hide */ 281df7627db715a7a2e7f646f02a07caf2347bb90b8Adam Powell public static final int PROFILE_HID = 3; 282332058050a42e0f8b8735caa5693aa59d520f220Jaikumar Ganesh /** @hide */ 283332058050a42e0f8b8735caa5693aa59d520f220Jaikumar Ganesh public static final int PROFILE_PANU = 4; 284332058050a42e0f8b8735caa5693aa59d520f220Jaikumar Ganesh /** @hide */ 285332058050a42e0f8b8735caa5693aa59d520f220Jaikumar Ganesh public static final int PROFILE_NAP = 5; 286005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly 287a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin /** 288a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin * Check class bits for possible bluetooth profile support. 289a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin * This is a simple heuristic that tries to guess if a device with the 290a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin * given class bits might support specified profile. It is not accurate for all 291a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin * devices. It tries to err on the side of false positives. 292a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin * @param profile The profile to be checked 293a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin * @return True if this device might support specified profile. 294005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly * @hide 295a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin */ 296005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly public boolean doesClassMatch(int profile) { 297a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin if (profile == PROFILE_A2DP) { 298005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly if (hasService(Service.RENDER)) { 299a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin return true; 300a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin } 301a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin // By the A2DP spec, sinks must indicate the RENDER service. 302a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin // However we found some that do not (Chordette). So lets also 303a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin // match on some other class bits. 304005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly switch (getDeviceClass()) { 305005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly case Device.AUDIO_VIDEO_HIFI_AUDIO: 306005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly case Device.AUDIO_VIDEO_HEADPHONES: 307005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly case Device.AUDIO_VIDEO_LOUDSPEAKER: 308005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly case Device.AUDIO_VIDEO_CAR_AUDIO: 309a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin return true; 310a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin default: 311a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin return false; 312a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin } 313a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin } else if (profile == PROFILE_HEADSET) { 314a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin // The render service class is required by the spec for HFP, so is a 315a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin // pretty good signal 316005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly if (hasService(Service.RENDER)) { 317a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin return true; 318a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin } 319a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin // Just in case they forgot the render service class 320005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly switch (getDeviceClass()) { 321005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly case Device.AUDIO_VIDEO_HANDSFREE: 322005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly case Device.AUDIO_VIDEO_WEARABLE_HEADSET: 323005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly case Device.AUDIO_VIDEO_CAR_AUDIO: 324a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin return true; 325a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin default: 326a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin return false; 327a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin } 328a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin } else if (profile == PROFILE_OPP) { 329005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly if (hasService(Service.OBJECT_TRANSFER)) { 330a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin return true; 331a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin } 332a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin 333005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly switch (getDeviceClass()) { 334005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly case Device.COMPUTER_UNCATEGORIZED: 335005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly case Device.COMPUTER_DESKTOP: 336005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly case Device.COMPUTER_SERVER: 337005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly case Device.COMPUTER_LAPTOP: 338005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly case Device.COMPUTER_HANDHELD_PC_PDA: 339005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly case Device.COMPUTER_PALM_SIZE_PC_PDA: 340005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly case Device.COMPUTER_WEARABLE: 341005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly case Device.PHONE_UNCATEGORIZED: 342005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly case Device.PHONE_CELLULAR: 343005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly case Device.PHONE_CORDLESS: 344005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly case Device.PHONE_SMART: 345005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly case Device.PHONE_MODEM_OR_GATEWAY: 346005b228cdfb369d9b3b325884c0337ba5968bf8cNick Pelly case Device.PHONE_ISDN: 347a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin return true; 348a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin default: 349a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin return false; 350a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin } 351df7627db715a7a2e7f646f02a07caf2347bb90b8Adam Powell } else if (profile == PROFILE_HID) { 352df7627db715a7a2e7f646f02a07caf2347bb90b8Adam Powell return (getDeviceClass() & Device.Major.PERIPHERAL) == Device.Major.PERIPHERAL; 353332058050a42e0f8b8735caa5693aa59d520f220Jaikumar Ganesh } else if (profile == PROFILE_PANU || profile == PROFILE_NAP){ 354332058050a42e0f8b8735caa5693aa59d520f220Jaikumar Ganesh // No good way to distinguish between the two, based on class bits. 355332058050a42e0f8b8735caa5693aa59d520f220Jaikumar Ganesh if (hasService(Service.NETWORKING)) { 356332058050a42e0f8b8735caa5693aa59d520f220Jaikumar Ganesh return true; 357332058050a42e0f8b8735caa5693aa59d520f220Jaikumar Ganesh } 358332058050a42e0f8b8735caa5693aa59d520f220Jaikumar Ganesh return (getDeviceClass() & Device.Major.NETWORKING) == Device.Major.NETWORKING; 359a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin } else { 360a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin return false; 361a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin } 362a4433af5ac677be7c1f63447c0cd78829bdee159Yue Lixin } 3639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project} 364