diff options
author | Pulkit Bhuwalka <pulkitb@google.com> | 2017-08-16 21:52:04 -0700 |
---|---|---|
committer | Pulkit Bhuwalka <pulkitb@google.com> | 2017-09-20 15:51:49 -0700 |
commit | 4729ea80cf268eb82091fe8f6c4a2071ca33606e (patch) | |
tree | 2e9967f969bcf8eab831171be6346d56fca32241 /framework/java/android/bluetooth/BluetoothClass.java | |
parent | 393c3cf68dd2da51f7c95bbf9991df77a6bc7a5c (diff) |
Modify Bluetooth Class of Device from Android stack
Bug: 36015415
Test: Modified Class of Device using sample app and verified device icon
change when discovering from a remote device.
Change-Id: Ie25f10be5560f9c090ebe489d5f3bb00cbca81ef
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothClass.java')
-rwxr-xr-x | framework/java/android/bluetooth/BluetoothClass.java | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/framework/java/android/bluetooth/BluetoothClass.java b/framework/java/android/bluetooth/BluetoothClass.java index 57e4abb129..f22ea6e88e 100755 --- a/framework/java/android/bluetooth/BluetoothClass.java +++ b/framework/java/android/bluetooth/BluetoothClass.java @@ -19,6 +19,10 @@ package android.bluetooth; import android.os.Parcel; import android.os.Parcelable; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.Arrays; + /** * Represents a Bluetooth class, which describes general characteristics * and capabilities of a device. For example, a Bluetooth class will @@ -275,6 +279,48 @@ public final class BluetoothClass implements Parcelable { return (mClass & Device.BITMASK); } + /** + * Return the Bluetooth Class of Device (CoD) value including the + * {@link BluetoothClass.Service}, {@link BluetoothClass.Device.Major} and + * minor device fields. + * + * <p>This value is an integer representation of Bluetooth CoD as in + * Bluetooth specification. + * + * @see <a href="Bluetooth CoD">https://www.bluetooth.com/specifications/assigned-numbers/baseband</a> + * + * @hide + */ + public int getClassOfDevice() { + return mClass; + } + + /** + * Return the Bluetooth Class of Device (CoD) value including the + * {@link BluetoothClass.Service}, {@link BluetoothClass.Device.Major} and + * minor device fields. + * + * <p>This value is a byte array representation of Bluetooth CoD as in + * Bluetooth specification. + * + * <p>Bluetooth COD information is 3 bytes, but stored as an int. Hence the + * MSB is useless and needs to be thrown away. The lower 3 bytes are + * converted into a byte array MSB to LSB. Hence, using BIG_ENDIAN. + * + * @see <a href="Bluetooth CoD">https://www.bluetooth.com/specifications/assigned-numbers/baseband</a> + * + * @hide + */ + public byte[] getClassOfDeviceBytes() { + byte[] bytes = ByteBuffer.allocate(4) + .order(ByteOrder.BIG_ENDIAN) + .putInt(mClass) + .array(); + + // Discard the top byte + return Arrays.copyOfRange(bytes, 1, bytes.length); + } + /** @hide */ public static final int PROFILE_HEADSET = 0; /** @hide */ |