Bug 834160 - Part 5/7: fix Telephony. r=smaug, f=htsai

--HG--
rename : dom/bluetooth/BluetoothRilListener.cpp => dom/bluetooth/BluetoothTelephonyListener.cpp
rename : dom/bluetooth/BluetoothRilListener.h => dom/bluetooth/BluetoothTelephonyListener.h
This commit is contained in:
Vicamo Yang 2013-03-06 17:53:23 +08:00
Родитель dc8fc0fb69
Коммит 9510ded1d6
12 изменённых файлов: 269 добавлений и 251 удалений

Просмотреть файл

@ -23,7 +23,7 @@
#include "nsIAudioManager.h"
#include "nsIObserverService.h"
#include "nsISettingsService.h"
#include "nsIRadioInterfaceLayer.h"
#include "nsITelephonyProvider.h"
#include "nsRadioInterfaceLayer.h"
#define AUDIO_VOLUME_BT_SCO "audio.volume.bt_sco"
@ -114,7 +114,7 @@ static CINDItem sCINDItems[] = {
class mozilla::dom::bluetooth::Call {
public:
Call(uint16_t aState = nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTED,
Call(uint16_t aState = nsITelephonyProvider::CALL_STATE_DISCONNECTED,
bool aDirection = false,
const nsAString& aNumber = NS_LITERAL_STRING(""),
int aType = TOA_UNKNOWN)
@ -398,7 +398,7 @@ BluetoothHfpManager::Init()
NS_WARNING("Cannot set up Hfp Observers!");
}
mListener = new BluetoothRilListener();
mListener = new BluetoothTelephonyListener();
if (!mListener->StartListening()) {
NS_WARNING("Failed to start listening RIL");
return false;
@ -899,15 +899,15 @@ BluetoothHfpManager::ReceiveSocketData(nsAutoPtr<UnixSocketRawData>& aMessage)
} else if (msg.Find("AT+CKPD") != -1) {
// For Headset Profile (HSP)
switch (mCurrentCallArray[mCurrentCallIndex].mState) {
case nsIRadioInterfaceLayer::CALL_STATE_INCOMING:
case nsITelephonyProvider::CALL_STATE_INCOMING:
NotifyDialer(NS_LITERAL_STRING("ATA"));
break;
case nsIRadioInterfaceLayer::CALL_STATE_CONNECTED:
case nsIRadioInterfaceLayer::CALL_STATE_DIALING:
case nsIRadioInterfaceLayer::CALL_STATE_ALERTING:
case nsITelephonyProvider::CALL_STATE_CONNECTED:
case nsITelephonyProvider::CALL_STATE_DIALING:
case nsITelephonyProvider::CALL_STATE_ALERTING:
NotifyDialer(NS_LITERAL_STRING("CHUP"));
break;
case nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTED:
case nsITelephonyProvider::CALL_STATE_DISCONNECTED:
NotifyDialer(NS_LITERAL_STRING("BLDN"));
break;
default:
@ -1089,7 +1089,7 @@ BluetoothHfpManager::SendCommand(const char* aCommand, uint8_t aValue)
uint32_t callNumbers = mCurrentCallArray.Length();
for (uint32_t i = 1; i < callNumbers; i++) {
Call& call = mCurrentCallArray[i];
if (call.mState == nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTED) {
if (call.mState == nsITelephonyProvider::CALL_STATE_DISCONNECTED) {
continue;
}
@ -1100,19 +1100,19 @@ BluetoothHfpManager::SendCommand(const char* aCommand, uint8_t aValue)
message += ",";
switch (call.mState) {
case nsIRadioInterfaceLayer::CALL_STATE_CONNECTED:
case nsITelephonyProvider::CALL_STATE_CONNECTED:
message.AppendInt(0);
break;
case nsIRadioInterfaceLayer::CALL_STATE_HELD:
case nsITelephonyProvider::CALL_STATE_HELD:
message.AppendInt(1);
break;
case nsIRadioInterfaceLayer::CALL_STATE_DIALING:
case nsITelephonyProvider::CALL_STATE_DIALING:
message.AppendInt(2);
break;
case nsIRadioInterfaceLayer::CALL_STATE_ALERTING:
case nsITelephonyProvider::CALL_STATE_ALERTING:
message.AppendInt(3);
break;
case nsIRadioInterfaceLayer::CALL_STATE_INCOMING:
case nsITelephonyProvider::CALL_STATE_INCOMING:
message.AppendInt((i == mCurrentCallIndex) ? 4 : 5);
break;
default:
@ -1176,11 +1176,11 @@ BluetoothHfpManager::HandleCallStateChanged(uint32_t aCallIndex,
uint32_t index = 1;
switch (aCallState) {
case nsIRadioInterfaceLayer::CALL_STATE_HELD:
case nsITelephonyProvider::CALL_STATE_HELD:
sCINDItems[CINDType::CALLHELD].value = CallHeldState::ONHOLD_ACTIVE;
SendCommand("+CIEV: ", CINDType::CALLHELD);
break;
case nsIRadioInterfaceLayer::CALL_STATE_INCOMING:
case nsITelephonyProvider::CALL_STATE_INCOMING:
mCurrentCallArray[aCallIndex].mDirection = true;
if (mCurrentCallIndex) {
@ -1207,14 +1207,14 @@ BluetoothHfpManager::HandleCallStateChanged(uint32_t aCallIndex,
sRingInterval);
}
break;
case nsIRadioInterfaceLayer::CALL_STATE_DIALING:
case nsITelephonyProvider::CALL_STATE_DIALING:
mCurrentCallArray[aCallIndex].mDirection = false;
UpdateCIND(CINDType::CALLSETUP, CallSetupState::OUTGOING, aSend);
GetSocketAddr(address);
OpenScoSocket(address);
break;
case nsIRadioInterfaceLayer::CALL_STATE_ALERTING:
case nsITelephonyProvider::CALL_STATE_ALERTING:
mCurrentCallArray[aCallIndex].mDirection = false;
UpdateCIND(CINDType::CALLSETUP, CallSetupState::OUTGOING_ALERTING, aSend);
@ -1223,22 +1223,22 @@ BluetoothHfpManager::HandleCallStateChanged(uint32_t aCallIndex,
GetSocketAddr(address);
OpenScoSocket(address);
break;
case nsIRadioInterfaceLayer::CALL_STATE_CONNECTED:
case nsITelephonyProvider::CALL_STATE_CONNECTED:
mCurrentCallIndex = aCallIndex;
switch (prevCallState) {
case nsIRadioInterfaceLayer::CALL_STATE_INCOMING:
case nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTED:
case nsITelephonyProvider::CALL_STATE_INCOMING:
case nsITelephonyProvider::CALL_STATE_DISCONNECTED:
// Incoming call, no break
sStopSendingRingFlag = true;
GetSocketAddr(address);
OpenScoSocket(address);
case nsIRadioInterfaceLayer::CALL_STATE_ALERTING:
case nsITelephonyProvider::CALL_STATE_ALERTING:
// Outgoing call
UpdateCIND(CINDType::CALL, CallState::IN_PROGRESS, aSend);
UpdateCIND(CINDType::CALLSETUP, CallSetupState::NO_CALLSETUP, aSend);
break;
case nsIRadioInterfaceLayer::CALL_STATE_HELD:
case nsITelephonyProvider::CALL_STATE_HELD:
// Check whether to update CINDType::CALLHELD or not
while (index < callArrayLength) {
if (index == mCurrentCallIndex) {
@ -1249,7 +1249,7 @@ BluetoothHfpManager::HandleCallStateChanged(uint32_t aCallIndex,
uint16_t state = mCurrentCallArray[index].mState;
// If there's another call on hold or other calls exist, no need to
// update CINDType::CALLHELD
if (state != nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTED) {
if (state != nsITelephonyProvider::CALL_STATE_DISCONNECTED) {
break;
}
index++;
@ -1263,24 +1263,24 @@ BluetoothHfpManager::HandleCallStateChanged(uint32_t aCallIndex,
NS_WARNING("Not handling state changed");
}
break;
case nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTED:
case nsITelephonyProvider::CALL_STATE_DISCONNECTED:
switch (prevCallState) {
case nsIRadioInterfaceLayer::CALL_STATE_INCOMING:
case nsIRadioInterfaceLayer::CALL_STATE_BUSY:
case nsITelephonyProvider::CALL_STATE_INCOMING:
case nsITelephonyProvider::CALL_STATE_BUSY:
// Incoming call, no break
sStopSendingRingFlag = true;
case nsIRadioInterfaceLayer::CALL_STATE_DIALING:
case nsIRadioInterfaceLayer::CALL_STATE_ALERTING:
case nsITelephonyProvider::CALL_STATE_DIALING:
case nsITelephonyProvider::CALL_STATE_ALERTING:
// Outgoing call
UpdateCIND(CINDType::CALLSETUP, CallSetupState::NO_CALLSETUP, aSend);
break;
case nsIRadioInterfaceLayer::CALL_STATE_CONNECTED:
case nsITelephonyProvider::CALL_STATE_CONNECTED:
// No call is ongoing
if (sCINDItems[CINDType::CALLHELD].value == CallHeldState::NO_CALLHELD) {
UpdateCIND(CINDType::CALL, CallState::NO_CALL, aSend);
}
break;
case nsIRadioInterfaceLayer::CALL_STATE_HELD:
case nsITelephonyProvider::CALL_STATE_HELD:
UpdateCIND(CINDType::CALLHELD, CallHeldState::NO_CALLHELD, aSend);
break;
default:
@ -1292,7 +1292,7 @@ BluetoothHfpManager::HandleCallStateChanged(uint32_t aCallIndex,
// and update mCurrentCallIndex
while (index < callArrayLength) {
if (mCurrentCallArray[index].mState !=
nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTED) {
nsITelephonyProvider::CALL_STATE_DISCONNECTED) {
mCurrentCallIndex = index;
break;
}
@ -1317,10 +1317,10 @@ BluetoothHfpManager::HandleCallStateChanged(uint32_t aCallIndex,
void
BluetoothHfpManager::OnConnectSuccess()
{
nsCOMPtr<nsIRILContentHelper> ril =
nsCOMPtr<nsITelephonyProvider> provider =
do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
NS_ENSURE_TRUE_VOID(ril);
ril->EnumerateCalls(mListener->GetCallback());
NS_ENSURE_TRUE_VOID(provider);
provider->EnumerateCalls(mListener->GetListener());
// For active connection request, we need to reply the DOMRequest
if (mRunnable) {

Просмотреть файл

@ -8,7 +8,7 @@
#define mozilla_dom_bluetooth_bluetoothhfpmanager_h__
#include "BluetoothCommon.h"
#include "BluetoothRilListener.h"
#include "BluetoothTelephonyListener.h"
#include "mozilla/ipc/UnixSocket.h"
#include "nsIObserver.h"
@ -110,7 +110,7 @@ private:
enum mozilla::ipc::SocketConnectionStatus mSocketStatus;
nsTArray<Call> mCurrentCallArray;
nsAutoPtr<BluetoothRilListener> mListener;
nsAutoPtr<BluetoothTelephonyListener> mListener;
nsRefPtr<BluetoothReplyRunnable> mRunnable;
};

Просмотреть файл

@ -1,95 +0,0 @@
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "BluetoothRilListener.h"
#include "BluetoothHfpManager.h"
#include "nsRadioInterfaceLayer.h"
#include "nsServiceManagerUtils.h"
#include "nsString.h"
USING_BLUETOOTH_NAMESPACE
class BluetoothRILTelephonyCallback : public nsIRILTelephonyCallback
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIRILTELEPHONYCALLBACK
BluetoothRILTelephonyCallback() { }
};
NS_IMPL_ISUPPORTS1(BluetoothRILTelephonyCallback, nsIRILTelephonyCallback)
NS_IMETHODIMP
BluetoothRILTelephonyCallback::CallStateChanged(uint32_t aCallIndex,
uint16_t aCallState,
const nsAString& aNumber,
bool aIsActive)
{
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
hfp->HandleCallStateChanged(aCallIndex, aCallState, aNumber, true);
return NS_OK;
}
NS_IMETHODIMP
BluetoothRILTelephonyCallback::EnumerateCallState(uint32_t aCallIndex,
uint16_t aCallState,
const nsAString_internal& aNumber,
bool aIsActive,
bool* aResult)
{
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
hfp->HandleCallStateChanged(aCallIndex, aCallState, aNumber, false);
*aResult = true;
return NS_OK;
}
NS_IMETHODIMP
BluetoothRILTelephonyCallback::NotifyError(int32_t aCallIndex,
const nsAString& aError)
{
return NS_OK;
}
BluetoothRilListener::BluetoothRilListener()
{
mRILTelephonyCallback = new BluetoothRILTelephonyCallback();
}
bool
BluetoothRilListener::StartListening()
{
nsCOMPtr<nsIRILContentHelper> ril =
do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
NS_ENSURE_TRUE(ril, false);
nsresult rv = ril->RegisterTelephonyCallback(mRILTelephonyCallback);
NS_ENSURE_SUCCESS(rv, false);
rv = ril->RegisterTelephonyMsg();
NS_ENSURE_SUCCESS(rv, false);
return true;
}
bool
BluetoothRilListener::StopListening()
{
nsCOMPtr<nsIRILContentHelper> ril =
do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
NS_ENSURE_TRUE(ril, false);
nsresult rv = ril->UnregisterTelephonyCallback(mRILTelephonyCallback);
return NS_FAILED(rv) ? false : true;
}
nsIRILTelephonyCallback*
BluetoothRilListener::GetCallback()
{
return mRILTelephonyCallback;
}

Просмотреть файл

@ -0,0 +1,97 @@
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "BluetoothTelephonyListener.h"
#include "BluetoothHfpManager.h"
#include "nsRadioInterfaceLayer.h"
#include "nsServiceManagerUtils.h"
#include "nsString.h"
USING_BLUETOOTH_NAMESPACE
namespace {
class TelephonyListener : public nsITelephonyListener
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSITELEPHONYLISTENER
TelephonyListener() { }
};
NS_IMPL_ISUPPORTS1(TelephonyListener, nsITelephonyListener)
NS_IMETHODIMP
TelephonyListener::CallStateChanged(uint32_t aCallIndex,
uint16_t aCallState,
const nsAString& aNumber,
bool aIsActive)
{
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
hfp->HandleCallStateChanged(aCallIndex, aCallState, aNumber, true);
return NS_OK;
}
NS_IMETHODIMP
TelephonyListener::EnumerateCallState(uint32_t aCallIndex,
uint16_t aCallState,
const nsAString_internal& aNumber,
bool aIsActive,
bool* aResult)
{
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
hfp->HandleCallStateChanged(aCallIndex, aCallState, aNumber, false);
*aResult = true;
return NS_OK;
}
NS_IMETHODIMP
TelephonyListener::NotifyError(int32_t aCallIndex,
const nsAString& aError)
{
return NS_OK;
}
} // anonymous namespace
BluetoothTelephonyListener::BluetoothTelephonyListener()
{
mTelephonyListener = new TelephonyListener();
}
bool
BluetoothTelephonyListener::StartListening()
{
nsCOMPtr<nsITelephonyProvider> provider =
do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
NS_ENSURE_TRUE(provider, false);
nsresult rv = provider->RegisterTelephonyMsg(mTelephonyListener);
NS_ENSURE_SUCCESS(rv, false);
return true;
}
bool
BluetoothTelephonyListener::StopListening()
{
nsCOMPtr<nsITelephonyProvider> provider =
do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
NS_ENSURE_TRUE(provider, false);
nsresult rv = provider->UnregisterTelephonyMsg(mTelephonyListener);
return NS_FAILED(rv) ? false : true;
}
nsITelephonyListener*
BluetoothTelephonyListener::GetListener()
{
return mTelephonyListener;
}

Просмотреть файл

@ -4,28 +4,28 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_bluetooth_bluetoothrillistener_h__
#define mozilla_dom_bluetooth_bluetoothrillistener_h__
#ifndef mozilla_dom_bluetooth_bluetoothtelephonylistener_h__
#define mozilla_dom_bluetooth_bluetoothtelephonylistener_h__
#include "BluetoothCommon.h"
#include "nsCOMPtr.h"
#include "nsIRadioInterfaceLayer.h"
#include "nsITelephonyProvider.h"
BEGIN_BLUETOOTH_NAMESPACE
class BluetoothRilListener
class BluetoothTelephonyListener
{
public:
BluetoothRilListener();
BluetoothTelephonyListener();
bool StartListening();
bool StopListening();
nsIRILTelephonyCallback* GetCallback();
nsITelephonyListener* GetListener();
private:
nsCOMPtr<nsIRILTelephonyCallback> mRILTelephonyCallback;
nsCOMPtr<nsITelephonyListener> mTelephonyListener;
};
END_BLUETOOTH_NAMESPACE

Просмотреть файл

@ -59,7 +59,7 @@ CPPSRCS += \
$(NULL)
ifdef MOZ_B2G_RIL
CPPSRCS += BluetoothRilListener.cpp
CPPSRCS += BluetoothTelephonyListener.cpp
endif
XPIDLSRCS = \

Просмотреть файл

@ -41,7 +41,7 @@ const RILNETWORKINTERFACE_CID =
Components.ID("{3bdd52a9-3965-4130-b569-0ac5afed045e}");
const nsIAudioManager = Ci.nsIAudioManager;
const nsIRadioInterfaceLayer = Ci.nsIRadioInterfaceLayer;
const nsITelephonyProvider = Ci.nsITelephonyProvider;
const kNetworkInterfaceStateChangedTopic = "network-interface-state-changed";
const kSmsReceivedObserverTopic = "sms-received";
@ -164,18 +164,18 @@ XPCOMUtils.defineLazyGetter(this, "PhoneNumberUtils", function () {
function convertRILCallState(state) {
switch (state) {
case RIL.CALL_STATE_ACTIVE:
return nsIRadioInterfaceLayer.CALL_STATE_CONNECTED;
return nsITelephonyProvider.CALL_STATE_CONNECTED;
case RIL.CALL_STATE_HOLDING:
return nsIRadioInterfaceLayer.CALL_STATE_HELD;
return nsITelephonyProvider.CALL_STATE_HELD;
case RIL.CALL_STATE_DIALING:
return nsIRadioInterfaceLayer.CALL_STATE_DIALING;
return nsITelephonyProvider.CALL_STATE_DIALING;
case RIL.CALL_STATE_ALERTING:
return nsIRadioInterfaceLayer.CALL_STATE_ALERTING;
return nsITelephonyProvider.CALL_STATE_ALERTING;
case RIL.CALL_STATE_INCOMING:
case RIL.CALL_STATE_WAITING:
return nsIRadioInterfaceLayer.CALL_STATE_INCOMING;
return nsITelephonyProvider.CALL_STATE_INCOMING;
case RIL.CALL_STATE_BUSY:
return nsIRadioInterfaceLayer.CALL_STATE_BUSY;
return nsITelephonyProvider.CALL_STATE_BUSY;
default:
throw new Error("Unknown rilCallState: " + state);
}
@ -1267,9 +1267,9 @@ RadioInterfaceLayer.prototype = {
_activeCall: null,
updateCallAudioState: function updateCallAudioState(call) {
switch (call.state) {
case nsIRadioInterfaceLayer.CALL_STATE_DIALING: // Fall through...
case nsIRadioInterfaceLayer.CALL_STATE_ALERTING:
case nsIRadioInterfaceLayer.CALL_STATE_CONNECTED:
case nsITelephonyProvider.CALL_STATE_DIALING: // Fall through...
case nsITelephonyProvider.CALL_STATE_ALERTING:
case nsITelephonyProvider.CALL_STATE_CONNECTED:
call.isActive = true;
this._activeCall = call;
gAudioManager.phoneState = nsIAudioManager.PHONE_STATE_IN_CALL;
@ -1280,7 +1280,7 @@ RadioInterfaceLayer.prototype = {
debug("Active call, put audio system into PHONE_STATE_IN_CALL: "
+ gAudioManager.phoneState);
break;
case nsIRadioInterfaceLayer.CALL_STATE_INCOMING:
case nsITelephonyProvider.CALL_STATE_INCOMING:
call.isActive = false;
if (!this._activeCall) {
// We can change the phone state into RINGTONE only when there's
@ -1290,8 +1290,8 @@ RadioInterfaceLayer.prototype = {
+ gAudioManager.phoneState);
}
break;
case nsIRadioInterfaceLayer.CALL_STATE_HELD: // Fall through...
case nsIRadioInterfaceLayer.CALL_STATE_DISCONNECTED:
case nsITelephonyProvider.CALL_STATE_HELD: // Fall through...
case nsITelephonyProvider.CALL_STATE_DISCONNECTED:
call.isActive = false;
if (this._activeCall &&
this._activeCall.callIndex == call.callIndex) {
@ -1350,7 +1350,7 @@ RadioInterfaceLayer.prototype = {
debug("handleCallStateChange: " + JSON.stringify(call));
call.state = convertRILCallState(call.state);
if (call.state == nsIRadioInterfaceLayer.CALL_STATE_DIALING) {
if (call.state == nsITelephonyProvider.CALL_STATE_DIALING) {
gSystemMessenger.broadcastMessage("telephony-new-call", {});
}
this.updateCallAudioState(call);
@ -1362,7 +1362,7 @@ RadioInterfaceLayer.prototype = {
*/
handleCallDisconnected: function handleCallDisconnected(call) {
debug("handleCallDisconnected: " + JSON.stringify(call));
call.state = nsIRadioInterfaceLayer.CALL_STATE_DISCONNECTED;
call.state = nsITelephonyProvider.CALL_STATE_DISCONNECTED;
let duration = ("started" in call && typeof call.started == "number") ?
new Date().getTime() - call.started : 0;
let data = {

Просмотреть файл

@ -28,6 +28,7 @@ XPIDLSRCS = \
nsIDOMTelephony.idl \
nsIDOMTelephonyCall.idl \
nsIDOMCallEvent.idl \
nsITelephonyProvider.idl \
$(NULL)
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -17,12 +17,13 @@
#include "nsContentUtils.h"
#include "nsDOMClassInfo.h"
#include "nsNetUtil.h"
#include "nsRadioInterfaceLayer.h"
#include "nsServiceManagerUtils.h"
#include "nsTArrayHelpers.h"
#include "TelephonyCall.h"
#define NS_RILCONTENTHELPER_CONTRACTID "@mozilla.org/ril/content-helper;1"
USING_TELEPHONY_NAMESPACE
namespace {
@ -33,6 +34,28 @@ TelephonyList* gTelephonyList;
} // anonymous namespace
class Telephony::Listener : public nsITelephonyListener
{
Telephony* mTelephony;
public:
NS_DECL_ISUPPORTS
NS_FORWARD_SAFE_NSITELEPHONYLISTENER(mTelephony)
Listener(Telephony* aTelephony)
: mTelephony(aTelephony)
{
MOZ_ASSERT(mTelephony);
}
void
Disconnect()
{
MOZ_ASSERT(mTelephony);
mTelephony = nullptr;
}
};
Telephony::Telephony()
: mActiveCall(nullptr), mCallsArray(nullptr), mRooted(false)
{
@ -45,11 +68,11 @@ Telephony::Telephony()
Telephony::~Telephony()
{
if (mRILTelephonyCallback) {
mRILTelephonyCallback->Disable();
if (mListener) {
mListener->Disconnect();
if (mRIL) {
mRIL->UnregisterTelephonyCallback(mRILTelephonyCallback);
if (mProvider) {
mProvider->UnregisterTelephonyMsg(mListener);
}
}
@ -72,10 +95,10 @@ Telephony::~Telephony()
// static
already_AddRefed<Telephony>
Telephony::Create(nsPIDOMWindow* aOwner, nsIRILContentHelper* aRIL)
Telephony::Create(nsPIDOMWindow* aOwner, nsITelephonyProvider* aProvider)
{
NS_ASSERTION(aOwner, "Null owner!");
NS_ASSERTION(aRIL, "Null RIL!");
NS_ASSERTION(aProvider, "Null provider!");
nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(aOwner);
NS_ENSURE_TRUE(sgo, nullptr);
@ -87,16 +110,13 @@ Telephony::Create(nsPIDOMWindow* aOwner, nsIRILContentHelper* aRIL)
telephony->BindToOwner(aOwner);
telephony->mRIL = aRIL;
telephony->mRILTelephonyCallback = new RILTelephonyCallback(telephony);
telephony->mProvider = aProvider;
telephony->mListener = new Listener(telephony);
nsresult rv = aRIL->EnumerateCalls(telephony->mRILTelephonyCallback);
nsresult rv = aProvider->EnumerateCalls(telephony->mListener);
NS_ENSURE_SUCCESS(rv, nullptr);
rv = aRIL->RegisterTelephonyCallback(telephony->mRILTelephonyCallback);
NS_ENSURE_SUCCESS(rv, nullptr);
rv = aRIL->RegisterTelephonyMsg();
rv = aProvider->RegisterTelephonyMsg(telephony->mListener);
NS_ENSURE_SUCCESS(rv, nullptr);
return telephony.forget();
@ -107,7 +127,7 @@ Telephony::CreateNewDialingCall(const nsAString& aNumber)
{
nsRefPtr<TelephonyCall> call =
TelephonyCall::Create(this, aNumber,
nsIRadioInterfaceLayer::CALL_STATE_DIALING);
nsITelephonyProvider::CALL_STATE_DIALING);
NS_ASSERTION(call, "This should never fail!");
NS_ASSERTION(mCalls.Contains(call), "Should have auto-added new call!");
@ -125,9 +145,9 @@ Telephony::NoteDialedCallFromOtherInstance(const nsAString& aNumber)
nsresult
Telephony::NotifyCallsChanged(TelephonyCall* aCall)
{
if (aCall->CallState() == nsIRadioInterfaceLayer::CALL_STATE_DIALING ||
aCall->CallState() == nsIRadioInterfaceLayer::CALL_STATE_ALERTING ||
aCall->CallState() == nsIRadioInterfaceLayer::CALL_STATE_CONNECTED) {
if (aCall->CallState() == nsITelephonyProvider::CALL_STATE_DIALING ||
aCall->CallState() == nsITelephonyProvider::CALL_STATE_ALERTING ||
aCall->CallState() == nsITelephonyProvider::CALL_STATE_CONNECTED) {
NS_ASSERTION(!mActiveCall, "Already have an active call!");
mActiveCall = aCall;
} else if (mActiveCall && mActiveCall->CallIndex() == aCall->CallIndex()) {
@ -147,7 +167,7 @@ Telephony::DialInternal(bool isEmergency,
for (uint32_t index = 0; index < mCalls.Length(); index++) {
const nsRefPtr<TelephonyCall>& tempCall = mCalls[index];
if (tempCall->IsOutgoing() &&
tempCall->CallState() < nsIRadioInterfaceLayer::CALL_STATE_CONNECTED) {
tempCall->CallState() < nsITelephonyProvider::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!");
@ -157,9 +177,9 @@ Telephony::DialInternal(bool isEmergency,
nsresult rv;
if (isEmergency) {
rv = mRIL->DialEmergency(aNumber);
rv = mProvider->DialEmergency(aNumber);
} else {
rv = mRIL->Dial(aNumber);
rv = mProvider->Dial(aNumber);
}
NS_ENSURE_SUCCESS(rv, rv);
@ -185,6 +205,8 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(Telephony,
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mCalls[i]");
cb.NoteXPCOMChild(tmp->mCalls[index]->ToISupports());
}
// Don't traverse mListener because it doesn't keep any reference to
// Telephony but a raw pointer instead.
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(Telephony,
@ -209,7 +231,7 @@ NS_IMPL_RELEASE_INHERITED(Telephony, nsDOMEventTargetHelper)
DOMCI_DATA(Telephony, Telephony)
NS_IMPL_ISUPPORTS1(Telephony::RILTelephonyCallback, nsIRILTelephonyCallback)
NS_IMPL_ISUPPORTS1(Telephony::Listener, nsITelephonyListener)
NS_IMETHODIMP
Telephony::Dial(const nsAString& aNumber, nsIDOMTelephonyCall** aResult)
@ -230,7 +252,7 @@ Telephony::DialEmergency(const nsAString& aNumber, nsIDOMTelephonyCall** aResult
NS_IMETHODIMP
Telephony::GetMuted(bool* aMuted)
{
nsresult rv = mRIL->GetMicrophoneMuted(aMuted);
nsresult rv = mProvider->GetMicrophoneMuted(aMuted);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
@ -239,7 +261,7 @@ Telephony::GetMuted(bool* aMuted)
NS_IMETHODIMP
Telephony::SetMuted(bool aMuted)
{
nsresult rv = mRIL->SetMicrophoneMuted(aMuted);
nsresult rv = mProvider->SetMicrophoneMuted(aMuted);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
@ -248,7 +270,7 @@ Telephony::SetMuted(bool aMuted)
NS_IMETHODIMP
Telephony::GetSpeakerEnabled(bool* aSpeakerEnabled)
{
nsresult rv = mRIL->GetSpeakerEnabled(aSpeakerEnabled);
nsresult rv = mProvider->GetSpeakerEnabled(aSpeakerEnabled);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
@ -257,7 +279,7 @@ Telephony::GetSpeakerEnabled(bool* aSpeakerEnabled)
NS_IMETHODIMP
Telephony::SetSpeakerEnabled(bool aSpeakerEnabled)
{
nsresult rv = mRIL->SetSpeakerEnabled(aSpeakerEnabled);
nsresult rv = mProvider->SetSpeakerEnabled(aSpeakerEnabled);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
@ -324,7 +346,7 @@ Telephony::StartTone(const nsAString& aDTMFChar)
return NS_ERROR_INVALID_ARG;
}
nsresult rv = mRIL->StartTone(aDTMFChar);
nsresult rv = mProvider->StartTone(aDTMFChar);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
@ -333,7 +355,7 @@ Telephony::StartTone(const nsAString& aDTMFChar)
NS_IMETHODIMP
Telephony::StopTone()
{
nsresult rv = mRIL->StopTone();
nsresult rv = mProvider->StopTone();
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
@ -357,7 +379,7 @@ Telephony::CallStateChanged(uint32_t aCallIndex, uint16_t aCallState,
if (tempCall->CallIndex() == kOutgoingPlaceholderCallIndex) {
NS_ASSERTION(!outgoingCall, "More than one outgoing call not supported!");
NS_ASSERTION(tempCall->CallState() ==
nsIRadioInterfaceLayer::CALL_STATE_DIALING,
nsITelephonyProvider::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.
@ -374,7 +396,7 @@ Telephony::CallStateChanged(uint32_t aCallIndex, uint16_t aCallState,
// an outgoing call then we must be seeing a status update for our outgoing
// call.
if (!modifiedCall &&
aCallState != nsIRadioInterfaceLayer::CALL_STATE_INCOMING &&
aCallState != nsITelephonyProvider::CALL_STATE_INCOMING &&
outgoingCall) {
outgoingCall->UpdateCallIndex(aCallIndex);
modifiedCall.swap(outgoingCall);
@ -396,7 +418,7 @@ Telephony::CallStateChanged(uint32_t aCallIndex, uint16_t aCallState,
// Didn't know anything about this call before now.
if (aCallState == nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTED) {
if (aCallState == nsITelephonyProvider::CALL_STATE_DISCONNECTED) {
// Do nothing since we didn't know anything about it before now and it's
// been ended already.
return NS_OK;
@ -408,7 +430,7 @@ Telephony::CallStateChanged(uint32_t aCallIndex, uint16_t aCallState,
NS_ASSERTION(mCalls.Contains(call), "Should have auto-added new call!");
if (aCallState == nsIRadioInterfaceLayer::CALL_STATE_INCOMING) {
if (aCallState == nsITelephonyProvider::CALL_STATE_INCOMING) {
nsresult rv = DispatchCallEvent(NS_LITERAL_STRING("incoming"), call);
NS_ENSURE_SUCCESS(rv, rv);
}
@ -518,7 +540,7 @@ NS_NewTelephony(nsPIDOMWindow* aWindow, nsIDOMTelephony** aTelephony)
return NS_OK;
}
nsCOMPtr<nsIRILContentHelper> ril =
nsCOMPtr<nsITelephonyProvider> ril =
do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
NS_ENSURE_TRUE(ril, NS_ERROR_UNEXPECTED);

Просмотреть файл

@ -11,7 +11,7 @@
#include "nsIDOMTelephony.h"
#include "nsIDOMTelephonyCall.h"
#include "nsIRadioInterfaceLayer.h"
#include "nsITelephonyProvider.h"
class nsIScriptContext;
class nsPIDOMWindow;
@ -21,30 +21,17 @@ BEGIN_TELEPHONY_NAMESPACE
class Telephony : public nsDOMEventTargetHelper,
public nsIDOMTelephony
{
class RILTelephonyCallback : public nsIRILTelephonyCallback
{
Telephony* mTelephony;
/**
* Class Telephony doesn't actually inherit nsITelephonyListener.
* Instead, it owns an nsITelephonyListener derived instance mListener
* and passes it to nsITelephonyProvider. The onreceived events are first
* delivered to mListener and then forwarded to its owner, Telephony. See
* also bug 775997 comment #51.
*/
class Listener;
public:
NS_DECL_ISUPPORTS
NS_FORWARD_SAFE_NSIRILTELEPHONYCALLBACK(mTelephony)
RILTelephonyCallback(Telephony* aTelephony)
: mTelephony(aTelephony)
{
NS_ASSERTION(mTelephony, "Null pointer!");
}
void
Disable()
{
NS_ASSERTION(mTelephony, "Disable called more than once!");
mTelephony = nullptr;
}
};
nsCOMPtr<nsIRILContentHelper> mRIL;
nsRefPtr<RILTelephonyCallback> mRILTelephonyCallback;
nsCOMPtr<nsITelephonyProvider> mProvider;
nsRefPtr<Listener> mListener;
TelephonyCall* mActiveCall;
nsTArray<nsRefPtr<TelephonyCall> > mCalls;
@ -58,14 +45,15 @@ class Telephony : public nsDOMEventTargetHelper,
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIDOMTELEPHONY
NS_DECL_NSIRILTELEPHONYCALLBACK
NS_DECL_NSITELEPHONYLISTENER
NS_FORWARD_NSIDOMEVENTTARGET(nsDOMEventTargetHelper::)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(
Telephony,
nsDOMEventTargetHelper)
static already_AddRefed<Telephony>
Create(nsPIDOMWindow* aOwner, nsIRILContentHelper* aRIL);
Create(nsPIDOMWindow* aOwner, nsITelephonyProvider* aProvider);
nsIDOMEventTarget*
ToIDOMEventTarget() const
@ -98,10 +86,10 @@ public:
NotifyCallsChanged(aCall);
}
nsIRILContentHelper*
RIL() const
nsITelephonyProvider*
Provider() const
{
return mRIL;
return mProvider;
}
private:

Просмотреть файл

@ -12,6 +12,7 @@
#include "GeneratedEvents.h"
#include "nsDOMClassInfo.h"
#include "Telephony.h"
#include "nsITelephonyProvider.h"
USING_TELEPHONY_NAMESPACE
@ -38,6 +39,14 @@ TelephonyCall::Create(Telephony* aTelephony, const nsAString& aNumber,
return call.forget();
}
TelephonyCall::TelephonyCall()
: mCallIndex(kOutgoingPlaceholderCallIndex),
mCallState(nsITelephonyProvider::CALL_STATE_UNKNOWN),
mLive(false),
mOutgoing(false)
{
}
void
TelephonyCall::ChangeStateInternal(uint16_t aCallState, bool aFireEvents)
{
@ -45,37 +54,37 @@ TelephonyCall::ChangeStateInternal(uint16_t aCallState, bool aFireEvents)
nsString stateString;
switch (aCallState) {
case nsIRadioInterfaceLayer::CALL_STATE_DIALING:
case nsITelephonyProvider::CALL_STATE_DIALING:
stateString.AssignLiteral("dialing");
break;
case nsIRadioInterfaceLayer::CALL_STATE_ALERTING:
case nsITelephonyProvider::CALL_STATE_ALERTING:
stateString.AssignLiteral("alerting");
break;
case nsIRadioInterfaceLayer::CALL_STATE_BUSY:
case nsITelephonyProvider::CALL_STATE_BUSY:
stateString.AssignLiteral("busy");
break;
case nsIRadioInterfaceLayer::CALL_STATE_CONNECTING:
case nsITelephonyProvider::CALL_STATE_CONNECTING:
stateString.AssignLiteral("connecting");
break;
case nsIRadioInterfaceLayer::CALL_STATE_CONNECTED:
case nsITelephonyProvider::CALL_STATE_CONNECTED:
stateString.AssignLiteral("connected");
break;
case nsIRadioInterfaceLayer::CALL_STATE_HOLDING:
case nsITelephonyProvider::CALL_STATE_HOLDING:
stateString.AssignLiteral("holding");
break;
case nsIRadioInterfaceLayer::CALL_STATE_HELD:
case nsITelephonyProvider::CALL_STATE_HELD:
stateString.AssignLiteral("held");
break;
case nsIRadioInterfaceLayer::CALL_STATE_RESUMING:
case nsITelephonyProvider::CALL_STATE_RESUMING:
stateString.AssignLiteral("resuming");
break;
case nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTING:
case nsITelephonyProvider::CALL_STATE_DISCONNECTING:
stateString.AssignLiteral("disconnecting");
break;
case nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTED:
case nsITelephonyProvider::CALL_STATE_DISCONNECTED:
stateString.AssignLiteral("disconnected");
break;
case nsIRadioInterfaceLayer::CALL_STATE_INCOMING:
case nsITelephonyProvider::CALL_STATE_INCOMING:
stateString.AssignLiteral("incoming");
break;
default:
@ -85,11 +94,11 @@ TelephonyCall::ChangeStateInternal(uint16_t aCallState, bool aFireEvents)
mState = stateString;
mCallState = aCallState;
if (aCallState == nsIRadioInterfaceLayer::CALL_STATE_DIALING) {
if (aCallState == nsITelephonyProvider::CALL_STATE_DIALING) {
mOutgoing = true;
}
if (aCallState == nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTED) {
if (aCallState == nsITelephonyProvider::CALL_STATE_DISCONNECTED) {
NS_ASSERTION(mLive, "Should be live!");
mTelephony->RemoveCall(this);
mLive = false;
@ -142,7 +151,7 @@ TelephonyCall::NotifyError(const nsAString& aError)
mError = DOMError::CreateWithName(aError);
// Do the state transitions
ChangeStateInternal(nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTED, true);
ChangeStateInternal(nsITelephonyProvider::CALL_STATE_DISCONNECTED, true);
nsresult rv = DispatchCallEvent(NS_LITERAL_STRING("error"), this);
if (NS_FAILED(rv)) {
@ -188,63 +197,63 @@ TelephonyCall::GetError(nsIDOMDOMError** aError)
NS_IMETHODIMP
TelephonyCall::Answer()
{
if (mCallState != nsIRadioInterfaceLayer::CALL_STATE_INCOMING) {
if (mCallState != nsITelephonyProvider::CALL_STATE_INCOMING) {
NS_WARNING("Answer on non-incoming call ignored!");
return NS_OK;
}
nsresult rv = mTelephony->RIL()->AnswerCall(mCallIndex);
nsresult rv = mTelephony->Provider()->AnswerCall(mCallIndex);
NS_ENSURE_SUCCESS(rv, rv);
ChangeStateInternal(nsIRadioInterfaceLayer::CALL_STATE_CONNECTING, true);
ChangeStateInternal(nsITelephonyProvider::CALL_STATE_CONNECTING, true);
return NS_OK;
}
NS_IMETHODIMP
TelephonyCall::HangUp()
{
if (mCallState == nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTING ||
mCallState == nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTED) {
if (mCallState == nsITelephonyProvider::CALL_STATE_DISCONNECTING ||
mCallState == nsITelephonyProvider::CALL_STATE_DISCONNECTED) {
NS_WARNING("HangUp on previously disconnected call ignored!");
return NS_OK;
}
nsresult rv = mCallState == nsIRadioInterfaceLayer::CALL_STATE_INCOMING ?
mTelephony->RIL()->RejectCall(mCallIndex) :
mTelephony->RIL()->HangUp(mCallIndex);
nsresult rv = mCallState == nsITelephonyProvider::CALL_STATE_INCOMING ?
mTelephony->Provider()->RejectCall(mCallIndex) :
mTelephony->Provider()->HangUp(mCallIndex);
NS_ENSURE_SUCCESS(rv, rv);
ChangeStateInternal(nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTING, true);
ChangeStateInternal(nsITelephonyProvider::CALL_STATE_DISCONNECTING, true);
return NS_OK;
}
NS_IMETHODIMP
TelephonyCall::Hold()
{
if (mCallState != nsIRadioInterfaceLayer::CALL_STATE_CONNECTED) {
if (mCallState != nsITelephonyProvider::CALL_STATE_CONNECTED) {
NS_WARNING("Hold non-connected call ignored!");
return NS_OK;
}
nsresult rv = mTelephony->RIL()->HoldCall(mCallIndex);
nsresult rv = mTelephony->Provider()->HoldCall(mCallIndex);
NS_ENSURE_SUCCESS(rv,rv);
ChangeStateInternal(nsIRadioInterfaceLayer::CALL_STATE_HOLDING, true);
ChangeStateInternal(nsITelephonyProvider::CALL_STATE_HOLDING, true);
return NS_OK;
}
NS_IMETHODIMP
TelephonyCall::Resume()
{
if (mCallState != nsIRadioInterfaceLayer::CALL_STATE_HELD) {
if (mCallState != nsITelephonyProvider::CALL_STATE_HELD) {
NS_WARNING("Resume non-held call ignored!");
return NS_OK;
}
nsresult rv = mTelephony->RIL()->ResumeCall(mCallIndex);
nsresult rv = mTelephony->Provider()->ResumeCall(mCallIndex);
NS_ENSURE_SUCCESS(rv,rv);
ChangeStateInternal(nsIRadioInterfaceLayer::CALL_STATE_RESUMING, true);
ChangeStateInternal(nsITelephonyProvider::CALL_STATE_RESUMING, true);
return NS_OK;
}

Просмотреть файл

@ -10,7 +10,6 @@
#include "TelephonyCommon.h"
#include "nsIDOMTelephonyCall.h"
#include "nsIRadioInterfaceLayer.h"
class nsPIDOMWindow;
@ -90,10 +89,7 @@ public:
NotifyError(const nsAString& aError);
private:
TelephonyCall()
: mCallIndex(kOutgoingPlaceholderCallIndex),
mCallState(nsIRadioInterfaceLayer::CALL_STATE_UNKNOWN), mLive(false), mOutgoing(false)
{ }
TelephonyCall();
~TelephonyCall()
{ }