OSDN Git Service

Resolve incoming pairing and connection issue
authorRavi Nagarajan <nravi@broadcom.com>
Fri, 29 Jun 2012 13:49:59 +0000 (19:19 +0530)
committerMatthew Xie <mattx@google.com>
Fri, 27 Jul 2012 05:33:54 +0000 (22:33 -0700)
When the remote side initiates pairing & connection, occassionally
connection is made before the phone has had a chance to do SDP.
In this case, the profile priorities are not initialized, which caused
us to incorrectly reject the incoming connection. Allow connection
if priority is undefined, but device is not unpaired

Change-Id: Icd8257adea19fc9a4d3853cd85da9bd791cfe505

Conflicts:

src/com/android/bluetooth/a2dp/A2dpStateMachine.java

src/com/android/bluetooth/a2dp/A2dpStateMachine.java
src/com/android/bluetooth/hfp/HeadsetStateMachine.java
src/com/android/bluetooth/hid/HidService.java

index 4f43d43..8d42512 100644 (file)
@@ -204,15 +204,21 @@ final class A2dpStateMachine extends StateMachine {
 
         // in Disconnected state
         private void processConnectionEvent(int state, BluetoothDevice device) {
+            int priority;
             switch (state) {
             case CONNECTION_STATE_DISCONNECTED:
                 Log.w(TAG, "Ignore HF DISCONNECTED event, device: " + device);
                 break;
             case CONNECTION_STATE_CONNECTING:
-                // check priority and accept or reject the connection
+                // check priority and accept or reject the connection. if priority is undefined
+                // it is likely that our SDP has not completed and peer is initiating the
+                // connection. Allow this connection, provided the device is bonded
                 // Since the state changes to  Connecting or directly Connected in some cases.Have the check both in
                 // CONNECTION_STATE_CONNECTING and CONNECTION_STATE_CONNECTED.
-                if (BluetoothProfile.PRIORITY_OFF < mService.getPriority(device)) {
+                priority = mService.getPriority(device);
+                if ((BluetoothProfile.PRIORITY_OFF < priority) ||
+                    ((BluetoothProfile.PRIORITY_UNDEFINED == priority) &&
+                     (device.getBondState() != BluetoothDevice.BOND_NONE))){
                     Log.i(TAG,"Incoming A2DP accepted");
                     broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTING,
                                              BluetoothProfile.STATE_DISCONNECTED);
@@ -230,8 +236,10 @@ final class A2dpStateMachine extends StateMachine {
                 break;
             case CONNECTION_STATE_CONNECTED:
                 Log.w(TAG, "A2DP Connected from Disconnected state");
-
-                if (BluetoothProfile.PRIORITY_OFF < mService.getPriority(device)) {
+                priority = mService.getPriority(device);
+                if ((BluetoothProfile.PRIORITY_OFF < priority) ||
+                    ((BluetoothProfile.PRIORITY_UNDEFINED == priority) &&
+                     (device.getBondState() != BluetoothDevice.BOND_NONE))){
                     Log.i(TAG,"Incoming A2DP accepted");
                     broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTED,
                                              BluetoothProfile.STATE_DISCONNECTED);
index a60b9ea..a58349e 100755 (executable)
@@ -301,15 +301,21 @@ final class HeadsetStateMachine extends StateMachine {
 
         // in Disconnected state
         private void processConnectionEvent(int state, BluetoothDevice device) {
+            int priority;
             switch (state) {
             case HeadsetHalConstants.CONNECTION_STATE_DISCONNECTED:
                 Log.w(TAG, "Ignore HF DISCONNECTED event, device: " + device);
                 break;
             case HeadsetHalConstants.CONNECTION_STATE_CONNECTING:
-                // check priority and accept or reject the connection
+                // check priority and accept or reject the connection. if priority is undefined
+                // it is likely that our SDP has not completed and peer is initiating the
+                // connection. Allow this connection, provided the device is bonded
                 // Since the state changes to  Connecting or directly Connected in some cases.Have the check both in
                 // CONNECTION_STATE_CONNECTING and CONNECTION_STATE_CONNECTED.
-                if (BluetoothProfile.PRIORITY_OFF < mService.getPriority(device)) {
+                priority = mService.getPriority(device);
+                if ((BluetoothProfile.PRIORITY_OFF < priority) ||
+                    ((BluetoothProfile.PRIORITY_UNDEFINED == priority) &&
+                     (device.getBondState() != BluetoothDevice.BOND_NONE))){
                     Log.i(TAG,"Incoming Hf accepted");
                     broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTING,
                                              BluetoothProfile.STATE_DISCONNECTED);
@@ -318,7 +324,8 @@ final class HeadsetStateMachine extends StateMachine {
                         transitionTo(mPending);
                     }
                 } else {
-                    Log.i(TAG,"Incoming Hf rejected");
+                    Log.i(TAG,"Incoming Hf rejected. priority=" + priority +
+                              " bondState=" + device.getBondState());
                     //reject the connection and stay in Disconnected state itself
                     disconnectHfpNative(getByteAddress(device));
                     // the other profile connection should be initiated
@@ -327,7 +334,13 @@ final class HeadsetStateMachine extends StateMachine {
                 break;
             case HeadsetHalConstants.CONNECTION_STATE_CONNECTED:
                 Log.w(TAG, "HFP Connected from Disconnected state");
-                if (BluetoothProfile.PRIORITY_OFF < mService.getPriority(device)) {
+                // check priority and accept or reject the connection. if priority is undefined
+                // it is likely that our SDP has not completed and peer is initiating the
+                // connection. Allow this connection, provided the device is bonded
+                priority = mService.getPriority(device);
+                if ((BluetoothProfile.PRIORITY_OFF < priority) ||
+                    ((BluetoothProfile.PRIORITY_UNDEFINED == priority) &&
+                     (device.getBondState() != BluetoothDevice.BOND_NONE))){
                     Log.i(TAG,"Incoming Hf accepted");
                     broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTED,
                                              BluetoothProfile.STATE_DISCONNECTED);
@@ -338,7 +351,8 @@ final class HeadsetStateMachine extends StateMachine {
                     configAudioParameters();
                 } else {
                     //reject the connection and stay in Disconnected state itself
-                    Log.d(TAG,"Incoming Hf rejected");
+                    Log.i(TAG,"Incoming Hf rejected. priority=" + priority +
+                              " bondState=" + device.getBondState());
                     disconnectHfpNative(getByteAddress(device));
                     // the other profile connection should be initiated
                     broadcastConnectOtherProfilesIntent(device);
index 5cccb09..2ed02b7 100755 (executable)
@@ -125,7 +125,8 @@ public class HidService extends ProfileService {
                         convertHalState(halState)+", prevState:"+prevState);
                      if(halState == CONN_STATE_CONNECTED &&
                         prevState == BluetoothInputDevice.STATE_DISCONNECTED &&
-                        BluetoothProfile.PRIORITY_OFF >= getPriority(device)) {
+                        (BluetoothProfile.PRIORITY_OFF == getPriority(device) ||
+                        device.getBondState() == BluetoothDevice.BOND_NONE)) {
                         Log.d(TAG,"Incoming HID connection rejected");
                         disconnectHidNative(Utils.getByteAddress(device));
                     } else {