use of android.bluetooth.BluetoothDevice 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;
}
use of android.bluetooth.BluetoothDevice 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;
}
use of android.bluetooth.BluetoothDevice in project XobotOS by xamarin.
the class BluetoothA2dpService method onBluetoothDisable.
private synchronized void onBluetoothDisable() {
if (!mAudioDevices.isEmpty()) {
BluetoothDevice[] devices = new BluetoothDevice[mAudioDevices.size()];
devices = mAudioDevices.keySet().toArray(devices);
for (BluetoothDevice device : devices) {
int state = getConnectionState(device);
switch(state) {
case BluetoothA2dp.STATE_CONNECTING:
case BluetoothA2dp.STATE_CONNECTED:
case BluetoothA2dp.STATE_PLAYING:
disconnectSinkNative(mBluetoothService.getObjectPathFromAddress(device.getAddress()));
handleSinkStateChange(device, state, BluetoothA2dp.STATE_DISCONNECTED);
break;
case BluetoothA2dp.STATE_DISCONNECTING:
handleSinkStateChange(device, BluetoothA2dp.STATE_DISCONNECTING, BluetoothA2dp.STATE_DISCONNECTED);
break;
}
}
mAudioDevices.clear();
}
mAudioManager.setParameters(BLUETOOTH_ENABLED + "=false");
}
use of android.bluetooth.BluetoothDevice in project XobotOS by xamarin.
the class BluetoothA2dpService method onConnectSinkResult.
/**
* Called by native code for the async response to a Connect
* method call to org.bluez.AudioSink.
*
* @param deviceObjectPath the object path for the connecting device
* @param result true on success; false on error
*/
private void onConnectSinkResult(String deviceObjectPath, boolean result) {
// when we a Sink Property Change
if (!result) {
if (deviceObjectPath != null) {
String address = mBluetoothService.getAddressFromObjectPath(deviceObjectPath);
if (address == null)
return;
BluetoothDevice device = mAdapter.getRemoteDevice(address);
int state = getConnectionState(device);
handleSinkStateChange(device, state, BluetoothA2dp.STATE_DISCONNECTED);
}
}
}
use of android.bluetooth.BluetoothDevice 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