Bug 993286 - Patch 1/3: Get call setup state from call array, r=echou, a=1.4+
authorBen Tian <btian@mozilla.com>
Thu, 24 Apr 2014 13:56:07 +0800
changeset 198384 b087214dfd96d39037e9505575f2322d9d82eda2
parent 198383 91946180b1e7a32cc6d86383b4db7a4a505cd2e7
child 198385 601899fbbbad15653560fe204c4eb6e3ade1faab
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, 1
bugs993286
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 993286 - Patch 1/3: Get call setup state from call array, r=echou, a=1.4+
dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.cpp
dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.h
--- a/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.cpp
+++ b/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.cpp
@@ -364,17 +364,16 @@ BluetoothHfpManager::Reset()
   mDialingRequestProcessed = true;
 
   mConnectionState = BTHF_CONNECTION_STATE_DISCONNECTED;
   mPrevConnectionState = BTHF_CONNECTION_STATE_DISCONNECTED;
   mAudioState = BTHF_AUDIO_STATE_DISCONNECTED;
 
   // Phone & Device CIND
   ResetCallArray();
-  mCallSetupState = nsITelephonyProvider::CALL_STATE_DISCONNECTED;
   mBattChg = 5;
   mService = 0;
   mRoam = 0;
   mSignal = 0;
 
   mController = nullptr;
 }
 
@@ -662,17 +661,17 @@ BluetoothHfpManager::ProcessAtCind()
 
   int numActive = GetNumberOfCalls(nsITelephonyProvider::CALL_STATE_CONNECTED);
   int numHeld = GetNumberOfCalls(nsITelephonyProvider::CALL_STATE_HELD);
 
   bt_status_t status = sBluetoothHfpInterface->cind_response(
                           mService,
                           numActive,
                           numHeld,
-                          ConvertToBthfCallState(mCallSetupState),
+                          ConvertToBthfCallState(GetCallSetupState()),
                           mSignal,
                           mRoam,
                           mBattChg);
   NS_ENSURE_TRUE_VOID(status == BT_STATUS_SUCCESS);
 }
 
 void
 BluetoothHfpManager::ProcessAtCops()
@@ -714,17 +713,17 @@ BluetoothHfpManager::ProcessUnknownAt(ch
 
 void
 BluetoothHfpManager::ProcessKeyPressed()
 {
   bool hasActiveCall =
     (FindFirstCall(nsITelephonyProvider::CALL_STATE_CONNECTED) > 0);
 
   // Refer to AOSP HeadsetStateMachine.processKeyPressed
-  if (mCallSetupState == nsITelephonyProvider::CALL_STATE_INCOMING
+  if (FindFirstCall(nsITelephonyProvider::CALL_STATE_INCOMING)
       && !hasActiveCall) {
     /**
      * Bluetooth HSP spec 4.2.2
      * There is an incoming call, notify Dialer to pick up the phone call
      * and SCO will be established after we get the CallStateChanged event
      * indicating the call is answered successfully.
      */
     ProcessAnswerCall();
@@ -998,26 +997,29 @@ BluetoothHfpManager::SendResponse(bthf_a
 
 void
 BluetoothHfpManager::UpdatePhoneCIND(uint32_t aCallIndex, bool aSend)
 {
   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_state_t callSetupState =
+    ConvertToBthfCallState(GetCallSetupState());
+  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,
-          mCurrentCallArray[aCallIndex].mState, numActive, numHeld, bthfCallState);
+  BT_LOGR("[%d] state %d => BTHF: active[%d] held[%d] setupstate[%d]",
+          aCallIndex, mCurrentCallArray[aCallIndex].mState,
+          numActive, numHeld, callSetupState);
 
   NS_ENSURE_TRUE_VOID(BT_STATUS_SUCCESS ==
     sBluetoothHfpInterface->phone_state_change(
-      numActive, numHeld, bthfCallState, number.get(), type));
+      numActive, numHeld, callSetupState, number.get(), type));
 }
 
 void
 BluetoothHfpManager::UpdateDeviceCIND()
 {
   NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
   NS_ENSURE_TRUE_VOID(BT_STATUS_SUCCESS ==
     sBluetoothHfpInterface->device_status_notification(
@@ -1051,16 +1053,35 @@ BluetoothHfpManager::GetNumberOfCalls(ui
     if (mCurrentCallArray[i].mState == aState) {
       ++num;
     }
   }
 
   return num;
 }
 
+uint16_t
+BluetoothHfpManager::GetCallSetupState()
+{
+  uint32_t callLength = mCurrentCallArray.Length();
+
+  for (uint32_t i = 1; i < callLength; ++i) {
+    switch (mCurrentCallArray[i].mState) {
+      case nsITelephonyProvider::CALL_STATE_INCOMING:
+      case nsITelephonyProvider::CALL_STATE_DIALING:
+      case nsITelephonyProvider::CALL_STATE_ALERTING:
+        return mCurrentCallArray[i].mState;
+      default:
+        break;
+    }
+  }
+
+  return nsITelephonyProvider::CALL_STATE_DISCONNECTED;
+}
+
 bthf_call_state_t
 BluetoothHfpManager::ConvertToBthfCallState(int aCallState)
 {
   bthf_call_state_t state;
 
   // Refer to AOSP BluetoothPhoneService.convertCallState
   if (aCallState == nsITelephonyProvider::CALL_STATE_INCOMING) {
     state = BTHF_CALL_STATE_INCOMING;
@@ -1110,32 +1131,16 @@ 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;
--- a/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.h
+++ b/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.h
@@ -142,29 +142,28 @@ private:
 
   void NotifyConnectionStateChanged(const nsAString& aType);
   void NotifyDialer(const nsAString& aCommand);
 
   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 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;
-  // Phone CIND
-  int mCallSetupState;
   // Device CIND
   int mBattChg;
   int mService;
   int mRoam;
   int mSignal;
 
   int mCurrentVgs;
   int mCurrentVgm;