use of android.bluetooth.BluetoothDevice in project platform_frameworks_base by android.
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 MidiService method addDeviceLocked.
// synchronize on mDevicesByInfo
private MidiDeviceInfo addDeviceLocked(int type, int numInputPorts, int numOutputPorts, String[] inputPortNames, String[] outputPortNames, Bundle properties, IMidiDeviceServer server, ServiceInfo serviceInfo, boolean isPrivate, int uid) {
int id = mNextDeviceId++;
MidiDeviceInfo deviceInfo = new MidiDeviceInfo(type, id, numInputPorts, numOutputPorts, inputPortNames, outputPortNames, properties, isPrivate);
if (server != null) {
try {
server.setDeviceInfo(deviceInfo);
} catch (RemoteException e) {
Log.e(TAG, "RemoteException in setDeviceInfo()");
return null;
}
}
Device device = null;
BluetoothDevice bluetoothDevice = null;
if (type == MidiDeviceInfo.TYPE_BLUETOOTH) {
bluetoothDevice = (BluetoothDevice) properties.getParcelable(MidiDeviceInfo.PROPERTY_BLUETOOTH_DEVICE);
device = mBluetoothDevices.get(bluetoothDevice);
if (device != null) {
device.setDeviceInfo(deviceInfo);
}
}
if (device == null) {
device = new Device(server, deviceInfo, serviceInfo, uid);
}
mDevicesByInfo.put(deviceInfo, device);
if (bluetoothDevice != null) {
mBluetoothDevices.put(bluetoothDevice, device);
}
synchronized (mClients) {
for (Client c : mClients.values()) {
c.deviceAdded(device);
}
}
return deviceInfo;
}
use of android.bluetooth.BluetoothDevice in project XobotOS by xamarin.
the class BluetoothEventLoop method onAgentAuthorize.
/**
* Called by native code on an Authorize method call to org.bluez.Agent.
*
* @param objectPath the path of the device requesting to be authorized
* @param deviceUuid the UUID of the requesting device
* @param nativeData reference for native data
*/
private void onAgentAuthorize(String objectPath, String deviceUuid, int nativeData) {
if (!mBluetoothService.isEnabled())
return;
String address = mBluetoothService.getAddressFromObjectPath(objectPath);
if (address == null) {
Log.e(TAG, "Unable to get device address in onAuthAgentAuthorize");
return;
}
boolean authorized = false;
ParcelUuid uuid = ParcelUuid.fromString(deviceUuid);
BluetoothDevice device = mAdapter.getRemoteDevice(address);
mAuthorizationAgentRequestData.put(address, new Integer(nativeData));
// remote service
if (mA2dp != null && (BluetoothUuid.isAudioSource(uuid) || BluetoothUuid.isAvrcpTarget(uuid) || BluetoothUuid.isAdvAudioDist(uuid)) && !isOtherSinkInNonDisconnectedState(address)) {
authorized = mA2dp.getPriority(device) > BluetoothProfile.PRIORITY_OFF;
if (authorized && !BluetoothUuid.isAvrcpTarget(uuid)) {
Log.i(TAG, "First check pass for incoming A2DP / AVRCP connection from " + address);
// Some headsets try to connect AVCTP before AVDTP - against the recommendation
// If AVCTP connection fails, we get stuck in IncomingA2DP state in the state
// machine. We don't handle AVCTP signals currently. We only send
// intents for AVDTP state changes. We need to handle both of them in
// some cases. For now, just don't move to incoming state in this case.
mBluetoothService.notifyIncomingA2dpConnection(address);
} else {
Log.i(TAG, "" + authorized + "Incoming A2DP / AVRCP connection from " + address);
mA2dp.allowIncomingConnect(device, authorized);
}
} else if (BluetoothUuid.isInputDevice(uuid)) {
// We can have more than 1 input device connected.
authorized = mBluetoothService.getInputDevicePriority(device) > BluetoothInputDevice.PRIORITY_OFF;
if (authorized) {
Log.i(TAG, "First check pass for incoming HID connection from " + address);
// notify profile state change
mBluetoothService.notifyIncomingHidConnection(address);
} else {
Log.i(TAG, "Rejecting incoming HID connection from " + address);
mBluetoothService.allowIncomingProfileConnect(device, authorized);
}
} else if (BluetoothUuid.isBnep(uuid)) {
// PAN doesn't go to the state machine, accept or reject from here
authorized = mBluetoothService.allowIncomingTethering();
mBluetoothService.allowIncomingProfileConnect(device, authorized);
} else {
Log.i(TAG, "Rejecting incoming " + deviceUuid + " connection from " + address);
mBluetoothService.allowIncomingProfileConnect(device, authorized);
}
log("onAgentAuthorize(" + objectPath + ", " + deviceUuid + ") = " + authorized);
}
use of android.bluetooth.BluetoothDevice in project XobotOS by xamarin.
the class BluetoothEventLoop method onDevicePropertyChanged.
/**
* Called by native code on a PropertyChanged signal from
* org.bluez.Device.
*
* @param deviceObjectPath the object path for the changed device
* @param propValues a string array containing the key and one or more
* values.
*/
private void onDevicePropertyChanged(String deviceObjectPath, String[] propValues) {
String name = propValues[0];
String address = mBluetoothService.getAddressFromObjectPath(deviceObjectPath);
if (address == null) {
Log.e(TAG, "onDevicePropertyChanged: Address of the remote device in null");
return;
}
log("Device property changed: " + address + " property: " + name + " value: " + propValues[1]);
BluetoothDevice device = mAdapter.getRemoteDevice(address);
if (name.equals("Name")) {
mBluetoothService.setRemoteDeviceProperty(address, name, propValues[1]);
Intent intent = new Intent(BluetoothDevice.ACTION_NAME_CHANGED);
intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
intent.putExtra(BluetoothDevice.EXTRA_NAME, propValues[1]);
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
mContext.sendBroadcast(intent, BLUETOOTH_PERM);
} else if (name.equals("Alias")) {
mBluetoothService.setRemoteDeviceProperty(address, name, propValues[1]);
} else if (name.equals("Class")) {
mBluetoothService.setRemoteDeviceProperty(address, name, propValues[1]);
Intent intent = new Intent(BluetoothDevice.ACTION_CLASS_CHANGED);
intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
intent.putExtra(BluetoothDevice.EXTRA_CLASS, new BluetoothClass(Integer.valueOf(propValues[1])));
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
mContext.sendBroadcast(intent, BLUETOOTH_PERM);
} else if (name.equals("Connected")) {
mBluetoothService.setRemoteDeviceProperty(address, name, propValues[1]);
Intent intent = null;
if (propValues[1].equals("true")) {
intent = new Intent(BluetoothDevice.ACTION_ACL_CONNECTED);
// for bluetooth docks.
if (mBluetoothService.isBluetoothDock(address)) {
mBluetoothService.setLinkTimeout(address, 8000);
}
} else {
intent = new Intent(BluetoothDevice.ACTION_ACL_DISCONNECTED);
}
intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
mContext.sendBroadcast(intent, BLUETOOTH_PERM);
} else if (name.equals("UUIDs")) {
String uuid = null;
int len = Integer.valueOf(propValues[1]);
if (len > 0) {
StringBuilder str = new StringBuilder();
for (int i = 2; i < propValues.length; i++) {
str.append(propValues[i]);
str.append(",");
}
uuid = str.toString();
}
mBluetoothService.setRemoteDeviceProperty(address, name, uuid);
// UUIDs have changed, query remote service channel and update cache.
mBluetoothService.updateDeviceServiceChannelCache(address);
mBluetoothService.sendUuidIntent(address);
} else if (name.equals("Paired")) {
if (propValues[1].equals("true")) {
// successful return value in onCreatePairedDeviceResult
if (null == mBluetoothService.getPendingOutgoingBonding()) {
mBluetoothService.setBondState(address, BluetoothDevice.BOND_BONDED);
}
} else {
mBluetoothService.setBondState(address, BluetoothDevice.BOND_NONE);
mBluetoothService.setRemoteDeviceProperty(address, "Trusted", "false");
}
} else if (name.equals("Trusted")) {
if (DBG)
log("set trust state succeeded, value is: " + propValues[1]);
mBluetoothService.setRemoteDeviceProperty(address, name, propValues[1]);
}
}
use of android.bluetooth.BluetoothDevice in project XobotOS by xamarin.
the class BluetoothEventLoop method onPanDevicePropertyChanged.
/**
* Called by native code on a PropertyChanged signal from
* org.bluez.Network.
*
* @param deviceObjectPath the object path for the changed PAN device
* @param propValues a string array containing the key and one or more
* values.
*/
private void onPanDevicePropertyChanged(String deviceObjectPath, String[] propValues) {
String name = propValues[0];
String address = mBluetoothService.getAddressFromObjectPath(deviceObjectPath);
if (address == null) {
Log.e(TAG, "onPanDevicePropertyChanged: Address of the remote device in null");
return;
}
if (DBG) {
log("Pan Device property changed: " + address + " property: " + name + " value: " + propValues[1]);
}
BluetoothDevice device = mAdapter.getRemoteDevice(address);
if (name.equals("Connected")) {
if (propValues[1].equals("false")) {
mBluetoothService.handlePanDeviceStateChange(device, BluetoothPan.STATE_DISCONNECTED, BluetoothPan.LOCAL_PANU_ROLE);
}
} else if (name.equals("Interface")) {
String iface = propValues[1];
if (!iface.equals("")) {
mBluetoothService.handlePanDeviceStateChange(device, iface, BluetoothPan.STATE_CONNECTED, BluetoothPan.LOCAL_PANU_ROLE);
}
}
}
Aggregations