use of android.bluetooth.BluetoothDevice in project XobotOS by xamarin.
the class BluetoothA2dpService method onSinkPropertyChanged.
/**
* Called by native code on a PropertyChanged signal from
* org.bluez.AudioSink.
*
* @param path the object path for the changed device
* @param propValues a string array containing the key and one or more
* values.
*/
private synchronized void onSinkPropertyChanged(String path, String[] propValues) {
if (!mBluetoothService.isEnabled()) {
return;
}
String name = propValues[0];
String address = mBluetoothService.getAddressFromObjectPath(path);
if (address == null) {
Log.e(TAG, "onSinkPropertyChanged: Address of the remote device in null");
return;
}
BluetoothDevice device = mAdapter.getRemoteDevice(address);
if (name.equals(PROPERTY_STATE)) {
int state = convertBluezSinkStringToState(propValues[1]);
log("A2DP: onSinkPropertyChanged newState is: " + state + "mPlayingA2dpDevice: " + mPlayingA2dpDevice);
if (mAudioDevices.get(device) == null) {
// This is for an incoming connection for a device not known to us.
// We have authorized it and bluez state has changed.
addAudioSink(device);
handleSinkStateChange(device, BluetoothA2dp.STATE_DISCONNECTED, state);
} else {
if (state == BluetoothA2dp.STATE_PLAYING && mPlayingA2dpDevice == null) {
mPlayingA2dpDevice = device;
handleSinkPlayingStateChange(device, state, BluetoothA2dp.STATE_NOT_PLAYING);
} else if (state == BluetoothA2dp.STATE_CONNECTED && mPlayingA2dpDevice != null) {
mPlayingA2dpDevice = null;
handleSinkPlayingStateChange(device, BluetoothA2dp.STATE_NOT_PLAYING, BluetoothA2dp.STATE_PLAYING);
} else {
mPlayingA2dpDevice = null;
int prevState = mAudioDevices.get(device);
handleSinkStateChange(device, prevState, state);
}
}
}
}
use of android.bluetooth.BluetoothDevice in project XobotOS by xamarin.
the class BluetoothEventLoop method onNetworkDeviceConnected.
/**
* Called by native code on a DeviceConnected signal from
* org.bluez.NetworkServer.
*
* @param address the MAC address of the connected device
* @param iface interface of remote network
* @param destUuid unused UUID parameter
*/
private void onNetworkDeviceConnected(String address, String iface, int destUuid) {
BluetoothDevice device = mAdapter.getRemoteDevice(address);
mBluetoothService.handlePanDeviceStateChange(device, iface, BluetoothPan.STATE_CONNECTED, BluetoothPan.LOCAL_NAP_ROLE);
}
use of android.bluetooth.BluetoothDevice in project android_frameworks_base by DirtyUnicorns.
the class MidiService method openBluetoothDevice.
@Override
public void openBluetoothDevice(IBinder token, BluetoothDevice bluetoothDevice, IMidiDeviceOpenCallback callback) {
Client client = getClient(token);
if (client == null)
return;
// Bluetooth devices are created on demand
Device device;
synchronized (mDevicesByInfo) {
device = mBluetoothDevices.get(bluetoothDevice);
if (device == null) {
device = new Device(bluetoothDevice);
mBluetoothDevices.put(bluetoothDevice, device);
}
}
// clear calling identity so bindService does not fail
long identity = Binder.clearCallingIdentity();
try {
client.addDeviceConnection(device, callback);
} finally {
Binder.restoreCallingIdentity(identity);
}
}
use of android.bluetooth.BluetoothDevice in project android_frameworks_base by DirtyUnicorns.
the class ScanResultTest method testScanResultParceling.
/**
* Test read and write parcel of ScanResult
*/
@SmallTest
public void testScanResultParceling() {
BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice("01:02:03:04:05:06");
byte[] scanRecord = new byte[] { 1, 2, 3 };
int rssi = -10;
long timestampMicros = 10000L;
ScanResult result = new ScanResult(device, ScanRecord.parseFromBytes(scanRecord), rssi, timestampMicros);
Parcel parcel = Parcel.obtain();
result.writeToParcel(parcel, 0);
// Need to reset parcel data position to the beginning.
parcel.setDataPosition(0);
ScanResult resultFromParcel = ScanResult.CREATOR.createFromParcel(parcel);
assertEquals(result, resultFromParcel);
}
use of android.bluetooth.BluetoothDevice in project android_frameworks_base by DirtyUnicorns.
the class ScanFilterTest method setUp.
@Override
protected void setUp() throws Exception {
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, // setName
0x04, // setName
0x09, // setName
0x50, // setName
0x65, // setName
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 };
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
BluetoothDevice device = adapter.getRemoteDevice(DEVICE_MAC);
mScanResult = new ScanResult(device, ScanRecord.parseFromBytes(scanRecord), -10, 1397545200000000L);
mFilterBuilder = new ScanFilter.Builder();
}
Aggregations