diff --git a/b2g/chrome/content/settings.js b/b2g/chrome/content/settings.js index 7400a67873c8..8459611668d6 100644 --- a/b2g/chrome/content/settings.js +++ b/b2g/chrome/content/settings.js @@ -157,6 +157,16 @@ SettingsListener.observe('language.current', 'en-US', function(value) { function(value) { Services.prefs.setCharPref('wap.UAProf.tagname', value); }); + + // DSDS default service IDs + ['mms', 'sms', 'telephony', 'voicemail'].forEach(function(key) { + SettingsListener.observe('ril.' + key + '.defaultServiceId', 0, + function(value) { + if (value != null) { + Services.prefs.setIntPref('dom.' + key + '.defaultServiceId', value); + } + }); + }); })(); //=================== DeviceInfo ==================== diff --git a/dom/mobilemessage/src/android/MmsService.cpp b/dom/mobilemessage/src/android/MmsService.cpp index fba2a2e358de..06df6effb37a 100644 --- a/dom/mobilemessage/src/android/MmsService.cpp +++ b/dom/mobilemessage/src/android/MmsService.cpp @@ -14,6 +14,13 @@ namespace mobilemessage { NS_IMPL_ISUPPORTS1(MmsService, nsIMmsService) +NS_IMETHODIMP +MmsService::GetMmsDefaultServiceId(uint32_t* aServiceId) +{ + NS_NOTYETIMPLEMENTED("Implement me!"); + return NS_ERROR_NOT_IMPLEMENTED; +} + NS_IMETHODIMP MmsService::Send(const JS::Value& aParameters, nsIMobileMessageCallback *aRequest) diff --git a/dom/mobilemessage/src/android/SmsService.cpp b/dom/mobilemessage/src/android/SmsService.cpp index 1da4b0a7ead8..f3a455fb6bc9 100644 --- a/dom/mobilemessage/src/android/SmsService.cpp +++ b/dom/mobilemessage/src/android/SmsService.cpp @@ -15,6 +15,14 @@ namespace mobilemessage { NS_IMPL_ISUPPORTS1(SmsService, nsISmsService) +NS_IMETHODIMP +SmsService::GetSmsDefaultServiceId(uint32_t* aServiceId) +{ + // Android has no official DSDS support. + *aServiceId = 0; + return NS_OK; +} + NS_IMETHODIMP SmsService::HasSupport(bool* aHasSupport) { diff --git a/dom/mobilemessage/src/fallback/MmsService.cpp b/dom/mobilemessage/src/fallback/MmsService.cpp index f49151aa04b1..11d5bcebed4b 100644 --- a/dom/mobilemessage/src/fallback/MmsService.cpp +++ b/dom/mobilemessage/src/fallback/MmsService.cpp @@ -13,6 +13,13 @@ namespace mobilemessage { NS_IMPL_ISUPPORTS1(MmsService, nsIMmsService) +NS_IMETHODIMP +MmsService::GetMmsDefaultServiceId(uint32_t* aServiceId) +{ + NS_NOTYETIMPLEMENTED("Implement me!"); + return NS_ERROR_NOT_IMPLEMENTED; +} + NS_IMETHODIMP MmsService::Send(const JS::Value& aParameters, nsIMobileMessageCallback *aRequest) diff --git a/dom/mobilemessage/src/fallback/SmsService.cpp b/dom/mobilemessage/src/fallback/SmsService.cpp index a04a46765491..b4595a5e800a 100644 --- a/dom/mobilemessage/src/fallback/SmsService.cpp +++ b/dom/mobilemessage/src/fallback/SmsService.cpp @@ -14,6 +14,13 @@ namespace mobilemessage { NS_IMPL_ISUPPORTS1(SmsService, nsISmsService) +NS_IMETHODIMP +SmsService::GetSmsDefaultServiceId(uint32_t* aServiceId) +{ + NS_ERROR("We should not be here!"); + return NS_ERROR_FAILURE; +} + NS_IMETHODIMP SmsService::HasSupport(bool* aHasSupport) { diff --git a/dom/mobilemessage/src/gonk/MmsService.js b/dom/mobilemessage/src/gonk/MmsService.js index 7e2610c3d309..c619043e97e3 100644 --- a/dom/mobilemessage/src/gonk/MmsService.js +++ b/dom/mobilemessage/src/gonk/MmsService.js @@ -108,6 +108,9 @@ const PREF_RETRIEVAL_RETRY_INTERVALS = (function () { return intervals; })(); +const kPrefRilNumRadioInterfaces = "ril.numRadioInterfaces"; +const kPrefDefaultServiceId = "dom.mms.defaultServiceId"; + XPCOMUtils.defineLazyServiceGetter(this, "gpps", "@mozilla.org/network/protocol-proxy-service;1", "nsIProtocolProxyService"); @@ -1189,6 +1192,17 @@ AcknowledgeTransaction.prototype = { } }; +function getDefaultServiceId() { + let id = Services.prefs.getIntPref(kPrefDefaultServiceId); + let numRil = Services.prefs.getIntPref(kPrefRilNumRadioInterfaces); + + if (id >= numRil || id < 0) { + id = 0; + } + + return id; +} + /** * MmsService */ @@ -1199,13 +1213,17 @@ function MmsService() { debug("Running protocol version: " + macro + "." + minor); } + Services.prefs.addObserver(kPrefDefaultServiceId, this, false); + this.mmsDefaultServiceId = getDefaultServiceId(); + // TODO: bug 810084 - support application identifier } MmsService.prototype = { classID: RIL_MMSSERVICE_CID, QueryInterface: XPCOMUtils.generateQI([Ci.nsIMmsService, - Ci.nsIWapPushApplication]), + Ci.nsIWapPushApplication, + Ci.nsIObserver]), /* * Whether or not should we enable X-Mms-Report-Allowed in M-NotifyResp.ind * and M-Acknowledge.ind PDU. @@ -1801,6 +1819,8 @@ MmsService.prototype = { // nsIMmsService + mmsDefaultServiceId: 0, + send: function send(aParams, aRequest) { if (DEBUG) debug("send: aParams: " + JSON.stringify(aParams)); @@ -2111,6 +2131,18 @@ MmsService.prototype = { break; } }, + + // nsIObserver + + observe: function observe(aSubject, aTopic, aData) { + switch (aTopic) { + case NS_PREFBRANCH_PREFCHANGE_TOPIC_ID: + if (aData === kPrefDefaultServiceId) { + this.mmsDefaultServiceId = getDefaultServiceId(); + } + break; + } + } }; this.NSGetFactory = XPCOMUtils.generateNSGetFactory([MmsService]); diff --git a/dom/mobilemessage/src/gonk/SmsService.cpp b/dom/mobilemessage/src/gonk/SmsService.cpp index a61382356883..4b25015f60f1 100644 --- a/dom/mobilemessage/src/gonk/SmsService.cpp +++ b/dom/mobilemessage/src/gonk/SmsService.cpp @@ -7,13 +7,40 @@ #include "SmsService.h" #include "jsapi.h" #include "SmsSegmentInfo.h" +#include "mozilla/Preferences.h" #include "nsServiceManagerUtils.h" +namespace { + +const char* kPrefRilNumRadioInterfaces = "ril.numRadioInterfaces"; +#define kPrefDefaultServiceId "dom.sms.defaultServiceId" +const char* kObservedPrefs[] = { + kPrefDefaultServiceId, + nullptr +}; + +uint32_t +getDefaultServiceId() +{ + int32_t id = mozilla::Preferences::GetInt(kPrefDefaultServiceId, 0); + int32_t numRil = mozilla::Preferences::GetInt(kPrefRilNumRadioInterfaces, 1); + + if (id >= numRil || id < 0) { + id = 0; + } + + return id; +} + +} // Anonymous namespace + namespace mozilla { namespace dom { namespace mobilemessage { -NS_IMPL_ISUPPORTS1(SmsService, nsISmsService) +NS_IMPL_ISUPPORTS2(SmsService, + nsISmsService, + nsIObserver) SmsService::SmsService() { @@ -22,6 +49,42 @@ SmsService::SmsService() ril->GetRadioInterface(0, getter_AddRefs(mRadioInterface)); } NS_WARN_IF_FALSE(mRadioInterface, "This shouldn't fail!"); + + // Initialize observer. + Preferences::AddStrongObservers(this, kObservedPrefs); + mDefaultServiceId = getDefaultServiceId(); +} + +/* + * Implementation of nsIObserver. + */ + +NS_IMETHODIMP +SmsService::Observe(nsISupports* aSubject, + const char* aTopic, + const PRUnichar* aData) +{ + if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) { + nsDependentString data(aData); + if (data.EqualsLiteral(kPrefDefaultServiceId)) { + mDefaultServiceId = getDefaultServiceId(); + } + return NS_OK; + } + + MOZ_ASSERT(false, "SmsService got unexpected topic!"); + return NS_ERROR_UNEXPECTED; +} + +/* + * Implementation of nsISmsService. + */ + +NS_IMETHODIMP +SmsService::GetSmsDefaultServiceId(uint32_t* aServiceId) +{ + *aServiceId = mDefaultServiceId; + return NS_OK; } NS_IMETHODIMP diff --git a/dom/mobilemessage/src/gonk/SmsService.h b/dom/mobilemessage/src/gonk/SmsService.h index a75512dbb863..8b3620be7070 100644 --- a/dom/mobilemessage/src/gonk/SmsService.h +++ b/dom/mobilemessage/src/gonk/SmsService.h @@ -7,6 +7,7 @@ #include "nsISmsService.h" #include "nsCOMPtr.h" +#include "nsIObserver.h" #include "nsIRadioInterfaceLayer.h" #include "nsTArray.h" #include "nsString.h" @@ -17,16 +18,20 @@ namespace dom { namespace mobilemessage { class SmsService MOZ_FINAL : public nsISmsService + , public nsIObserver { public: NS_DECL_ISUPPORTS NS_DECL_NSISMSSERVICE + NS_DECL_NSIOBSERVER + SmsService(); protected: // TODO: Bug 854326 - B2G Multi-SIM: support multiple SIM cards for SMS/MMS nsCOMPtr mRadioInterface; nsTArray mSilentNumbers; + uint32_t mDefaultServiceId; }; } // namespace mobilemessage diff --git a/dom/mobilemessage/src/ipc/SmsIPCService.cpp b/dom/mobilemessage/src/ipc/SmsIPCService.cpp index 876bb2a2f4fc..9180dccc1d5f 100644 --- a/dom/mobilemessage/src/ipc/SmsIPCService.cpp +++ b/dom/mobilemessage/src/ipc/SmsIPCService.cpp @@ -17,12 +17,23 @@ #include "mozilla/dom/MobileMessageManagerBinding.h" #include "mozilla/dom/MozMmsMessageBinding.h" #include "mozilla/dom/BindingUtils.h" +#include "mozilla/Preferences.h" +#include "nsString.h" using namespace mozilla::dom; using namespace mozilla::dom::mobilemessage; namespace { +const char* kPrefRilNumRadioInterfaces = "ril.numRadioInterfaces"; +#define kPrefMmsDefaultServiceId "dom.mms.defaultServiceId" +#define kPrefSmsDefaultServiceId "dom.sms.defaultServiceId" +const char* kObservedPrefs[] = { + kPrefMmsDefaultServiceId, + kPrefSmsDefaultServiceId, + nullptr +}; + // TODO: Bug 767082 - WebSMS: sSmsChild leaks at shutdown PSmsChild* gSmsChild; @@ -74,16 +85,69 @@ SendCursorRequest(const IPCMobileMessageCursor& aRequest, actor.forget(aResult); return NS_OK; } + +uint32_t +getDefaultServiceId(const char* aPrefKey) +{ + int32_t id = mozilla::Preferences::GetInt(aPrefKey, 0); + int32_t numRil = mozilla::Preferences::GetInt(kPrefRilNumRadioInterfaces, 1); + + if (id >= numRil || id < 0) { + id = 0; + } + + return id; +} + } // anonymous namespace -NS_IMPL_ISUPPORTS3(SmsIPCService, +NS_IMPL_ISUPPORTS4(SmsIPCService, nsISmsService, nsIMmsService, - nsIMobileMessageDatabaseService) + nsIMobileMessageDatabaseService, + nsIObserver) + +SmsIPCService::SmsIPCService() +{ + Preferences::AddStrongObservers(this, kObservedPrefs); + mMmsDefaultServiceId = getDefaultServiceId(kPrefMmsDefaultServiceId); + mSmsDefaultServiceId = getDefaultServiceId(kPrefSmsDefaultServiceId); +} + +/* + * Implementation of nsIObserver. + */ + +NS_IMETHODIMP +SmsIPCService::Observe(nsISupports* aSubject, + const char* aTopic, + const PRUnichar* aData) +{ + if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) { + nsDependentString data(aData); + if (data.EqualsLiteral(kPrefMmsDefaultServiceId)) { + mMmsDefaultServiceId = getDefaultServiceId(kPrefMmsDefaultServiceId); + } else if (data.EqualsLiteral(kPrefSmsDefaultServiceId)) { + mSmsDefaultServiceId = getDefaultServiceId(kPrefSmsDefaultServiceId); + } + return NS_OK; + } + + MOZ_ASSERT(false, "SmsIPCService got unexpected topic!"); + return NS_ERROR_UNEXPECTED; +} /* * Implementation of nsISmsService. */ + +NS_IMETHODIMP +SmsIPCService::GetSmsDefaultServiceId(uint32_t* aServiceId) +{ + *aServiceId = mSmsDefaultServiceId; + return NS_OK; +} + NS_IMETHODIMP SmsIPCService::HasSupport(bool* aHasSupport) { @@ -236,6 +300,17 @@ GetSendMmsMessageRequestFromParams(const JS::Value& aParam, return true; } +/* + * Implementation of nsIMmsService. + */ + +NS_IMETHODIMP +SmsIPCService::GetMmsDefaultServiceId(uint32_t* aServiceId) +{ + *aServiceId = mMmsDefaultServiceId; + return NS_OK; +} + NS_IMETHODIMP SmsIPCService::Send(const JS::Value& aParameters, nsIMobileMessageCallback *aRequest) diff --git a/dom/mobilemessage/src/ipc/SmsIPCService.h b/dom/mobilemessage/src/ipc/SmsIPCService.h index 98b9a7737efd..8fbc12c7660e 100644 --- a/dom/mobilemessage/src/ipc/SmsIPCService.h +++ b/dom/mobilemessage/src/ipc/SmsIPCService.h @@ -9,6 +9,7 @@ #include "nsISmsService.h" #include "nsIMmsService.h" #include "nsIMobileMessageDatabaseService.h" +#include "nsIObserver.h" #include "mozilla/Attributes.h" namespace mozilla { @@ -20,12 +21,20 @@ class PSmsChild; class SmsIPCService MOZ_FINAL : public nsISmsService , public nsIMmsService , public nsIMobileMessageDatabaseService + , public nsIObserver { public: NS_DECL_ISUPPORTS NS_DECL_NSISMSSERVICE NS_DECL_NSIMMSSERVICE NS_DECL_NSIMOBILEMESSAGEDATABASESERVICE + NS_DECL_NSIOBSERVER + + SmsIPCService(); + +private: + uint32_t mMmsDefaultServiceId; + uint32_t mSmsDefaultServiceId; }; } // namespace mobilemessage diff --git a/dom/system/gonk/RILContentHelper.js b/dom/system/gonk/RILContentHelper.js index 3feb403f1671..fd60d57a95e0 100644 --- a/dom/system/gonk/RILContentHelper.js +++ b/dom/system/gonk/RILContentHelper.js @@ -29,7 +29,9 @@ const NS_XPCOM_SHUTDOWN_OBSERVER_ID = "xpcom-shutdown"; const NS_PREFBRANCH_PREFCHANGE_TOPIC_ID = "nsPref:changed"; +const kPrefRilNumRadioInterfaces = "ril.numRadioInterfaces"; const kPrefRilDebuggingEnabled = "ril.debugging.enabled"; +const kPrefVoicemailDefaultServiceId = "dom.voicemail.defaultServiceId"; let DEBUG; function debug(s) { @@ -119,8 +121,7 @@ XPCOMUtils.defineLazyGetter(this, "gNumRadioInterfaces", function () { return ril.numRadioInterfaces; } - let num = cpmm.sendSyncMessage("RIL:GetNumRadioInterfaces")[0]; - return num; + return Services.prefs.getIntPref(kPrefRilNumRadioInterfaces); }); function MobileIccCardLockResult(options) { @@ -452,6 +453,7 @@ function RILContentHelper() { dataConnectionInfo: new MobileConnectionInfo() }; this.voicemailInfo = new VoicemailInfo(); + this.voicemailDefaultServiceId = this.getVoicemailDefaultServiceId(); this.initDOMRequestHelper(/* aWindow */ null, RIL_IPC_MSG_NAMES); this._windowsMap = []; @@ -459,6 +461,7 @@ function RILContentHelper() { Services.obs.addObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false); Services.prefs.addObserver(kPrefRilDebuggingEnabled, this, false); + Services.prefs.addObserver(kPrefVoicemailDefaultServiceId, this, false); } RILContentHelper.prototype = { @@ -1318,6 +1321,17 @@ RILContentHelper.prototype = { voicemailStatus: null, + voicemailDefaultServiceId: 0, + getVoicemailDefaultServiceId: function getVoicemailDefaultServiceId() { + let id = Services.prefs.getIntPref(kPrefVoicemailDefaultServiceId); + + if (id >= gNumRadioInterfaces || id < 0) { + id = 0; + } + + return id; + }, + getVoicemailInfo: function getVoicemailInfo() { // Get voicemail infomation by IPC only on first time. this.getVoicemailInfo = function getVoicemailInfo() { @@ -1332,9 +1346,11 @@ RILContentHelper.prototype = { return this.voicemailInfo; }, + get voicemailNumber() { return this.getVoicemailInfo().number; }, + get voicemailDisplayName() { return this.getVoicemailInfo().displayName; }, @@ -1413,6 +1429,8 @@ RILContentHelper.prototype = { case NS_PREFBRANCH_PREFCHANGE_TOPIC_ID: if (data == kPrefRilDebuggingEnabled) { this.updateDebugFlag(); + } else if (data == kPrefVoicemailDefaultServiceId) { + this.voicemailDefaultServiceId = this.getVoicemailDefaultServiceId(); } break; diff --git a/dom/system/gonk/RadioInterfaceLayer.js b/dom/system/gonk/RadioInterfaceLayer.js index 6eb28463b2f2..ead6f59abe58 100644 --- a/dom/system/gonk/RadioInterfaceLayer.js +++ b/dom/system/gonk/RadioInterfaceLayer.js @@ -76,6 +76,7 @@ const NS_PREFBRANCH_PREFCHANGE_TOPIC_ID = "nsPref:changed"; const kPrefCellBroadcastDisabled = "ril.cellbroadcast.disabled"; const kPrefClirModePreference = "ril.clirMode"; +const kPrefRilNumRadioInterfaces = "ril.numRadioInterfaces"; const DOM_MOBILE_MESSAGE_DELIVERY_RECEIVED = "received"; const DOM_MOBILE_MESSAGE_DELIVERY_SENDING = "sending"; @@ -86,7 +87,6 @@ const RADIO_POWER_OFF_TIMEOUT = 30000; const SMS_HANDLED_WAKELOCK_TIMEOUT = 5000; const RIL_IPC_MOBILECONNECTION_MSG_NAMES = [ - "RIL:GetNumRadioInterfaces", "RIL:GetRilContext", "RIL:GetAvailableNetworks", "RIL:SelectNetwork", @@ -111,7 +111,6 @@ const RIL_IPC_MOBILECONNECTION_MSG_NAMES = [ ]; const RIL_IPC_ICCMANAGER_MSG_NAMES = [ - "RIL:GetNumRadioInterfaces", "RIL:SendStkResponse", "RIL:SendStkMenuSelection", "RIL:SendStkTimerExpiration", @@ -129,13 +128,11 @@ const RIL_IPC_ICCMANAGER_MSG_NAMES = [ ]; const RIL_IPC_VOICEMAIL_MSG_NAMES = [ - "RIL:GetNumRadioInterfaces", "RIL:RegisterVoicemailMsg", "RIL:GetVoicemailInfo" ]; const RIL_IPC_CELLBROADCAST_MSG_NAMES = [ - "RIL:GetNumRadioInterfaces", "RIL:RegisterCellBroadcastMsg" ]; @@ -399,8 +396,6 @@ XPCOMUtils.defineLazyGetter(this, "gMessageManager", function () { } switch (msg.name) { - case "RIL:GetNumRadioInterfaces": - return this.ril.numRadioInterfaces; case "RIL:RegisterMobileConnectionMsg": this._registerMessageTarget("mobileconnection", msg.target); return null; @@ -471,6 +466,25 @@ XPCOMUtils.defineLazyGetter(this, "gMessageManager", function () { }; }); +// Initialize shared preference 'ril.numRadioInterfaces' according to system +// property. +try { + Services.prefs.setIntPref(kPrefRilNumRadioInterfaces, (function () { + // When Gonk property "ro.moz.ril.numclients" is not set, return 1; if + // explicitly set to any number larger-equal than 0, return num; else, return + // 1 for compatibility. + try { + let numString = libcutils.property_get("ro.moz.ril.numclients", "1"); + let num = parseInt(numString, 10); + if (num >= 0) { + return num; + } + } catch (e) {} + + return 1; + })()); +} catch (e) {} + function IccInfo() {} IccInfo.prototype = { iccType: null, @@ -572,16 +586,9 @@ RadioInterfaceLayer.prototype = { XPCOMUtils.defineLazyGetter(RadioInterfaceLayer.prototype, "numRadioInterfaces", function () { - // When Gonk property "ro.moz.ril.numclients" is not set, return 1; if - // explicitly set to any number larger-equal than 0, return num; else, return - // 1 for compatibility. try { - let numString = libcutils.property_get("ro.moz.ril.numclients", "1"); - let num = parseInt(numString, 10); - if (num >= 0) { - return num; - } - } catch (e) {} + return Services.prefs.getIntPref(kPrefRilNumRadioInterfaces); + } catch(e) {} return 1; }); diff --git a/dom/telephony/gonk/TelephonyProvider.js b/dom/telephony/gonk/TelephonyProvider.js index 25488cffa14e..123011220c17 100644 --- a/dom/telephony/gonk/TelephonyProvider.js +++ b/dom/telephony/gonk/TelephonyProvider.js @@ -22,7 +22,9 @@ const NS_XPCOM_SHUTDOWN_OBSERVER_ID = "xpcom-shutdown"; const NS_PREFBRANCH_PREFCHANGE_TOPIC_ID = "nsPref:changed"; +const kPrefRilNumRadioInterfaces = "ril.numRadioInterfaces"; const kPrefRilDebuggingEnabled = "ril.debugging.enabled"; +const kPrefDefaultServiceId = "dom.telephony.defaultServiceId"; const nsIAudioManager = Ci.nsIAudioManager; const nsITelephonyProvider = Ci.nsITelephonyProvider; @@ -86,8 +88,10 @@ function TelephonyProvider() { this._listeners = []; this._updateDebugFlag(); + this.defaultServiceId = this._getDefaultServiceId(); Services.prefs.addObserver(kPrefRilDebuggingEnabled, this, false); + Services.prefs.addObserver(kPrefDefaultServiceId, this, false); Services.obs.addObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false); } @@ -273,10 +277,23 @@ TelephonyProvider.prototype = { } catch (e) {} }, + _getDefaultServiceId: function _getDefaultServiceId() { + let id = Services.prefs.getIntPref(kPrefDefaultServiceId); + let numRil = Services.prefs.getIntPref(kPrefRilNumRadioInterfaces); + + if (id >= numRil || id < 0) { + id = 0; + } + + return id; + }, + /** * nsITelephonyProvider interface. */ + defaultServiceId: 0, + registerListener: function(aListener) { if (this._listeners.indexOf(aListener) >= 0) { throw Cr.NS_ERROR_UNEXPECTED; @@ -513,6 +530,8 @@ TelephonyProvider.prototype = { case NS_PREFBRANCH_PREFCHANGE_TOPIC_ID: if (aData === kPrefRilDebuggingEnabled) { this._updateDebugFlag(); + } else if (aData === kPrefDefaultServiceId) { + this.defaultServiceId = this._getDefaultServiceId(); } break; diff --git a/dom/telephony/ipc/TelephonyIPCProvider.cpp b/dom/telephony/ipc/TelephonyIPCProvider.cpp index 3b40a31271c3..6da47f8face6 100644 --- a/dom/telephony/ipc/TelephonyIPCProvider.cpp +++ b/dom/telephony/ipc/TelephonyIPCProvider.cpp @@ -3,22 +3,52 @@ * 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/. */ +#include "ipc/TelephonyIPCProvider.h" + #include "mozilla/dom/ContentChild.h" #include "mozilla/dom/telephony/TelephonyChild.h" -#include "ipc/TelephonyIPCProvider.h" +#include "mozilla/Preferences.h" USING_TELEPHONY_NAMESPACE using namespace mozilla::dom; -NS_IMPL_ISUPPORTS2(TelephonyIPCProvider, +namespace { + +const char* kPrefRilNumRadioInterfaces = "ril.numRadioInterfaces"; +#define kPrefDefaultServiceId "dom.telephony.defaultServiceId" +const char* kObservedPrefs[] = { + kPrefDefaultServiceId, + nullptr +}; + +uint32_t +getDefaultServiceId() +{ + int32_t id = mozilla::Preferences::GetInt(kPrefDefaultServiceId, 0); + int32_t numRil = mozilla::Preferences::GetInt(kPrefRilNumRadioInterfaces, 1); + + if (id >= numRil || id < 0) { + id = 0; + } + + return id; +} + +} // Anonymous namespace + +NS_IMPL_ISUPPORTS3(TelephonyIPCProvider, nsITelephonyProvider, - nsITelephonyListener) + nsITelephonyListener, + nsIObserver) TelephonyIPCProvider::TelephonyIPCProvider() { // Deallocated in ContentChild::DeallocPTelephonyChild(). mPTelephonyChild = new TelephonyChild(this); ContentChild::GetSingleton()->SendPTelephonyConstructor(mPTelephonyChild); + + Preferences::AddStrongObservers(this, kObservedPrefs); + mDefaultServiceId = getDefaultServiceId(); } TelephonyIPCProvider::~TelephonyIPCProvider() @@ -27,10 +57,38 @@ TelephonyIPCProvider::~TelephonyIPCProvider() mPTelephonyChild = nullptr; } +/* + * Implementation of nsIObserver. + */ + +NS_IMETHODIMP +TelephonyIPCProvider::Observe(nsISupports* aSubject, + const char* aTopic, + const PRUnichar* aData) +{ + if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) { + nsDependentString data(aData); + if (data.EqualsLiteral(kPrefDefaultServiceId)) { + mDefaultServiceId = getDefaultServiceId(); + } + return NS_OK; + } + + MOZ_ASSERT(false, "TelephonyIPCProvider got unexpected topic!"); + return NS_ERROR_UNEXPECTED; +} + /* * Implementation of nsITelephonyProvider. */ +NS_IMETHODIMP +TelephonyIPCProvider::GetDefaultServiceId(uint32_t* aServiceId) +{ + *aServiceId = mDefaultServiceId; + return NS_OK; +} + NS_IMETHODIMP TelephonyIPCProvider::RegisterListener(nsITelephonyListener *aListener) { diff --git a/dom/telephony/ipc/TelephonyIPCProvider.h b/dom/telephony/ipc/TelephonyIPCProvider.h index 928fd1d6567c..215bc7a9deb6 100644 --- a/dom/telephony/ipc/TelephonyIPCProvider.h +++ b/dom/telephony/ipc/TelephonyIPCProvider.h @@ -8,6 +8,7 @@ #include "mozilla/dom/telephony/TelephonyCommon.h" #include "mozilla/Attributes.h" +#include "nsIObserver.h" #include "nsITelephonyProvider.h" BEGIN_TELEPHONY_NAMESPACE @@ -16,11 +17,13 @@ class PTelephonyChild; class TelephonyIPCProvider MOZ_FINAL : public nsITelephonyProvider , public nsITelephonyListener + , public nsIObserver { public: NS_DECL_ISUPPORTS NS_DECL_NSITELEPHONYPROVIDER NS_DECL_NSITELEPHONYLISTENER + NS_DECL_NSIOBSERVER TelephonyIPCProvider(); @@ -30,6 +33,7 @@ protected: private: nsTArray > mListeners; PTelephonyChild* mPTelephonyChild; + uint32_t mDefaultServiceId; }; END_TELEPHONY_NAMESPACE diff --git a/modules/libpref/src/init/all.js b/modules/libpref/src/init/all.js index d2b84cf01cc6..eab693dcba9f 100644 --- a/modules/libpref/src/init/all.js +++ b/modules/libpref/src/init/all.js @@ -4300,7 +4300,9 @@ pref("dom.sms.enabled", false); // 7-bit default alphabet. pref("dom.sms.strict7BitEncoding", false); pref("dom.sms.requestStatusReport", true); -pref("dom.mms.requestStatusReport", true); +// Numeric default service id for SMS API calls with |serviceId| parameter +// omitted. +pref("dom.sms.defaultServiceId", 0); // WebContacts pref("dom.mozContacts.enabled", false); @@ -4426,6 +4428,8 @@ pref("wap.UAProf.tagname", "x-wap-profile"); // @see OMA-TS-MMS_ENC-V1_3-20110913-A clause 7.3.34 pref("dom.mms.version", 19); +pref("dom.mms.requestStatusReport", true); + // Retrieval mode for MMS // manual: Manual retrieval mode. // automatic: Automatic retrieval mode even in roaming. @@ -4438,10 +4442,15 @@ pref("dom.mms.sendRetryInterval", 300000); pref("dom.mms.retrievalRetryCount", 4); pref("dom.mms.retrievalRetryIntervals", "60000,300000,600000,1800000"); - +// Numeric default service id for MMS API calls with |serviceId| parameter +// omitted. +pref("dom.mms.defaultServiceId", 0); // Debug enabler for MMS. pref("mms.debugging.enabled", false); +// Number of RadioInterface instances to create. +pref("ril.numRadioInterfaces", 0); + // If the user puts a finger down on an element and we think the user // might be executing a pan gesture, how long do we wait before // tentatively deciding the gesture is actually a tap and activating @@ -4477,6 +4486,9 @@ pref("dom.datastore.enabled", false); // Telephony API pref("dom.telephony.enabled", false); +// Numeric default service id for WebTelephony API calls with |serviceId| +// parameter omitted. +pref("dom.telephony.defaultServiceId", 0); // Cell Broadcast API pref("dom.cellbroadcast.enabled", false); @@ -4489,6 +4501,9 @@ pref("dom.mobileconnection.enabled", false); // Voice Mail API pref("dom.voicemail.enabled", false); +// Numeric default service id for Voice Mail API calls with |serviceId| +// parameter omitted. +pref("dom.voicemail.defaultServiceId", 0); // DOM Inter-App Communication API. pref("dom.inter-app-communication-api.enabled", false);