Bug 993286 - Patch 2/3: Support AT+CHLD=3 to merge calls, r=echou, a=1.4+
authorBen Tian <btian@mozilla.com>
Thu, 24 Apr 2014 14:55:27 +0800
changeset 180364 601899fbbbad15653560fe204c4eb6e3ade1faab
parent 180363 b087214dfd96d39037e9505575f2322d9d82eda2
child 180365 3e77a85ed5fbaf2ff296c261a9be4066fb4f7194
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersechou, 1
bugs993286
milestone31.0a1
Bug 993286 - Patch 2/3: Support AT+CHLD=3 to merge calls, r=echou, a=1.4+
dom/bluetooth/bluedroid/b2g_bdroid_buildcfg.h
dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.cpp
dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.h
--- a/dom/bluetooth/bluedroid/b2g_bdroid_buildcfg.h
+++ b/dom/bluetooth/bluedroid/b2g_bdroid_buildcfg.h
@@ -32,11 +32,11 @@
 ******************************************************************************/
 /* AG feature masks */
 #define BTIF_HF_FEATURES   ( BTA_AG_FEAT_3WAY | \
                              BTA_AG_FEAT_REJECT | \
                              BTA_AG_FEAT_ECS    | \
                              BTA_AG_FEAT_EXTERR)
 
 /* CHLD values */
-#define BTA_AG_CHLD_VAL    "(0,1,2)"
+#define BTA_AG_CHLD_VAL    "(0,1,2,3)"
 
 #endif /* B2G_BDROID_BUILDCFG_H */
--- a/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.cpp
+++ b/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.cpp
@@ -517,17 +517,17 @@ void
 BluetoothHfpManager::ProcessConnectionState(bthf_connection_state_t aState,
                                             bt_bdaddr_t* aBdAddress)
 {
   BT_LOGR("state %d", aState);
 
   mPrevConnectionState = mConnectionState;
   mConnectionState = aState;
 
-  if (aState == BTHF_CONNECTION_STATE_CONNECTED) {
+  if (aState == BTHF_CONNECTION_STATE_SLC_CONNECTED) {
     BdAddressTypeToString(aBdAddress, mDeviceAddress);
     BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::NOTIFY_CONN_STATE_CHANGED,
                         NS_LITERAL_STRING(BLUETOOTH_HFP_STATUS_CHANGED_ID));
   } else if (aState == BTHF_CONNECTION_STATE_DISCONNECTED) {
     DisconnectSco();
     BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::NOTIFY_CONN_STATE_CHANGED,
                         NS_LITERAL_STRING(BLUETOOTH_HFP_STATUS_CHANGED_ID));
   }
@@ -597,16 +597,17 @@ BluetoothHfpManager::ProcessDtmfCmd(char
 
 void
 BluetoothHfpManager::ProcessAtChld(bthf_chld_type_t aChld)
 {
   nsAutoCString message("CHLD=");
   message.AppendInt((int)aChld);
   BT_HF_DISPATCH_MAIN(MainThreadTaskCmd::NOTIFY_DIALER,
                       NS_ConvertUTF8toUTF16(message));
+
   SendResponse(BTHF_AT_RESPONSE_OK);
 }
 
 void BluetoothHfpManager::ProcessDialCall(char *aNumber)
 {
   nsAutoCString message(aNumber);
 
   // There are three cases based on aNumber,
@@ -991,17 +992,17 @@ void
 BluetoothHfpManager::SendResponse(bthf_at_response_t aResponseCode)
 {
   NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
   NS_ENSURE_TRUE_VOID(BT_STATUS_SUCCESS ==
     sBluetoothHfpInterface->at_response(aResponseCode, 0));
 }
 
 void
-BluetoothHfpManager::UpdatePhoneCIND(uint32_t aCallIndex, bool aSend)
+BluetoothHfpManager::UpdatePhoneCIND(uint32_t aCallIndex)
 {
   NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
 
   int numActive = GetNumberOfCalls(nsITelephonyProvider::CALL_STATE_CONNECTED);
   int numHeld = GetNumberOfCalls(nsITelephonyProvider::CALL_STATE_HELD);
   bthf_call_state_t callSetupState =
     ConvertToBthfCallState(GetCallSetupState());
   nsAutoCString number =
@@ -1104,44 +1105,46 @@ void
 BluetoothHfpManager::HandleCallStateChanged(uint32_t aCallIndex,
                                             uint16_t aCallState,
                                             const nsAString& aError,
                                             const nsAString& aNumber,
                                             const bool aIsOutgoing,
                                             const bool aIsConference,
                                             bool aSend)
 {
-  if (!IsConnected()) {
-    // Normal case. No need to print out warnings.
-    return;
-  }
-
   // aCallIndex can be UINT32_MAX for the pending outgoing call state update.
   // aCallIndex will be updated again after real call state changes. See Bug
   // 990467.
   if (aCallIndex == UINT32_MAX) {
     return;
   }
 
+  // Update call state only
   while (aCallIndex >= mCurrentCallArray.Length()) {
     Call call;
     mCurrentCallArray.AppendElement(call);
   }
+  mCurrentCallArray[aCallIndex].mState = aCallState;
 
-  mCurrentCallArray[aCallIndex].mState = aCallState;
+  // Return if SLC is disconnected
+  if (!IsConnected()) {
+    return;
+  }
+
   mCurrentCallArray[aCallIndex].mNumber = aNumber;
   mCurrentCallArray[aCallIndex].mDirection = (aIsOutgoing) ?
                                               BTHF_CALL_DIRECTION_OUTGOING :
                                               BTHF_CALL_DIRECTION_INCOMING;
   // Same logic as implementation in ril_worker.js
   if (aNumber.Length() && aNumber[0] == '+') {
     mCurrentCallArray[aCallIndex].mType = BTHF_CALL_ADDRTYPE_INTERNATIONAL;
   }
 
-  UpdatePhoneCIND(aCallIndex, aSend);
+  // Notify bluedroid of phone state change
+  UpdatePhoneCIND(aCallIndex);
 
   switch (aCallState) {
     case nsITelephonyProvider::CALL_STATE_DIALING:
       // We've send Dialer a dialing request and this is the response.
       if (!mDialingRequestProcessed) {
         SendResponse(BTHF_AT_RESPONSE_OK);
         mDialingRequestProcessed = true;
       }
@@ -1275,18 +1278,17 @@ bool
 BluetoothHfpManager::IsScoConnected()
 {
   return (mAudioState == BTHF_AUDIO_STATE_CONNECTED);
 }
 
 bool
 BluetoothHfpManager::IsConnected()
 {
-  return (mConnectionState == BTHF_CONNECTION_STATE_SLC_CONNECTED ||
-          mConnectionState == BTHF_CONNECTION_STATE_CONNECTED);
+  return (mConnectionState == BTHF_CONNECTION_STATE_SLC_CONNECTED);
 }
 
 void
 BluetoothHfpManager::Connect(const nsAString& aDeviceAddress,
                              BluetoothProfileController* aController)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aController && !mController);
--- a/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.h
+++ b/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.h
@@ -145,17 +145,17 @@ private:
 
   PhoneType GetPhoneType(const nsAString& aType);
   void ResetCallArray();
   uint32_t FindFirstCall(uint16_t aState);
   uint32_t GetNumberOfCalls(uint16_t aState);
   uint16_t GetCallSetupState();
   bthf_call_state_t ConvertToBthfCallState(int aCallState);
 
-  void UpdatePhoneCIND(uint32_t aCallIndex, bool aSend = true);
+  void UpdatePhoneCIND(uint32_t aCallIndex);
   void UpdateDeviceCIND();
   void SendCLCC(Call& aCall, int aIndex);
   void SendLine(const char* aMessage);
   void SendResponse(bthf_at_response_t aResponseCode);
 
   int mConnectionState;
   int mPrevConnectionState;
   int mAudioState;