Add a method to check whether a UUID is 32bit.
Change-Id: I92e8bab560b2083e9f4855d28b3f54f2120ef628
This commit is contained in:
@@ -273,11 +273,29 @@ public final class BluetoothUuid {
|
||||
* @param parcelUuid
|
||||
* @return true if the parcelUuid can be converted to 16 bit uuid, false otherwise.
|
||||
*/
|
||||
public static boolean isShortUuid(ParcelUuid parcelUuid) {
|
||||
public static boolean is16BitUuid(ParcelUuid parcelUuid) {
|
||||
UUID uuid = parcelUuid.getUuid();
|
||||
if (uuid.getLeastSignificantBits() != BASE_UUID.getUuid().getLeastSignificantBits()) {
|
||||
return false;
|
||||
}
|
||||
return ((uuid.getMostSignificantBits() & 0xFFFF0000FFFFFFFFL) == 0x1000L);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check whether the given parcelUuid can be converted to 32 bit bluetooth uuid.
|
||||
*
|
||||
* @param parcelUuid
|
||||
* @return true if the parcelUuid can be converted to 32 bit uuid, false otherwise.
|
||||
*/
|
||||
public static boolean is32BitUuid(ParcelUuid parcelUuid) {
|
||||
UUID uuid = parcelUuid.getUuid();
|
||||
if (uuid.getLeastSignificantBits() != BASE_UUID.getUuid().getLeastSignificantBits()) {
|
||||
return false;
|
||||
}
|
||||
if (is16BitUuid(parcelUuid)) {
|
||||
return false;
|
||||
}
|
||||
return ((uuid.getMostSignificantBits() & 0xFFFFFFFFL) == 0x1000L);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,4 +47,20 @@ public class BluetoothUuidTest extends TestCase {
|
||||
assertEquals(ParcelUuid.fromString("FF0F0E0D-0C0B-0A09-0807-0060504030201"),
|
||||
BluetoothUuid.parseUuidFrom(uuid128));
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testUuidType() {
|
||||
assertTrue(BluetoothUuid.is16BitUuid(
|
||||
ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB")));
|
||||
assertFalse(BluetoothUuid.is32BitUuid(
|
||||
ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB")));
|
||||
|
||||
assertFalse(BluetoothUuid.is16BitUuid(
|
||||
ParcelUuid.fromString("FE33110B-0000-1000-8000-00805F9B34FB")));
|
||||
assertTrue(BluetoothUuid.is32BitUuid(
|
||||
ParcelUuid.fromString("FE33110B-0000-1000-8000-00805F9B34FB")));
|
||||
assertFalse(BluetoothUuid.is32BitUuid(
|
||||
ParcelUuid.fromString("FE33110B-1000-1000-8000-00805F9B34FB")));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user