diff options
Diffstat (limited to 'core/java/android/server/BluetoothEventLoop.java')
-rw-r--r-- | core/java/android/server/BluetoothEventLoop.java | 132 |
1 files changed, 123 insertions, 9 deletions
diff --git a/core/java/android/server/BluetoothEventLoop.java b/core/java/android/server/BluetoothEventLoop.java index 6bb6d76..c066862 100644 --- a/core/java/android/server/BluetoothEventLoop.java +++ b/core/java/android/server/BluetoothEventLoop.java @@ -20,6 +20,8 @@ import android.bluetooth.BluetoothA2dp; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothClass; import android.bluetooth.BluetoothDevice; +import android.bluetooth.BluetoothInputDevice; +import android.bluetooth.BluetoothPan; import android.bluetooth.BluetoothUuid; import android.content.Context; import android.content.Intent; @@ -364,7 +366,8 @@ class BluetoothEventLoop { return; } if (DBG) { - log("Device property changed:" + address + "property:" + name); + log("Device property changed: " + address + " property: " + + name + " value: " + propValues[1]); } BluetoothDevice device = mAdapter.getRemoteDevice(address); if (name.equals("Name")) { @@ -433,6 +436,39 @@ class BluetoothEventLoop { } } + private void onInputDevicePropertyChanged(String path, String[] propValues) { + String address = mBluetoothService.getAddressFromObjectPath(path); + if (address == null) { + Log.e(TAG, "onInputDevicePropertyChanged: Address of the remote device in null"); + return; + } + log(" Input Device : Name of Property is:" + propValues[0]); + boolean state = false; + if (propValues[1].equals("true")) { + state = true; + } + mBluetoothService.handleInputDevicePropertyChange(address, state); + } + + 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")) { + int state = propValues[1].equals("true") ? BluetoothInputDevice.STATE_CONNECTED : + BluetoothInputDevice.STATE_DISCONNECTED; + mBluetoothService.handlePanDeviceStateChange(device, state); + } + } + private String checkPairingRequestAndGetAddress(String objectPath, int nativeData) { String address = mBluetoothService.getAddressFromObjectPath(objectPath); if (address == null) { @@ -590,6 +626,8 @@ class BluetoothEventLoop { } private boolean onAgentAuthorize(String objectPath, String deviceUuid) { + if (!mBluetoothService.isEnabled()) return false; + String address = mBluetoothService.getAddressFromObjectPath(objectPath); if (address == null) { Log.e(TAG, "Unable to get device address in onAuthAgentAuthorize"); @@ -598,15 +636,15 @@ class BluetoothEventLoop { boolean authorized = false; ParcelUuid uuid = ParcelUuid.fromString(deviceUuid); - BluetoothA2dp a2dp = new BluetoothA2dp(mContext); + BluetoothDevice device = mAdapter.getRemoteDevice(address); // Bluez sends the UUID of the local service being accessed, _not_ the // remote service - if (mBluetoothService.isEnabled() && - (BluetoothUuid.isAudioSource(uuid) || BluetoothUuid.isAvrcpTarget(uuid) - || BluetoothUuid.isAdvAudioDist(uuid)) && - !isOtherSinkInNonDisconnectingState(address)) { - BluetoothDevice device = mAdapter.getRemoteDevice(address); + if ((BluetoothUuid.isAudioSource(uuid) || BluetoothUuid.isAvrcpTarget(uuid) + || BluetoothUuid.isAdvAudioDist(uuid)) && + !isOtherSinkInNonDisconnectingState(address)) { + BluetoothA2dp a2dp = new BluetoothA2dp(mContext); + authorized = a2dp.getSinkPriority(device) > BluetoothA2dp.PRIORITY_OFF; if (authorized) { Log.i(TAG, "Allowing incoming A2DP / AVRCP connection from " + address); @@ -614,6 +652,18 @@ class BluetoothEventLoop { } else { Log.i(TAG, "Rejecting incoming A2DP / AVRCP connection from " + address); } + } else if (BluetoothUuid.isInputDevice(uuid) && !isOtherInputDeviceConnected(address)) { + BluetoothInputDevice inputDevice = new BluetoothInputDevice(mContext); + authorized = inputDevice.getInputDevicePriority(device) > + BluetoothInputDevice.PRIORITY_OFF; + if (authorized) { + Log.i(TAG, "Allowing incoming HID connection from " + address); + } else { + Log.i(TAG, "Rejecting incoming HID connection from " + address); + } + } else if (BluetoothUuid.isBnep(uuid) || BluetoothUuid.isNap(uuid) && + mBluetoothService.isTetheringOn()){ + authorized = true; } else { Log.i(TAG, "Rejecting incoming " + deviceUuid + " connection from " + address); } @@ -621,6 +671,18 @@ class BluetoothEventLoop { return authorized; } + private boolean isOtherInputDeviceConnected(String address) { + Set<BluetoothDevice> devices = + mBluetoothService.lookupInputDevicesMatchingStates(new int[] { + BluetoothInputDevice.STATE_CONNECTING, + BluetoothInputDevice.STATE_CONNECTED}); + + for (BluetoothDevice device : devices) { + if (!device.getAddress().equals(address)) return true; + } + return false; + } + private boolean onAgentOutOfBandDataAvailable(String objectPath) { if (!mBluetoothService.isEnabled()) return false; @@ -631,8 +693,6 @@ class BluetoothEventLoop { mAdapter.getRemoteDevice(address)) != null) { return true; } - return false; - } private boolean isOtherSinkInNonDisconnectingState(String address) { @@ -686,6 +746,60 @@ 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 onPanDeviceConnectionResult(String path, boolean result) { + log ("onPanDeviceConnectionResult " + path + " " + 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.getPanDeviceState(device); + if (state == BluetoothPan.STATE_CONNECTING) { + connected = false; + } else if (state == BluetoothPan.STATE_DISCONNECTING) { + 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); + } + } + + private void onNetworkDeviceDisconnected(String address) { + BluetoothDevice device = mAdapter.getRemoteDevice(address); + mBluetoothService.handlePanDeviceStateChange(device, BluetoothPan.STATE_DISCONNECTED); + } + + private void onNetworkDeviceConnected(String address, int destUuid) { + BluetoothDevice device = mAdapter.getRemoteDevice(address); + mBluetoothService.handlePanDeviceStateChange(device, BluetoothPan.STATE_CONNECTED); + } + private void onRestartRequired() { if (mBluetoothService.isEnabled()) { Log.e(TAG, "*** A serious error occured (did bluetoothd crash?) - " + |