2012-04-20 01:33:25 +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/. */
|
|
|
|
|
2014-09-21 11:24:42 +04:00
|
|
|
#include "mozilla/dom/MobileConnection.h"
|
2013-10-29 12:12:41 +04:00
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
#include "MobileConnectionCallback.h"
|
2014-01-03 09:55:27 +04:00
|
|
|
#include "mozilla/dom/CFStateChangeEvent.h"
|
|
|
|
#include "mozilla/dom/DataErrorEvent.h"
|
2014-04-24 10:37:49 +04:00
|
|
|
#include "mozilla/dom/MozClirModeEvent.h"
|
2014-01-03 09:55:27 +04:00
|
|
|
#include "mozilla/dom/MozEmergencyCbModeEvent.h"
|
|
|
|
#include "mozilla/dom/MozOtaStatusEvent.h"
|
2014-06-11 23:38:55 +04:00
|
|
|
#include "mozilla/dom/ToJSValue.h"
|
2014-01-03 09:55:27 +04:00
|
|
|
#include "mozilla/dom/USSDReceivedEvent.h"
|
2013-08-13 03:13:38 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2014-05-05 10:36:20 +04:00
|
|
|
#include "mozilla/Services.h"
|
2013-08-14 16:50:22 +04:00
|
|
|
#include "nsIDOMDOMRequest.h"
|
2013-05-03 05:37:51 +04:00
|
|
|
#include "nsIPermissionManager.h"
|
2014-01-02 12:01:15 +04:00
|
|
|
#include "nsIVariant.h"
|
2012-10-03 10:29:07 +04:00
|
|
|
#include "nsJSON.h"
|
2014-05-05 10:36:20 +04:00
|
|
|
#include "nsJSUtils.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
2012-10-17 15:17:19 +04:00
|
|
|
|
2014-09-25 18:10:42 +04:00
|
|
|
#ifdef CONVERT_STRING_TO_NULLABLE_ENUM
|
|
|
|
#undef CONVERT_STRING_TO_NULLABLE_ENUM
|
|
|
|
#endif
|
2014-05-05 10:36:20 +04:00
|
|
|
#define CONVERT_STRING_TO_NULLABLE_ENUM(_string, _enumType, _enum) \
|
|
|
|
{ \
|
|
|
|
uint32_t i = 0; \
|
|
|
|
for (const EnumEntry* entry = _enumType##Values::strings; \
|
|
|
|
entry->value; \
|
|
|
|
++entry, ++i) { \
|
|
|
|
if (_string.EqualsASCII(entry->value)) { \
|
|
|
|
_enum.SetValue(static_cast<_enumType>(i)); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CONVERT_ENUM_TO_STRING(_enumType, _enum, _string) \
|
|
|
|
{ \
|
|
|
|
uint32_t index = uint32_t(_enum); \
|
|
|
|
_string.AssignASCII(_enumType##Values::strings[index].value, \
|
|
|
|
_enumType##Values::strings[index].length); \
|
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
using mozilla::ErrorResult;
|
2014-01-02 07:06:17 +04:00
|
|
|
using namespace mozilla::dom;
|
2014-09-21 11:24:42 +04:00
|
|
|
using namespace mozilla::dom::mobileconnection;
|
2013-03-06 13:53:12 +04:00
|
|
|
|
2013-12-09 05:59:17 +04:00
|
|
|
class MobileConnection::Listener MOZ_FINAL : public nsIMobileConnectionListener
|
2013-03-06 13:53:12 +04:00
|
|
|
{
|
|
|
|
MobileConnection* mMobileConnection;
|
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_FORWARD_SAFE_NSIMOBILECONNECTIONLISTENER(mMobileConnection)
|
|
|
|
|
2014-09-05 07:22:49 +04:00
|
|
|
explicit Listener(MobileConnection* aMobileConnection)
|
2013-03-06 13:53:12 +04:00
|
|
|
: mMobileConnection(aMobileConnection)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mMobileConnection);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Disconnect()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mMobileConnection);
|
|
|
|
mMobileConnection = nullptr;
|
|
|
|
}
|
2014-07-11 11:58:01 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
~Listener()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mMobileConnection);
|
|
|
|
}
|
2013-03-06 13:53:12 +04:00
|
|
|
};
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(MobileConnection::Listener, nsIMobileConnectionListener)
|
2013-03-06 13:53:12 +04:00
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(MobileConnection)
|
|
|
|
|
2012-04-20 01:33:25 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(MobileConnection,
|
2014-04-01 10:13:50 +04:00
|
|
|
DOMEventTargetHelper)
|
2013-03-06 13:53:12 +04:00
|
|
|
// Don't traverse mListener because it doesn't keep any reference to
|
2014-09-21 11:24:43 +04:00
|
|
|
// MobileConnection but a raw pointer instead. Neither does mMobileConnection
|
|
|
|
// because it's an xpcom service owned object and is only released at shutting
|
|
|
|
// down.
|
2014-05-05 10:36:20 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mVoice)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mData)
|
2012-04-20 01:33:25 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(MobileConnection,
|
2014-04-01 10:13:50 +04:00
|
|
|
DOMEventTargetHelper)
|
2014-08-07 08:21:29 +04:00
|
|
|
tmp->Shutdown();
|
2014-05-05 10:36:20 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mVoice)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mData)
|
2012-04-20 01:33:25 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(MobileConnection)
|
2014-08-20 05:01:49 +04:00
|
|
|
// MobileConnection does not expose nsIMobileConnectionListener. mListener is
|
|
|
|
// the exposed nsIMobileConnectionListener and forwards the calls it receives
|
|
|
|
// to us.
|
2014-04-01 10:13:50 +04:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
2012-04-20 01:33:25 +04:00
|
|
|
|
2014-04-01 10:13:50 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(MobileConnection, DOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(MobileConnection, DOMEventTargetHelper)
|
2012-04-20 01:33:25 +04:00
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
MobileConnection::MobileConnection(nsPIDOMWindow* aWindow, uint32_t aClientId)
|
|
|
|
: DOMEventTargetHelper(aWindow)
|
2012-04-20 01:33:25 +04:00
|
|
|
{
|
2014-09-21 11:24:43 +04:00
|
|
|
nsCOMPtr<nsIMobileConnectionService> service =
|
|
|
|
do_GetService(NS_MOBILE_CONNECTION_SERVICE_CONTRACTID);
|
2012-04-20 01:33:25 +04:00
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
// Not being able to acquire the service isn't fatal since we check
|
2012-04-20 01:33:25 +04:00
|
|
|
// for it explicitly below.
|
2014-09-21 11:24:43 +04:00
|
|
|
if (!service) {
|
2014-07-02 13:38:23 +04:00
|
|
|
NS_WARNING("Could not acquire nsIMobileConnectionService!");
|
2013-03-06 13:53:12 +04:00
|
|
|
return;
|
2012-04-20 01:33:25 +04:00
|
|
|
}
|
2012-04-20 01:33:25 +04:00
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
nsresult rv = service->GetItemByServiceId(aClientId,
|
|
|
|
getter_AddRefs(mMobileConnection));
|
|
|
|
if (NS_FAILED(rv) || !mMobileConnection) {
|
|
|
|
NS_WARNING("Could not acquire nsIMobileConnection!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-03 05:37:51 +04:00
|
|
|
mListener = new Listener(this);
|
2014-05-05 10:36:20 +04:00
|
|
|
mVoice = new MobileConnectionInfo(GetOwner());
|
|
|
|
mData = new MobileConnectionInfo(GetOwner());
|
2013-05-03 05:37:51 +04:00
|
|
|
|
2013-12-23 06:59:43 +04:00
|
|
|
if (CheckPermission("mobileconnection")) {
|
2014-09-21 11:24:43 +04:00
|
|
|
DebugOnly<nsresult> rv = mMobileConnection->RegisterListener(mListener);
|
2013-05-03 05:37:51 +04:00
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
|
2014-07-02 13:38:23 +04:00
|
|
|
"Failed registering mobile connection messages with service");
|
2014-05-05 10:36:20 +04:00
|
|
|
UpdateVoice();
|
|
|
|
UpdateData();
|
2013-05-03 05:37:51 +04:00
|
|
|
}
|
2012-04-20 01:33:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MobileConnection::Shutdown()
|
|
|
|
{
|
2014-08-07 08:21:29 +04:00
|
|
|
if (mListener) {
|
2014-09-21 11:24:43 +04:00
|
|
|
if (mMobileConnection) {
|
|
|
|
mMobileConnection->UnregisterListener(mListener);
|
2014-08-07 08:21:29 +04:00
|
|
|
}
|
|
|
|
|
2013-03-06 13:53:12 +04:00
|
|
|
mListener->Disconnect();
|
|
|
|
mListener = nullptr;
|
2012-04-20 01:33:25 +04:00
|
|
|
}
|
2012-04-20 01:33:25 +04:00
|
|
|
}
|
|
|
|
|
2014-07-11 11:58:01 +04:00
|
|
|
MobileConnection::~MobileConnection()
|
|
|
|
{
|
2014-08-07 08:21:29 +04:00
|
|
|
Shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MobileConnection::DisconnectFromOwner()
|
|
|
|
{
|
|
|
|
DOMEventTargetHelper::DisconnectFromOwner();
|
|
|
|
// Event listeners can't be handled anymore, so we can shutdown
|
|
|
|
// the MobileConnection.
|
|
|
|
Shutdown();
|
2014-07-11 11:58:01 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
JSObject*
|
|
|
|
MobileConnection::WrapObject(JSContext* aCx)
|
|
|
|
{
|
|
|
|
return MozMobileConnectionBinding::Wrap(aCx, this);
|
|
|
|
}
|
2012-04-20 01:33:25 +04:00
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
bool
|
|
|
|
MobileConnection::CheckPermission(const char* aType) const
|
2013-05-03 05:37:51 +04:00
|
|
|
{
|
2014-05-05 10:36:20 +04:00
|
|
|
nsCOMPtr<nsIPermissionManager> permMgr =
|
|
|
|
mozilla::services::GetPermissionManager();
|
|
|
|
NS_ENSURE_TRUE(permMgr, false);
|
2013-05-03 05:37:51 +04:00
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
uint32_t permission = nsIPermissionManager::DENY_ACTION;
|
|
|
|
permMgr->TestPermissionFromWindow(GetOwner(), aType, &permission);
|
|
|
|
return permission == nsIPermissionManager::ALLOW_ACTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MobileConnection::UpdateVoice()
|
|
|
|
{
|
2014-09-21 11:24:43 +04:00
|
|
|
if (!mMobileConnection) {
|
2014-05-05 10:36:20 +04:00
|
|
|
return;
|
2013-05-03 05:37:51 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
nsCOMPtr<nsIMobileConnectionInfo> info;
|
2014-09-21 11:24:43 +04:00
|
|
|
mMobileConnection->GetVoice(getter_AddRefs(info));
|
2014-05-05 10:36:20 +04:00
|
|
|
mVoice->Update(info);
|
2013-05-03 05:37:51 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
void
|
|
|
|
MobileConnection::UpdateData()
|
2013-05-03 05:37:51 +04:00
|
|
|
{
|
2014-09-21 11:24:43 +04:00
|
|
|
if (!mMobileConnection) {
|
2014-05-05 10:36:20 +04:00
|
|
|
return;
|
2013-05-03 05:37:51 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
nsCOMPtr<nsIMobileConnectionInfo> info;
|
2014-09-21 11:24:43 +04:00
|
|
|
mMobileConnection->GetData(getter_AddRefs(info));
|
2014-05-05 10:36:20 +04:00
|
|
|
mData->Update(info);
|
2013-05-03 05:37:51 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
// WebIDL interface
|
2013-05-03 05:37:51 +04:00
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
void
|
|
|
|
MobileConnection::GetLastKnownNetwork(nsString& aRetVal) const
|
2013-05-03 05:37:51 +04:00
|
|
|
{
|
2014-05-05 10:36:20 +04:00
|
|
|
aRetVal.SetIsVoid(true);
|
2013-05-03 05:37:51 +04:00
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
if (!mMobileConnection) {
|
2014-05-05 10:36:20 +04:00
|
|
|
return;
|
|
|
|
}
|
2013-05-03 05:37:51 +04:00
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
mMobileConnection->GetLastKnownNetwork(aRetVal);
|
2013-05-03 05:37:51 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
void
|
|
|
|
MobileConnection::GetLastKnownHomeNetwork(nsString& aRetVal) const
|
2012-04-20 01:33:25 +04:00
|
|
|
{
|
2014-05-05 10:36:20 +04:00
|
|
|
aRetVal.SetIsVoid(true);
|
2013-05-03 05:37:51 +04:00
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
if (!mMobileConnection) {
|
2014-05-05 10:36:20 +04:00
|
|
|
return;
|
2012-04-20 01:33:25 +04:00
|
|
|
}
|
2014-05-05 10:36:20 +04:00
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
mMobileConnection->GetLastKnownHomeNetwork(aRetVal);
|
2012-04-20 01:33:25 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
// All fields below require the "mobileconnection" permission.
|
2013-05-03 05:37:51 +04:00
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
MobileConnectionInfo*
|
|
|
|
MobileConnection::Voice() const
|
|
|
|
{
|
|
|
|
return mVoice;
|
2013-11-13 12:51:04 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
MobileConnectionInfo*
|
|
|
|
MobileConnection::Data() const
|
2013-11-13 12:51:04 +04:00
|
|
|
{
|
2014-05-05 10:36:20 +04:00
|
|
|
return mData;
|
2012-04-20 01:33:25 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
void
|
|
|
|
MobileConnection::GetIccId(nsString& aRetVal) const
|
2012-06-20 02:52:06 +04:00
|
|
|
{
|
2014-05-05 10:36:20 +04:00
|
|
|
aRetVal.SetIsVoid(true);
|
2013-05-03 05:37:51 +04:00
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
if (!mMobileConnection) {
|
2014-05-05 10:36:20 +04:00
|
|
|
return;
|
2012-06-20 02:52:06 +04:00
|
|
|
}
|
2014-05-05 10:36:20 +04:00
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
mMobileConnection->GetIccId(aRetVal);
|
2012-06-20 02:52:06 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
Nullable<MobileNetworkSelectionMode>
|
|
|
|
MobileConnection::GetNetworkSelectionMode() const
|
2013-11-21 18:08:50 +04:00
|
|
|
{
|
2014-05-05 10:36:20 +04:00
|
|
|
Nullable<MobileNetworkSelectionMode> retVal =
|
|
|
|
Nullable<MobileNetworkSelectionMode>();
|
2013-11-21 18:08:50 +04:00
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
if (!mMobileConnection) {
|
2014-05-05 10:36:20 +04:00
|
|
|
return retVal;
|
2013-11-21 18:08:50 +04:00
|
|
|
}
|
2014-05-05 10:36:20 +04:00
|
|
|
|
|
|
|
nsAutoString mode;
|
2014-09-21 11:24:43 +04:00
|
|
|
mMobileConnection->GetNetworkSelectionMode(mode);
|
2014-05-05 10:36:20 +04:00
|
|
|
CONVERT_STRING_TO_NULLABLE_ENUM(mode, MobileNetworkSelectionMode, retVal);
|
|
|
|
|
|
|
|
return retVal;
|
2013-11-21 18:08:50 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
Nullable<MobileRadioState>
|
|
|
|
MobileConnection::GetRadioState() const
|
2014-01-02 12:01:15 +04:00
|
|
|
{
|
2014-05-05 10:36:20 +04:00
|
|
|
Nullable<MobileRadioState> retVal = Nullable<MobileRadioState>();
|
2014-01-02 12:01:15 +04:00
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
if (!mMobileConnection) {
|
2014-05-05 10:36:20 +04:00
|
|
|
return retVal;
|
2014-01-02 12:01:15 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
nsAutoString state;
|
2014-09-21 11:24:43 +04:00
|
|
|
mMobileConnection->GetRadioState(state);
|
2014-05-05 10:36:20 +04:00
|
|
|
CONVERT_STRING_TO_NULLABLE_ENUM(state, MobileRadioState, retVal);
|
|
|
|
|
|
|
|
return retVal;
|
2014-01-02 12:01:15 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
void
|
|
|
|
MobileConnection::GetSupportedNetworkTypes(nsTArray<MobileNetworkType>& aTypes) const
|
2012-04-20 01:33:25 +04:00
|
|
|
{
|
2014-09-21 11:24:43 +04:00
|
|
|
if (!mMobileConnection) {
|
2014-05-05 10:36:20 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
char16_t** types = nullptr;
|
|
|
|
uint32_t length = 0;
|
2012-04-20 01:33:25 +04:00
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
nsresult rv = mMobileConnection->GetSupportedNetworkTypes(&types, &length);
|
|
|
|
NS_ENSURE_SUCCESS_VOID(rv);
|
2014-05-05 10:36:20 +04:00
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
|
|
|
nsDependentString rawType(types[i]);
|
|
|
|
Nullable<MobileNetworkType> type = Nullable<MobileNetworkType>();
|
|
|
|
CONVERT_STRING_TO_NULLABLE_ENUM(rawType, MobileNetworkType, type);
|
2014-05-05 10:36:20 +04:00
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
if (!type.IsNull()) {
|
|
|
|
aTypes.AppendElement(type.Value());
|
2014-05-05 10:36:20 +04:00
|
|
|
}
|
|
|
|
}
|
2014-09-21 11:24:43 +04:00
|
|
|
|
|
|
|
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(length, types);
|
2014-05-05 10:36:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
MobileConnection::GetNetworks(ErrorResult& aRv)
|
|
|
|
{
|
2014-09-21 11:24:43 +04:00
|
|
|
if (!mMobileConnection) {
|
2014-05-05 10:36:20 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2012-04-20 01:33:25 +04:00
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsRefPtr<MobileConnectionCallback> requestCallback =
|
|
|
|
new MobileConnectionCallback(GetOwner(), request);
|
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
nsresult rv = mMobileConnection->GetNetworks(requestCallback);
|
2014-05-05 10:36:20 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
return request.forget();
|
2012-04-20 01:33:25 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
MobileConnection::SelectNetwork(MobileNetworkInfo& aNetwork, ErrorResult& aRv)
|
2012-06-20 02:52:06 +04:00
|
|
|
{
|
2014-09-21 11:24:43 +04:00
|
|
|
if (!mMobileConnection) {
|
2014-05-05 10:36:20 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsRefPtr<MobileConnectionCallback> requestCallback =
|
|
|
|
new MobileConnectionCallback(GetOwner(), request);
|
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
nsresult rv = mMobileConnection->SelectNetwork(&aNetwork, requestCallback);
|
2014-05-05 10:36:20 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
2012-06-20 02:52:06 +04:00
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
return request.forget();
|
2012-06-20 02:52:06 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
MobileConnection::SelectNetworkAutomatically(ErrorResult& aRv)
|
2012-06-20 02:52:06 +04:00
|
|
|
{
|
2014-09-21 11:24:43 +04:00
|
|
|
if (!mMobileConnection) {
|
2014-05-05 10:36:20 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsRefPtr<MobileConnectionCallback> requestCallback =
|
|
|
|
new MobileConnectionCallback(GetOwner(), request);
|
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
nsresult rv =
|
|
|
|
mMobileConnection->SelectNetworkAutomatically(requestCallback);
|
2014-05-05 10:36:20 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
2012-06-20 02:52:06 +04:00
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
return request.forget();
|
2012-06-20 02:52:06 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
MobileConnection::SetPreferredNetworkType(MobilePreferredNetworkType& aType,
|
|
|
|
ErrorResult& aRv)
|
2013-12-11 07:14:41 +04:00
|
|
|
{
|
2014-09-21 11:24:43 +04:00
|
|
|
if (!mMobileConnection) {
|
2014-05-05 10:36:20 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2013-12-11 07:14:41 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
nsAutoString type;
|
|
|
|
CONVERT_ENUM_TO_STRING(MobilePreferredNetworkType, aType, type);
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsRefPtr<MobileConnectionCallback> requestCallback =
|
|
|
|
new MobileConnectionCallback(GetOwner(), request);
|
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
nsresult rv =
|
|
|
|
mMobileConnection->SetPreferredNetworkType(type, requestCallback);
|
2014-05-05 10:36:20 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
return request.forget();
|
2013-12-11 07:14:41 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
MobileConnection::GetPreferredNetworkType(ErrorResult& aRv)
|
2013-12-11 07:14:41 +04:00
|
|
|
{
|
2014-09-21 11:24:43 +04:00
|
|
|
if (!mMobileConnection) {
|
2014-05-05 10:36:20 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2013-12-11 07:14:41 +04:00
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsRefPtr<MobileConnectionCallback> requestCallback =
|
|
|
|
new MobileConnectionCallback(GetOwner(), request);
|
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
nsresult rv = mMobileConnection->GetPreferredNetworkType(requestCallback);
|
2014-05-05 10:36:20 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
return request.forget();
|
2013-12-11 07:14:41 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
MobileConnection::SetRoamingPreference(MobileRoamingMode& aMode,
|
|
|
|
ErrorResult& aRv)
|
2013-06-10 11:40:08 +04:00
|
|
|
{
|
2014-09-21 11:24:43 +04:00
|
|
|
if (!mMobileConnection) {
|
2014-05-05 10:36:20 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString mode;
|
|
|
|
CONVERT_ENUM_TO_STRING(MobileRoamingMode, aMode, mode);
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsRefPtr<MobileConnectionCallback> requestCallback =
|
|
|
|
new MobileConnectionCallback(GetOwner(), request);
|
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
nsresult rv = mMobileConnection->SetRoamingPreference(mode, requestCallback);
|
2014-05-05 10:36:20 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
2013-06-10 11:40:08 +04:00
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
return request.forget();
|
2013-06-10 11:40:08 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
MobileConnection::GetRoamingPreference(ErrorResult& aRv)
|
2013-06-10 11:40:08 +04:00
|
|
|
{
|
2014-09-21 11:24:43 +04:00
|
|
|
if (!mMobileConnection) {
|
2014-05-05 10:36:20 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2013-06-10 11:40:08 +04:00
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsRefPtr<MobileConnectionCallback> requestCallback =
|
|
|
|
new MobileConnectionCallback(GetOwner(), request);
|
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
nsresult rv = mMobileConnection->GetRoamingPreference(requestCallback);
|
2014-05-05 10:36:20 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
2014-07-02 13:38:23 +04:00
|
|
|
return nullptr;
|
2014-05-05 10:36:20 +04:00
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
return request.forget();
|
2013-06-10 11:40:08 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
MobileConnection::SetVoicePrivacyMode(bool aEnabled, ErrorResult& aRv)
|
2013-08-14 12:21:05 +04:00
|
|
|
{
|
2014-09-21 11:24:43 +04:00
|
|
|
if (!mMobileConnection) {
|
2014-05-05 10:36:20 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsRefPtr<MobileConnectionCallback> requestCallback =
|
|
|
|
new MobileConnectionCallback(GetOwner(), request);
|
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
nsresult rv =
|
|
|
|
mMobileConnection->SetVoicePrivacyMode(aEnabled, requestCallback);
|
2014-05-05 10:36:20 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
2013-08-14 12:21:05 +04:00
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
return request.forget();
|
2013-08-14 12:21:05 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
MobileConnection::GetVoicePrivacyMode(ErrorResult& aRv)
|
2013-08-14 12:21:05 +04:00
|
|
|
{
|
2014-09-21 11:24:43 +04:00
|
|
|
if (!mMobileConnection) {
|
2014-05-05 10:36:20 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsRefPtr<MobileConnectionCallback> requestCallback =
|
|
|
|
new MobileConnectionCallback(GetOwner(), request);
|
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
nsresult rv = mMobileConnection->GetVoicePrivacyMode(requestCallback);
|
2014-05-05 10:36:20 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
2013-08-14 12:21:05 +04:00
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
return request.forget();
|
2013-08-14 12:21:05 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
MobileConnection::SendMMI(const nsAString& aMMIString, ErrorResult& aRv)
|
2012-06-11 03:44:50 +04:00
|
|
|
{
|
2014-09-21 11:24:43 +04:00
|
|
|
if (!mMobileConnection) {
|
2014-05-05 10:36:20 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsRefPtr<MobileConnectionCallback> requestCallback =
|
|
|
|
new MobileConnectionCallback(GetOwner(), request);
|
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
nsresult rv = mMobileConnection->SendMMI(aMMIString, requestCallback);
|
2014-05-05 10:36:20 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
2012-06-11 03:44:50 +04:00
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
return request.forget();
|
2012-06-11 03:44:50 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
MobileConnection::CancelMMI(ErrorResult& aRv)
|
2012-06-11 03:44:50 +04:00
|
|
|
{
|
2014-09-21 11:24:43 +04:00
|
|
|
if (!mMobileConnection) {
|
2014-05-05 10:36:20 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsRefPtr<MobileConnectionCallback> requestCallback =
|
|
|
|
new MobileConnectionCallback(GetOwner(), request);
|
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
nsresult rv = mMobileConnection->CancelMMI(requestCallback);
|
2014-05-05 10:36:20 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
2012-06-11 03:44:50 +04:00
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
return request.forget();
|
2012-06-11 03:44:50 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
MobileConnection::GetCallForwardingOption(uint16_t aReason, ErrorResult& aRv)
|
2012-10-31 17:58:32 +04:00
|
|
|
{
|
2014-09-21 11:24:43 +04:00
|
|
|
if (!mMobileConnection) {
|
2014-05-05 10:36:20 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsRefPtr<MobileConnectionCallback> requestCallback =
|
|
|
|
new MobileConnectionCallback(GetOwner(), request);
|
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
nsresult rv = mMobileConnection->GetCallForwarding(aReason, requestCallback);
|
2014-05-05 10:36:20 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
2012-10-31 17:58:32 +04:00
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
return request.forget();
|
2012-10-31 17:58:32 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
MobileConnection::SetCallForwardingOption(const MozCallForwardingOptions& aOptions,
|
|
|
|
ErrorResult& aRv)
|
2012-10-31 17:58:32 +04:00
|
|
|
{
|
2014-09-21 11:24:43 +04:00
|
|
|
if (!mMobileConnection) {
|
2014-05-05 10:36:20 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2012-10-31 17:58:32 +04:00
|
|
|
}
|
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
AutoJSAPI jsapi;
|
2014-06-25 19:24:22 +04:00
|
|
|
if (!NS_WARN_IF(jsapi.Init(GetOwner()))) {
|
2014-06-25 07:57:16 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSContext *cx = jsapi.cx();
|
2014-05-05 10:36:20 +04:00
|
|
|
JS::Rooted<JS::Value> options(cx);
|
2014-06-11 23:38:55 +04:00
|
|
|
if (!ToJSValue(cx, aOptions, &options)) {
|
2014-05-05 10:36:20 +04:00
|
|
|
aRv.Throw(NS_ERROR_TYPE_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsRefPtr<MobileConnectionCallback> requestCallback =
|
|
|
|
new MobileConnectionCallback(GetOwner(), request);
|
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
nsresult rv = mMobileConnection->SetCallForwarding(options, requestCallback);
|
2014-05-05 10:36:20 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
return request.forget();
|
2012-10-31 17:58:32 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
MobileConnection::GetCallBarringOption(const MozCallBarringOptions& aOptions,
|
|
|
|
ErrorResult& aRv)
|
2013-05-21 09:12:59 +04:00
|
|
|
{
|
2014-09-21 11:24:43 +04:00
|
|
|
if (!mMobileConnection) {
|
2014-05-05 10:36:20 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
AutoJSAPI jsapi;
|
2014-06-25 19:24:22 +04:00
|
|
|
if (!NS_WARN_IF(jsapi.Init(GetOwner()))) {
|
2014-06-25 07:57:16 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSContext *cx = jsapi.cx();
|
2014-05-05 10:36:20 +04:00
|
|
|
JS::Rooted<JS::Value> options(cx);
|
2014-06-11 23:38:55 +04:00
|
|
|
if (!ToJSValue(cx, aOptions, &options)) {
|
2014-05-05 10:36:20 +04:00
|
|
|
aRv.Throw(NS_ERROR_TYPE_ERR);
|
|
|
|
return nullptr;
|
2013-05-21 09:12:59 +04:00
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsRefPtr<MobileConnectionCallback> requestCallback =
|
|
|
|
new MobileConnectionCallback(GetOwner(), request);
|
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
nsresult rv = mMobileConnection->GetCallBarring(options, requestCallback);
|
2014-05-05 10:36:20 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
return request.forget();
|
2013-05-21 09:12:59 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
MobileConnection::SetCallBarringOption(const MozCallBarringOptions& aOptions,
|
|
|
|
ErrorResult& aRv)
|
2013-05-21 09:12:59 +04:00
|
|
|
{
|
2014-09-21 11:24:43 +04:00
|
|
|
if (!mMobileConnection) {
|
2014-05-05 10:36:20 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
AutoJSAPI jsapi;
|
2014-06-25 19:24:22 +04:00
|
|
|
if (!NS_WARN_IF(jsapi.Init(GetOwner()))) {
|
2014-06-25 07:57:16 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSContext *cx = jsapi.cx();
|
2014-05-05 10:36:20 +04:00
|
|
|
JS::Rooted<JS::Value> options(cx);
|
2014-06-11 23:38:55 +04:00
|
|
|
if (!ToJSValue(cx, aOptions, &options)) {
|
2014-05-05 10:36:20 +04:00
|
|
|
aRv.Throw(NS_ERROR_TYPE_ERR);
|
|
|
|
return nullptr;
|
2013-05-21 09:12:59 +04:00
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsRefPtr<MobileConnectionCallback> requestCallback =
|
|
|
|
new MobileConnectionCallback(GetOwner(), request);
|
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
nsresult rv = mMobileConnection->SetCallBarring(options, requestCallback);
|
2014-05-05 10:36:20 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
return request.forget();
|
2013-05-21 09:12:59 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
MobileConnection::ChangeCallBarringPassword(const MozCallBarringOptions& aOptions,
|
|
|
|
ErrorResult& aRv)
|
2013-08-27 05:53:30 +04:00
|
|
|
{
|
2014-09-21 11:24:43 +04:00
|
|
|
if (!mMobileConnection) {
|
2014-05-05 10:36:20 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
AutoJSAPI jsapi;
|
2014-06-25 19:24:22 +04:00
|
|
|
if (!NS_WARN_IF(jsapi.Init(GetOwner()))) {
|
2014-06-25 07:57:16 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSContext *cx = jsapi.cx();
|
2014-05-05 10:36:20 +04:00
|
|
|
JS::Rooted<JS::Value> options(cx);
|
2014-06-11 23:38:55 +04:00
|
|
|
if (!ToJSValue(cx, aOptions, &options)) {
|
2014-05-05 10:36:20 +04:00
|
|
|
aRv.Throw(NS_ERROR_TYPE_ERR);
|
|
|
|
return nullptr;
|
2013-08-27 05:53:30 +04:00
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsRefPtr<MobileConnectionCallback> requestCallback =
|
|
|
|
new MobileConnectionCallback(GetOwner(), request);
|
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
nsresult rv =
|
|
|
|
mMobileConnection->ChangeCallBarringPassword(options, requestCallback);
|
2014-05-05 10:36:20 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
return request.forget();
|
2013-08-27 05:53:30 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
MobileConnection::GetCallWaitingOption(ErrorResult& aRv)
|
2013-04-18 16:18:48 +04:00
|
|
|
{
|
2014-09-21 11:24:43 +04:00
|
|
|
if (!mMobileConnection) {
|
2014-05-05 10:36:20 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsRefPtr<MobileConnectionCallback> requestCallback =
|
|
|
|
new MobileConnectionCallback(GetOwner(), request);
|
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
nsresult rv = mMobileConnection->GetCallWaiting(requestCallback);
|
2014-05-05 10:36:20 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
2013-04-18 16:18:48 +04:00
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
return request.forget();
|
2013-04-18 16:18:48 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
MobileConnection::SetCallWaitingOption(bool aEnabled, ErrorResult& aRv)
|
2013-04-18 16:18:48 +04:00
|
|
|
{
|
2014-09-21 11:24:43 +04:00
|
|
|
if (!mMobileConnection) {
|
2014-05-05 10:36:20 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsRefPtr<MobileConnectionCallback> requestCallback =
|
|
|
|
new MobileConnectionCallback(GetOwner(), request);
|
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
nsresult rv = mMobileConnection->SetCallWaiting(aEnabled, requestCallback);
|
2014-05-05 10:36:20 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
2013-04-18 16:18:48 +04:00
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
return request.forget();
|
2013-04-18 16:18:48 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
MobileConnection::GetCallingLineIdRestriction(ErrorResult& aRv)
|
2013-07-18 01:18:24 +04:00
|
|
|
{
|
2014-09-21 11:24:43 +04:00
|
|
|
if (!mMobileConnection) {
|
2014-05-05 10:36:20 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2013-07-18 01:18:24 +04:00
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsRefPtr<MobileConnectionCallback> requestCallback =
|
|
|
|
new MobileConnectionCallback(GetOwner(), request);
|
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
nsresult rv =
|
|
|
|
mMobileConnection->GetCallingLineIdRestriction(requestCallback);
|
2014-05-05 10:36:20 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
return request.forget();
|
2013-07-18 01:18:24 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
MobileConnection::SetCallingLineIdRestriction(uint16_t aMode,
|
|
|
|
ErrorResult& aRv)
|
2013-07-18 01:18:24 +04:00
|
|
|
{
|
2014-09-21 11:24:43 +04:00
|
|
|
if (!mMobileConnection) {
|
2014-05-05 10:36:20 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsRefPtr<MobileConnectionCallback> requestCallback =
|
|
|
|
new MobileConnectionCallback(GetOwner(), request);
|
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
nsresult rv =
|
|
|
|
mMobileConnection->SetCallingLineIdRestriction(aMode, requestCallback);
|
2014-05-05 10:36:20 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
2013-07-18 01:18:24 +04:00
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
return request.forget();
|
2013-07-18 01:18:24 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
MobileConnection::ExitEmergencyCbMode(ErrorResult& aRv)
|
2013-08-14 16:50:22 +04:00
|
|
|
{
|
2014-09-21 11:24:43 +04:00
|
|
|
if (!mMobileConnection) {
|
2014-05-05 10:36:20 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2013-08-14 16:50:22 +04:00
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsRefPtr<MobileConnectionCallback> requestCallback =
|
|
|
|
new MobileConnectionCallback(GetOwner(), request);
|
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
nsresult rv = mMobileConnection->ExitEmergencyCbMode(requestCallback);
|
2014-05-05 10:36:20 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
return request.forget();
|
2013-08-14 16:50:22 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
MobileConnection::SetRadioEnabled(bool aEnabled, ErrorResult& aRv)
|
2013-11-21 18:08:50 +04:00
|
|
|
{
|
2014-09-21 11:24:43 +04:00
|
|
|
if (!mMobileConnection) {
|
2014-05-05 10:36:20 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsRefPtr<MobileConnectionCallback> requestCallback =
|
|
|
|
new MobileConnectionCallback(GetOwner(), request);
|
|
|
|
|
2014-09-21 11:24:43 +04:00
|
|
|
nsresult rv = mMobileConnection->SetRadioEnabled(aEnabled, requestCallback);
|
2014-05-05 10:36:20 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
2013-11-21 18:08:50 +04:00
|
|
|
}
|
|
|
|
|
2014-07-02 13:38:23 +04:00
|
|
|
return request.forget();
|
2013-11-21 18:08:50 +04:00
|
|
|
}
|
|
|
|
|
2013-03-06 13:53:12 +04:00
|
|
|
// nsIMobileConnectionListener
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MobileConnection::NotifyVoiceChanged()
|
|
|
|
{
|
2013-05-03 05:37:51 +04:00
|
|
|
if (!CheckPermission("mobileconnection")) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
UpdateVoice();
|
|
|
|
|
2013-03-06 13:53:12 +04:00
|
|
|
return DispatchTrustedEvent(NS_LITERAL_STRING("voicechange"));
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MobileConnection::NotifyDataChanged()
|
|
|
|
{
|
2013-05-03 05:37:51 +04:00
|
|
|
if (!CheckPermission("mobileconnection")) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-05-05 10:36:20 +04:00
|
|
|
UpdateData();
|
|
|
|
|
2013-03-06 13:53:12 +04:00
|
|
|
return DispatchTrustedEvent(NS_LITERAL_STRING("datachange"));
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MobileConnection::NotifyUssdReceived(const nsAString& aMessage,
|
|
|
|
bool aSessionEnded)
|
|
|
|
{
|
2013-05-03 05:37:51 +04:00
|
|
|
if (!CheckPermission("mobileconnection")) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-01-03 09:55:27 +04:00
|
|
|
USSDReceivedEventInit init;
|
|
|
|
init.mBubbles = false;
|
|
|
|
init.mCancelable = false;
|
|
|
|
init.mMessage = aMessage;
|
|
|
|
init.mSessionEnded = aSessionEnded;
|
2013-03-06 13:53:12 +04:00
|
|
|
|
2014-01-03 09:55:27 +04:00
|
|
|
nsRefPtr<USSDReceivedEvent> event =
|
|
|
|
USSDReceivedEvent::Constructor(this, NS_LITERAL_STRING("ussdreceived"), init);
|
2013-03-06 13:53:12 +04:00
|
|
|
|
2014-01-03 09:55:27 +04:00
|
|
|
return DispatchTrustedEvent(event);
|
2013-03-06 13:53:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MobileConnection::NotifyDataError(const nsAString& aMessage)
|
|
|
|
{
|
2013-05-03 05:37:51 +04:00
|
|
|
if (!CheckPermission("mobileconnection")) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-01-03 09:55:27 +04:00
|
|
|
DataErrorEventInit init;
|
|
|
|
init.mBubbles = false;
|
|
|
|
init.mCancelable = false;
|
|
|
|
init.mMessage = aMessage;
|
2013-03-06 13:53:12 +04:00
|
|
|
|
2014-01-03 09:55:27 +04:00
|
|
|
nsRefPtr<DataErrorEvent> event =
|
|
|
|
DataErrorEvent::Constructor(this, NS_LITERAL_STRING("dataerror"), init);
|
2013-03-06 13:53:12 +04:00
|
|
|
|
2014-01-03 09:55:27 +04:00
|
|
|
return DispatchTrustedEvent(event);
|
2013-03-06 13:53:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-07-02 13:38:23 +04:00
|
|
|
MobileConnection::NotifyCFStateChanged(bool aSuccess,
|
|
|
|
unsigned short aAction,
|
|
|
|
unsigned short aReason,
|
|
|
|
const nsAString& aNumber,
|
|
|
|
unsigned short aSeconds,
|
|
|
|
unsigned short aServiceClass)
|
2013-03-06 13:53:12 +04:00
|
|
|
{
|
2013-05-03 05:37:51 +04:00
|
|
|
if (!CheckPermission("mobileconnection")) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-01-03 09:55:27 +04:00
|
|
|
CFStateChangeEventInit init;
|
|
|
|
init.mBubbles = false;
|
|
|
|
init.mCancelable = false;
|
|
|
|
init.mSuccess = aSuccess;
|
|
|
|
init.mAction = aAction;
|
|
|
|
init.mReason = aReason;
|
|
|
|
init.mNumber = aNumber;
|
|
|
|
init.mTimeSeconds = aSeconds;
|
|
|
|
init.mServiceClass = aServiceClass;
|
2013-03-06 13:53:12 +04:00
|
|
|
|
2014-01-03 09:55:27 +04:00
|
|
|
nsRefPtr<CFStateChangeEvent> event =
|
|
|
|
CFStateChangeEvent::Constructor(this, NS_LITERAL_STRING("cfstatechange"), init);
|
2013-03-06 13:53:12 +04:00
|
|
|
|
2014-01-03 09:55:27 +04:00
|
|
|
return DispatchTrustedEvent(event);
|
2013-03-06 13:53:12 +04:00
|
|
|
}
|
2013-08-14 16:50:22 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MobileConnection::NotifyEmergencyCbModeChanged(bool aActive,
|
|
|
|
uint32_t aTimeoutMs)
|
|
|
|
{
|
|
|
|
if (!CheckPermission("mobileconnection")) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-01-03 09:55:27 +04:00
|
|
|
MozEmergencyCbModeEventInit init;
|
|
|
|
init.mBubbles = false;
|
|
|
|
init.mCancelable = false;
|
|
|
|
init.mActive = aActive;
|
|
|
|
init.mTimeoutMs = aTimeoutMs;
|
2013-08-14 16:50:22 +04:00
|
|
|
|
2014-01-03 09:55:27 +04:00
|
|
|
nsRefPtr<MozEmergencyCbModeEvent> event =
|
|
|
|
MozEmergencyCbModeEvent::Constructor(this, NS_LITERAL_STRING("emergencycbmodechange"), init);
|
2013-08-14 16:50:22 +04:00
|
|
|
|
2014-01-03 09:55:27 +04:00
|
|
|
return DispatchTrustedEvent(event);
|
2013-08-14 16:50:22 +04:00
|
|
|
}
|
2013-08-27 16:25:53 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MobileConnection::NotifyOtaStatusChanged(const nsAString& aStatus)
|
|
|
|
{
|
|
|
|
if (!CheckPermission("mobileconnection")) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-01-03 09:55:27 +04:00
|
|
|
MozOtaStatusEventInit init;
|
|
|
|
init.mBubbles = false;
|
|
|
|
init.mCancelable = false;
|
|
|
|
init.mStatus = aStatus;
|
2013-08-27 16:25:53 +04:00
|
|
|
|
2014-01-03 09:55:27 +04:00
|
|
|
nsRefPtr<MozOtaStatusEvent> event =
|
|
|
|
MozOtaStatusEvent::Constructor(this, NS_LITERAL_STRING("otastatuschange"), init);
|
2013-08-27 16:25:53 +04:00
|
|
|
|
2014-01-03 09:55:27 +04:00
|
|
|
return DispatchTrustedEvent(event);
|
2013-08-27 16:25:53 +04:00
|
|
|
}
|
2013-10-30 08:02:47 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MobileConnection::NotifyIccChanged()
|
|
|
|
{
|
2013-11-13 12:51:04 +04:00
|
|
|
if (!CheckPermission("mobileconnection")) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DispatchTrustedEvent(NS_LITERAL_STRING("iccchange"));
|
|
|
|
}
|
2013-11-21 18:08:50 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MobileConnection::NotifyRadioStateChanged()
|
|
|
|
{
|
|
|
|
if (!CheckPermission("mobileconnection")) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DispatchTrustedEvent(NS_LITERAL_STRING("radiostatechange"));
|
2013-12-09 05:59:17 +04:00
|
|
|
}
|
2014-04-24 10:37:49 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MobileConnection::NotifyClirModeChanged(uint32_t aMode)
|
|
|
|
{
|
|
|
|
if (!CheckPermission("mobileconnection")) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
MozClirModeEventInit init;
|
|
|
|
init.mBubbles = false;
|
|
|
|
init.mCancelable = false;
|
|
|
|
init.mMode = aMode;
|
|
|
|
|
|
|
|
nsRefPtr<MozClirModeEvent> event =
|
|
|
|
MozClirModeEvent::Constructor(this, NS_LITERAL_STRING("clirmodechange"), init);
|
|
|
|
|
|
|
|
return DispatchTrustedEvent(event);
|
|
|
|
}
|
2014-07-02 13:38:23 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MobileConnection::NotifyLastKnownNetworkChanged()
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MobileConnection::NotifyLastKnownHomeNetworkChanged()
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MobileConnection::NotifyNetworkSelectionModeChanged()
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|