1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "mozilla/dom/MobileConnection.h"
7 #include "MobileConnectionCallback.h"
8 #include "mozilla/AsyncEventDispatcher.h"
9 #include "mozilla/dom/CFStateChangeEvent.h"
10 #include "mozilla/dom/DataErrorEvent.h"
11 #include "mozilla/dom/ImsRegHandler.h"
12 #include "mozilla/dom/MozClirModeEvent.h"
13 #include "mozilla/dom/MozEmergencyCbModeEvent.h"
14 #include "mozilla/dom/MozOtaStatusEvent.h"
15 #include "mozilla/dom/ToJSValue.h"
16 #include "mozilla/Preferences.h"
17 #include "mozilla/Services.h"
18 #include "nsIDOMDOMRequest.h"
19 #include "nsIPermissionManager.h"
20 #include "nsIVariant.h"
22 #include "nsJSUtils.h"
23 #include "nsRadioInterfaceLayer.h"
24 #include "nsServiceManagerUtils.h"
27 #include "nsIIccInfo.h"
30 #define MOBILECONN_ERROR_INVALID_PARAMETER NS_LITERAL_STRING("InvalidParameter")
31 #define MOBILECONN_ERROR_INVALID_PASSWORD NS_LITERAL_STRING("InvalidPassword")
33 #ifdef CONVERT_STRING_TO_NULLABLE_ENUM
34 #undef CONVERT_STRING_TO_NULLABLE_ENUM
36 #define CONVERT_STRING_TO_NULLABLE_ENUM(_string, _enumType, _enum) \
39 for (const EnumEntry* entry = _enumType##Values::strings; \
42 if (_string.EqualsASCII(entry->value)) { \
43 _enum.SetValue(static_cast<_enumType>(i)); \
48 using mozilla::ErrorResult
;
49 using namespace mozilla::dom
;
50 using namespace mozilla::dom::mobileconnection
;
52 class MobileConnection::Listener MOZ_FINAL
: public nsIMobileConnectionListener
54 , public nsIIccListener
57 MobileConnection
* mMobileConnection
;
61 NS_FORWARD_SAFE_NSIMOBILECONNECTIONLISTENER(mMobileConnection
)
63 NS_FORWARD_SAFE_NSIICCLISTENER(mMobileConnection
)
66 explicit Listener(MobileConnection
* aMobileConnection
)
67 : mMobileConnection(aMobileConnection
)
69 MOZ_ASSERT(mMobileConnection
);
74 MOZ_ASSERT(mMobileConnection
);
75 mMobileConnection
= nullptr;
81 MOZ_ASSERT(!mMobileConnection
);
86 NS_IMPL_ISUPPORTS(MobileConnection::Listener
, nsIMobileConnectionListener
,
89 NS_IMPL_ISUPPORTS(MobileConnection::Listener
, nsIMobileConnectionListener
)
92 NS_IMPL_CYCLE_COLLECTION_CLASS(MobileConnection
)
94 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(MobileConnection
,
96 // Don't traverse mListener because it doesn't keep any reference to
97 // MobileConnection but a raw pointer instead. Neither does mMobileConnection
98 // because it's an xpcom service owned object and is only released at shutting
100 NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mVoice
)
101 NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mData
)
102 NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mImsHandler
)
103 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
105 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(MobileConnection
,
106 DOMEventTargetHelper
)
108 NS_IMPL_CYCLE_COLLECTION_UNLINK(mVoice
)
109 NS_IMPL_CYCLE_COLLECTION_UNLINK(mData
)
110 NS_IMPL_CYCLE_COLLECTION_UNLINK(mImsHandler
)
111 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
113 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(MobileConnection
)
114 // MobileConnection does not expose nsIMobileConnectionListener. mListener is
115 // the exposed nsIMobileConnectionListener and forwards the calls it receives
117 NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper
)
119 NS_IMPL_ADDREF_INHERITED(MobileConnection
, DOMEventTargetHelper
)
120 NS_IMPL_RELEASE_INHERITED(MobileConnection
, DOMEventTargetHelper
)
122 MobileConnection::MobileConnection(nsPIDOMWindow
* aWindow
, uint32_t aClientId
)
123 : DOMEventTargetHelper(aWindow
)
124 , mClientId(aClientId
)
126 nsCOMPtr
<nsIMobileConnectionService
> service
=
127 do_GetService(NS_MOBILE_CONNECTION_SERVICE_CONTRACTID
);
129 // Per WebAPI design, mIccId should be null instead of an empty string when no
130 // SIM card is inserted. Set null as default value.
131 mIccId
.SetIsVoid(true);
133 // Not being able to acquire the service isn't fatal since we check
134 // for it explicitly below.
136 NS_WARNING("Could not acquire nsIMobileConnectionService!");
140 nsresult rv
= service
->GetItemByServiceId(mClientId
,
141 getter_AddRefs(mMobileConnection
));
143 mIcc
= do_GetService(NS_RILCONTENTHELPER_CONTRACTID
);
145 if (NS_FAILED(rv
) || !mMobileConnection
|| !mIcc
) {
146 NS_WARNING("Could not acquire nsIMobileConnection or nsIIccProvider!");
148 if (NS_FAILED(rv
) || !mMobileConnection
) {
149 NS_WARNING("Could not acquire nsIMobileConnection!");
150 #endif // MOZ_B2G_RIL
154 mListener
= new Listener(this);
155 mVoice
= new MobileConnectionInfo(GetOwner());
156 mData
= new MobileConnectionInfo(GetOwner());
158 if (CheckPermission("mobileconnection")) {
159 DebugOnly
<nsresult
> rv
= mMobileConnection
->RegisterListener(mListener
);
160 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv
),
161 "Failed registering mobile connection messages with service");
166 rv
= mIcc
->RegisterIccMsg(mClientId
, mListener
);
167 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv
),
168 "Failed registering icc messages with service");
170 #endif // MOZ_B2G_RIL
175 MobileConnection::Shutdown()
178 if (mMobileConnection
) {
179 mMobileConnection
->UnregisterListener(mListener
);
184 mIcc
->UnregisterIccMsg(mClientId
, mListener
);
186 #endif // MOZ_B2G_RIL
188 mListener
->Disconnect();
193 MobileConnection::~MobileConnection()
199 MobileConnection::DisconnectFromOwner()
201 DOMEventTargetHelper::DisconnectFromOwner();
202 // Event listeners can't be handled anymore, so we can shutdown
203 // the MobileConnection.
208 MobileConnection::WrapObject(JSContext
* aCx
)
210 return MozMobileConnectionBinding::Wrap(aCx
, this);
214 MobileConnection::CheckPermission(const char* aType
) const
216 nsCOMPtr
<nsIPermissionManager
> permMgr
=
217 mozilla::services::GetPermissionManager();
218 NS_ENSURE_TRUE(permMgr
, false);
220 uint32_t permission
= nsIPermissionManager::DENY_ACTION
;
221 permMgr
->TestPermissionFromWindow(GetOwner(), aType
, &permission
);
222 return permission
== nsIPermissionManager::ALLOW_ACTION
;
226 MobileConnection::UpdateVoice()
228 if (!mMobileConnection
) {
232 nsCOMPtr
<nsIMobileConnectionInfo
> info
;
233 mMobileConnection
->GetVoice(getter_AddRefs(info
));
234 mVoice
->Update(info
);
238 MobileConnection::UpdateData()
240 if (!mMobileConnection
) {
244 nsCOMPtr
<nsIMobileConnectionInfo
> info
;
245 mMobileConnection
->GetData(getter_AddRefs(info
));
250 MobileConnection::UpdateIccId()
254 nsCOMPtr
<nsIIccInfo
> iccInfo
;
256 NS_SUCCEEDED(mIcc
->GetIccInfo(mClientId
, getter_AddRefs(iccInfo
))) &&
258 iccInfo
->GetIccid(iccId
);
260 iccId
.SetIsVoid(true);
263 if (!mIccId
.Equals(iccId
)) {
267 #endif // MOZ_B2G_RIL
273 MobileConnection::NotifyError(nsIDOMDOMRequest
* aRequest
, const nsAString
& aMessage
)
275 nsCOMPtr
<nsIDOMRequestService
> rs
= do_GetService(DOMREQUEST_SERVICE_CONTRACTID
);
276 NS_ENSURE_TRUE(rs
, NS_ERROR_FAILURE
);
278 return rs
->FireErrorAsync(aRequest
, aMessage
);
282 MobileConnection::IsValidPassword(const nsAString
& aPassword
)
284 // Check valid PIN for supplementary services. See TS.22.004 clause 5.2.
285 if (aPassword
.IsEmpty() || aPassword
.Length() != 4) {
290 int32_t password
= nsString(aPassword
).ToInteger(&rv
);
291 return NS_SUCCEEDED(rv
) && password
>= 0 && password
<= 9999;
295 MobileConnection::IsValidCallForwardingReason(int32_t aReason
)
297 return aReason
>= nsIMobileConnection::CALL_FORWARD_REASON_UNCONDITIONAL
&&
298 aReason
<= nsIMobileConnection::CALL_FORWARD_REASON_ALL_CONDITIONAL_CALL_FORWARDING
;
302 MobileConnection::IsValidCallForwardingAction(int32_t aAction
)
304 return aAction
>= nsIMobileConnection::CALL_FORWARD_ACTION_DISABLE
&&
305 aAction
<= nsIMobileConnection::CALL_FORWARD_ACTION_ERASURE
&&
306 // Set operation doesn't allow "query" action.
307 aAction
!= nsIMobileConnection::CALL_FORWARD_ACTION_QUERY_STATUS
;
311 MobileConnection::IsValidCallBarringProgram(int32_t aProgram
)
313 return aProgram
>= nsIMobileConnection::CALL_BARRING_PROGRAM_ALL_OUTGOING
&&
314 aProgram
<= nsIMobileConnection::CALL_BARRING_PROGRAM_INCOMING_ROAMING
;
318 MobileConnection::IsValidCallBarringOptions(const MozCallBarringOptions
& aOptions
,
321 if (!aOptions
.mServiceClass
.WasPassed() || aOptions
.mServiceClass
.Value().IsNull() ||
322 !aOptions
.mProgram
.WasPassed() || aOptions
.mProgram
.Value().IsNull() ||
323 !IsValidCallBarringProgram(aOptions
.mProgram
.Value().Value())) {
327 // For setting callbarring options, |enabled| and |password| are required.
329 (!aOptions
.mEnabled
.WasPassed() || aOptions
.mEnabled
.Value().IsNull() ||
330 !aOptions
.mPassword
.WasPassed() || aOptions
.mPassword
.Value().IsVoid())) {
338 MobileConnection::IsValidCallForwardingOptions(const MozCallForwardingOptions
& aOptions
)
340 if (!aOptions
.mReason
.WasPassed() || aOptions
.mReason
.Value().IsNull() ||
341 !aOptions
.mAction
.WasPassed() || aOptions
.mAction
.Value().IsNull() ||
342 !IsValidCallForwardingReason(aOptions
.mReason
.Value().Value()) ||
343 !IsValidCallForwardingAction(aOptions
.mAction
.Value().Value())) {
353 MobileConnection::GetLastKnownNetwork(nsString
& aRetVal
) const
355 aRetVal
.SetIsVoid(true);
357 if (!mMobileConnection
) {
361 mMobileConnection
->GetLastKnownNetwork(aRetVal
);
365 MobileConnection::GetLastKnownHomeNetwork(nsString
& aRetVal
) const
367 aRetVal
.SetIsVoid(true);
369 if (!mMobileConnection
) {
373 mMobileConnection
->GetLastKnownHomeNetwork(aRetVal
);
376 // All fields below require the "mobileconnection" permission.
378 MobileConnectionInfo
*
379 MobileConnection::Voice() const
384 MobileConnectionInfo
*
385 MobileConnection::Data() const
391 MobileConnection::GetIccId(nsString
& aRetVal
) const
396 Nullable
<MobileNetworkSelectionMode
>
397 MobileConnection::GetNetworkSelectionMode() const
399 Nullable
<MobileNetworkSelectionMode
> retVal
=
400 Nullable
<MobileNetworkSelectionMode
>();
402 if (!mMobileConnection
) {
406 int32_t mode
= nsIMobileConnection::NETWORK_SELECTION_MODE_UNKNOWN
;
407 if (NS_SUCCEEDED(mMobileConnection
->GetNetworkSelectionMode(&mode
)) &&
408 mode
!= nsIMobileConnection::NETWORK_SELECTION_MODE_UNKNOWN
) {
409 MOZ_ASSERT(mode
< static_cast<int32_t>(MobileNetworkSelectionMode::EndGuard_
));
410 retVal
.SetValue(static_cast<MobileNetworkSelectionMode
>(mode
));
416 Nullable
<MobileRadioState
>
417 MobileConnection::GetRadioState() const
419 Nullable
<MobileRadioState
> retVal
= Nullable
<MobileRadioState
>();
421 if (!mMobileConnection
) {
425 int32_t state
= nsIMobileConnection::MOBILE_RADIO_STATE_UNKNOWN
;
426 if (NS_SUCCEEDED(mMobileConnection
->GetRadioState(&state
)) &&
427 state
!= nsIMobileConnection::MOBILE_RADIO_STATE_UNKNOWN
) {
428 MOZ_ASSERT(state
< static_cast<int32_t>(MobileRadioState::EndGuard_
));
429 retVal
.SetValue(static_cast<MobileRadioState
>(state
));
436 MobileConnection::GetSupportedNetworkTypes(nsTArray
<MobileNetworkType
>& aTypes
) const
438 if (!mMobileConnection
) {
442 int32_t* types
= nullptr;
445 nsresult rv
= mMobileConnection
->GetSupportedNetworkTypes(&types
, &length
);
446 NS_ENSURE_SUCCESS_VOID(rv
);
448 for (uint32_t i
= 0; i
< length
; ++i
) {
449 int32_t type
= types
[i
];
451 MOZ_ASSERT(type
< static_cast<int32_t>(MobileNetworkType::EndGuard_
));
452 aTypes
.AppendElement(static_cast<MobileNetworkType
>(type
));
455 nsMemory::Free(types
);
458 already_AddRefed
<ImsRegHandler
>
459 MobileConnection::GetImsHandler() const
461 if (!mMobileConnection
) {
466 nsRefPtr
<ImsRegHandler
> handler
= mImsHandler
;
467 return handler
.forget();
470 nsCOMPtr
<nsIImsRegService
> imsService
= do_GetService(IMS_REG_SERVICE_CONTRACTID
);
472 NS_WARNING("Could not acquire nsIImsRegService!");
476 nsCOMPtr
<nsIImsRegHandler
> internalHandler
;
477 imsService
->GetHandlerByServiceId(mClientId
, getter_AddRefs(internalHandler
));
478 // ImsRegHandler is optional, always check even if it was retreived successfully.
479 if (!internalHandler
) {
480 NS_WARNING("Could not acquire nsIImsRegHandler!");
484 mImsHandler
= new ImsRegHandler(GetOwner(), internalHandler
);
485 nsRefPtr
<ImsRegHandler
> handler
= mImsHandler
;
487 return handler
.forget();
490 already_AddRefed
<DOMRequest
>
491 MobileConnection::GetNetworks(ErrorResult
& aRv
)
493 if (!mMobileConnection
) {
494 aRv
.Throw(NS_ERROR_FAILURE
);
498 nsRefPtr
<DOMRequest
> request
= new DOMRequest(GetOwner());
499 nsRefPtr
<MobileConnectionCallback
> requestCallback
=
500 new MobileConnectionCallback(GetOwner(), request
);
502 nsresult rv
= mMobileConnection
->GetNetworks(requestCallback
);
508 return request
.forget();
511 already_AddRefed
<DOMRequest
>
512 MobileConnection::SelectNetwork(MobileNetworkInfo
& aNetwork
, ErrorResult
& aRv
)
514 if (!mMobileConnection
) {
515 aRv
.Throw(NS_ERROR_FAILURE
);
519 nsRefPtr
<DOMRequest
> request
= new DOMRequest(GetOwner());
520 nsRefPtr
<MobileConnectionCallback
> requestCallback
=
521 new MobileConnectionCallback(GetOwner(), request
);
523 nsresult rv
= mMobileConnection
->SelectNetwork(&aNetwork
, requestCallback
);
529 return request
.forget();
532 already_AddRefed
<DOMRequest
>
533 MobileConnection::SelectNetworkAutomatically(ErrorResult
& aRv
)
535 if (!mMobileConnection
) {
536 aRv
.Throw(NS_ERROR_FAILURE
);
540 nsRefPtr
<DOMRequest
> request
= new DOMRequest(GetOwner());
541 nsRefPtr
<MobileConnectionCallback
> requestCallback
=
542 new MobileConnectionCallback(GetOwner(), request
);
545 mMobileConnection
->SelectNetworkAutomatically(requestCallback
);
551 return request
.forget();
554 already_AddRefed
<DOMRequest
>
555 MobileConnection::SetPreferredNetworkType(MobilePreferredNetworkType
& aType
,
558 if (!mMobileConnection
) {
559 aRv
.Throw(NS_ERROR_FAILURE
);
563 int32_t type
= static_cast<int32_t>(aType
);
565 nsRefPtr
<DOMRequest
> request
= new DOMRequest(GetOwner());
566 nsRefPtr
<MobileConnectionCallback
> requestCallback
=
567 new MobileConnectionCallback(GetOwner(), request
);
570 mMobileConnection
->SetPreferredNetworkType(type
, requestCallback
);
576 return request
.forget();
579 already_AddRefed
<DOMRequest
>
580 MobileConnection::GetPreferredNetworkType(ErrorResult
& aRv
)
582 if (!mMobileConnection
) {
583 aRv
.Throw(NS_ERROR_FAILURE
);
587 nsRefPtr
<DOMRequest
> request
= new DOMRequest(GetOwner());
588 nsRefPtr
<MobileConnectionCallback
> requestCallback
=
589 new MobileConnectionCallback(GetOwner(), request
);
591 nsresult rv
= mMobileConnection
->GetPreferredNetworkType(requestCallback
);
597 return request
.forget();
600 already_AddRefed
<DOMRequest
>
601 MobileConnection::SetRoamingPreference(MobileRoamingMode
& aMode
,
604 if (!mMobileConnection
) {
605 aRv
.Throw(NS_ERROR_FAILURE
);
609 int32_t mode
= static_cast<int32_t>(aMode
);
611 nsRefPtr
<DOMRequest
> request
= new DOMRequest(GetOwner());
612 nsRefPtr
<MobileConnectionCallback
> requestCallback
=
613 new MobileConnectionCallback(GetOwner(), request
);
615 nsresult rv
= mMobileConnection
->SetRoamingPreference(mode
, requestCallback
);
621 return request
.forget();
624 already_AddRefed
<DOMRequest
>
625 MobileConnection::GetRoamingPreference(ErrorResult
& aRv
)
627 if (!mMobileConnection
) {
628 aRv
.Throw(NS_ERROR_FAILURE
);
632 nsRefPtr
<DOMRequest
> request
= new DOMRequest(GetOwner());
633 nsRefPtr
<MobileConnectionCallback
> requestCallback
=
634 new MobileConnectionCallback(GetOwner(), request
);
636 nsresult rv
= mMobileConnection
->GetRoamingPreference(requestCallback
);
642 return request
.forget();
645 already_AddRefed
<DOMRequest
>
646 MobileConnection::SetVoicePrivacyMode(bool aEnabled
, ErrorResult
& aRv
)
648 if (!mMobileConnection
) {
649 aRv
.Throw(NS_ERROR_FAILURE
);
653 nsRefPtr
<DOMRequest
> request
= new DOMRequest(GetOwner());
654 nsRefPtr
<MobileConnectionCallback
> requestCallback
=
655 new MobileConnectionCallback(GetOwner(), request
);
658 mMobileConnection
->SetVoicePrivacyMode(aEnabled
, requestCallback
);
664 return request
.forget();
667 already_AddRefed
<DOMRequest
>
668 MobileConnection::GetVoicePrivacyMode(ErrorResult
& aRv
)
670 if (!mMobileConnection
) {
671 aRv
.Throw(NS_ERROR_FAILURE
);
675 nsRefPtr
<DOMRequest
> request
= new DOMRequest(GetOwner());
676 nsRefPtr
<MobileConnectionCallback
> requestCallback
=
677 new MobileConnectionCallback(GetOwner(), request
);
679 nsresult rv
= mMobileConnection
->GetVoicePrivacyMode(requestCallback
);
685 return request
.forget();
688 already_AddRefed
<DOMRequest
>
689 MobileConnection::GetCallForwardingOption(uint16_t aReason
, ErrorResult
& aRv
)
691 if (!mMobileConnection
) {
692 aRv
.Throw(NS_ERROR_FAILURE
);
696 nsRefPtr
<DOMRequest
> request
= new DOMRequest(GetOwner());
698 if (!IsValidCallForwardingReason(aReason
)) {
699 nsresult rv
= NotifyError(request
, MOBILECONN_ERROR_INVALID_PARAMETER
);
704 return request
.forget();
707 nsRefPtr
<MobileConnectionCallback
> requestCallback
=
708 new MobileConnectionCallback(GetOwner(), request
);
710 nsresult rv
= mMobileConnection
->GetCallForwarding(aReason
, requestCallback
);
716 return request
.forget();
719 already_AddRefed
<DOMRequest
>
720 MobileConnection::SetCallForwardingOption(const MozCallForwardingOptions
& aOptions
,
723 if (!mMobileConnection
) {
724 aRv
.Throw(NS_ERROR_FAILURE
);
728 nsRefPtr
<DOMRequest
> request
= new DOMRequest(GetOwner());
730 if (!IsValidCallForwardingOptions(aOptions
)) {
731 nsresult rv
= NotifyError(request
, MOBILECONN_ERROR_INVALID_PARAMETER
);
736 return request
.forget();
739 // Fill in optional attributes.
740 uint16_t timeSeconds
= 0;
741 if (aOptions
.mTimeSeconds
.WasPassed() && !aOptions
.mTimeSeconds
.Value().IsNull()) {
742 timeSeconds
= aOptions
.mTimeSeconds
.Value().Value();
744 uint16_t serviceClass
= nsIMobileConnection::ICC_SERVICE_CLASS_NONE
;
745 if (aOptions
.mServiceClass
.WasPassed() && !aOptions
.mServiceClass
.Value().IsNull()) {
746 serviceClass
= aOptions
.mServiceClass
.Value().Value();
749 if (aOptions
.mNumber
.WasPassed()) {
750 number
= aOptions
.mNumber
.Value();
752 number
.SetIsVoid(true);
755 nsRefPtr
<MobileConnectionCallback
> requestCallback
=
756 new MobileConnectionCallback(GetOwner(), request
);
758 nsresult rv
= mMobileConnection
->SetCallForwarding(aOptions
.mAction
.Value().Value(),
759 aOptions
.mReason
.Value().Value(),
769 return request
.forget();
772 already_AddRefed
<DOMRequest
>
773 MobileConnection::GetCallBarringOption(const MozCallBarringOptions
& aOptions
,
776 if (!mMobileConnection
) {
777 aRv
.Throw(NS_ERROR_FAILURE
);
781 nsRefPtr
<DOMRequest
> request
= new DOMRequest(GetOwner());
783 if (!IsValidCallBarringOptions(aOptions
, false)) {
784 nsresult rv
= NotifyError(request
, MOBILECONN_ERROR_INVALID_PARAMETER
);
789 return request
.forget();
792 // Fill in optional attributes.
793 nsAutoString password
;
794 if (aOptions
.mPassword
.WasPassed()) {
795 password
= aOptions
.mPassword
.Value();
797 password
.SetIsVoid(true);
800 nsRefPtr
<MobileConnectionCallback
> requestCallback
=
801 new MobileConnectionCallback(GetOwner(), request
);
803 nsresult rv
= mMobileConnection
->GetCallBarring(aOptions
.mProgram
.Value().Value(),
805 aOptions
.mServiceClass
.Value().Value(),
812 return request
.forget();
815 already_AddRefed
<DOMRequest
>
816 MobileConnection::SetCallBarringOption(const MozCallBarringOptions
& aOptions
,
819 if (!mMobileConnection
) {
820 aRv
.Throw(NS_ERROR_FAILURE
);
824 nsRefPtr
<DOMRequest
> request
= new DOMRequest(GetOwner());
826 if (!IsValidCallBarringOptions(aOptions
, true)) {
827 nsresult rv
= NotifyError(request
, MOBILECONN_ERROR_INVALID_PARAMETER
);
832 return request
.forget();
835 nsRefPtr
<MobileConnectionCallback
> requestCallback
=
836 new MobileConnectionCallback(GetOwner(), request
);
838 nsresult rv
= mMobileConnection
->SetCallBarring(aOptions
.mProgram
.Value().Value(),
839 aOptions
.mEnabled
.Value().Value(),
840 aOptions
.mPassword
.Value(),
841 aOptions
.mServiceClass
.Value().Value(),
848 return request
.forget();
851 already_AddRefed
<DOMRequest
>
852 MobileConnection::ChangeCallBarringPassword(const MozCallBarringOptions
& aOptions
,
855 if (!mMobileConnection
) {
856 aRv
.Throw(NS_ERROR_FAILURE
);
860 nsRefPtr
<DOMRequest
> request
= new DOMRequest(GetOwner());
862 if (!aOptions
.mPin
.WasPassed() || aOptions
.mPin
.Value().IsVoid() ||
863 !aOptions
.mNewPin
.WasPassed() || aOptions
.mNewPin
.Value().IsVoid() ||
864 !IsValidPassword(aOptions
.mPin
.Value()) ||
865 !IsValidPassword(aOptions
.mNewPin
.Value())) {
866 nsresult rv
= NotifyError(request
, MOBILECONN_ERROR_INVALID_PASSWORD
);
871 return request
.forget();
874 nsRefPtr
<MobileConnectionCallback
> requestCallback
=
875 new MobileConnectionCallback(GetOwner(), request
);
878 mMobileConnection
->ChangeCallBarringPassword(aOptions
.mPin
.Value(),
879 aOptions
.mNewPin
.Value(),
886 return request
.forget();
889 already_AddRefed
<DOMRequest
>
890 MobileConnection::GetCallWaitingOption(ErrorResult
& aRv
)
892 if (!mMobileConnection
) {
893 aRv
.Throw(NS_ERROR_FAILURE
);
897 nsRefPtr
<DOMRequest
> request
= new DOMRequest(GetOwner());
898 nsRefPtr
<MobileConnectionCallback
> requestCallback
=
899 new MobileConnectionCallback(GetOwner(), request
);
901 nsresult rv
= mMobileConnection
->GetCallWaiting(requestCallback
);
907 return request
.forget();
910 already_AddRefed
<DOMRequest
>
911 MobileConnection::SetCallWaitingOption(bool aEnabled
, ErrorResult
& aRv
)
913 if (!mMobileConnection
) {
914 aRv
.Throw(NS_ERROR_FAILURE
);
918 nsRefPtr
<DOMRequest
> request
= new DOMRequest(GetOwner());
919 nsRefPtr
<MobileConnectionCallback
> requestCallback
=
920 new MobileConnectionCallback(GetOwner(), request
);
922 nsresult rv
= mMobileConnection
->SetCallWaiting(aEnabled
, requestCallback
);
928 return request
.forget();
931 already_AddRefed
<DOMRequest
>
932 MobileConnection::GetCallingLineIdRestriction(ErrorResult
& aRv
)
934 if (!mMobileConnection
) {
935 aRv
.Throw(NS_ERROR_FAILURE
);
939 nsRefPtr
<DOMRequest
> request
= new DOMRequest(GetOwner());
940 nsRefPtr
<MobileConnectionCallback
> requestCallback
=
941 new MobileConnectionCallback(GetOwner(), request
);
944 mMobileConnection
->GetCallingLineIdRestriction(requestCallback
);
950 return request
.forget();
953 already_AddRefed
<DOMRequest
>
954 MobileConnection::SetCallingLineIdRestriction(uint16_t aMode
,
957 if (!mMobileConnection
) {
958 aRv
.Throw(NS_ERROR_FAILURE
);
962 nsRefPtr
<DOMRequest
> request
= new DOMRequest(GetOwner());
963 nsRefPtr
<MobileConnectionCallback
> requestCallback
=
964 new MobileConnectionCallback(GetOwner(), request
);
967 mMobileConnection
->SetCallingLineIdRestriction(aMode
, requestCallback
);
973 return request
.forget();
976 already_AddRefed
<DOMRequest
>
977 MobileConnection::ExitEmergencyCbMode(ErrorResult
& aRv
)
979 if (!mMobileConnection
) {
980 aRv
.Throw(NS_ERROR_FAILURE
);
984 nsRefPtr
<DOMRequest
> request
= new DOMRequest(GetOwner());
985 nsRefPtr
<MobileConnectionCallback
> requestCallback
=
986 new MobileConnectionCallback(GetOwner(), request
);
988 nsresult rv
= mMobileConnection
->ExitEmergencyCbMode(requestCallback
);
994 return request
.forget();
997 already_AddRefed
<DOMRequest
>
998 MobileConnection::SetRadioEnabled(bool aEnabled
, ErrorResult
& aRv
)
1000 if (!mMobileConnection
) {
1001 aRv
.Throw(NS_ERROR_FAILURE
);
1005 nsRefPtr
<DOMRequest
> request
= new DOMRequest(GetOwner());
1006 nsRefPtr
<MobileConnectionCallback
> requestCallback
=
1007 new MobileConnectionCallback(GetOwner(), request
);
1009 nsresult rv
= mMobileConnection
->SetRadioEnabled(aEnabled
, requestCallback
);
1010 if (NS_FAILED(rv
)) {
1015 return request
.forget();
1018 // nsIMobileConnectionListener
1021 MobileConnection::NotifyVoiceChanged()
1023 if (!CheckPermission("mobileconnection")) {
1029 return DispatchTrustedEvent(NS_LITERAL_STRING("voicechange"));
1033 MobileConnection::NotifyDataChanged()
1035 if (!CheckPermission("mobileconnection")) {
1041 return DispatchTrustedEvent(NS_LITERAL_STRING("datachange"));
1045 MobileConnection::NotifyDataError(const nsAString
& aMessage
)
1047 if (!CheckPermission("mobileconnection")) {
1051 DataErrorEventInit init
;
1052 init
.mBubbles
= false;
1053 init
.mCancelable
= false;
1054 init
.mMessage
= aMessage
;
1056 nsRefPtr
<DataErrorEvent
> event
=
1057 DataErrorEvent::Constructor(this, NS_LITERAL_STRING("dataerror"), init
);
1059 return DispatchTrustedEvent(event
);
1063 MobileConnection::NotifyCFStateChanged(unsigned short aAction
,
1064 unsigned short aReason
,
1065 const nsAString
& aNumber
,
1066 unsigned short aSeconds
,
1067 unsigned short aServiceClass
)
1069 if (!CheckPermission("mobileconnection")) {
1073 CFStateChangeEventInit init
;
1074 init
.mBubbles
= false;
1075 init
.mCancelable
= false;
1076 init
.mAction
= aAction
;
1077 init
.mReason
= aReason
;
1078 init
.mNumber
= aNumber
;
1079 init
.mTimeSeconds
= aSeconds
;
1080 init
.mServiceClass
= aServiceClass
;
1082 nsRefPtr
<CFStateChangeEvent
> event
=
1083 CFStateChangeEvent::Constructor(this, NS_LITERAL_STRING("cfstatechange"), init
);
1085 return DispatchTrustedEvent(event
);
1089 MobileConnection::NotifyEmergencyCbModeChanged(bool aActive
,
1090 uint32_t aTimeoutMs
)
1092 if (!CheckPermission("mobileconnection")) {
1096 MozEmergencyCbModeEventInit init
;
1097 init
.mBubbles
= false;
1098 init
.mCancelable
= false;
1099 init
.mActive
= aActive
;
1100 init
.mTimeoutMs
= aTimeoutMs
;
1102 nsRefPtr
<MozEmergencyCbModeEvent
> event
=
1103 MozEmergencyCbModeEvent::Constructor(this, NS_LITERAL_STRING("emergencycbmodechange"), init
);
1105 return DispatchTrustedEvent(event
);
1109 MobileConnection::NotifyOtaStatusChanged(const nsAString
& aStatus
)
1111 if (!CheckPermission("mobileconnection")) {
1115 MozOtaStatusEventInit init
;
1116 init
.mBubbles
= false;
1117 init
.mCancelable
= false;
1118 init
.mStatus
= aStatus
;
1120 nsRefPtr
<MozOtaStatusEvent
> event
=
1121 MozOtaStatusEvent::Constructor(this, NS_LITERAL_STRING("otastatuschange"), init
);
1123 return DispatchTrustedEvent(event
);
1127 MobileConnection::NotifyRadioStateChanged()
1129 if (!CheckPermission("mobileconnection")) {
1133 return DispatchTrustedEvent(NS_LITERAL_STRING("radiostatechange"));
1137 MobileConnection::NotifyClirModeChanged(uint32_t aMode
)
1139 if (!CheckPermission("mobileconnection")) {
1143 MozClirModeEventInit init
;
1144 init
.mBubbles
= false;
1145 init
.mCancelable
= false;
1148 nsRefPtr
<MozClirModeEvent
> event
=
1149 MozClirModeEvent::Constructor(this, NS_LITERAL_STRING("clirmodechange"), init
);
1151 return DispatchTrustedEvent(event
);
1155 MobileConnection::NotifyLastKnownNetworkChanged()
1161 MobileConnection::NotifyLastKnownHomeNetworkChanged()
1167 MobileConnection::NotifyNetworkSelectionModeChanged()
1176 MobileConnection::NotifyStkCommand(const nsAString
& aMessage
)
1182 MobileConnection::NotifyStkSessionEnd()
1188 MobileConnection::NotifyCardStateChanged()
1194 MobileConnection::NotifyIccInfoChanged()
1196 if (!CheckPermission("mobileconnection")) {
1200 if (!UpdateIccId()) {
1204 nsRefPtr
<AsyncEventDispatcher
> asyncDispatcher
=
1205 new AsyncEventDispatcher(this, NS_LITERAL_STRING("iccchange"), false);
1207 return asyncDispatcher
->PostDOMEvent();
1209 #endif // MOZ_B2G_RIL