OSDN Git Service

Fix the issue where HID connection was failing on first connection randomly.
authorSyed Ibrahim M <syedibra@broadcom.com>
Thu, 31 May 2012 10:30:04 +0000 (16:00 +0530)
committerAndroid (Google) Code Review <android-gerrit@google.com>
Tue, 17 Jul 2012 05:10:25 +0000 (22:10 -0700)
Made changes in HidService to send a STATE_CONNECTING broadcast when HIDService.connect() is invoked;
Also before rejecting the incoming connection, check if the connection is transitioning from STATE_DISCONNECTED to STATE_CONNECTED and then only do a disconnectHidNative(). The normal flow of HID connect would transition from STATE_CONNECTING to STATE_CONNECTED

Change-Id: Ia416e3a70fc6c3561c3530091691367c5da2674c

src/com/android/bluetooth/hid/HidService.java

index e0d7be7..5cccb09 100755 (executable)
@@ -118,7 +118,19 @@ public class HidService extends ProfileService {
                 {
                     BluetoothDevice device = getDevice((byte[]) msg.obj);
                     int halState = msg.arg1;
-                    broadcastConnectionState(device, convertHalState(halState));
+                    Integer prevStateInteger = mInputDevices.get(device);
+                    int prevState = (prevStateInteger == null) ?
+                        BluetoothInputDevice.STATE_DISCONNECTED :prevStateInteger;
+                    if(DBG) Log.d(TAG, "MESSAGE_CONNECT_STATE_CHANGED newState:"+
+                        convertHalState(halState)+", prevState:"+prevState);
+                     if(halState == CONN_STATE_CONNECTED &&
+                        prevState == BluetoothInputDevice.STATE_DISCONNECTED &&
+                        BluetoothProfile.PRIORITY_OFF >= getPriority(device)) {
+                        Log.d(TAG,"Incoming HID connection rejected");
+                        disconnectHidNative(Utils.getByteAddress(device));
+                    } else {
+                        broadcastConnectionState(device, convertHalState(halState));
+                    }
                 }
                     break;
                 case MESSAGE_GET_PROTOCOL_MODE: