use of android.bluetooth.BluetoothDevice in project XobotOS by xamarin.
the class BluetoothEventLoop method onInputDeviceConnectionResult.
/**
* Called by native code for the async response to a Connect
* method call to org.bluez.Input.
*
* @param path the path of the specified input device
* @param result Result code of the operation.
*/
private void onInputDeviceConnectionResult(String path, int result) {
// Success case gets handled by Property Change signal
if (result != BluetoothInputDevice.INPUT_OPERATION_SUCCESS) {
String address = mBluetoothService.getAddressFromObjectPath(path);
if (address == null)
return;
boolean connected = false;
BluetoothDevice device = mAdapter.getRemoteDevice(address);
int state = mBluetoothService.getInputDeviceConnectionState(device);
if (state == BluetoothInputDevice.STATE_CONNECTING) {
if (result == BluetoothInputDevice.INPUT_CONNECT_FAILED_ALREADY_CONNECTED) {
connected = true;
} else {
connected = false;
}
} else if (state == BluetoothInputDevice.STATE_DISCONNECTING) {
if (result == BluetoothInputDevice.INPUT_DISCONNECT_FAILED_NOT_CONNECTED) {
connected = false;
} else {
// There is no better way to handle this, this shouldn't happen
connected = true;
}
} else {
Log.e(TAG, "Error onInputDeviceConnectionResult. State is:" + state);
}
mBluetoothService.handleInputDevicePropertyChange(address, connected);
}
}
use of android.bluetooth.BluetoothDevice in project XobotOS by xamarin.
the class BluetoothEventLoop method onPanDeviceConnectionResult.
/**
* Called by native code for the async response to a Connect
* method call to org.bluez.Network.
*
* @param path the path of the specified PAN device
* @param result Result code of the operation.
*/
private void onPanDeviceConnectionResult(String path, int result) {
log("onPanDeviceConnectionResult " + path + " " + result);
// Success case gets handled by Property Change signal
if (result != BluetoothPan.PAN_OPERATION_SUCCESS) {
String address = mBluetoothService.getAddressFromObjectPath(path);
if (address == null)
return;
boolean connected = false;
BluetoothDevice device = mAdapter.getRemoteDevice(address);
int state = mBluetoothService.getPanDeviceConnectionState(device);
if (state == BluetoothPan.STATE_CONNECTING) {
if (result == BluetoothPan.PAN_CONNECT_FAILED_ALREADY_CONNECTED) {
connected = true;
} else {
connected = false;
}
} else if (state == BluetoothPan.STATE_DISCONNECTING) {
if (result == BluetoothPan.PAN_DISCONNECT_FAILED_NOT_CONNECTED) {
connected = false;
} else {
// There is no better way to handle this, this shouldn't happen
connected = true;
}
} else {
Log.e(TAG, "Error onPanDeviceConnectionResult. State is: " + state + " result: " + result);
}
int newState = connected ? BluetoothPan.STATE_CONNECTED : BluetoothPan.STATE_DISCONNECTED;
mBluetoothService.handlePanDeviceStateChange(device, newState, BluetoothPan.LOCAL_PANU_ROLE);
}
}
use of android.bluetooth.BluetoothDevice in project XobotOS by xamarin.
the class BluetoothHealthProfileHandler method onHealthDevicePropertyChanged.
/*package*/
void onHealthDevicePropertyChanged(String devicePath, String channelPath) {
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
String address = mBluetoothService.getAddressFromObjectPath(devicePath);
if (address == null)
return;
//TODO: Fix this in Bluez
if (channelPath.equals("/")) {
// This means that the main channel is being destroyed.
return;
}
BluetoothDevice device = adapter.getRemoteDevice(address);
BluetoothHealthAppConfiguration config = findHealthApplication(device, channelPath);
if (config != null) {
HealthChannel chan = findChannelByPath(device, channelPath);
if (chan == null) {
errorLog("Health Channel is not present:" + channelPath);
} else {
chan.mMainChannel = true;
}
}
}
use of android.bluetooth.BluetoothDevice in project XobotOS by xamarin.
the class BluetoothPanProfileHandler method disconnectPanServerDevices.
private boolean disconnectPanServerDevices() {
debugLog("disconnect all PAN devices");
for (BluetoothDevice device : mPanDevices.keySet()) {
BluetoothPanDevice panDevice = mPanDevices.get(device);
int state = panDevice.mState;
if (state == BluetoothPan.STATE_CONNECTED && panDevice.mLocalRole == BluetoothPan.LOCAL_NAP_ROLE) {
String objectPath = mBluetoothService.getObjectPathFromAddress(device.getAddress());
handlePanDeviceStateChange(device, panDevice.mIface, BluetoothPan.STATE_DISCONNECTING, panDevice.mLocalRole);
if (!mBluetoothService.disconnectPanServerDeviceNative(objectPath, device.getAddress(), panDevice.mIface)) {
errorLog("could not disconnect Pan Server Device " + device.getAddress());
// Restore prev state
handlePanDeviceStateChange(device, panDevice.mIface, state, panDevice.mLocalRole);
return false;
}
}
}
return true;
}
use of android.bluetooth.BluetoothDevice in project XobotOS by xamarin.
the class BluetoothPanProfileHandler method connectPanDevice.
boolean connectPanDevice(BluetoothDevice device) {
String objectPath = mBluetoothService.getObjectPathFromAddress(device.getAddress());
if (DBG)
Log.d(TAG, "connect PAN(" + objectPath + ")");
if (getPanDeviceConnectionState(device) != BluetoothPan.STATE_DISCONNECTED) {
errorLog(device + " already connected to PAN");
}
int connectedCount = 0;
for (BluetoothDevice panDevice : mPanDevices.keySet()) {
if (getPanDeviceConnectionState(panDevice) == BluetoothPan.STATE_CONNECTED) {
connectedCount++;
}
}
if (connectedCount > 8) {
debugLog(device + " could not connect to PAN because 8 other devices are" + "already connected");
return false;
}
// Send interface as null as it is not known
handlePanDeviceStateChange(device, null, BluetoothPan.STATE_CONNECTING, BluetoothPan.LOCAL_PANU_ROLE);
if (mBluetoothService.connectPanDeviceNative(objectPath, "nap")) {
debugLog("connecting to PAN");
return true;
} else {
handlePanDeviceStateChange(device, null, BluetoothPan.STATE_DISCONNECTED, BluetoothPan.LOCAL_PANU_ROLE);
errorLog("could not connect to PAN");
return false;
}
}
Aggregations