Bug 993289: Fix the logic while updating call setup state, f=btian, r=echou
authorJocelyn Liu <joliu@mozilla.com>
Tue, 22 Apr 2014 16:42:38 +0800
changeset 198045 72ad241c645cb5f29eebbadcf364375297f750d3
parent 198044 feebdb44fc8249493a98a1aacaf2caef4ed0c3d3
child 198046 47c889ef369cda34cfc65eab0f0971eba67b60a8
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersechou
bugs993289
milestone31.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 993289: Fix the logic while updating call setup state, f=btian, r=echou
dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.cpp
--- a/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.cpp
+++ b/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.cpp
@@ -994,35 +994,26 @@ BluetoothHfpManager::SendResponse(bthf_a
   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)
 {
-  // Update callsetup state
-  uint16_t callState = mCurrentCallArray[aCallIndex].mState;
-  if (callState == nsITelephonyProvider::CALL_STATE_CONNECTED ||
-      callState == nsITelephonyProvider::CALL_STATE_HELD) {
-    mCallSetupState = nsITelephonyProvider::CALL_STATE_DISCONNECTED;
-  } else {
-    mCallSetupState = callState;
-  }
-
   NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
 
   int numActive = GetNumberOfCalls(nsITelephonyProvider::CALL_STATE_CONNECTED);
   int numHeld = GetNumberOfCalls(nsITelephonyProvider::CALL_STATE_HELD);
   bthf_call_state_t bthfCallState = ConvertToBthfCallState(mCallSetupState);
   nsAutoCString number = NS_ConvertUTF16toUTF8(mCurrentCallArray[aCallIndex].mNumber);
   bthf_call_addrtype_t type = mCurrentCallArray[aCallIndex].mType;
 
-  BT_LOGR("[%d] state %d => BTHF: active[%d] held[%d] state[%d]",
-          aCallIndex, callState, numActive, numHeld, bthfCallState);
+  BT_LOGR("[%d] state %d => BTHF: active[%d] held[%d] state[%d]", aCallIndex,
+          mCurrentCallArray[aCallIndex].mState, numActive, numHeld, bthfCallState);
 
   NS_ENSURE_TRUE_VOID(BT_STATUS_SUCCESS ==
     sBluetoothHfpInterface->phone_state_change(
       numActive, numHeld, bthfCallState, number.get(), type));
 }
 
 void
 BluetoothHfpManager::UpdateDeviceCIND()
@@ -1119,16 +1110,32 @@ BluetoothHfpManager::HandleCallStateChan
   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;
   }
 
+  bool isSetupCall = (aCallState == nsITelephonyProvider::CALL_STATE_INCOMING ||
+                      aCallState == nsITelephonyProvider::CALL_STATE_ALERTING ||
+                      aCallState == nsITelephonyProvider::CALL_STATE_DIALING);
+  bool hasSetupCall = (FindFirstCall(nsITelephonyProvider::CALL_STATE_INCOMING) ||
+                       FindFirstCall(nsITelephonyProvider::CALL_STATE_ALERTING) ||
+                       FindFirstCall(nsITelephonyProvider::CALL_STATE_DIALING));
+
+  // Update callsetup state when
+  // 1) this call is in call setup
+  // 2) all calls in the call array including this call are not in call setup
+  if (isSetupCall) {
+    mCallSetupState = aCallState;
+  } else if (!hasSetupCall) {
+    mCallSetupState = nsITelephonyProvider::CALL_STATE_DISCONNECTED;
+  }
+
   UpdatePhoneCIND(aCallIndex, aSend);
 
   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;