use of android.os.ParcelUuid in project android_frameworks_base by crdroidandroid.
the class BluetoothUuid method parseUuidFrom.
/**
* 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.
*/
public static ParcelUuid parseUuidFrom(byte[] uuidBytes) {
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));
}
use of android.os.ParcelUuid in project android_frameworks_base by crdroidandroid.
the class AdvertiseData method writeToParcel.
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeList(mServiceUuids);
// mManufacturerSpecificData could not be null.
dest.writeInt(mManufacturerSpecificData.size());
for (int i = 0; i < mManufacturerSpecificData.size(); ++i) {
dest.writeInt(mManufacturerSpecificData.keyAt(i));
byte[] data = mManufacturerSpecificData.valueAt(i);
if (data == null) {
dest.writeInt(0);
} else {
dest.writeInt(1);
dest.writeInt(data.length);
dest.writeByteArray(data);
}
}
dest.writeInt(mServiceData.size());
for (ParcelUuid uuid : mServiceData.keySet()) {
dest.writeParcelable(uuid, flags);
byte[] data = mServiceData.get(uuid);
if (data == null) {
dest.writeInt(0);
} else {
dest.writeInt(1);
dest.writeInt(data.length);
dest.writeByteArray(data);
}
}
dest.writeByte((byte) (getIncludeTxPowerLevel() ? 1 : 0));
dest.writeByte((byte) (getIncludeDeviceName() ? 1 : 0));
}
use of android.os.ParcelUuid in project android_frameworks_base by crdroidandroid.
the class BluetoothGattIncludedService method writeToParcel.
public void writeToParcel(Parcel out, int flags) {
out.writeParcelable(new ParcelUuid(mUuid), 0);
out.writeInt(mInstanceId);
out.writeInt(mServiceType);
}
use of android.os.ParcelUuid in project android_frameworks_base by crdroidandroid.
the class BluetoothGattServer method removeService.
/**
* Removes a service from the list of services to be provided.
*
* <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
*
* @param service Service to be removed.
* @return true, if the service has been removed
*/
public boolean removeService(BluetoothGattService service) {
if (DBG)
Log.d(TAG, "removeService() - service: " + service.getUuid());
if (mService == null || mServerIf == 0)
return false;
BluetoothGattService intService = getService(service.getUuid(), service.getInstanceId(), service.getType());
if (intService == null)
return false;
try {
mService.removeService(mServerIf, service.getType(), service.getInstanceId(), new ParcelUuid(service.getUuid()));
mServices.remove(intService);
} catch (RemoteException e) {
Log.e(TAG, "", e);
return false;
}
return true;
}
use of android.os.ParcelUuid in project android_frameworks_base by crdroidandroid.
the class BluetoothGattService method writeToParcel.
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeParcelable(new ParcelUuid(mUuid), 0);
out.writeInt(mInstanceId);
out.writeInt(mServiceType);
out.writeTypedList(mCharacteristics);
ArrayList<BluetoothGattIncludedService> includedServices = new ArrayList<BluetoothGattIncludedService>(mIncludedServices.size());
for (BluetoothGattService s : mIncludedServices) {
includedServices.add(new BluetoothGattIncludedService(s.getUuid(), s.getInstanceId(), s.getType()));
}
out.writeTypedList(includedServices);
}
Aggregations