Search in sources :

Example 51 with ParcelUuid

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));
}
Also used : ParcelUuid(android.os.ParcelUuid) UUID(java.util.UUID) ByteBuffer(java.nio.ByteBuffer)

Example 52 with ParcelUuid

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));
}
Also used : ParcelUuid(android.os.ParcelUuid)

Example 53 with ParcelUuid

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);
}
Also used : ParcelUuid(android.os.ParcelUuid)

Example 54 with ParcelUuid

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;
}
Also used : ParcelUuid(android.os.ParcelUuid) RemoteException(android.os.RemoteException)

Example 55 with ParcelUuid

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);
}
Also used : ParcelUuid(android.os.ParcelUuid) ArrayList(java.util.ArrayList)

Aggregations

ParcelUuid (android.os.ParcelUuid)147 SmallTest (android.test.suitebuilder.annotation.SmallTest)43 RemoteException (android.os.RemoteException)29 UUID (java.util.UUID)24 ArrayList (java.util.ArrayList)23 GenericSoundModel (android.hardware.soundtrigger.SoundTrigger.GenericSoundModel)20 Parcel (android.os.Parcel)20 ScanFilter (android.bluetooth.le.ScanFilter)19 RecognitionConfig (android.hardware.soundtrigger.SoundTrigger.RecognitionConfig)12 LargeTest (android.test.suitebuilder.annotation.LargeTest)12 ScanRecord (android.bluetooth.le.ScanRecord)10 BluetoothDevice (android.bluetooth.BluetoothDevice)9 Socket (java.net.Socket)9 DataOutputStream (java.io.DataOutputStream)8 ByteBuffer (java.nio.ByteBuffer)8 SparseArray (android.util.SparseArray)6 RequiresPermission (android.annotation.RequiresPermission)5 BluetoothClass (android.bluetooth.BluetoothClass)5 BluetoothLeScanner (android.bluetooth.le.BluetoothLeScanner)5 ScanCallback (android.bluetooth.le.ScanCallback)5