Search in sources :

Example 1 with ParcelUuid

use of android.os.ParcelUuid in project android_frameworks_base by ParanoidAndroid.

the class BluetoothGatt method writeDescriptor.

/**
     * Write the value of a given descriptor to the associated remote device.
     *
     * <p>A {@link BluetoothGattCallback#onDescriptorWrite} callback is
     * triggered to report the result of the write operation.
     *
     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
     *
     * @param descriptor Descriptor to write to the associated remote device
     * @return true, if the write operation was initiated successfully
     */
public boolean writeDescriptor(BluetoothGattDescriptor descriptor) {
    if (DBG)
        Log.d(TAG, "writeDescriptor() - uuid: " + descriptor.getUuid());
    if (mService == null || mClientIf == 0)
        return false;
    BluetoothGattCharacteristic characteristic = descriptor.getCharacteristic();
    if (characteristic == null)
        return false;
    BluetoothGattService service = characteristic.getService();
    if (service == null)
        return false;
    BluetoothDevice device = service.getDevice();
    if (device == null)
        return false;
    try {
        mService.writeDescriptor(mClientIf, device.getAddress(), service.getType(), service.getInstanceId(), new ParcelUuid(service.getUuid()), characteristic.getInstanceId(), new ParcelUuid(characteristic.getUuid()), new ParcelUuid(descriptor.getUuid()), characteristic.getWriteType(), AUTHENTICATION_NONE, descriptor.getValue());
    } catch (RemoteException e) {
        Log.e(TAG, "", e);
        return false;
    }
    return true;
}
Also used : ParcelUuid(android.os.ParcelUuid) BluetoothDevice(android.bluetooth.BluetoothDevice) RemoteException(android.os.RemoteException)

Example 2 with ParcelUuid

use of android.os.ParcelUuid in project android_frameworks_base by ParanoidAndroid.

the class BluetoothGatt method readCharacteristic.

/**
     * Reads the requested characteristic from the associated remote device.
     *
     * <p>This is an asynchronous operation. The result of the read operation
     * is reported by the {@link BluetoothGattCallback#onCharacteristicRead}
     * callback.
     *
     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
     *
     * @param characteristic Characteristic to read from the remote device
     * @return true, if the read operation was initiated successfully
     */
public boolean readCharacteristic(BluetoothGattCharacteristic characteristic) {
    if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_READ) == 0)
        return false;
    if (DBG)
        Log.d(TAG, "readCharacteristic() - uuid: " + characteristic.getUuid());
    if (mService == null || mClientIf == 0)
        return false;
    BluetoothGattService service = characteristic.getService();
    if (service == null)
        return false;
    BluetoothDevice device = service.getDevice();
    if (device == null)
        return false;
    try {
        mService.readCharacteristic(mClientIf, device.getAddress(), service.getType(), service.getInstanceId(), new ParcelUuid(service.getUuid()), characteristic.getInstanceId(), new ParcelUuid(characteristic.getUuid()), AUTHENTICATION_NONE);
    } catch (RemoteException e) {
        Log.e(TAG, "", e);
        return false;
    }
    return true;
}
Also used : ParcelUuid(android.os.ParcelUuid) BluetoothDevice(android.bluetooth.BluetoothDevice) RemoteException(android.os.RemoteException)

Example 3 with ParcelUuid

use of android.os.ParcelUuid in project android_frameworks_base by ParanoidAndroid.

the class BluetoothGattServer method addService.

/**
     * Add a service to the list of services to be hosted.
     *
     * <p>Once a service has been addded to the the list, the service and it's
     * included characteristics will be provided by the local device.
     *
     * <p>If the local device has already exposed services when this function
     * is called, a service update notification will be sent to all clients.
     *
     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
     *
     * @param service Service to be added to the list of services provided
     *                by this device.
     * @return true, if the service has been added successfully
     */
public boolean addService(BluetoothGattService service) {
    if (DBG)
        Log.d(TAG, "addService() - service: " + service.getUuid());
    if (mService == null || mServerIf == 0)
        return false;
    mServices.add(service);
    try {
        mService.beginServiceDeclaration(mServerIf, service.getType(), service.getInstanceId(), service.getHandles(), new ParcelUuid(service.getUuid()));
        List<BluetoothGattService> includedServices = service.getIncludedServices();
        for (BluetoothGattService includedService : includedServices) {
            mService.addIncludedService(mServerIf, includedService.getType(), includedService.getInstanceId(), new ParcelUuid(includedService.getUuid()));
        }
        List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics();
        for (BluetoothGattCharacteristic characteristic : characteristics) {
            int permission = ((characteristic.getKeySize() - 7) << 12) + characteristic.getPermissions();
            mService.addCharacteristic(mServerIf, new ParcelUuid(characteristic.getUuid()), characteristic.getProperties(), permission);
            List<BluetoothGattDescriptor> descriptors = characteristic.getDescriptors();
            for (BluetoothGattDescriptor descriptor : descriptors) {
                permission = ((characteristic.getKeySize() - 7) << 12) + descriptor.getPermissions();
                mService.addDescriptor(mServerIf, new ParcelUuid(descriptor.getUuid()), permission);
            }
        }
        mService.endServiceDeclaration(mServerIf);
    } catch (RemoteException e) {
        Log.e(TAG, "", e);
        return false;
    }
    return true;
}
Also used : ParcelUuid(android.os.ParcelUuid) RemoteException(android.os.RemoteException)

Example 4 with ParcelUuid

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

Example 5 with ParcelUuid

use of android.os.ParcelUuid in project android_frameworks_base by ResurrectionRemix.

the class ScanRecordTest method testParser.

@SmallTest
public void testParser() {
    byte[] scanRecord = new byte[] { // advertising flags
    0x02, // advertising flags
    0x01, // advertising flags
    0x1a, // 16 bit service uuids
    0x05, // 16 bit service uuids
    0x02, // 16 bit service uuids
    0x0b, // 16 bit service uuids
    0x11, // 16 bit service uuids
    0x0a, // 16 bit service uuids
    0x11, // name
    0x04, // name
    0x09, // name
    0x50, // name
    0x65, // name
    0x64, // tx power level
    0x02, // tx power level
    0x0A, // tx power level
    (byte) 0xec, // service data
    0x05, // service data
    0x16, // service data
    0x0b, // service data
    0x11, // service data
    0x50, // service data
    0x64, // manufacturer specific data
    0x05, // manufacturer specific data
    (byte) 0xff, // manufacturer specific data
    (byte) 0xe0, // manufacturer specific data
    0x00, // manufacturer specific data
    0x02, // manufacturer specific data
    0x15, // an unknown data type won't cause trouble
    0x03, // an unknown data type won't cause trouble
    0x50, // an unknown data type won't cause trouble
    0x01, // an unknown data type won't cause trouble
    0x02 };
    ScanRecord data = ScanRecord.parseFromBytes(scanRecord);
    assertEquals(0x1a, data.getAdvertiseFlags());
    ParcelUuid uuid1 = ParcelUuid.fromString("0000110A-0000-1000-8000-00805F9B34FB");
    ParcelUuid uuid2 = ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB");
    assertTrue(data.getServiceUuids().contains(uuid1));
    assertTrue(data.getServiceUuids().contains(uuid2));
    assertEquals("Ped", data.getDeviceName());
    assertEquals(-20, data.getTxPowerLevel());
    assertTrue(data.getManufacturerSpecificData().get(0x00E0) != null);
    assertArrayEquals(new byte[] { 0x02, 0x15 }, data.getManufacturerSpecificData().get(0x00E0));
    assertTrue(data.getServiceData().containsKey(uuid2));
    assertArrayEquals(new byte[] { 0x50, 0x64 }, data.getServiceData().get(uuid2));
}
Also used : ParcelUuid(android.os.ParcelUuid) ScanRecord(android.bluetooth.le.ScanRecord) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Aggregations

ParcelUuid (android.os.ParcelUuid)172 SmallTest (android.test.suitebuilder.annotation.SmallTest)43 ScanFilter (android.bluetooth.le.ScanFilter)34 RemoteException (android.os.RemoteException)29 UUID (java.util.UUID)26 ArrayList (java.util.ArrayList)25 GenericSoundModel (android.hardware.soundtrigger.SoundTrigger.GenericSoundModel)20 Parcel (android.os.Parcel)20 TargetApi (android.annotation.TargetApi)13 BluetoothDevice (android.bluetooth.BluetoothDevice)12 RecognitionConfig (android.hardware.soundtrigger.SoundTrigger.RecognitionConfig)12 LargeTest (android.test.suitebuilder.annotation.LargeTest)12 NonNull (androidx.annotation.NonNull)12 ScanRecord (android.bluetooth.le.ScanRecord)10 Socket (java.net.Socket)9 ByteBuffer (java.nio.ByteBuffer)9 ScanSettings (android.bluetooth.le.ScanSettings)8 DataOutputStream (java.io.DataOutputStream)8 BluetoothClass (android.bluetooth.BluetoothClass)7 ScanCallback (android.bluetooth.le.ScanCallback)6