2013-06-01 10:53:06 +04: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 15:12:37 +04: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-10 02:28:47 +04:00
|
|
|
|
|
|
|
#include "Telephony.h"
|
2014-09-22 09:34:00 +04:00
|
|
|
|
|
|
|
#include "mozilla/Preferences.h"
|
2014-06-11 05:23:34 +04:00
|
|
|
#include "mozilla/dom/CallEvent.h"
|
2014-09-22 09:34:00 +04:00
|
|
|
#include "mozilla/dom/MozMobileConnectionBinding.h"
|
2014-02-27 10:12:30 +04:00
|
|
|
#include "mozilla/dom/Promise.h"
|
2014-09-22 09:34:00 +04:00
|
|
|
#include "mozilla/dom/TelephonyBinding.h"
|
|
|
|
|
2012-02-24 17:14:37 +04:00
|
|
|
#include "nsCharSeparatedTokenizer.h"
|
2012-01-10 02:28:47 +04:00
|
|
|
#include "nsContentUtils.h"
|
2014-09-22 09:34:00 +04:00
|
|
|
#include "nsIPermissionManager.h"
|
|
|
|
#include "nsIURI.h"
|
2012-02-24 17:14:37 +04:00
|
|
|
#include "nsNetUtil.h"
|
2014-09-22 09:34:00 +04:00
|
|
|
#include "nsPIDOMWindow.h"
|
2013-01-28 11:39:50 +04:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2013-05-09 14:44:13 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2012-01-10 02:28:47 +04:00
|
|
|
|
2013-07-15 12:27:19 +04:00
|
|
|
#include "CallsList.h"
|
2012-01-10 02:28:47 +04:00
|
|
|
#include "TelephonyCall.h"
|
2013-07-06 14:24:55 +04:00
|
|
|
#include "TelephonyCallGroup.h"
|
2014-04-10 10:25:42 +04:00
|
|
|
#include "TelephonyCallId.h"
|
2014-10-15 10:50:00 +04:00
|
|
|
#include "TelephonyDialCallback.h"
|
2012-01-10 02:28:47 +04:00
|
|
|
|
2014-09-21 11:24:44 +04: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 14:44:13 +04:00
|
|
|
using namespace mozilla::dom;
|
2014-09-22 09:34:00 +04:00
|
|
|
using namespace mozilla::dom::telephony;
|
2013-09-07 10:19:53 +04:00
|
|
|
using mozilla::ErrorResult;
|
2012-01-10 02:28:47 +04:00
|
|
|
|
2013-03-06 13:53:23 +04:00
|
|
|
class Telephony::Listener : public nsITelephonyListener
|
|
|
|
{
|
|
|
|
Telephony* mTelephony;
|
|
|
|
|
2014-06-23 23:56:07 +04:00
|
|
|
virtual ~Listener() {}
|
|
|
|
|
2013-03-06 13:53:23 +04:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_FORWARD_SAFE_NSITELEPHONYLISTENER(mTelephony)
|
|
|
|
|
2014-09-02 02:26:43 +04:00
|
|
|
explicit Listener(Telephony* aTelephony)
|
2013-03-06 13:53:23 +04:00
|
|
|
: mTelephony(aTelephony)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mTelephony);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Disconnect()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mTelephony);
|
|
|
|
mTelephony = nullptr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-12-17 01:57:23 +03:00
|
|
|
Telephony::Telephony(nsPIDOMWindow* aOwner)
|
|
|
|
: DOMEventTargetHelper(aOwner)
|
2013-05-09 14:44:13 +04:00
|
|
|
{
|
2014-12-17 01:57:23 +03:00
|
|
|
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aOwner);
|
|
|
|
MOZ_ASSERT(global);
|
2013-05-09 14:44:13 +04:00
|
|
|
|
2014-12-17 01:57:23 +03:00
|
|
|
ErrorResult rv;
|
|
|
|
nsRefPtr<Promise> promise = Promise::Create(global, rv);
|
|
|
|
MOZ_ASSERT(!rv.Failed());
|
2013-05-09 14:44:13 +04:00
|
|
|
|
2014-12-17 01:57:23 +03:00
|
|
|
mReadyPromise = promise;
|
2012-02-24 17:14:37 +04:00
|
|
|
}
|
|
|
|
|
2012-01-10 02:28:47 +04:00
|
|
|
Telephony::~Telephony()
|
|
|
|
{
|
2013-08-20 11:57:19 +04:00
|
|
|
Shutdown();
|
2012-01-10 02:28:47 +04:00
|
|
|
}
|
|
|
|
|
2013-08-20 11:57:19 +04:00
|
|
|
void
|
|
|
|
Telephony::Shutdown()
|
|
|
|
{
|
|
|
|
if (mListener) {
|
|
|
|
mListener->Disconnect();
|
|
|
|
|
2014-06-03 18:15:30 +04:00
|
|
|
if (mService) {
|
|
|
|
mService->UnregisterListener(mListener);
|
|
|
|
mService = nullptr;
|
2013-08-20 11:57:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mListener = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-15 12:27:19 +04: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 17:13:33 +03:00
|
|
|
Telephony::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-07-15 12:27:19 +04: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 17:13:33 +03:00
|
|
|
return TelephonyBinding::Wrap(aCx, this, aGivenProto);
|
2013-07-15 12:27:19 +04:00
|
|
|
}
|
|
|
|
|
2012-01-10 02:28:47 +04:00
|
|
|
// static
|
|
|
|
already_AddRefed<Telephony>
|
2013-07-12 18:36:13 +04:00
|
|
|
Telephony::Create(nsPIDOMWindow* aOwner, ErrorResult& aRv)
|
2012-01-10 02:28:47 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aOwner, "Null owner!");
|
2013-07-12 18:36:13 +04:00
|
|
|
|
2014-06-03 18:15:25 +04:00
|
|
|
nsCOMPtr<nsITelephonyService> ril =
|
|
|
|
do_GetService(TELEPHONY_SERVICE_CONTRACTID);
|
2013-07-12 18:36:13 +04:00
|
|
|
if (!ril) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-01-10 02:28:47 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(aOwner);
|
2013-07-12 18:36:13 +04:00
|
|
|
if (!sgo) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-01-10 02:28:47 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptContext> scriptContext = sgo->GetContext();
|
2013-07-12 18:36:13 +04:00
|
|
|
if (!scriptContext) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-01-10 02:28:47 +04:00
|
|
|
|
2014-01-07 06:53:23 +04:00
|
|
|
nsRefPtr<Telephony> telephony = new Telephony(aOwner);
|
2012-03-14 02:11:16 +04:00
|
|
|
|
2014-06-03 18:15:30 +04:00
|
|
|
telephony->mService = ril;
|
2013-03-06 13:53:23 +04:00
|
|
|
telephony->mListener = new Listener(telephony);
|
2013-07-15 12:27:19 +04:00
|
|
|
telephony->mCallsList = new CallsList(telephony);
|
2013-07-06 14:24:55 +04:00
|
|
|
telephony->mGroup = TelephonyCallGroup::Create(telephony);
|
2012-01-10 02:28:47 +04:00
|
|
|
|
2013-07-12 18:36:13 +04:00
|
|
|
nsresult rv = ril->EnumerateCalls(telephony->mListener);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-01-10 02:28:47 +04:00
|
|
|
|
|
|
|
return telephony.forget();
|
|
|
|
}
|
|
|
|
|
2013-10-31 16:05:51 +04:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
Telephony::IsValidNumber(const nsAString& aNumber)
|
|
|
|
{
|
|
|
|
return !aNumber.IsEmpty();
|
|
|
|
}
|
|
|
|
|
2013-10-31 16:05:51 +04: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 16:05:51 +04:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
Telephony::IsActiveState(uint16_t aCallState) {
|
2014-06-03 18:15:25 +04:00
|
|
|
return aCallState == nsITelephonyService::CALL_STATE_DIALING ||
|
|
|
|
aCallState == nsITelephonyService::CALL_STATE_ALERTING ||
|
|
|
|
aCallState == nsITelephonyService::CALL_STATE_CONNECTED;
|
2013-10-31 16:05:51 +04:00
|
|
|
}
|
|
|
|
|
2013-10-31 16:05:51 +04:00
|
|
|
uint32_t
|
2015-04-09 20:22:37 +03:00
|
|
|
Telephony::GetServiceId(const Optional<uint32_t>& aServiceId,
|
|
|
|
bool aGetIfActiveCall)
|
2013-10-31 16:05:51 +04:00
|
|
|
{
|
|
|
|
if (aServiceId.WasPassed()) {
|
|
|
|
return aServiceId.Value();
|
2015-04-09 20:22:37 +03: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 16:05:51 +04:00
|
|
|
}
|
2015-04-09 20:22:37 +03:00
|
|
|
|
|
|
|
uint32_t serviceId = 0;
|
|
|
|
mService->GetDefaultServiceId(&serviceId);
|
|
|
|
return serviceId;
|
2013-10-31 16:05:51 +04:00
|
|
|
}
|
|
|
|
|
2014-02-27 10:12:30 +04:00
|
|
|
already_AddRefed<Promise>
|
2013-10-31 16:05:51 +04:00
|
|
|
Telephony::DialInternal(uint32_t aServiceId, const nsAString& aNumber,
|
2014-07-19 05:31:11 +04:00
|
|
|
bool aEmergency, ErrorResult& aRv)
|
2012-07-20 16:08:24 +04:00
|
|
|
{
|
2014-02-27 10:12:30 +04:00
|
|
|
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
|
|
|
|
if (!global) {
|
2014-02-26 23:27:54 +04:00
|
|
|
return nullptr;
|
2014-02-26 23:03:56 +04:00
|
|
|
}
|
|
|
|
|
2014-07-19 05:31:11 +04:00
|
|
|
nsRefPtr<Promise> promise = Promise::Create(global, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-02-27 10:12:30 +04:00
|
|
|
|
|
|
|
if (!IsValidNumber(aNumber) || !IsValidServiceId(aServiceId)) {
|
2014-06-03 19:38:38 +04:00
|
|
|
promise->MaybeReject(NS_ERROR_DOM_INVALID_ACCESS_ERR);
|
2014-02-27 10:12:30 +04:00
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2014-10-15 10:50:00 +04:00
|
|
|
nsCOMPtr<nsITelephonyDialCallback> callback =
|
2014-12-23 10:46:09 +03:00
|
|
|
new TelephonyDialCallback(GetOwner(), this, promise);
|
2014-09-22 09:34:00 +04:00
|
|
|
|
2014-06-24 14:52:00 +04:00
|
|
|
nsresult rv = mService->Dial(aServiceId, aNumber, aEmergency, callback);
|
2013-07-15 12:27:19 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2014-06-03 19:38:38 +04:00
|
|
|
promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
|
2014-02-27 10:12:30 +04:00
|
|
|
return promise.forget();
|
2014-02-26 23:27:54 +04:00
|
|
|
}
|
|
|
|
|
2014-02-27 10:12:30 +04:00
|
|
|
return promise.forget();
|
2012-07-20 16:08:24 +04:00
|
|
|
}
|
|
|
|
|
2015-01-08 11:33:51 +03: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 14:52:00 +04: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 16:05:51 +04:00
|
|
|
already_AddRefed<TelephonyCall>
|
2014-06-24 14:52:00 +04: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 16:05:51 +04:00
|
|
|
{
|
2014-06-24 14:52:00 +04:00
|
|
|
// We don't have to create an already ended call.
|
|
|
|
if (aCallState == nsITelephonyService::CALL_STATE_DISCONNECTED) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-10-31 16:05:51 +04:00
|
|
|
nsRefPtr<TelephonyCall> call =
|
2014-06-24 14:52:00 +04:00
|
|
|
TelephonyCall::Create(this, aId, aServiceId, aCallIndex, aCallState,
|
|
|
|
aEmergency, aConference, aSwitchable, aMergeable);
|
2013-10-31 16:05:51 +04:00
|
|
|
|
2014-06-24 14:52:00 +04: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 16:05:51 +04:00
|
|
|
|
|
|
|
return call.forget();
|
|
|
|
}
|
|
|
|
|
2014-07-21 21:17:00 +04:00
|
|
|
nsresult
|
|
|
|
Telephony::NotifyEvent(const nsAString& aType)
|
|
|
|
{
|
|
|
|
return DispatchCallEvent(aType, nullptr);
|
|
|
|
}
|
|
|
|
|
2013-10-31 16:05:51 +04:00
|
|
|
nsresult
|
|
|
|
Telephony::NotifyCallsChanged(TelephonyCall* aCall)
|
|
|
|
{
|
|
|
|
return DispatchCallEvent(NS_LITERAL_STRING("callschanged"), aCall);
|
|
|
|
}
|
|
|
|
|
2013-07-06 14:24:55 +04:00
|
|
|
already_AddRefed<TelephonyCall>
|
2013-10-31 16:05:51 +04:00
|
|
|
Telephony::GetCall(uint32_t aServiceId, uint32_t aCallIndex)
|
2013-07-06 14:24:55 +04:00
|
|
|
{
|
|
|
|
nsRefPtr<TelephonyCall> call;
|
|
|
|
|
2013-10-31 16:05:51 +04: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 14:24:55 +04:00
|
|
|
call = tempCall;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return call.forget();
|
|
|
|
}
|
|
|
|
|
2013-10-31 16:05:51 +04:00
|
|
|
already_AddRefed<TelephonyCall>
|
2013-10-31 16:05:51 +04:00
|
|
|
Telephony::GetCallFromEverywhere(uint32_t aServiceId, uint32_t aCallIndex)
|
2013-10-31 16:05:51 +04:00
|
|
|
{
|
2013-10-31 16:05:51 +04:00
|
|
|
nsRefPtr<TelephonyCall> call = GetCall(aServiceId, aCallIndex);
|
2013-10-31 16:05:51 +04:00
|
|
|
|
|
|
|
if (!call) {
|
2013-10-31 16:05:51 +04:00
|
|
|
call = mGroup->GetCall(aServiceId, aCallIndex);
|
2013-07-06 14:24:55 +04:00
|
|
|
}
|
|
|
|
|
2013-10-31 16:05:51 +04:00
|
|
|
return call.forget();
|
2013-07-06 14:24:55 +04:00
|
|
|
}
|
|
|
|
|
2015-01-08 11:33:51 +03: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);
|
|
|
|
|
2015-04-28 06:28:00 +03:00
|
|
|
nsAutoString disconnectedReason;
|
|
|
|
aInfo->GetDisconnectedReason(disconnectedReason);
|
|
|
|
|
2015-01-08 11:33:51 +03:00
|
|
|
// State changed.
|
|
|
|
if (call->CallState() != callState) {
|
|
|
|
if (callState == nsITelephonyService::CALL_STATE_DISCONNECTED) {
|
2015-04-28 06:28:00 +03:00
|
|
|
call->UpdateDisconnectedReason(disconnectedReason);
|
|
|
|
call->ChangeState(nsITelephonyService::CALL_STATE_DISCONNECTED);
|
2015-01-08 11:33:51 +03: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-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(Telephony)
|
|
|
|
|
2012-01-10 02:28:47 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(Telephony,
|
2014-04-01 10:13:50 +04:00
|
|
|
DOMEventTargetHelper)
|
2013-07-15 12:27:19 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCalls)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCallsList)
|
2013-07-06 14:24:55 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGroup)
|
2014-12-17 01:57:23 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mReadyPromise)
|
2012-01-10 02:28:47 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(Telephony,
|
2014-04-01 10:13:50 +04:00
|
|
|
DOMEventTargetHelper)
|
2013-08-20 11:57:19 +04:00
|
|
|
tmp->Shutdown();
|
2013-07-15 12:27:19 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCalls)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCallsList)
|
2013-07-06 14:24:55 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mGroup)
|
2014-12-17 01:57:23 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mReadyPromise)
|
2012-01-10 02:28:47 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(Telephony)
|
2014-08-20 05:01:49 +04:00
|
|
|
// Telephony does not expose nsITelephonyListener. mListener is the exposed
|
|
|
|
// nsITelephonyListener and forwards the calls it receives to us.
|
2014-04-01 10:13:50 +04:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
2012-01-10 02:28:47 +04:00
|
|
|
|
2014-04-01 10:13:50 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(Telephony, DOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(Telephony, DOMEventTargetHelper)
|
2012-01-10 02:28:47 +04:00
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(Telephony::Listener, nsITelephonyListener)
|
2012-01-10 02:28:47 +04:00
|
|
|
|
2013-07-15 12:27:19 +04:00
|
|
|
// Telephony WebIDL
|
2013-05-09 14:44:13 +04:00
|
|
|
|
2014-02-27 10:12:30 +04:00
|
|
|
already_AddRefed<Promise>
|
2014-07-19 05:31:11 +04:00
|
|
|
Telephony::Dial(const nsAString& aNumber, const Optional<uint32_t>& aServiceId,
|
|
|
|
ErrorResult& aRv)
|
2012-01-10 02:28:47 +04:00
|
|
|
{
|
2015-04-09 20:22:37 +03:00
|
|
|
uint32_t serviceId = GetServiceId(aServiceId);
|
2014-07-19 05:31:11 +04:00
|
|
|
nsRefPtr<Promise> promise = DialInternal(serviceId, aNumber, false, aRv);
|
2014-02-27 10:12:30 +04:00
|
|
|
return promise.forget();
|
2012-07-20 16:08:24 +04:00
|
|
|
}
|
2012-01-10 02:28:47 +04:00
|
|
|
|
2014-02-27 10:12:30 +04:00
|
|
|
already_AddRefed<Promise>
|
2013-10-31 16:05:51 +04:00
|
|
|
Telephony::DialEmergency(const nsAString& aNumber,
|
2014-07-19 05:31:11 +04:00
|
|
|
const Optional<uint32_t>& aServiceId,
|
|
|
|
ErrorResult& aRv)
|
2012-07-20 16:08:24 +04:00
|
|
|
{
|
2015-04-09 20:22:37 +03:00
|
|
|
uint32_t serviceId = GetServiceId(aServiceId);
|
2014-07-19 05:31:11 +04:00
|
|
|
nsRefPtr<Promise> promise = DialInternal(serviceId, aNumber, true, aRv);
|
2014-02-27 10:12:30 +04:00
|
|
|
return promise.forget();
|
2012-01-10 02:28:47 +04:00
|
|
|
}
|
|
|
|
|
2015-01-07 09:37:03 +03: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 20:22:37 +03:00
|
|
|
uint32_t serviceId = GetServiceId(aServiceId,
|
|
|
|
true /* aGetIfActiveCall */);
|
2015-01-07 09:37:03 +03: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 16:05:51 +04:00
|
|
|
void
|
2013-10-31 16:05:51 +04:00
|
|
|
Telephony::StartTone(const nsAString& aDTMFChar,
|
|
|
|
const Optional<uint32_t>& aServiceId,
|
|
|
|
ErrorResult& aRv)
|
2013-10-31 16:05:51 +04:00
|
|
|
{
|
2015-04-09 20:22:37 +03:00
|
|
|
uint32_t serviceId = GetServiceId(aServiceId,
|
|
|
|
true /* aGetIfActiveCall */);
|
2013-10-31 16:05:51 +04:00
|
|
|
|
2013-10-31 16:05:51 +04:00
|
|
|
if (aDTMFChar.IsEmpty()) {
|
|
|
|
NS_WARNING("Empty tone string will be ignored");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-31 16:05:51 +04:00
|
|
|
if (aDTMFChar.Length() > 1 || !IsValidServiceId(serviceId)) {
|
2013-10-31 16:05:51 +04:00
|
|
|
aRv.Throw(NS_ERROR_INVALID_ARG);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-03 18:15:30 +04:00
|
|
|
aRv = mService->StartTone(serviceId, aDTMFChar);
|
2013-10-31 16:05:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-10-31 16:05:51 +04:00
|
|
|
Telephony::StopTone(const Optional<uint32_t>& aServiceId, ErrorResult& aRv)
|
2013-10-31 16:05:51 +04:00
|
|
|
{
|
2015-04-09 20:22:37 +03:00
|
|
|
uint32_t serviceId = GetServiceId(aServiceId,
|
|
|
|
true /* aGetIfActiveCall */);
|
2013-10-31 16:05:51 +04:00
|
|
|
|
|
|
|
if (!IsValidServiceId(serviceId)) {
|
|
|
|
aRv.Throw(NS_ERROR_INVALID_ARG);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-03 18:15:30 +04:00
|
|
|
aRv = mService->StopTone(serviceId);
|
2013-10-31 16:05:51 +04:00
|
|
|
}
|
|
|
|
|
2013-07-15 12:27:19 +04:00
|
|
|
bool
|
|
|
|
Telephony::GetMuted(ErrorResult& aRv) const
|
2012-01-10 02:28:47 +04:00
|
|
|
{
|
2013-07-15 12:27:19 +04:00
|
|
|
bool muted = false;
|
2014-06-03 18:15:30 +04:00
|
|
|
aRv = mService->GetMicrophoneMuted(&muted);
|
2012-01-10 02:28:47 +04:00
|
|
|
|
2013-07-15 12:27:19 +04:00
|
|
|
return muted;
|
2012-01-10 02:28:47 +04:00
|
|
|
}
|
|
|
|
|
2013-07-15 12:27:19 +04:00
|
|
|
void
|
|
|
|
Telephony::SetMuted(bool aMuted, ErrorResult& aRv)
|
2012-01-10 02:28:47 +04:00
|
|
|
{
|
2014-06-03 18:15:30 +04:00
|
|
|
aRv = mService->SetMicrophoneMuted(aMuted);
|
2012-01-10 02:28:47 +04:00
|
|
|
}
|
|
|
|
|
2013-07-15 12:27:19 +04:00
|
|
|
bool
|
|
|
|
Telephony::GetSpeakerEnabled(ErrorResult& aRv) const
|
2012-01-10 02:28:47 +04:00
|
|
|
{
|
2013-07-15 12:27:19 +04:00
|
|
|
bool enabled = false;
|
2014-06-03 18:15:30 +04:00
|
|
|
aRv = mService->GetSpeakerEnabled(&enabled);
|
2012-01-10 02:28:47 +04:00
|
|
|
|
2013-07-15 12:27:19 +04:00
|
|
|
return enabled;
|
2012-01-10 02:28:47 +04:00
|
|
|
}
|
|
|
|
|
2013-07-15 12:27:19 +04:00
|
|
|
void
|
|
|
|
Telephony::SetSpeakerEnabled(bool aEnabled, ErrorResult& aRv)
|
2012-01-10 02:28:47 +04:00
|
|
|
{
|
2014-06-03 18:15:30 +04:00
|
|
|
aRv = mService->SetSpeakerEnabled(aEnabled);
|
2012-01-10 02:28:47 +04:00
|
|
|
}
|
|
|
|
|
2013-07-06 14:24:55 +04:00
|
|
|
void
|
2013-09-17 19:16:02 +04:00
|
|
|
Telephony::GetActive(Nullable<OwningTelephonyCallOrTelephonyCallGroup>& aValue)
|
2012-01-10 02:28:47 +04:00
|
|
|
{
|
2014-06-13 03:34:00 +04:00
|
|
|
if (mGroup->CallState() == nsITelephonyService::CALL_STATE_CONNECTED) {
|
2013-07-06 14:24:55 +04:00
|
|
|
aValue.SetValue().SetAsTelephonyCallGroup() = mGroup;
|
|
|
|
} else {
|
2014-06-13 03:34:00 +04: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 14:24:55 +04:00
|
|
|
aValue.SetNull();
|
|
|
|
}
|
2012-01-10 02:28:47 +04:00
|
|
|
}
|
|
|
|
|
2013-07-15 12:27:19 +04:00
|
|
|
already_AddRefed<CallsList>
|
|
|
|
Telephony::Calls() const
|
2012-01-10 02:28:47 +04:00
|
|
|
{
|
2013-07-15 12:27:19 +04:00
|
|
|
nsRefPtr<CallsList> list = mCallsList;
|
|
|
|
return list.forget();
|
2012-01-10 02:28:47 +04:00
|
|
|
}
|
|
|
|
|
2013-07-06 14:24:55 +04:00
|
|
|
already_AddRefed<TelephonyCallGroup>
|
|
|
|
Telephony::ConferenceGroup() const
|
|
|
|
{
|
|
|
|
nsRefPtr<TelephonyCallGroup> group = mGroup;
|
|
|
|
return group.forget();
|
|
|
|
}
|
|
|
|
|
2014-12-17 01:57:23 +03:00
|
|
|
already_AddRefed<Promise>
|
|
|
|
Telephony::GetReady(ErrorResult& aRv) const
|
2013-05-09 14:44:13 +04:00
|
|
|
{
|
2014-12-17 01:57:23 +03:00
|
|
|
if (!mReadyPromise) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
2013-05-09 14:44:13 +04:00
|
|
|
}
|
2014-12-17 01:57:23 +03:00
|
|
|
|
|
|
|
nsRefPtr<Promise> promise = mReadyPromise;
|
|
|
|
return promise.forget();
|
2013-05-09 14:44:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsITelephonyListener
|
2012-01-10 02:28:47 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2015-04-24 13:10:37 +03:00
|
|
|
Telephony::CallStateChanged(uint32_t aLength, nsITelephonyCallInfo** aAllInfo)
|
2015-01-08 11:33:51 +03:00
|
|
|
{
|
2015-04-24 13:10:37 +03:00
|
|
|
for (uint32_t i = 0; i < aLength; ++i) {
|
|
|
|
HandleCallInfo(aAllInfo[i]);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2015-01-08 11:33:51 +03:00
|
|
|
}
|
2012-01-10 02:28:47 +04:00
|
|
|
|
2015-01-08 11:33:51 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Telephony::EnumerateCallState(nsITelephonyCallInfo* aInfo)
|
|
|
|
{
|
|
|
|
return HandleCallInfo(aInfo);
|
2012-01-10 02:28:47 +04:00
|
|
|
}
|
|
|
|
|
2013-07-06 14:24:55 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Telephony::ConferenceCallStateChanged(uint16_t aCallState)
|
|
|
|
{
|
|
|
|
mGroup->ChangeState(aCallState);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-05-09 14:44:13 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Telephony::EnumerateCallStateComplete()
|
|
|
|
{
|
2014-09-04 08:45:00 +04: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-17 01:57:23 +03:00
|
|
|
if (mReadyPromise) {
|
|
|
|
mReadyPromise->MaybeResolve(JS::UndefinedHandleValue);
|
2014-07-21 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
2014-06-03 18:15:30 +04:00
|
|
|
if (NS_FAILED(mService->RegisterListener(mListener))) {
|
2014-03-05 16:19:38 +04:00
|
|
|
NS_WARNING("Failed to register listener!");
|
|
|
|
}
|
2013-05-09 14:44:13 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-10 02:28:47 +04:00
|
|
|
NS_IMETHODIMP
|
2013-10-31 16:05:51 +04:00
|
|
|
Telephony::SupplementaryServiceNotification(uint32_t aServiceId,
|
|
|
|
int32_t aCallIndex,
|
2013-08-06 00:28:14 +04:00
|
|
|
uint16_t aNotification)
|
|
|
|
{
|
|
|
|
nsRefPtr<TelephonyCall> associatedCall;
|
2014-02-27 10:12:30 +04:00
|
|
|
if (!mCalls.IsEmpty()) {
|
2013-10-31 16:05:51 +04:00
|
|
|
associatedCall = GetCall(aServiceId, aCallIndex);
|
2013-08-06 00:28:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
switch (aNotification) {
|
2014-06-03 18:15:25 +04:00
|
|
|
case nsITelephonyService::NOTIFICATION_REMOTE_HELD:
|
2013-08-06 00:28:14 +04:00
|
|
|
rv = DispatchCallEvent(NS_LITERAL_STRING("remoteheld"), associatedCall);
|
|
|
|
break;
|
2014-06-03 18:15:25 +04:00
|
|
|
case nsITelephonyService::NOTIFICATION_REMOTE_RESUMED:
|
2013-08-06 00:28:14 +04: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;
|
|
|
|
}
|
|
|
|
|
2013-07-30 13:08:53 +04:00
|
|
|
NS_IMETHODIMP
|
2014-04-10 10:25:42 +04:00
|
|
|
Telephony::NotifyCdmaCallWaiting(uint32_t aServiceId, const nsAString& aNumber,
|
|
|
|
uint16_t aNumberPresentation,
|
|
|
|
const nsAString& aName,
|
|
|
|
uint16_t aNamePresentation)
|
2013-07-30 13:08:53 +04:00
|
|
|
{
|
2014-01-15 18:41:50 +04:00
|
|
|
MOZ_ASSERT(mCalls.Length() == 1);
|
|
|
|
|
|
|
|
nsRefPtr<TelephonyCall> callToNotify = mCalls[0];
|
|
|
|
MOZ_ASSERT(callToNotify && callToNotify->ServiceId() == aServiceId);
|
2013-07-30 13:08:53 +04:00
|
|
|
|
2014-04-10 10:25:42 +04:00
|
|
|
nsRefPtr<TelephonyCallId> id =
|
|
|
|
new TelephonyCallId(GetOwner(), aNumber, aNumberPresentation, aName,
|
|
|
|
aNamePresentation);
|
|
|
|
callToNotify->UpdateSecondId(id);
|
2013-07-30 13:08:53 +04:00
|
|
|
DispatchCallEvent(NS_LITERAL_STRING("callschanged"), callToNotify);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-10-28 10:43:14 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Telephony::NotifyConferenceError(const nsAString& aName,
|
|
|
|
const nsAString& aMessage)
|
|
|
|
{
|
|
|
|
mGroup->NotifyError(aName, aMessage);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-28 11:39:50 +04:00
|
|
|
nsresult
|
|
|
|
Telephony::DispatchCallEvent(const nsAString& aType,
|
2013-07-15 12:27:19 +04:00
|
|
|
TelephonyCall* aCall)
|
2013-01-28 11:39:50 +04:00
|
|
|
{
|
2014-07-21 21:17:00 +04:00
|
|
|
// If it is an incoming event, the call should not be null.
|
|
|
|
MOZ_ASSERT(!aType.EqualsLiteral("incoming") || aCall);
|
2013-01-28 11:39:50 +04:00
|
|
|
|
2014-06-11 05:23:34 +04:00
|
|
|
CallEventInit init;
|
|
|
|
init.mBubbles = false;
|
|
|
|
init.mCancelable = false;
|
|
|
|
init.mCall = aCall;
|
|
|
|
|
|
|
|
nsRefPtr<CallEvent> event = CallEvent::Constructor(this, aType, init);
|
2013-01-28 11:39:50 +04:00
|
|
|
|
2013-07-15 12:27:19 +04:00
|
|
|
return DispatchTrustedEvent(event);
|
2013-01-28 11:39:50 +04:00
|
|
|
}
|
|
|
|
|
2014-09-21 11:24:44 +04: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();
|
|
|
|
}
|