diff options
author | Jaikumar Ganesh <jaikumar@google.com> | 2010-07-19 16:28:27 -0700 |
---|---|---|
committer | Jaikumar Ganesh <jaikumar@google.com> | 2010-07-21 10:43:02 -0700 |
commit | de07503a382e81ba82f4cd4dee81ff2fbf3295bc (patch) | |
tree | fc3d73fe306195e9c4080901d74e635323bd3db0 /core/java/android/server | |
parent | c3ee99d9eb7e8b4b20c2b8f1c548373e1017e0d3 (diff) | |
download | frameworks_base-de07503a382e81ba82f4cd4dee81ff2fbf3295bc.zip frameworks_base-de07503a382e81ba82f4cd4dee81ff2fbf3295bc.tar.gz frameworks_base-de07503a382e81ba82f4cd4dee81ff2fbf3295bc.tar.bz2 |
Add HID to the state machine and add native call backs.
Change-Id: Ib9f3e476d4176bc04e23e7674dc54aa5a6417308
Diffstat (limited to 'core/java/android/server')
-rw-r--r-- | core/java/android/server/BluetoothEventLoop.java | 20 | ||||
-rw-r--r-- | core/java/android/server/BluetoothService.java | 39 |
2 files changed, 55 insertions, 4 deletions
diff --git a/core/java/android/server/BluetoothEventLoop.java b/core/java/android/server/BluetoothEventLoop.java index 9b7a73d..eb9b62b 100644 --- a/core/java/android/server/BluetoothEventLoop.java +++ b/core/java/android/server/BluetoothEventLoop.java @@ -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?) - " + diff --git a/core/java/android/server/BluetoothService.java b/core/java/android/server/BluetoothService.java index d7cd933..68eba6e 100644 --- a/core/java/android/server/BluetoothService.java +++ b/core/java/android/server/BluetoothService.java @@ -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"); |