FileDocCategorySizeDatePackage
BluetoothUuid.javaAPI DocAndroid 5.1 API11121Thu Mar 12 22:22:10 GMT 2015android.bluetooth

BluetoothUuid

public final class BluetoothUuid extends Object
Static helper methods and constants to decode the ParcelUuid of remote devices.
hide

Fields Summary
public static final android.os.ParcelUuid
AudioSink
public static final android.os.ParcelUuid
AudioSource
public static final android.os.ParcelUuid
AdvAudioDist
public static final android.os.ParcelUuid
HSP
public static final android.os.ParcelUuid
HSP_AG
public static final android.os.ParcelUuid
Handsfree
public static final android.os.ParcelUuid
Handsfree_AG
public static final android.os.ParcelUuid
AvrcpController
public static final android.os.ParcelUuid
AvrcpTarget
public static final android.os.ParcelUuid
ObexObjectPush
public static final android.os.ParcelUuid
Hid
public static final android.os.ParcelUuid
Hogp
public static final android.os.ParcelUuid
PANU
public static final android.os.ParcelUuid
NAP
public static final android.os.ParcelUuid
BNEP
public static final android.os.ParcelUuid
PBAP_PCE
public static final android.os.ParcelUuid
PBAP_PSE
public static final android.os.ParcelUuid
MAP
public static final android.os.ParcelUuid
MNS
public static final android.os.ParcelUuid
MAS
public static final android.os.ParcelUuid
BASE_UUID
public static final int
UUID_BYTES_16_BIT
Length of bytes for 16 bit UUID
public static final int
UUID_BYTES_32_BIT
Length of bytes for 32 bit UUID
public static final int
UUID_BYTES_128_BIT
Length of bytes for 128 bit UUID
public static final android.os.ParcelUuid[]
RESERVED_UUIDS
Constructors Summary
Methods Summary
public static booleancontainsAllUuids(android.os.ParcelUuid[] uuidA, android.os.ParcelUuid[] uuidB)
Returns true if all the ParcelUuids in ParcelUuidB are present in ParcelUuidA

param
uuidA - Array of ParcelUuidsA
param
uuidB - Array of ParcelUuidsB

        if (uuidA == null && uuidB == null) return true;

        if (uuidA == null) {
            return uuidB.length == 0 ? true : false;
        }

        if (uuidB == null) return true;

        HashSet<ParcelUuid> uuidSet = new HashSet<ParcelUuid> (Arrays.asList(uuidA));
        for (ParcelUuid uuid: uuidB) {
            if (!uuidSet.contains(uuid)) return false;
        }
        return true;
    
public static booleancontainsAnyUuid(android.os.ParcelUuid[] uuidA, android.os.ParcelUuid[] uuidB)
Returns true if there any common ParcelUuids in uuidA and uuidB.

param
uuidA - List of ParcelUuids
param
uuidB - List of ParcelUuids

        if (uuidA == null && uuidB == null) return true;

        if (uuidA == null) {
            return uuidB.length == 0 ? true : false;
        }

        if (uuidB == null) {
            return uuidA.length == 0 ? true : false;
        }

        HashSet<ParcelUuid> uuidSet = new HashSet<ParcelUuid> (Arrays.asList(uuidA));
        for (ParcelUuid uuid: uuidB) {
            if (uuidSet.contains(uuid)) return true;
        }
        return false;
    
public static intgetServiceIdentifierFromParcelUuid(android.os.ParcelUuid parcelUuid)
Extract the Service Identifier or the actual uuid from the Parcel Uuid. For example, if 0000110B-0000-1000-8000-00805F9B34FB is the parcel Uuid, this function will return 110B

param
parcelUuid
return
the service identifier.

        UUID uuid = parcelUuid.getUuid();
        long value = (uuid.getMostSignificantBits() & 0x0000FFFF00000000L) >>> 32;
        return (int)value;
    
public static booleanis16BitUuid(android.os.ParcelUuid parcelUuid)
Check whether the given parcelUuid can be converted to 16 bit bluetooth uuid.

param
parcelUuid
return
true if the parcelUuid can be converted to 16 bit uuid, false otherwise.

        UUID uuid = parcelUuid.getUuid();
        if (uuid.getLeastSignificantBits() != BASE_UUID.getUuid().getLeastSignificantBits()) {
            return false;
        }
        return ((uuid.getMostSignificantBits() & 0xFFFF0000FFFFFFFFL) == 0x1000L);
    
public static booleanis32BitUuid(android.os.ParcelUuid parcelUuid)
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.

        UUID uuid = parcelUuid.getUuid();
        if (uuid.getLeastSignificantBits() != BASE_UUID.getUuid().getLeastSignificantBits()) {
            return false;
        }
        if (is16BitUuid(parcelUuid)) {
            return false;
        }
        return ((uuid.getMostSignificantBits() & 0xFFFFFFFFL) == 0x1000L);
    
public static booleanisAdvAudioDist(android.os.ParcelUuid uuid)

        return uuid.equals(AdvAudioDist);
    
public static booleanisAudioSink(android.os.ParcelUuid uuid)

        return uuid.equals(AudioSink);
    
public static booleanisAudioSource(android.os.ParcelUuid uuid)


         
        return uuid.equals(AudioSource);
    
public static booleanisAvrcpController(android.os.ParcelUuid uuid)

        return uuid.equals(AvrcpController);
    
public static booleanisAvrcpTarget(android.os.ParcelUuid uuid)

        return uuid.equals(AvrcpTarget);
    
public static booleanisBnep(android.os.ParcelUuid uuid)

        return uuid.equals(BNEP);
    
public static booleanisHandsfree(android.os.ParcelUuid uuid)

        return uuid.equals(Handsfree);
    
public static booleanisHeadset(android.os.ParcelUuid uuid)

        return uuid.equals(HSP);
    
public static booleanisInputDevice(android.os.ParcelUuid uuid)

        return uuid.equals(Hid);
    
public static booleanisMap(android.os.ParcelUuid uuid)

        return uuid.equals(MAP);
    
public static booleanisMas(android.os.ParcelUuid uuid)

        return uuid.equals(MAS);
    
public static booleanisMns(android.os.ParcelUuid uuid)

        return uuid.equals(MNS);
    
public static booleanisNap(android.os.ParcelUuid uuid)

        return uuid.equals(NAP);
    
public static booleanisPanu(android.os.ParcelUuid uuid)

        return uuid.equals(PANU);
    
public static booleanisUuidPresent(android.os.ParcelUuid[] uuidArray, android.os.ParcelUuid uuid)
Returns true if ParcelUuid is present in uuidArray

param
uuidArray - Array of ParcelUuids
param
uuid

        if ((uuidArray == null || uuidArray.length == 0) && uuid == null)
            return true;

        if (uuidArray == null)
            return false;

        for (ParcelUuid element: uuidArray) {
            if (element.equals(uuid)) return true;
        }
        return false;
    
public static android.os.ParcelUuidparseUuidFrom(byte[] uuidBytes)
Parse UUID from bytes. The {@code uuidBytes} can represent a 16-bit, 32-bit or 128-bit UUID, but the returned UUID is always in 128-bit format. Note UUID is little endian in Bluetooth.

param
uuidBytes Byte representation of uuid.
return
{@link ParcelUuid} parsed from bytes.
throws
IllegalArgumentException If the {@code uuidBytes} cannot be parsed.

        if (uuidBytes == null) {
            throw new IllegalArgumentException("uuidBytes cannot be null");
        }
        int length = uuidBytes.length;
        if (length != UUID_BYTES_16_BIT && length != UUID_BYTES_32_BIT &&
                length != UUID_BYTES_128_BIT) {
            throw new IllegalArgumentException("uuidBytes length invalid - " + length);
        }

        // Construct a 128 bit UUID.
        if (length == UUID_BYTES_128_BIT) {
            ByteBuffer buf = ByteBuffer.wrap(uuidBytes).order(ByteOrder.LITTLE_ENDIAN);
            long msb = buf.getLong(8);
            long lsb = buf.getLong(0);
            return new ParcelUuid(new UUID(msb, lsb));
        }

        // For 16 bit and 32 bit UUID we need to convert them to 128 bit value.
        // 128_bit_value = uuid * 2^96 + BASE_UUID
        long shortUuid;
        if (length == UUID_BYTES_16_BIT) {
            shortUuid = uuidBytes[0] & 0xFF;
            shortUuid += (uuidBytes[1] & 0xFF) << 8;
        } else {
            shortUuid = uuidBytes[0] & 0xFF ;
            shortUuid += (uuidBytes[1] & 0xFF) << 8;
            shortUuid += (uuidBytes[2] & 0xFF) << 16;
            shortUuid += (uuidBytes[3] & 0xFF) << 24;
        }
        long msb = BASE_UUID.getUuid().getMostSignificantBits() + (shortUuid << 32);
        long lsb = BASE_UUID.getUuid().getLeastSignificantBits();
        return new ParcelUuid(new UUID(msb, lsb));