2013-05-31 23:53:06 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2012-01-09 14:28:47 -08:00
|
|
|
|
|
|
|
#include "Telephony.h"
|
2014-09-21 22:34:00 -07:00
|
|
|
|
|
|
|
#include "mozilla/Preferences.h"
|
2014-06-10 18:23:34 -07:00
|
|
|
#include "mozilla/dom/CallEvent.h"
|
2014-09-21 22:34:00 -07:00
|
|
|
#include "mozilla/dom/MozMobileConnectionBinding.h"
|
2014-02-26 22:12:30 -08:00
|
|
|
#include "mozilla/dom/Promise.h"
|
2014-09-21 22:34:00 -07:00
|
|
|
#include "mozilla/dom/TelephonyBinding.h"
|
|
|
|
|
2012-02-24 05:14:37 -08:00
|
|
|
#include "nsCharSeparatedTokenizer.h"
|
2012-01-09 14:28:47 -08:00
|
|
|
#include "nsContentUtils.h"
|
2014-09-21 22:34:00 -07:00
|
|
|
#include "nsIPermissionManager.h"
|
|
|
|
#include "nsIURI.h"
|
2012-02-24 05:14:37 -08:00
|
|
|
#include "nsNetUtil.h"
|
2014-09-21 22:34:00 -07:00
|
|
|
#include "nsPIDOMWindow.h"
|
2013-01-27 23:39:50 -08:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2013-05-09 03:44:13 -07:00
|
|
|
#include "nsThreadUtils.h"
|
2012-01-09 14:28:47 -08:00
|
|
|
|
2013-07-15 01:27:19 -07:00
|
|
|
#include "CallsList.h"
|
2012-01-09 14:28:47 -08:00
|
|
|
#include "TelephonyCall.h"
|
2013-07-06 03:24:55 -07:00
|
|
|
#include "TelephonyCallGroup.h"
|
2014-04-09 23:25:42 -07:00
|
|
|
#include "TelephonyCallId.h"
|
2014-10-14 23:50:00 -07:00
|
|
|
#include "TelephonyDialCallback.h"
|
2012-01-09 14:28:47 -08:00
|
|
|
|
2014-09-21 00:24:44 -07:00
|
|
|
// Service instantiation
|
|
|
|
#include "ipc/TelephonyIPCService.h"
|
|
|
|
#if defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_RIL)
|
|
|
|
#include "nsIGonkTelephonyService.h"
|
|
|
|
#endif
|
|
|
|
#include "nsXULAppAPI.h" // For XRE_GetProcessType()
|
|
|
|
|
2013-05-09 03:44:13 -07:00
|
|
|
using namespace mozilla::dom;
|
2014-09-21 22:34:00 -07:00
|
|
|
using namespace mozilla::dom::telephony;
|
2013-09-06 23:19:53 -07:00
|
|
|
using mozilla::ErrorResult;
|
2012-01-09 14:28:47 -08:00
|
|
|
|
2013-03-06 01:53:23 -08:00
|
|
|
class Telephony::Listener : public nsITelephonyListener
|
|
|
|
{
|
|
|
|
Telephony* mTelephony;
|
|
|
|
|
2014-06-23 12:56:07 -07:00
|
|
|
virtual ~Listener() {}
|
|
|
|
|
2013-03-06 01:53:23 -08:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_FORWARD_SAFE_NSITELEPHONYLISTENER(mTelephony)
|
|
|
|
|
2014-09-01 15:26:43 -07:00
|
|
|
explicit Listener(Telephony* aTelephony)
|
2013-03-06 01:53:23 -08:00
|
|
|
: mTelephony(aTelephony)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mTelephony);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Disconnect()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mTelephony);
|
|
|
|
mTelephony = nullptr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-12-16 14:57:23 -08:00
|
|
|
Telephony::Telephony(nsPIDOMWindow* aOwner)
|
|
|
|
: DOMEventTargetHelper(aOwner)
|
2013-05-09 03:44:13 -07:00
|
|
|
{
|
2014-12-16 14:57:23 -08:00
|
|
|
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aOwner);
|
|
|
|
MOZ_ASSERT(global);
|
2013-05-09 03:44:13 -07:00
|
|
|
|
2014-12-16 14:57:23 -08:00
|
|
|
ErrorResult rv;
|
|
|
|
nsRefPtr<Promise> promise = Promise::Create(global, rv);
|
|
|
|
MOZ_ASSERT(!rv.Failed());
|
2013-05-09 03:44:13 -07:00
|
|
|
|
2014-12-16 14:57:23 -08:00
|
|
|
mReadyPromise = promise;
|
2012-02-24 05:14:37 -08:00
|
|
|
}
|
|
|
|
|
2012-01-09 14:28:47 -08:00
|
|
|
Telephony::~Telephony()
|
|
|
|
{
|
2013-08-20 00:57:19 -07:00
|
|
|
Shutdown();
|
2012-01-09 14:28:47 -08:00
|
|
|
}
|
|
|
|
|
2013-08-20 00:57:19 -07:00
|
|
|
void
|
|
|
|
Telephony::Shutdown()
|
|
|
|
{
|
|
|
|
if (mListener) {
|
|
|
|
mListener->Disconnect();
|
|
|
|
|
2014-06-03 07:15:30 -07:00
|
|
|
if (mService) {
|
|
|
|
mService->UnregisterListener(mListener);
|
|
|
|
mService = nullptr;
|
2013-08-20 00:57:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
mListener = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-15 01:27:19 -07:00
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 07:13:33 -07:00
|
|
|
Telephony::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-07-15 01:27:19 -07:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 07:13:33 -07:00
|
|
|
return TelephonyBinding::Wrap(aCx, this, aGivenProto);
|
2013-07-15 01:27:19 -07:00
|
|
|
}
|
|
|
|
|
2012-01-09 14:28:47 -08:00
|
|
|
// static
|
|
|
|
already_AddRefed<Telephony>
|
2013-07-12 07:36:13 -07:00
|
|
|
Telephony::Create(nsPIDOMWindow* aOwner, ErrorResult& aRv)
|
2012-01-09 14:28:47 -08:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aOwner, "Null owner!");
|
2013-07-12 07:36:13 -07:00
|
|
|
|
2014-06-03 07:15:25 -07:00
|
|
|
nsCOMPtr<nsITelephonyService> ril =
|
|
|
|
do_GetService(TELEPHONY_SERVICE_CONTRACTID);
|
2013-07-12 07:36:13 -07:00
|
|
|
if (!ril) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-01-09 14:28:47 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(aOwner);
|
2013-07-12 07:36:13 -07:00
|
|
|
if (!sgo) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-01-09 14:28:47 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptContext> scriptContext = sgo->GetContext();
|
2013-07-12 07:36:13 -07:00
|
|
|
if (!scriptContext) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-01-09 14:28:47 -08:00
|
|
|
|
2014-01-06 18:53:23 -08:00
|
|
|
nsRefPtr<Telephony> telephony = new Telephony(aOwner);
|
2012-03-13 15:11:16 -07:00
|
|
|
|
2014-06-03 07:15:30 -07:00
|
|
|
telephony->mService = ril;
|
2013-03-06 01:53:23 -08:00
|
|
|
telephony->mListener = new Listener(telephony);
|
2013-07-15 01:27:19 -07:00
|
|
|
telephony->mCallsList = new CallsList(telephony);
|
2013-07-06 03:24:55 -07:00
|
|
|
telephony->mGroup = TelephonyCallGroup::Create(telephony);
|
2012-01-09 14:28:47 -08:00
|
|
|
|
2013-07-12 07:36:13 -07:00
|
|
|
nsresult rv = ril->EnumerateCalls(telephony->mListener);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-01-09 14:28:47 -08:00
|
|
|
|
|
|
|
return telephony.forget();
|
|
|
|
}
|
|
|
|
|
2013-10-31 05:05:51 -07:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
Telephony::IsValidNumber(const nsAString& aNumber)
|
|
|
|
{
|
|
|
|
return !aNumber.IsEmpty();
|
|
|
|
}
|
|
|
|
|
2013-10-31 05:05:51 -07:00
|
|
|
// static
|
|
|
|
uint32_t
|
|
|
|
Telephony::GetNumServices() {
|
|
|
|
return mozilla::Preferences::GetInt("ril.numRadioInterfaces", 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
bool
|
|
|
|
Telephony::IsValidServiceId(uint32_t aServiceId)
|
|
|
|
{
|
|
|
|
return aServiceId < GetNumServices();
|
|
|
|
}
|
|
|
|
|
2013-10-31 05:05:51 -07:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
Telephony::IsActiveState(uint16_t aCallState) {
|
2014-06-03 07:15:25 -07:00
|
|
|
return aCallState == nsITelephonyService::CALL_STATE_DIALING ||
|
|
|
|
aCallState == nsITelephonyService::CALL_STATE_ALERTING ||
|
|
|
|
aCallState == nsITelephonyService::CALL_STATE_CONNECTED;
|
2013-10-31 05:05:51 -07:00
|
|
|
}
|
|
|
|
|
2013-10-31 05:05:51 -07:00
|
|
|
uint32_t
|
2015-04-09 10:22:37 -07:00
|
|
|
Telephony::GetServiceId(const Optional<uint32_t>& aServiceId,
|
|
|
|
bool aGetIfActiveCall)
|
2013-10-31 05:05:51 -07:00
|
|
|
{
|
|
|
|
if (aServiceId.WasPassed()) {
|
|
|
|
return aServiceId.Value();
|
2015-04-09 10:22:37 -07:00
|
|
|
} else if (aGetIfActiveCall) {
|
|
|
|
nsTArray<nsRefPtr<TelephonyCall> > &calls = mCalls;
|
|
|
|
if (mGroup->CallState() == nsITelephonyService::CALL_STATE_CONNECTED) {
|
|
|
|
calls = mGroup->CallsArray();
|
|
|
|
}
|
|
|
|
for (uint32_t i = 0; i < calls.Length(); i++) {
|
|
|
|
if (IsActiveState(calls[i]->CallState())) {
|
|
|
|
return calls[i]->mServiceId;
|
|
|
|
}
|
|
|
|
}
|
2013-10-31 05:05:51 -07:00
|
|
|
}
|
2015-04-09 10:22:37 -07:00
|
|
|
|
|
|
|
uint32_t serviceId = 0;
|
|
|
|
mService->GetDefaultServiceId(&serviceId);
|
|
|
|
return serviceId;
|
2013-10-31 05:05:51 -07:00
|
|
|
}
|
|
|
|
|
2013-10-31 05:05:51 -07:00
|
|
|
bool
|
|
|
|
Telephony::HasDialingCall()
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < mCalls.Length(); i++) {
|
|
|
|
const nsRefPtr<TelephonyCall>& call = mCalls[i];
|
2014-06-03 07:15:25 -07:00
|
|
|
if (call->CallState() > nsITelephonyService::CALL_STATE_UNKNOWN &&
|
|
|
|
call->CallState() < nsITelephonyService::CALL_STATE_CONNECTED) {
|
2013-10-31 05:05:51 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-26 22:12:30 -08:00
|
|
|
already_AddRefed<Promise>
|
2013-10-31 05:05:51 -07:00
|
|
|
Telephony::DialInternal(uint32_t aServiceId, const nsAString& aNumber,
|
2014-07-18 18:31:11 -07:00
|
|
|
bool aEmergency, ErrorResult& aRv)
|
2012-07-20 05:08:24 -07:00
|
|
|
{
|
2014-02-26 22:12:30 -08:00
|
|
|
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
|
|
|
|
if (!global) {
|
2014-02-26 11:27:54 -08:00
|
|
|
return nullptr;
|
2014-02-26 11:03:56 -08:00
|
|
|
}
|
|
|
|
|
2014-07-18 18:31:11 -07:00
|
|
|
nsRefPtr<Promise> promise = Promise::Create(global, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-02-26 22:12:30 -08:00
|
|
|
|
|
|
|
if (!IsValidNumber(aNumber) || !IsValidServiceId(aServiceId)) {
|
2014-06-03 08:38:38 -07:00
|
|
|
promise->MaybeReject(NS_ERROR_DOM_INVALID_ACCESS_ERR);
|
2014-02-26 22:12:30 -08:00
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2013-10-31 05:05:51 -07:00
|
|
|
// We only support one outgoing call at a time.
|
|
|
|
if (HasDialingCall()) {
|
2014-06-03 08:38:38 -07:00
|
|
|
promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
|
2014-02-26 22:12:30 -08:00
|
|
|
return promise.forget();
|
2012-07-20 05:08:24 -07:00
|
|
|
}
|
|
|
|
|
2014-10-14 23:50:00 -07:00
|
|
|
nsCOMPtr<nsITelephonyDialCallback> callback =
|
2014-12-22 23:46:09 -08:00
|
|
|
new TelephonyDialCallback(GetOwner(), this, promise);
|
2014-09-21 22:34:00 -07:00
|
|
|
|
2014-06-24 03:52:00 -07:00
|
|
|
nsresult rv = mService->Dial(aServiceId, aNumber, aEmergency, callback);
|
2013-07-15 01:27:19 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
2014-06-03 08:38:38 -07:00
|
|
|
promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
|
2014-02-26 22:12:30 -08:00
|
|
|
return promise.forget();
|
2014-02-26 11:27:54 -08:00
|
|
|
}
|
|
|
|
|
2014-02-26 22:12:30 -08:00
|
|
|
return promise.forget();
|
2012-07-20 05:08:24 -07:00
|
|
|
}
|
|
|
|
|
2015-01-08 00:33:51 -08:00
|
|
|
already_AddRefed<TelephonyCallId>
|
|
|
|
Telephony::CreateCallId(nsITelephonyCallInfo *aInfo)
|
|
|
|
{
|
|
|
|
nsAutoString number;
|
|
|
|
nsAutoString name;
|
|
|
|
uint16_t numberPresentation;
|
|
|
|
uint16_t namePresentation;
|
|
|
|
|
|
|
|
aInfo->GetNumber(number);
|
|
|
|
aInfo->GetName(name);
|
|
|
|
aInfo->GetNumberPresentation(&numberPresentation);
|
|
|
|
aInfo->GetNamePresentation(&namePresentation);
|
|
|
|
|
|
|
|
return CreateCallId(number, numberPresentation, name, namePresentation);
|
|
|
|
}
|
|
|
|
|
2014-06-24 03:52:00 -07:00
|
|
|
already_AddRefed<TelephonyCallId>
|
|
|
|
Telephony::CreateCallId(const nsAString& aNumber, uint16_t aNumberPresentation,
|
|
|
|
const nsAString& aName, uint16_t aNamePresentation)
|
|
|
|
{
|
|
|
|
nsRefPtr<TelephonyCallId> id =
|
|
|
|
new TelephonyCallId(GetOwner(), aNumber, aNumberPresentation,
|
|
|
|
aName, aNamePresentation);
|
|
|
|
|
|
|
|
return id.forget();
|
|
|
|
}
|
|
|
|
|
2013-10-31 05:05:51 -07:00
|
|
|
already_AddRefed<TelephonyCall>
|
2014-06-24 03:52:00 -07:00
|
|
|
Telephony::CreateCall(TelephonyCallId* aId, uint32_t aServiceId,
|
|
|
|
uint32_t aCallIndex, uint16_t aCallState,
|
|
|
|
bool aEmergency, bool aConference,
|
|
|
|
bool aSwitchable, bool aMergeable)
|
2013-10-31 05:05:51 -07:00
|
|
|
{
|
2014-06-24 03:52:00 -07:00
|
|
|
// We don't have to create an already ended call.
|
|
|
|
if (aCallState == nsITelephonyService::CALL_STATE_DISCONNECTED) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-10-31 05:05:51 -07:00
|
|
|
nsRefPtr<TelephonyCall> call =
|
2014-06-24 03:52:00 -07:00
|
|
|
TelephonyCall::Create(this, aId, aServiceId, aCallIndex, aCallState,
|
|
|
|
aEmergency, aConference, aSwitchable, aMergeable);
|
2013-10-31 05:05:51 -07:00
|
|
|
|
2014-06-24 03:52:00 -07:00
|
|
|
NS_ASSERTION(call, "This should never fail!");
|
|
|
|
NS_ASSERTION(aConference ? mGroup->CallsArray().Contains(call)
|
|
|
|
: mCalls.Contains(call),
|
|
|
|
"Should have auto-added new call!");
|
2013-10-31 05:05:51 -07:00
|
|
|
|
|
|
|
return call.forget();
|
|
|
|
}
|
|
|
|
|
2014-07-21 10:17:00 -07:00
|
|
|
nsresult
|
|
|
|
Telephony::NotifyEvent(const nsAString& aType)
|
|
|
|
{
|
|
|
|
return DispatchCallEvent(aType, nullptr);
|
|
|
|
}
|
|
|
|
|
2013-10-31 05:05:51 -07:00
|
|
|
nsresult
|
|
|
|
Telephony::NotifyCallsChanged(TelephonyCall* aCall)
|
|
|
|
{
|
|
|
|
return DispatchCallEvent(NS_LITERAL_STRING("callschanged"), aCall);
|
|
|
|
}
|
|
|
|
|
2013-07-06 03:24:55 -07:00
|
|
|
already_AddRefed<TelephonyCall>
|
2013-10-31 05:05:51 -07:00
|
|
|
Telephony::GetCall(uint32_t aServiceId, uint32_t aCallIndex)
|
2013-07-06 03:24:55 -07:00
|
|
|
{
|
|
|
|
nsRefPtr<TelephonyCall> call;
|
|
|
|
|
2013-10-31 05:05:51 -07:00
|
|
|
for (uint32_t i = 0; i < mCalls.Length(); i++) {
|
|
|
|
nsRefPtr<TelephonyCall>& tempCall = mCalls[i];
|
|
|
|
if (tempCall->ServiceId() == aServiceId &&
|
|
|
|
tempCall->CallIndex() == aCallIndex) {
|
2013-07-06 03:24:55 -07:00
|
|
|
call = tempCall;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return call.forget();
|
|
|
|
}
|
|
|
|
|
2013-10-31 05:05:51 -07:00
|
|
|
already_AddRefed<TelephonyCall>
|
2013-10-31 05:05:51 -07:00
|
|
|
Telephony::GetCallFromEverywhere(uint32_t aServiceId, uint32_t aCallIndex)
|
2013-10-31 05:05:51 -07:00
|
|
|
{
|
2013-10-31 05:05:51 -07:00
|
|
|
nsRefPtr<TelephonyCall> call = GetCall(aServiceId, aCallIndex);
|
2013-10-31 05:05:51 -07:00
|
|
|
|
|
|
|
if (!call) {
|
2013-10-31 05:05:51 -07:00
|
|
|
call = mGroup->GetCall(aServiceId, aCallIndex);
|
2013-07-06 03:24:55 -07:00
|
|
|
}
|
|
|
|
|
2013-10-31 05:05:51 -07:00
|
|
|
return call.forget();
|
2013-07-06 03:24:55 -07:00
|
|
|
}
|
|
|
|
|
2015-01-08 00:33:51 -08:00
|
|
|
nsresult
|
|
|
|
Telephony::HandleCallInfo(nsITelephonyCallInfo* aInfo)
|
|
|
|
{
|
|
|
|
uint32_t serviceId;
|
|
|
|
uint32_t callIndex;
|
|
|
|
uint16_t callState;
|
|
|
|
bool isEmergency;
|
|
|
|
bool isConference;
|
|
|
|
bool isSwitchable;
|
|
|
|
bool isMergeable;
|
|
|
|
|
|
|
|
aInfo->GetClientId(&serviceId);
|
|
|
|
aInfo->GetCallIndex(&callIndex);
|
|
|
|
aInfo->GetCallState(&callState);
|
|
|
|
aInfo->GetIsEmergency(&isEmergency);
|
|
|
|
aInfo->GetIsConference(&isConference);
|
|
|
|
aInfo->GetIsSwitchable(&isSwitchable);
|
|
|
|
aInfo->GetIsMergeable(&isMergeable);
|
|
|
|
|
|
|
|
nsRefPtr<TelephonyCall> call = GetCallFromEverywhere(serviceId, callIndex);
|
|
|
|
|
|
|
|
if (!call) {
|
|
|
|
nsRefPtr<TelephonyCallId> id = CreateCallId(aInfo);
|
|
|
|
call = CreateCall(id, serviceId, callIndex, callState, isEmergency,
|
|
|
|
isConference, isSwitchable, isMergeable);
|
|
|
|
|
|
|
|
if (call && callState == nsITelephonyService::CALL_STATE_INCOMING) {
|
|
|
|
nsresult rv = DispatchCallEvent(NS_LITERAL_STRING("incoming"), call);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
call->UpdateEmergency(isEmergency);
|
|
|
|
call->UpdateSwitchable(isSwitchable);
|
|
|
|
call->UpdateMergeable(isMergeable);
|
|
|
|
|
|
|
|
nsAutoString number;
|
|
|
|
aInfo->GetNumber(number);
|
|
|
|
nsRefPtr<TelephonyCallId> id = call->Id();
|
|
|
|
id->UpdateNumber(number);
|
|
|
|
|
|
|
|
// State changed.
|
|
|
|
if (call->CallState() != callState) {
|
|
|
|
if (callState == nsITelephonyService::CALL_STATE_DISCONNECTED) {
|
2015-05-13 14:15:57 -07:00
|
|
|
call->ChangeStateInternal(callState, true);
|
2015-01-08 00:33:51 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We don't fire the statechange event on a call in conference here.
|
|
|
|
// Instead, the event will be fired later in
|
|
|
|
// TelephonyCallGroup::ChangeState(). Thus the sequence of firing the
|
|
|
|
// statechange events is guaranteed: first on TelephonyCallGroup then on
|
|
|
|
// individual TelephonyCall objects.
|
|
|
|
bool fireEvent = !isConference;
|
|
|
|
call->ChangeStateInternal(callState, fireEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Group changed.
|
|
|
|
nsRefPtr<TelephonyCallGroup> group = call->GetGroup();
|
|
|
|
|
|
|
|
if (!group && isConference) {
|
|
|
|
// Add to conference.
|
|
|
|
NS_ASSERTION(mCalls.Contains(call), "Should in mCalls");
|
|
|
|
mGroup->AddCall(call);
|
|
|
|
RemoveCall(call);
|
|
|
|
} else if (group && !isConference) {
|
|
|
|
// Remove from conference.
|
|
|
|
NS_ASSERTION(mGroup->CallsArray().Contains(call), "Should in mGroup");
|
|
|
|
mGroup->RemoveCall(call);
|
|
|
|
AddCall(call);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-08-01 18:29:05 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(Telephony)
|
|
|
|
|
2012-01-09 14:28:47 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(Telephony,
|
2014-03-31 23:13:50 -07:00
|
|
|
DOMEventTargetHelper)
|
2013-07-15 01:27:19 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCalls)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCallsList)
|
2013-07-06 03:24:55 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGroup)
|
2014-12-16 14:57:23 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mReadyPromise)
|
2012-01-09 14:28:47 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(Telephony,
|
2014-03-31 23:13:50 -07:00
|
|
|
DOMEventTargetHelper)
|
2013-08-20 00:57:19 -07:00
|
|
|
tmp->Shutdown();
|
2013-07-15 01:27:19 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCalls)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCallsList)
|
2013-07-06 03:24:55 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mGroup)
|
2014-12-16 14:57:23 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mReadyPromise)
|
2012-01-09 14:28:47 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(Telephony)
|
2014-08-19 18:01:49 -07:00
|
|
|
// Telephony does not expose nsITelephonyListener. mListener is the exposed
|
|
|
|
// nsITelephonyListener and forwards the calls it receives to us.
|
2014-03-31 23:13:50 -07:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
2012-01-09 14:28:47 -08:00
|
|
|
|
2014-03-31 23:13:50 -07:00
|
|
|
NS_IMPL_ADDREF_INHERITED(Telephony, DOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(Telephony, DOMEventTargetHelper)
|
2012-01-09 14:28:47 -08:00
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(Telephony::Listener, nsITelephonyListener)
|
2012-01-09 14:28:47 -08:00
|
|
|
|
2013-07-15 01:27:19 -07:00
|
|
|
// Telephony WebIDL
|
2013-05-09 03:44:13 -07:00
|
|
|
|
2014-02-26 22:12:30 -08:00
|
|
|
already_AddRefed<Promise>
|
2014-07-18 18:31:11 -07:00
|
|
|
Telephony::Dial(const nsAString& aNumber, const Optional<uint32_t>& aServiceId,
|
|
|
|
ErrorResult& aRv)
|
2012-01-09 14:28:47 -08:00
|
|
|
{
|
2015-04-09 10:22:37 -07:00
|
|
|
uint32_t serviceId = GetServiceId(aServiceId);
|
2014-07-18 18:31:11 -07:00
|
|
|
nsRefPtr<Promise> promise = DialInternal(serviceId, aNumber, false, aRv);
|
2014-02-26 22:12:30 -08:00
|
|
|
return promise.forget();
|
2012-07-20 05:08:24 -07:00
|
|
|
}
|
2012-01-09 14:28:47 -08:00
|
|
|
|
2014-02-26 22:12:30 -08:00
|
|
|
already_AddRefed<Promise>
|
2013-10-31 05:05:51 -07:00
|
|
|
Telephony::DialEmergency(const nsAString& aNumber,
|
2014-07-18 18:31:11 -07:00
|
|
|
const Optional<uint32_t>& aServiceId,
|
|
|
|
ErrorResult& aRv)
|
2012-07-20 05:08:24 -07:00
|
|
|
{
|
2015-04-09 10:22:37 -07:00
|
|
|
uint32_t serviceId = GetServiceId(aServiceId);
|
2014-07-18 18:31:11 -07:00
|
|
|
nsRefPtr<Promise> promise = DialInternal(serviceId, aNumber, true, aRv);
|
2014-02-26 22:12:30 -08:00
|
|
|
return promise.forget();
|
2012-01-09 14:28:47 -08:00
|
|
|
}
|
|
|
|
|
2015-01-06 22:37:03 -08:00
|
|
|
already_AddRefed<Promise>
|
|
|
|
Telephony::SendTones(const nsAString& aDTMFChars,
|
|
|
|
uint32_t aPauseDuration,
|
|
|
|
uint32_t aToneDuration,
|
|
|
|
const Optional<uint32_t>& aServiceId,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2015-04-09 10:22:37 -07:00
|
|
|
uint32_t serviceId = GetServiceId(aServiceId,
|
|
|
|
true /* aGetIfActiveCall */);
|
2015-01-06 22:37:03 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
|
|
|
|
if (!global) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<Promise> promise = Promise::Create(global, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aDTMFChars.IsEmpty()) {
|
|
|
|
NS_WARNING("Empty tone string will be ignored");
|
|
|
|
promise->MaybeReject(NS_ERROR_DOM_INVALID_ACCESS_ERR);
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!IsValidServiceId(serviceId)) {
|
|
|
|
aRv.Throw(NS_ERROR_INVALID_ARG);
|
|
|
|
promise->MaybeReject(NS_ERROR_DOM_INVALID_ACCESS_ERR);
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsITelephonyCallback> callback =
|
|
|
|
new TelephonyCallback(promise);
|
|
|
|
|
|
|
|
aRv = mService->SendTones(serviceId, aDTMFChars, aPauseDuration,
|
|
|
|
aToneDuration, callback);
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2013-10-31 05:05:51 -07:00
|
|
|
void
|
2013-10-31 05:05:51 -07:00
|
|
|
Telephony::StartTone(const nsAString& aDTMFChar,
|
|
|
|
const Optional<uint32_t>& aServiceId,
|
|
|
|
ErrorResult& aRv)
|
2013-10-31 05:05:51 -07:00
|
|
|
{
|
2015-04-09 10:22:37 -07:00
|
|
|
uint32_t serviceId = GetServiceId(aServiceId,
|
|
|
|
true /* aGetIfActiveCall */);
|
2013-10-31 05:05:51 -07:00
|
|
|
|
2013-10-31 05:05:51 -07:00
|
|
|
if (aDTMFChar.IsEmpty()) {
|
|
|
|
NS_WARNING("Empty tone string will be ignored");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-31 05:05:51 -07:00
|
|
|
if (aDTMFChar.Length() > 1 || !IsValidServiceId(serviceId)) {
|
2013-10-31 05:05:51 -07:00
|
|
|
aRv.Throw(NS_ERROR_INVALID_ARG);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-03 07:15:30 -07:00
|
|
|
aRv = mService->StartTone(serviceId, aDTMFChar);
|
2013-10-31 05:05:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-10-31 05:05:51 -07:00
|
|
|
Telephony::StopTone(const Optional<uint32_t>& aServiceId, ErrorResult& aRv)
|
2013-10-31 05:05:51 -07:00
|
|
|
{
|
2015-04-09 10:22:37 -07:00
|
|
|
uint32_t serviceId = GetServiceId(aServiceId,
|
|
|
|
true /* aGetIfActiveCall */);
|
2013-10-31 05:05:51 -07:00
|
|
|
|
|
|
|
if (!IsValidServiceId(serviceId)) {
|
|
|
|
aRv.Throw(NS_ERROR_INVALID_ARG);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-03 07:15:30 -07:00
|
|
|
aRv = mService->StopTone(serviceId);
|
2013-10-31 05:05:51 -07:00
|
|
|
}
|
|
|
|
|
2013-07-15 01:27:19 -07:00
|
|
|
bool
|
|
|
|
Telephony::GetMuted(ErrorResult& aRv) const
|
2012-01-09 14:28:47 -08:00
|
|
|
{
|
2013-07-15 01:27:19 -07:00
|
|
|
bool muted = false;
|
2014-06-03 07:15:30 -07:00
|
|
|
aRv = mService->GetMicrophoneMuted(&muted);
|
2012-01-09 14:28:47 -08:00
|
|
|
|
2013-07-15 01:27:19 -07:00
|
|
|
return muted;
|
2012-01-09 14:28:47 -08:00
|
|
|
}
|
|
|
|
|
2013-07-15 01:27:19 -07:00
|
|
|
void
|
|
|
|
Telephony::SetMuted(bool aMuted, ErrorResult& aRv)
|
2012-01-09 14:28:47 -08:00
|
|
|
{
|
2014-06-03 07:15:30 -07:00
|
|
|
aRv = mService->SetMicrophoneMuted(aMuted);
|
2012-01-09 14:28:47 -08:00
|
|
|
}
|
|
|
|
|
2013-07-15 01:27:19 -07:00
|
|
|
bool
|
|
|
|
Telephony::GetSpeakerEnabled(ErrorResult& aRv) const
|
2012-01-09 14:28:47 -08:00
|
|
|
{
|
2013-07-15 01:27:19 -07:00
|
|
|
bool enabled = false;
|
2014-06-03 07:15:30 -07:00
|
|
|
aRv = mService->GetSpeakerEnabled(&enabled);
|
2012-01-09 14:28:47 -08:00
|
|
|
|
2013-07-15 01:27:19 -07:00
|
|
|
return enabled;
|
2012-01-09 14:28:47 -08:00
|
|
|
}
|
|
|
|
|
2013-07-15 01:27:19 -07:00
|
|
|
void
|
|
|
|
Telephony::SetSpeakerEnabled(bool aEnabled, ErrorResult& aRv)
|
2012-01-09 14:28:47 -08:00
|
|
|
{
|
2014-06-03 07:15:30 -07:00
|
|
|
aRv = mService->SetSpeakerEnabled(aEnabled);
|
2012-01-09 14:28:47 -08:00
|
|
|
}
|
|
|
|
|
2013-07-06 03:24:55 -07:00
|
|
|
void
|
2013-09-17 08:16:02 -07:00
|
|
|
Telephony::GetActive(Nullable<OwningTelephonyCallOrTelephonyCallGroup>& aValue)
|
2012-01-09 14:28:47 -08:00
|
|
|
{
|
2014-06-12 16:34:00 -07:00
|
|
|
if (mGroup->CallState() == nsITelephonyService::CALL_STATE_CONNECTED) {
|
2013-07-06 03:24:55 -07:00
|
|
|
aValue.SetValue().SetAsTelephonyCallGroup() = mGroup;
|
|
|
|
} else {
|
2014-06-12 16:34:00 -07:00
|
|
|
// Search the first active call.
|
|
|
|
for (uint32_t i = 0; i < mCalls.Length(); i++) {
|
|
|
|
if (IsActiveState(mCalls[i]->CallState())) {
|
|
|
|
aValue.SetValue().SetAsTelephonyCall() = mCalls[i];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-07-06 03:24:55 -07:00
|
|
|
aValue.SetNull();
|
|
|
|
}
|
2012-01-09 14:28:47 -08:00
|
|
|
}
|
|
|
|
|
2013-07-15 01:27:19 -07:00
|
|
|
already_AddRefed<CallsList>
|
|
|
|
Telephony::Calls() const
|
2012-01-09 14:28:47 -08:00
|
|
|
{
|
2013-07-15 01:27:19 -07:00
|
|
|
nsRefPtr<CallsList> list = mCallsList;
|
|
|
|
return list.forget();
|
2012-01-09 14:28:47 -08:00
|
|
|
}
|
|
|
|
|
2013-07-06 03:24:55 -07:00
|
|
|
already_AddRefed<TelephonyCallGroup>
|
|
|
|
Telephony::ConferenceGroup() const
|
|
|
|
{
|
|
|
|
nsRefPtr<TelephonyCallGroup> group = mGroup;
|
|
|
|
return group.forget();
|
|
|
|
}
|
|
|
|
|
2014-12-16 14:57:23 -08:00
|
|
|
already_AddRefed<Promise>
|
|
|
|
Telephony::GetReady(ErrorResult& aRv) const
|
2013-05-09 03:44:13 -07:00
|
|
|
{
|
2014-12-16 14:57:23 -08:00
|
|
|
if (!mReadyPromise) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
2013-05-09 03:44:13 -07:00
|
|
|
}
|
2014-12-16 14:57:23 -08:00
|
|
|
|
|
|
|
nsRefPtr<Promise> promise = mReadyPromise;
|
|
|
|
return promise.forget();
|
2013-05-09 03:44:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsITelephonyListener
|
2012-01-09 14:28:47 -08:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2015-04-24 03:10:37 -07:00
|
|
|
Telephony::CallStateChanged(uint32_t aLength, nsITelephonyCallInfo** aAllInfo)
|
2015-01-08 00:33:51 -08:00
|
|
|
{
|
2015-04-24 03:10:37 -07:00
|
|
|
for (uint32_t i = 0; i < aLength; ++i) {
|
|
|
|
HandleCallInfo(aAllInfo[i]);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2015-01-08 00:33:51 -08:00
|
|
|
}
|
2012-01-09 14:28:47 -08:00
|
|
|
|
2015-01-08 00:33:51 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Telephony::EnumerateCallState(nsITelephonyCallInfo* aInfo)
|
|
|
|
{
|
|
|
|
return HandleCallInfo(aInfo);
|
2012-01-09 14:28:47 -08:00
|
|
|
}
|
|
|
|
|
2013-07-06 03:24:55 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Telephony::ConferenceCallStateChanged(uint16_t aCallState)
|
|
|
|
{
|
|
|
|
mGroup->ChangeState(aCallState);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-05-09 03:44:13 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Telephony::EnumerateCallStateComplete()
|
|
|
|
{
|
2014-09-03 21:45:00 -07:00
|
|
|
// Set conference state.
|
|
|
|
if (mGroup->CallsArray().Length() >= 2) {
|
|
|
|
const nsTArray<nsRefPtr<TelephonyCall> > &calls = mGroup->CallsArray();
|
|
|
|
|
|
|
|
uint16_t callState = calls[0]->CallState();
|
|
|
|
for (uint32_t i = 1; i < calls.Length(); i++) {
|
|
|
|
if (calls[i]->CallState() != callState) {
|
|
|
|
callState = nsITelephonyService::CALL_STATE_UNKNOWN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mGroup->ChangeState(callState);
|
|
|
|
}
|
|
|
|
|
2014-12-16 14:57:23 -08:00
|
|
|
if (mReadyPromise) {
|
|
|
|
mReadyPromise->MaybeResolve(JS::UndefinedHandleValue);
|
2014-07-21 10:17:00 -07:00
|
|
|
}
|
|
|
|
|
2014-06-03 07:15:30 -07:00
|
|
|
if (NS_FAILED(mService->RegisterListener(mListener))) {
|
2014-03-05 04:19:38 -08:00
|
|
|
NS_WARNING("Failed to register listener!");
|
|
|
|
}
|
2013-05-09 03:44:13 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-09 14:28:47 -08:00
|
|
|
NS_IMETHODIMP
|
2013-10-31 05:05:51 -07:00
|
|
|
Telephony::SupplementaryServiceNotification(uint32_t aServiceId,
|
|
|
|
int32_t aCallIndex,
|
2013-08-05 13:28:14 -07:00
|
|
|
uint16_t aNotification)
|
|
|
|
{
|
|
|
|
nsRefPtr<TelephonyCall> associatedCall;
|
2014-02-26 22:12:30 -08:00
|
|
|
if (!mCalls.IsEmpty()) {
|
2013-10-31 05:05:51 -07:00
|
|
|
associatedCall = GetCall(aServiceId, aCallIndex);
|
2013-08-05 13:28:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
switch (aNotification) {
|
2014-06-03 07:15:25 -07:00
|
|
|
case nsITelephonyService::NOTIFICATION_REMOTE_HELD:
|
2013-08-05 13:28:14 -07:00
|
|
|
rv = DispatchCallEvent(NS_LITERAL_STRING("remoteheld"), associatedCall);
|
|
|
|
break;
|
2014-06-03 07:15:25 -07:00
|
|
|
case nsITelephonyService::NOTIFICATION_REMOTE_RESUMED:
|
2013-08-05 13:28:14 -07:00
|
|
|
rv = DispatchCallEvent(NS_LITERAL_STRING("remoteresumed"), associatedCall);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ERROR("Got a bad notification!");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-05-13 14:15:57 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Telephony::NotifyError(uint32_t aServiceId,
|
|
|
|
int32_t aCallIndex,
|
|
|
|
const nsAString& aError)
|
|
|
|
{
|
|
|
|
nsRefPtr<TelephonyCall> callToNotify =
|
|
|
|
GetCallFromEverywhere(aServiceId, aCallIndex);
|
|
|
|
if (!callToNotify) {
|
|
|
|
NS_ERROR("Don't call me with a bad call index!");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the call state to 'disconnected' and remove it from the calls list.
|
|
|
|
callToNotify->UpdateDisconnectedReason(aError);
|
|
|
|
callToNotify->NotifyError(aError);
|
|
|
|
callToNotify->ChangeState(nsITelephonyService::CALL_STATE_DISCONNECTED);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-07-30 02:08:53 -07:00
|
|
|
NS_IMETHODIMP
|
2014-04-09 23:25:42 -07:00
|
|
|
Telephony::NotifyCdmaCallWaiting(uint32_t aServiceId, const nsAString& aNumber,
|
|
|
|
uint16_t aNumberPresentation,
|
|
|
|
const nsAString& aName,
|
|
|
|
uint16_t aNamePresentation)
|
2013-07-30 02:08:53 -07:00
|
|
|
{
|
2014-01-15 06:41:50 -08:00
|
|
|
MOZ_ASSERT(mCalls.Length() == 1);
|
|
|
|
|
|
|
|
nsRefPtr<TelephonyCall> callToNotify = mCalls[0];
|
|
|
|
MOZ_ASSERT(callToNotify && callToNotify->ServiceId() == aServiceId);
|
2013-07-30 02:08:53 -07:00
|
|
|
|
2014-04-09 23:25:42 -07:00
|
|
|
nsRefPtr<TelephonyCallId> id =
|
|
|
|
new TelephonyCallId(GetOwner(), aNumber, aNumberPresentation, aName,
|
|
|
|
aNamePresentation);
|
|
|
|
callToNotify->UpdateSecondId(id);
|
2013-07-30 02:08:53 -07:00
|
|
|
DispatchCallEvent(NS_LITERAL_STRING("callschanged"), callToNotify);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-10-27 23:43:14 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Telephony::NotifyConferenceError(const nsAString& aName,
|
|
|
|
const nsAString& aMessage)
|
|
|
|
{
|
|
|
|
mGroup->NotifyError(aName, aMessage);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-27 23:39:50 -08:00
|
|
|
nsresult
|
|
|
|
Telephony::DispatchCallEvent(const nsAString& aType,
|
2013-07-15 01:27:19 -07:00
|
|
|
TelephonyCall* aCall)
|
2013-01-27 23:39:50 -08:00
|
|
|
{
|
2014-07-21 10:17:00 -07:00
|
|
|
// If it is an incoming event, the call should not be null.
|
|
|
|
MOZ_ASSERT(!aType.EqualsLiteral("incoming") || aCall);
|
2013-01-27 23:39:50 -08:00
|
|
|
|
2014-06-10 18:23:34 -07:00
|
|
|
CallEventInit init;
|
|
|
|
init.mBubbles = false;
|
|
|
|
init.mCancelable = false;
|
|
|
|
init.mCall = aCall;
|
|
|
|
|
|
|
|
nsRefPtr<CallEvent> event = CallEvent::Constructor(this, aType, init);
|
2013-01-27 23:39:50 -08:00
|
|
|
|
2013-07-15 01:27:19 -07:00
|
|
|
return DispatchTrustedEvent(event);
|
2013-01-27 23:39:50 -08:00
|
|
|
}
|
|
|
|
|
2014-09-21 00:24:44 -07:00
|
|
|
already_AddRefed<nsITelephonyService>
|
|
|
|
NS_CreateTelephonyService()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsITelephonyService> service;
|
|
|
|
|
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
|
|
|
service = new mozilla::dom::telephony::TelephonyIPCService();
|
|
|
|
} else {
|
|
|
|
#if defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_RIL)
|
|
|
|
service = do_CreateInstance(GONK_TELEPHONY_SERVICE_CONTRACTID);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return service.forget();
|
|
|
|
}
|