use of android.os.ParcelUuid in project platform_frameworks_base by android.
the class GenericSoundModelTest method testUpdateGenericSoundModel.
@SmallTest
public void testUpdateGenericSoundModel() throws Exception {
GenericSoundModel model = new_sound_model();
// Update sound model
soundTriggerService.updateSoundModel(model);
loadedModelUuids.add(model.uuid);
// Confirm it was updated
GenericSoundModel returnedModel = soundTriggerService.getSoundModel(new ParcelUuid(model.uuid));
assertEquals(model, returnedModel);
}
use of android.os.ParcelUuid in project physical-web by google.
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 XobotOS by xamarin.
the class BluetoothService method sendUuidIntent.
/* Broadcast the Uuid intent */
/*package*/
synchronized void sendUuidIntent(String address) {
ParcelUuid[] uuid = getUuidFromCache(address);
Intent intent = new Intent(BluetoothDevice.ACTION_UUID);
intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mAdapter.getRemoteDevice(address));
intent.putExtra(BluetoothDevice.EXTRA_UUID, uuid);
mContext.sendBroadcast(intent, BLUETOOTH_ADMIN_PERM);
mUuidIntentTracker.remove(address);
}
use of android.os.ParcelUuid in project XobotOS by xamarin.
the class BluetoothService method updateDeviceServiceChannelCache.
/*package*/
void updateDeviceServiceChannelCache(String address) {
if (DBG)
Log.d(TAG, "updateDeviceServiceChannelCache(" + address + ")");
// We are storing the rfcomm channel numbers only for the uuids
// we are interested in.
ParcelUuid[] deviceUuids = getRemoteUuids(address);
ArrayList<ParcelUuid> applicationUuids = new ArrayList<ParcelUuid>();
synchronized (this) {
for (RemoteService service : mUuidCallbackTracker.keySet()) {
if (service.address.equals(address)) {
applicationUuids.add(service.uuid);
}
}
}
Map<ParcelUuid, Integer> uuidToChannelMap = new HashMap<ParcelUuid, Integer>();
// Retrieve RFCOMM channel for default uuids
for (ParcelUuid uuid : RFCOMM_UUIDS) {
if (BluetoothUuid.isUuidPresent(deviceUuids, uuid)) {
int channel = getDeviceServiceChannelForUuid(address, uuid);
uuidToChannelMap.put(uuid, channel);
if (DBG)
Log.d(TAG, "\tuuid(system): " + uuid + " " + channel);
}
}
// Retrieve RFCOMM channel for application requested uuids
for (ParcelUuid uuid : applicationUuids) {
if (BluetoothUuid.isUuidPresent(deviceUuids, uuid)) {
int channel = getDeviceServiceChannelForUuid(address, uuid);
uuidToChannelMap.put(uuid, channel);
if (DBG)
Log.d(TAG, "\tuuid(application): " + uuid + " " + channel);
}
}
synchronized (this) {
// Make application callbacks
for (Iterator<RemoteService> iter = mUuidCallbackTracker.keySet().iterator(); iter.hasNext(); ) {
RemoteService service = iter.next();
if (service.address.equals(address)) {
if (uuidToChannelMap.containsKey(service.uuid)) {
int channel = uuidToChannelMap.get(service.uuid);
if (DBG)
Log.d(TAG, "Making callback for " + service.uuid + " with result " + channel);
IBluetoothCallback callback = mUuidCallbackTracker.get(service);
if (callback != null) {
try {
callback.onRfcommChannelFound(channel);
} catch (RemoteException e) {
Log.e(TAG, "", e);
}
}
iter.remove();
}
}
}
// Update cache
mDeviceServiceChannelCache.put(address, uuidToChannelMap);
}
}
use of android.os.ParcelUuid in project XobotOS by xamarin.
the class BluetoothA2dpService method onBluetoothEnable.
private synchronized void onBluetoothEnable() {
String devices = mBluetoothService.getProperty("Devices", true);
if (devices != null) {
String[] paths = devices.split(",");
for (String path : paths) {
String address = mBluetoothService.getAddressFromObjectPath(path);
BluetoothDevice device = mAdapter.getRemoteDevice(address);
ParcelUuid[] remoteUuids = mBluetoothService.getRemoteUuids(address);
if (remoteUuids != null)
if (BluetoothUuid.containsAnyUuid(remoteUuids, new ParcelUuid[] { BluetoothUuid.AudioSink, BluetoothUuid.AdvAudioDist })) {
addAudioSink(device);
}
}
}
mAudioManager.setParameters(BLUETOOTH_ENABLED + "=true");
mAudioManager.setParameters("A2dpSuspended=false");
}
Aggregations