summaryrefslogtreecommitdiff
path: root/core/java/android/bluetooth/BluetoothClass.java
diff options
context:
space:
mode:
authorPulkit Bhuwalka <pulkitb@google.com>2017-08-16 21:52:04 -0700
committerPulkit Bhuwalka <pulkitb@google.com>2017-09-20 15:51:49 -0700
commit66d61238802704659f170697ecfaacb116870950 (patch)
treed2a2c65b03164d6c549785cfbfb73315474189d9 /core/java/android/bluetooth/BluetoothClass.java
parentd763e341b5cbe7449e7acba7179715e817b48c03 (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 'core/java/android/bluetooth/BluetoothClass.java')
-rwxr-xr-xcore/java/android/bluetooth/BluetoothClass.java46
1 files changed, 46 insertions, 0 deletions
diff --git a/core/java/android/bluetooth/BluetoothClass.java b/core/java/android/bluetooth/BluetoothClass.java
index 57e4abb12987..f22ea6e88e04 100755
--- a/core/java/android/bluetooth/BluetoothClass.java
+++ b/core/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 */