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
This commit is contained in:
Ben Turner 2012-01-11 18:17:26 -08:00
parent a7e158984c
commit cd9dfe6aea
4 changed files with 77 additions and 16 deletions

View File

@ -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<TelephonyCall>& 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,23 +368,50 @@ 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<TelephonyCall> modifiedCall;
nsRefPtr<TelephonyCall> outgoingCall;
for (PRUint32 index = 0; index < mCalls.Length(); index++) {
nsRefPtr<TelephonyCall>& tempCall = mCalls[index];
if (tempCall->CallIndex() == aCallIndex) {
// This can call back and modify the array... Grab a real ref here.
nsRefPtr<TelephonyCall> call = tempCall;
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(call);
SwitchActiveCall(modifiedCall);
}
// Change state.
call->ChangeState(aCallState);
return NS_OK;
}
}
// Didn't know anything about this call before now, must be incoming.
NS_ASSERTION(aCallState == nsITelephone::CALL_STATE_INCOMING,

View File

@ -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);

View File

@ -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<TelephonyCall>
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()

View File

@ -60,6 +60,10 @@ class nsIDOMTelephonyCall;
BEGIN_TELEPHONY_NAMESPACE
enum {
kOutgoingPlaceholderCallIndex = PR_UINT32_MAX
};
class Telephony;
class TelephonyCall;