OSDN Git Service

Connection state change has to be handled in AudioOn state. Some headsets send RFCOMM...
authorRavi Nagarajan <nravi@broadcom.com>
Thu, 19 Apr 2012 08:15:47 +0000 (13:45 +0530)
committerAndroid (Google) Code Review <android-gerrit@google.com>
Tue, 17 Jul 2012 05:01:17 +0000 (22:01 -0700)
Change-Id: Ib80a49cbd959055624baae6e5a35022c628f4bba

src/com/android/bluetooth/hfp/HeadsetStateMachine.java

index 38beed0..c2c1ed7 100755 (executable)
@@ -811,6 +811,9 @@ final class HeadsetStateMachine extends StateMachine {
                         log("event type: " + event.type);
                     }
                     switch (event.type) {
+                        case EVENT_TYPE_CONNECTION_STATE_CHANGED:
+                            processConnectionEvent(event.valueInt, event.device);
+                            break;
                         case EVENT_TYPE_AUDIO_STATE_CHANGED:
                             processAudioEvent(event.valueInt, event.device);
                             break;
@@ -867,6 +870,28 @@ final class HeadsetStateMachine extends StateMachine {
             return retValue;
         }
 
+        // in AudioOn state. Some headsets disconnect RFCOMM prior to SCO down. Handle this
+        private void processConnectionEvent(int state, BluetoothDevice device) {
+            switch (state) {
+                case HeadsetHalConstants.CONNECTION_STATE_DISCONNECTED:
+                    if (mCurrentDevice.equals(device)) {
+                        processAudioEvent (HeadsetHalConstants.AUDIO_STATE_DISCONNECTED, device);
+                        broadcastConnectionState(mCurrentDevice, BluetoothProfile.STATE_DISCONNECTED,
+                                                 BluetoothProfile.STATE_CONNECTED);
+                        synchronized (HeadsetStateMachine.this) {
+                            mCurrentDevice = null;
+                            transitionTo(mDisconnected);
+                        }
+                    } else {
+                        Log.e(TAG, "Disconnected from unknown device: " + device);
+                    }
+                    break;
+              default:
+                  Log.e(TAG, "Connection State Device: " + device + " bad state: " + state);
+                  break;
+            }
+        }
+
         // in AudioOn state
         private void processAudioEvent(int state, BluetoothDevice device) {
             if (!mCurrentDevice.equals(device)) {