Bug 804436 - Patch 2: Failed to connect from a headset again after turn off and turn on the headset. r=qdot, a=blocking-basecamp
authorGina Yeh <gyeh@mozilla.com>
Fri, 26 Oct 2012 17:28:39 +0800
changeset 113740 b471cb0a563827f309e1a6702c6ab3eaa09dbea8
parent 113739 5c200eb5ddf7adbf952aa47ad2eca8bf0fe79658
child 113741 af799b3ec743461281df01cd0eab4bbad79e7aed
push id2483
push userryanvm@gmail.com
push dateSun, 28 Oct 2012 01:55:17 +0000
treeherdermozilla-aurora@029f67cb42b7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot, blocking-basecamp
bugs804436
milestone18.0a2
Bug 804436 - Patch 2: Failed to connect from a headset again after turn off and turn on the headset. r=qdot, a=blocking-basecamp
dom/bluetooth/BluetoothHfpManager.cpp
dom/bluetooth/BluetoothHfpManager.h
--- a/dom/bluetooth/BluetoothHfpManager.cpp
+++ b/dom/bluetooth/BluetoothHfpManager.cpp
@@ -235,16 +235,18 @@ BluetoothHfpManager::BluetoothHfpManager
   sCINDItems[CINDType::CALL].value = CallState::NO_CALL;
   sCINDItems[CINDType::CALLSETUP].value = CallSetupState::NO_CALLSETUP;
   sCINDItems[CINDType::CALLHELD].value = CallHeldState::NO_CALLHELD;
 }
 
 bool
 BluetoothHfpManager::Init()
 {
+  mSocketStatus = GetConnectionStatus();
+
   sHfpObserver = new BluetoothHfpManagerObserver();
   if (!sHfpObserver->Init()) {
     NS_WARNING("Cannot set up Hfp Observers!");
   }
 
   mListener = new BluetoothRilListener();
   if (!mListener->StartListening()) {
     NS_WARNING("Failed to start listening RIL");
@@ -612,29 +614,31 @@ BluetoothHfpManager::Listen()
     return false;
   }
 
   nsresult rv = bs->ListenSocketViaService(BluetoothReservedChannels::HANDSFREE_AG,
                                            BluetoothSocketType::RFCOMM,
                                            true,
                                            false,
                                            this);
+
+  mSocketStatus = GetConnectionStatus();
+
   return NS_FAILED(rv) ? false : true;
 }
 
 void
 BluetoothHfpManager::Disconnect()
 {
   if (GetConnectionStatus() == SocketConnectionStatus::SOCKET_DISCONNECTED) {
     NS_WARNING("BluetoothHfpManager has disconnected!");
     return;
   }
 
   CloseSocket();
-  Listen();
 }
 
 bool
 BluetoothHfpManager::SendLine(const char* aMessage)
 {
   const char* kHfpCrlf = "\xd\xa";
   nsAutoCString msg;
 
@@ -842,27 +846,34 @@ BluetoothHfpManager::OnConnectSuccess()
   GetSocketAddr(mDevicePath);
 
   if (mCurrentCallState == nsIRadioInterfaceLayer::CALL_STATE_CONNECTED ||
       mCurrentCallState == nsIRadioInterfaceLayer::CALL_STATE_DIALING ||
       mCurrentCallState == nsIRadioInterfaceLayer::CALL_STATE_ALERTING) {
     OpenScoSocket(mDevicePath);
   }
 
+  mSocketStatus = GetConnectionStatus();
+
   NotifySettings();
 }
 
 void
 BluetoothHfpManager::OnConnectError()
 {
   CloseSocket();
+  mSocketStatus = GetConnectionStatus();
   // If connecting for some reason didn't work, restart listening
   Listen();
 }
 
 void
 BluetoothHfpManager::OnDisconnect()
 {
-  NotifySettings();
+  if (mSocketStatus == SocketConnectionStatus::SOCKET_CONNECTED) {
+    Listen();
+    NotifySettings();
+  }
+
   sCINDItems[CINDType::CALL].value = CallState::NO_CALL;
   sCINDItems[CINDType::CALLSETUP].value = CallSetupState::NO_CALLSETUP;
   sCINDItems[CINDType::CALLHELD].value = CallHeldState::NO_CALLHELD;
 }
--- a/dom/bluetooth/BluetoothHfpManager.h
+++ b/dom/bluetooth/BluetoothHfpManager.h
@@ -50,14 +50,15 @@ private:
   virtual void OnConnectError() MOZ_OVERRIDE;
   virtual void OnDisconnect() MOZ_OVERRIDE;
 
   int mCurrentVgs;
   int mCurrentCallIndex;
   int mCurrentCallState;
   bool mReceiveVgsFlag;
   nsString mDevicePath;
+  enum mozilla::ipc::SocketConnectionStatus mSocketStatus;
   nsAutoPtr<BluetoothRilListener> mListener;
 };
 
 END_BLUETOOTH_NAMESPACE
 
 #endif