From cd9dfe6aea4c7194ca48d57f425646fb6faedeed Mon Sep 17 00:00:00 2001 From: Ben Turner Date: Wed, 11 Jan 2012 18:17:26 -0800 Subject: [PATCH] Bug 717158 - 'B2G telephony: unknown (outgoing) call index is assumed to be incoming later'. r=cjones. --HG-- extra : transplant_source : %7B%A6XC%07%87%20%A9W%AA.Le%A5%7B%1A%81%F1%FE%B5 --- dom/telephony/Telephony.cpp | 64 ++++++++++++++++++++++++++------- dom/telephony/TelephonyCall.cpp | 4 +++ dom/telephony/TelephonyCall.h | 21 +++++++++-- dom/telephony/TelephonyCommon.h | 4 +++ 4 files changed, 77 insertions(+), 16 deletions(-) diff --git a/dom/telephony/Telephony.cpp b/dom/telephony/Telephony.cpp index e218e05e34e..a04ad56ef46 100644 --- a/dom/telephony/Telephony.cpp +++ b/dom/telephony/Telephony.cpp @@ -202,6 +202,17 @@ Telephony::Dial(const nsAString& aNumber, nsIDOMTelephonyCall** aResult) { NS_ENSURE_ARG(!aNumber.IsEmpty()); + for (PRUint32 index = 0; index < mCalls.Length(); index++) { + const nsRefPtr& tempCall = mCalls[index]; + if (tempCall->IsOutgoing() && + tempCall->CallState() < nsITelephone::CALL_STATE_CONNECTED) { + // One call has been dialed already and we only support one outgoing call + // at a time. + NS_WARNING("Only permitted to dial one call at a time!"); + return NS_ERROR_NOT_AVAILABLE; + } + } + nsresult rv = mTelephone->Dial(aNumber); NS_ENSURE_SUCCESS(rv, rv); @@ -357,24 +368,51 @@ NS_IMETHODIMP Telephony::CallStateChanged(PRUint32 aCallIndex, PRUint16 aCallState, const nsAString& aNumber) { - // If we already know about this call then just update its state. + NS_ASSERTION(aCallIndex != kOutgoingPlaceholderCallIndex, + "This should never happen!"); + + nsRefPtr modifiedCall; + nsRefPtr outgoingCall; + for (PRUint32 index = 0; index < mCalls.Length(); index++) { nsRefPtr& tempCall = mCalls[index]; - if (tempCall->CallIndex() == aCallIndex) { - // This can call back and modify the array... Grab a real ref here. - nsRefPtr call = tempCall; - - // See if this should replace our current active call. - if (aCallState == nsITelephone::CALL_STATE_CONNECTED) { - SwitchActiveCall(call); - } - - // Change state. - call->ChangeState(aCallState); - return NS_OK; + if (tempCall->CallIndex() == kOutgoingPlaceholderCallIndex) { + NS_ASSERTION(!outgoingCall, "More than one outgoing call not supported!"); + NS_ASSERTION(tempCall->CallState() == nsITelephone::CALL_STATE_DIALING, + "Something really wrong here!"); + // Stash this for later, we may need it if aCallIndex doesn't match one of + // our other calls. + outgoingCall = tempCall; + } else if (tempCall->CallIndex() == aCallIndex) { + // We already know about this call so just update its state. + modifiedCall = tempCall; + outgoingCall = nsnull; + break; } } + // If nothing matched above and the call state isn't incoming but we do have + // an outgoing call then we must be seeing a status update for our outgoing + // call. + if (!modifiedCall && + aCallState != nsITelephone::CALL_STATE_INCOMING && + outgoingCall) { + outgoingCall->UpdateCallIndex(aCallIndex); + modifiedCall.swap(outgoingCall); + } + + if (modifiedCall) { + // Change state. + modifiedCall->ChangeState(aCallState); + + // See if this should replace our current active call. + if (aCallState == nsITelephone::CALL_STATE_CONNECTED) { + SwitchActiveCall(modifiedCall); + } + + return NS_OK; + } + // Didn't know anything about this call before now, must be incoming. NS_ASSERTION(aCallState == nsITelephone::CALL_STATE_INCOMING, "Serious logic problem here!"); diff --git a/dom/telephony/TelephonyCall.cpp b/dom/telephony/TelephonyCall.cpp index cebad2d3c2c..d6eac16ae3a 100644 --- a/dom/telephony/TelephonyCall.cpp +++ b/dom/telephony/TelephonyCall.cpp @@ -115,6 +115,10 @@ TelephonyCall::ChangeStateInternal(PRUint16 aCallState, bool aFireEvents) mState = stateString; mCallState = aCallState; + if (aCallState == nsITelephone::CALL_STATE_DIALING) { + mOutgoing = true; + } + if (aCallState == nsITelephone::CALL_STATE_DISCONNECTED) { NS_ASSERTION(mLive, "Should be live!"); mTelephony->RemoveCall(this); diff --git a/dom/telephony/TelephonyCall.h b/dom/telephony/TelephonyCall.h index 9beff093307..8664ba072f8 100644 --- a/dom/telephony/TelephonyCall.h +++ b/dom/telephony/TelephonyCall.h @@ -70,6 +70,7 @@ class TelephonyCall : public nsDOMEventTargetWrapperCache, PRUint32 mCallIndex; PRUint16 mCallState; bool mLive; + bool mOutgoing; public: NS_DECL_ISUPPORTS_INHERITED @@ -80,7 +81,7 @@ public: static already_AddRefed Create(Telephony* aTelephony, const nsAString& aNumber, PRUint16 aCallState, - PRUint32 aCallIndex = PR_UINT32_MAX); + PRUint32 aCallIndex = kOutgoingPlaceholderCallIndex); nsIDOMEventTarget* ToIDOMEventTarget() const @@ -107,16 +108,30 @@ public: return mCallIndex; } + void + UpdateCallIndex(PRUint32 aCallIndex) + { + NS_ASSERTION(mCallIndex == kOutgoingPlaceholderCallIndex, + "Call index should not be set!"); + mCallIndex = aCallIndex; + } + PRUint16 CallState() const { return mCallState; } + bool + IsOutgoing() const + { + return mOutgoing; + } + private: TelephonyCall() - : mCallIndex(PR_UINT32_MAX), mCallState(nsITelephone::CALL_STATE_UNKNOWN), - mLive(false) + : mCallIndex(kOutgoingPlaceholderCallIndex), + mCallState(nsITelephone::CALL_STATE_UNKNOWN), mLive(false), mOutgoing(false) { } ~TelephonyCall() diff --git a/dom/telephony/TelephonyCommon.h b/dom/telephony/TelephonyCommon.h index 5324edd7ad1..74607c7712f 100644 --- a/dom/telephony/TelephonyCommon.h +++ b/dom/telephony/TelephonyCommon.h @@ -60,6 +60,10 @@ class nsIDOMTelephonyCall; BEGIN_TELEPHONY_NAMESPACE +enum { + kOutgoingPlaceholderCallIndex = PR_UINT32_MAX +}; + class Telephony; class TelephonyCall;