diff --git a/dom/mobileconnection/Assertions.cpp b/dom/mobileconnection/Assertions.cpp index b544011334a..be5e53b0d1e 100644 --- a/dom/mobileconnection/Assertions.cpp +++ b/dom/mobileconnection/Assertions.cpp @@ -28,5 +28,24 @@ ASSERT_MOBILE_RADIO_STATE_EQUALITY(Disabled, MOBILE_RADIO_STATE_DISABLED); #undef ASSERT_MOBILE_RADIO_STATE_EQUALITY +#define ASSERT_PREFERRED_NETWORK_TYPE_EQUALITY(webidlState, xpidlState) \ + static_assert(static_cast(MobilePreferredNetworkType::webidlState) == nsIMobileConnection::xpidlState, \ + "MobilePreferredNetworkType::" #webidlState " should equal to nsIMobileConnection::" #xpidlState) + +ASSERT_PREFERRED_NETWORK_TYPE_EQUALITY(Wcdma_gsm, PREFERRED_NETWORK_TYPE_WCDMA_GSM); +ASSERT_PREFERRED_NETWORK_TYPE_EQUALITY(Gsm, PREFERRED_NETWORK_TYPE_GSM_ONLY); +ASSERT_PREFERRED_NETWORK_TYPE_EQUALITY(Wcdma, PREFERRED_NETWORK_TYPE_WCDMA_ONLY); +ASSERT_PREFERRED_NETWORK_TYPE_EQUALITY(Wcdma_gsm_auto, PREFERRED_NETWORK_TYPE_WCDMA_GSM_AUTO); +ASSERT_PREFERRED_NETWORK_TYPE_EQUALITY(Cdma_evdo, PREFERRED_NETWORK_TYPE_CDMA_EVDO); +ASSERT_PREFERRED_NETWORK_TYPE_EQUALITY(Cdma, PREFERRED_NETWORK_TYPE_CDMA_ONLY); +ASSERT_PREFERRED_NETWORK_TYPE_EQUALITY(Evdo, PREFERRED_NETWORK_TYPE_EVDO_ONLY); +ASSERT_PREFERRED_NETWORK_TYPE_EQUALITY(Wcdma_gsm_cdma_evdo, PREFERRED_NETWORK_TYPE_WCDMA_GSM_CDMA_EVDO); +ASSERT_PREFERRED_NETWORK_TYPE_EQUALITY(Lte_cdma_evdo, PREFERRED_NETWORK_TYPE_LTE_CDMA_EVDO); +ASSERT_PREFERRED_NETWORK_TYPE_EQUALITY(Lte_wcdma_gsm, PREFERRED_NETWORK_TYPE_LTE_WCDMA_GSM); +ASSERT_PREFERRED_NETWORK_TYPE_EQUALITY(Lte_wcdma_gsm_cdma_evdo, PREFERRED_NETWORK_TYPE_LTE_WCDMA_GSM_CDMA_EVDO); +ASSERT_PREFERRED_NETWORK_TYPE_EQUALITY(Lte, PREFERRED_NETWORK_TYPE_LTE_ONLY); + +#undef ASSERT_PREFERRED_NETWORK_TYPE_EQUALITY + } // namespace dom } // namespace mozilla diff --git a/dom/mobileconnection/MobileConnection.cpp b/dom/mobileconnection/MobileConnection.cpp index 33c02ff79a1..1dc97443a16 100644 --- a/dom/mobileconnection/MobileConnection.cpp +++ b/dom/mobileconnection/MobileConnection.cpp @@ -477,8 +477,7 @@ MobileConnection::SetPreferredNetworkType(MobilePreferredNetworkType& aType, return nullptr; } - nsAutoString type; - CONVERT_ENUM_TO_STRING(MobilePreferredNetworkType, aType, type); + int32_t type = static_cast(aType); nsRefPtr request = new DOMRequest(GetOwner()); nsRefPtr requestCallback = diff --git a/dom/mobileconnection/MobileConnectionCallback.cpp b/dom/mobileconnection/MobileConnectionCallback.cpp index 121b5b1e6ab..bc81a327a5a 100644 --- a/dom/mobileconnection/MobileConnectionCallback.cpp +++ b/dom/mobileconnection/MobileConnectionCallback.cpp @@ -15,6 +15,13 @@ namespace mozilla { namespace dom { namespace mobileconnection { +#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); \ +} + NS_IMPL_ISUPPORTS(MobileConnectionCallback, nsIMobileConnectionCallback) MobileConnectionCallback::MobileConnectionCallback(nsPIDOMWindow* aWindow, @@ -349,6 +356,18 @@ MobileConnectionCallback::NotifyGetClirStatusSuccess(uint16_t aN, uint16_t aM) return NotifySuccess(jsResult); }; +NS_IMETHODIMP +MobileConnectionCallback::NotifyGetPreferredNetworkTypeSuccess(int32_t aType) +{ + MOZ_ASSERT(aType < static_cast(MobilePreferredNetworkType::EndGuard_)); + MobilePreferredNetworkType type = static_cast(aType); + + nsAutoString typeString; + CONVERT_ENUM_TO_STRING(MobilePreferredNetworkType, type, typeString); + + return NotifySuccessWithString(typeString); +}; + NS_IMETHODIMP MobileConnectionCallback::NotifyError(const nsAString& aName, const nsAString& aMessage, diff --git a/dom/mobileconnection/ipc/MobileConnectionChild.cpp b/dom/mobileconnection/ipc/MobileConnectionChild.cpp index 61d72455502..41b907153d2 100644 --- a/dom/mobileconnection/ipc/MobileConnectionChild.cpp +++ b/dom/mobileconnection/ipc/MobileConnectionChild.cpp @@ -178,11 +178,10 @@ MobileConnectionChild::SelectNetworkAutomatically(nsIMobileConnectionCallback* a NS_IMETHODIMP -MobileConnectionChild::SetPreferredNetworkType(const nsAString& aType, +MobileConnectionChild::SetPreferredNetworkType(int32_t aType, nsIMobileConnectionCallback* aCallback) { - return SendRequest(SetPreferredNetworkTypeRequest(nsAutoString(aType)), - aCallback) + return SendRequest(SetPreferredNetworkTypeRequest(aType), aCallback) ? NS_OK : NS_ERROR_FAILURE; } @@ -661,6 +660,12 @@ MobileConnectionRequestChild::DoReply(const MobileConnectionReplySuccessClirStat aReply.m())); } +bool +MobileConnectionRequestChild::DoReply(const MobileConnectionReplySuccessPreferredNetworkType& aReply) +{ + return NS_SUCCEEDED(mRequestCallback->NotifyGetPreferredNetworkTypeSuccess(aReply.type())); +} + bool MobileConnectionRequestChild::DoReply(const MobileConnectionReplyError& aReply) { @@ -715,6 +720,8 @@ MobileConnectionRequestChild::Recv__delete__(const MobileConnectionReply& aReply return DoReply(aReply.get_MobileConnectionReplySuccessCallBarring()); case MobileConnectionReply::TMobileConnectionReplySuccessClirStatus: return DoReply(aReply.get_MobileConnectionReplySuccessClirStatus()); + case MobileConnectionReply::TMobileConnectionReplySuccessPreferredNetworkType: + return DoReply(aReply.get_MobileConnectionReplySuccessPreferredNetworkType()); case MobileConnectionReply::TMobileConnectionReplyError: return DoReply(aReply.get_MobileConnectionReplyError()); case MobileConnectionReply::TMobileConnectionReplyErrorMmi: diff --git a/dom/mobileconnection/ipc/MobileConnectionChild.h b/dom/mobileconnection/ipc/MobileConnectionChild.h index d549ee8ebcc..f2532ebe5ef 100644 --- a/dom/mobileconnection/ipc/MobileConnectionChild.h +++ b/dom/mobileconnection/ipc/MobileConnectionChild.h @@ -163,6 +163,9 @@ public: bool DoReply(const MobileConnectionReplySuccessClirStatus& aReply); + bool + DoReply(const MobileConnectionReplySuccessPreferredNetworkType& aReply); + bool DoReply(const MobileConnectionReplyError& aReply); diff --git a/dom/mobileconnection/ipc/MobileConnectionParent.cpp b/dom/mobileconnection/ipc/MobileConnectionParent.cpp index c8e4b91c5ad..3413bc423b0 100644 --- a/dom/mobileconnection/ipc/MobileConnectionParent.cpp +++ b/dom/mobileconnection/ipc/MobileConnectionParent.cpp @@ -642,6 +642,12 @@ MobileConnectionRequestParent::NotifyGetClirStatusSuccess(uint16_t aN, return SendReply(MobileConnectionReplySuccessClirStatus(aN, aM)); } +NS_IMETHODIMP +MobileConnectionRequestParent::NotifyGetPreferredNetworkTypeSuccess(int32_t aType) +{ + return SendReply(MobileConnectionReplySuccessPreferredNetworkType(aType)); +} + NS_IMETHODIMP MobileConnectionRequestParent::NotifyError(const nsAString& aName, const nsAString& aMessage, diff --git a/dom/mobileconnection/ipc/PMobileConnection.ipdl b/dom/mobileconnection/ipc/PMobileConnection.ipdl index 70eaba2c412..d118c7ffd1c 100644 --- a/dom/mobileconnection/ipc/PMobileConnection.ipdl +++ b/dom/mobileconnection/ipc/PMobileConnection.ipdl @@ -72,7 +72,7 @@ struct SelectNetworkAutoRequest struct SetPreferredNetworkTypeRequest { - nsString type; + int32_t type; }; struct GetPreferredNetworkTypeRequest diff --git a/dom/mobileconnection/ipc/PMobileConnectionRequest.ipdl b/dom/mobileconnection/ipc/PMobileConnectionRequest.ipdl index e224bc368e1..bf2071dc0b6 100644 --- a/dom/mobileconnection/ipc/PMobileConnectionRequest.ipdl +++ b/dom/mobileconnection/ipc/PMobileConnectionRequest.ipdl @@ -70,6 +70,11 @@ struct MobileConnectionReplySuccessClirStatus uint16_t m; }; +struct MobileConnectionReplySuccessPreferredNetworkType +{ + int32_t type; +}; + // Error struct MobileConnectionReplyError { @@ -95,6 +100,7 @@ union MobileConnectionReply MobileConnectionReplySuccessCallForwarding; MobileConnectionReplySuccessCallBarring; MobileConnectionReplySuccessClirStatus; + MobileConnectionReplySuccessPreferredNetworkType; // Error MobileConnectionReplyError; MobileConnectionReplyErrorMmi;