Add HID to the state machine and add native call backs.

Change-Id: Ib9f3e476d4176bc04e23e7674dc54aa5a6417308
This commit is contained in:
Jaikumar Ganesh
2010-07-19 16:28:27 -07:00
parent c3ee99d9eb
commit de07503a38
6 changed files with 367 additions and 22 deletions

View File

@@ -693,6 +693,26 @@ class BluetoothEventLoop {
}
}
private void onInputDeviceConnectionResult(String path, boolean result) {
// Success case gets handled by Property Change signal
if (!result) {
String address = mBluetoothService.getAddressFromObjectPath(path);
if (address == null) return;
boolean connected = false;
BluetoothDevice device = mAdapter.getRemoteDevice(address);
int state = mBluetoothService.getInputDeviceState(device);
if (state == BluetoothInputDevice.STATE_CONNECTING) {
connected = false;
} else if (state == BluetoothInputDevice.STATE_DISCONNECTING) {
connected = true;
} else {
Log.e(TAG, "Error onInputDeviceConnectionResult. State is:" + state);
}
mBluetoothService.handleInputDevicePropertyChange(address, connected);
}
}
private void onRestartRequired() {
if (mBluetoothService.isEnabled()) {
Log.e(TAG, "*** A serious error occured (did bluetoothd crash?) - " +

View File

@@ -132,6 +132,7 @@ public class BluetoothService extends IBluetooth.Stub {
private final HashMap<String, BluetoothDeviceProfileState> mDeviceProfileState;
private final BluetoothProfileState mA2dpProfileState;
private final BluetoothProfileState mHfpProfileState;
private final BluetoothProfileState mHidProfileState;
private BluetoothA2dpService mA2dpService;
private final HashMap<BluetoothDevice, Integer> mInputDevices;
@@ -196,9 +197,11 @@ public class BluetoothService extends IBluetooth.Stub {
mDeviceProfileState = new HashMap<String, BluetoothDeviceProfileState>();
mA2dpProfileState = new BluetoothProfileState(mContext, BluetoothProfileState.A2DP);
mHfpProfileState = new BluetoothProfileState(mContext, BluetoothProfileState.HFP);
mHidProfileState = new BluetoothProfileState(mContext, BluetoothProfileState.HID);
mHfpProfileState.start();
mA2dpProfileState.start();
mHidProfileState.start();
IntentFilter filter = new IntentFilter();
registerForAirplaneMode(filter);
@@ -1241,13 +1244,27 @@ public class BluetoothService extends IBluetooth.Stub {
getInputDevicePriority(device) == BluetoothInputDevice.PRIORITY_OFF) {
return false;
}
if(connectInputDeviceNative(objectPath)) {
handleInputDeviceStateChange(device, BluetoothInputDevice.STATE_CONNECTING);
BluetoothDeviceProfileState state = mDeviceProfileState.get(device.getAddress());
if (state != null) {
Message msg = new Message();
msg.arg1 = BluetoothDeviceProfileState.CONNECT_HID_OUTGOING;
msg.obj = state;
mHidProfileState.sendMessage(msg);
return true;
}
return false;
}
public synchronized boolean connectInputDeviceInternal(BluetoothDevice device) {
String objectPath = getObjectPathFromAddress(device.getAddress());
handleInputDeviceStateChange(device, BluetoothInputDevice.STATE_CONNECTING);
if (!connectInputDeviceNative(objectPath)) {
handleInputDeviceStateChange(device, BluetoothInputDevice.STATE_DISCONNECTED);
return false;
}
return true;
}
public synchronized boolean disconnectInputDevice(BluetoothDevice device) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH_ADMIN permission");
@@ -1256,13 +1273,27 @@ public class BluetoothService extends IBluetooth.Stub {
if (objectPath == null || getConnectedInputDevices().length == 0) {
return false;
}
if(disconnectInputDeviceNative(objectPath)) {
handleInputDeviceStateChange(device, BluetoothInputDevice.STATE_DISCONNECTING);
BluetoothDeviceProfileState state = mDeviceProfileState.get(device.getAddress());
if (state != null) {
Message msg = new Message();
msg.arg1 = BluetoothDeviceProfileState.DISCONNECT_HID_OUTGOING;
msg.obj = state;
mHidProfileState.sendMessage(msg);
return true;
}
return false;
}
public synchronized boolean disconnectInputDeviceInternal(BluetoothDevice device) {
String objectPath = getObjectPathFromAddress(device.getAddress());
handleInputDeviceStateChange(device, BluetoothInputDevice.STATE_DISCONNECTING);
if (!disconnectInputDeviceNative(objectPath)) {
handleInputDeviceStateChange(device, BluetoothInputDevice.STATE_CONNECTED);
return false;
}
return true;
}
public synchronized int getInputDeviceState(BluetoothDevice device) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");