2012-07-20 09:10:44 +00:00
|
|
|
/* Copyright 2012 Mozilla Foundation and Mozilla contributors
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2011-12-05 07:58:27 +00:00
|
|
|
|
2012-01-09 22:28:47 +00:00
|
|
|
"use strict";
|
|
|
|
|
2011-12-05 07:58:27 +00:00
|
|
|
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2011-12-24 05:02:52 +00:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2013-06-22 14:22:05 +00:00
|
|
|
Cu.import("resource://gre/modules/Sntp.jsm");
|
2013-09-30 09:24:54 +00:00
|
|
|
Cu.import("resource://gre/modules/systemlibs.js");
|
2013-11-21 14:09:14 +00:00
|
|
|
Cu.import("resource://gre/modules/Promise.jsm");
|
2014-02-18 14:41:36 +00:00
|
|
|
Cu.import("resource://gre/modules/FileUtils.jsm");
|
2011-12-05 07:58:27 +00:00
|
|
|
|
2014-05-07 22:53:17 +00:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "RIL", function () {
|
|
|
|
let obj = {};
|
|
|
|
Cu.import("resource://gre/modules/ril_consts.js", obj);
|
|
|
|
return obj;
|
|
|
|
});
|
2012-01-09 22:28:47 +00:00
|
|
|
|
2013-12-20 20:56:35 +00:00
|
|
|
// Ril quirk to attach data registration on demand.
|
|
|
|
let RILQUIRKS_DATA_REGISTRATION_ON_DEMAND =
|
|
|
|
libcutils.property_get("ro.moz.ril.data_reg_on_demand", "false") == "true";
|
|
|
|
|
2014-05-05 07:12:14 +00:00
|
|
|
// Ril quirk to control the uicc/data subscription.
|
|
|
|
let RILQUIRKS_SUBSCRIPTION_CONTROL =
|
|
|
|
libcutils.property_get("ro.moz.ril.subscription_control", "false") == "true";
|
|
|
|
|
2014-01-15 14:40:49 +00:00
|
|
|
// Ril quirk to always turn the radio off for the client without SIM card
|
|
|
|
// except hw default client.
|
|
|
|
let RILQUIRKS_RADIO_OFF_WO_CARD =
|
|
|
|
libcutils.property_get("ro.moz.ril.radio_off_wo_card", "false") == "true";
|
|
|
|
|
2014-03-11 14:17:57 +00:00
|
|
|
// Ril quirk to enable IPv6 protocol/roaming protocol in APN settings.
|
|
|
|
let RILQUIRKS_HAVE_IPV6 =
|
|
|
|
libcutils.property_get("ro.moz.ril.ipv6", "false") == "true";
|
|
|
|
|
2012-01-19 20:53:32 +00:00
|
|
|
const RADIOINTERFACELAYER_CID =
|
2012-01-09 23:18:23 +00:00
|
|
|
Components.ID("{2d831c8d-6017-435b-a80c-e5d422810cea}");
|
2013-07-02 09:36:37 +00:00
|
|
|
const RADIOINTERFACE_CID =
|
|
|
|
Components.ID("{6a7c91f0-a2b3-4193-8562-8969296c0b54}");
|
2012-09-26 12:52:21 +00:00
|
|
|
const RILNETWORKINTERFACE_CID =
|
|
|
|
Components.ID("{3bdd52a9-3965-4130-b569-0ac5afed045e}");
|
2011-12-05 07:58:27 +00:00
|
|
|
|
2013-10-24 08:14:59 +00:00
|
|
|
const NS_XPCOM_SHUTDOWN_OBSERVER_ID = "xpcom-shutdown";
|
2014-03-10 03:36:42 +00:00
|
|
|
const kNetworkConnStateChangedTopic = "network-connection-state-changed";
|
2013-09-07 11:09:54 +00:00
|
|
|
const kSmsReceivedObserverTopic = "sms-received";
|
|
|
|
const kSilentSmsReceivedObserverTopic = "silent-sms-received";
|
|
|
|
const kSmsSendingObserverTopic = "sms-sending";
|
|
|
|
const kSmsSentObserverTopic = "sms-sent";
|
|
|
|
const kSmsFailedObserverTopic = "sms-failed";
|
|
|
|
const kSmsDeliverySuccessObserverTopic = "sms-delivery-success";
|
|
|
|
const kSmsDeliveryErrorObserverTopic = "sms-delivery-error";
|
2012-04-24 20:46:42 +00:00
|
|
|
const kMozSettingsChangedObserverTopic = "mozsettings-changed";
|
2012-09-05 20:00:06 +00:00
|
|
|
const kSysMsgListenerReadyObserverTopic = "system-message-listener-ready";
|
2012-10-23 07:15:53 +00:00
|
|
|
const kSysClockChangeObserverTopic = "system-clock-change";
|
2013-06-06 07:28:59 +00:00
|
|
|
const kScreenStateChangedTopic = "screen-state-changed";
|
2013-10-24 08:14:59 +00:00
|
|
|
|
|
|
|
const kSettingsClockAutoUpdateEnabled = "time.clock.automatic-update.enabled";
|
|
|
|
const kSettingsClockAutoUpdateAvailable = "time.clock.automatic-update.available";
|
|
|
|
const kSettingsTimezoneAutoUpdateEnabled = "time.timezone.automatic-update.enabled";
|
|
|
|
const kSettingsTimezoneAutoUpdateAvailable = "time.timezone.automatic-update.available";
|
|
|
|
|
|
|
|
const NS_PREFBRANCH_PREFCHANGE_TOPIC_ID = "nsPref:changed";
|
|
|
|
|
2013-10-24 08:15:06 +00:00
|
|
|
const kPrefRilNumRadioInterfaces = "ril.numRadioInterfaces";
|
2014-05-20 22:50:00 +00:00
|
|
|
const kPrefRilDebuggingEnabled = "ril.debugging.enabled";
|
2012-10-30 10:53:27 +00:00
|
|
|
|
2013-09-07 11:09:54 +00:00
|
|
|
const DOM_MOBILE_MESSAGE_DELIVERY_RECEIVED = "received";
|
|
|
|
const DOM_MOBILE_MESSAGE_DELIVERY_SENDING = "sending";
|
|
|
|
const DOM_MOBILE_MESSAGE_DELIVERY_SENT = "sent";
|
|
|
|
const DOM_MOBILE_MESSAGE_DELIVERY_ERROR = "error";
|
|
|
|
|
2013-09-07 06:19:57 +00:00
|
|
|
const RADIO_POWER_OFF_TIMEOUT = 30000;
|
2013-09-10 13:51:47 +00:00
|
|
|
const SMS_HANDLED_WAKELOCK_TIMEOUT = 5000;
|
2014-01-15 14:40:49 +00:00
|
|
|
const HW_DEFAULT_CLIENT_ID = 0;
|
2012-09-28 05:43:35 +00:00
|
|
|
|
2014-11-24 02:15:25 +00:00
|
|
|
const INT32_MAX = 2147483647;
|
|
|
|
|
2014-11-25 01:44:33 +00:00
|
|
|
const NETWORK_TYPE_UNKNOWN = Ci.nsINetworkInterface.NETWORK_TYPE_UNKNOWN;
|
|
|
|
const NETWORK_TYPE_WIFI = Ci.nsINetworkInterface.NETWORK_TYPE_WIFI;
|
|
|
|
const NETWORK_TYPE_MOBILE = Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE;
|
|
|
|
const NETWORK_TYPE_MOBILE_MMS = Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS;
|
|
|
|
const NETWORK_TYPE_MOBILE_SUPL = Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL;
|
|
|
|
const NETWORK_TYPE_MOBILE_IMS = Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_IMS;
|
|
|
|
const NETWORK_TYPE_MOBILE_DUN = Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_DUN;
|
|
|
|
|
2014-08-28 23:51:41 +00:00
|
|
|
const RIL_IPC_ICCMANAGER_MSG_NAMES = [
|
2014-02-10 11:55:22 +00:00
|
|
|
"RIL:GetRilContext",
|
2012-04-10 12:04:27 +00:00
|
|
|
"RIL:SendStkResponse",
|
2012-09-28 05:43:35 +00:00
|
|
|
"RIL:SendStkMenuSelection",
|
2012-11-28 08:16:20 +00:00
|
|
|
"RIL:SendStkTimerExpiration",
|
2012-09-11 02:34:36 +00:00
|
|
|
"RIL:SendStkEventDownload",
|
2013-04-11 07:12:09 +00:00
|
|
|
"RIL:GetCardLockState",
|
|
|
|
"RIL:UnlockCardLock",
|
|
|
|
"RIL:SetCardLock",
|
Bug 875710: Added getCardLockRetryCount to nsIIccProvider, r=vyang, sr=mounir
This patch adds getCardLockRetryCount to nsIIccProvider and its
implementations. This method allows callers to query the number
of remaining tries for unlocking a SIM-card lock. Supported locks
are 'pin', 'puk', 'pin2', 'puk2', 'nck', 'cck', and 'spck'. The
call returns a DOM request that returns the retry count in its
success handler, or signals an appropriate error.
Reading the retry count is an optional feature and may not be
supported for all lock types. In this case the DOM request receives
and error with the name GECKO_ERROR_NOT_SUPPORTED. For an invalid
lock type, the error name is GECKO_ERROR_GENERIC_FAILURE.
getCardLockRetryCount replaces retryCount in nsIDOMMobileConnection,
which is now deprecated.
--HG--
extra : rebase_source : d1d11612f836652dca85f7c701f09e7af962e3b7
2013-07-09 14:06:05 +00:00
|
|
|
"RIL:GetCardLockRetryCount",
|
2013-02-25 09:27:26 +00:00
|
|
|
"RIL:IccOpenChannel",
|
|
|
|
"RIL:IccExchangeAPDU",
|
|
|
|
"RIL:IccCloseChannel",
|
2013-03-06 02:51:40 +00:00
|
|
|
"RIL:ReadIccContacts",
|
2013-09-07 11:32:23 +00:00
|
|
|
"RIL:UpdateIccContact",
|
2014-01-27 18:22:00 +00:00
|
|
|
"RIL:RegisterIccMsg",
|
|
|
|
"RIL:MatchMvno"
|
2012-10-09 10:07:11 +00:00
|
|
|
];
|
|
|
|
|
2014-05-20 22:50:00 +00:00
|
|
|
// set to true in ril_consts.js to see debug messages
|
|
|
|
var DEBUG = RIL.DEBUG_RIL;
|
|
|
|
|
|
|
|
function updateDebugFlag() {
|
|
|
|
// Read debug setting from pref
|
|
|
|
let debugPref;
|
|
|
|
try {
|
|
|
|
debugPref = Services.prefs.getBoolPref(kPrefRilDebuggingEnabled);
|
|
|
|
} catch (e) {
|
|
|
|
debugPref = false;
|
|
|
|
}
|
|
|
|
DEBUG = RIL.DEBUG_RIL || debugPref;
|
|
|
|
}
|
|
|
|
updateDebugFlag();
|
|
|
|
|
|
|
|
function debug(s) {
|
|
|
|
dump("-*- RadioInterfaceLayer: " + s + "\n");
|
|
|
|
}
|
|
|
|
|
2013-09-07 11:09:54 +00:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "gPowerManagerService",
|
|
|
|
"@mozilla.org/power/powermanagerservice;1",
|
|
|
|
"nsIPowerManagerService");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "gMobileMessageService",
|
|
|
|
"@mozilla.org/mobilemessage/mobilemessageservice;1",
|
|
|
|
"nsIMobileMessageService");
|
|
|
|
|
2013-07-29 22:50:22 +00:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "gSmsService",
|
2013-09-07 11:09:54 +00:00
|
|
|
"@mozilla.org/sms/smsservice;1",
|
|
|
|
"nsISmsService");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "gMobileMessageDatabaseService",
|
|
|
|
"@mozilla.org/mobilemessage/rilmobilemessagedatabaseservice;1",
|
|
|
|
"nsIRilMobileMessageDatabaseService");
|
2013-09-06 21:28:10 +00:00
|
|
|
|
2013-09-07 11:32:23 +00:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "ppmm",
|
|
|
|
"@mozilla.org/parentprocessmessagemanager;1",
|
|
|
|
"nsIMessageBroadcaster");
|
|
|
|
|
2012-05-24 05:12:07 +00:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "gSettingsService",
|
|
|
|
"@mozilla.org/settingsService;1",
|
|
|
|
"nsISettingsService");
|
|
|
|
|
2012-08-31 14:45:32 +00:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "gSystemMessenger",
|
|
|
|
"@mozilla.org/system-message-internal;1",
|
|
|
|
"nsISystemMessagesInternal");
|
|
|
|
|
2012-09-26 12:52:21 +00:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "gNetworkManager",
|
|
|
|
"@mozilla.org/network/manager;1",
|
|
|
|
"nsINetworkManager");
|
|
|
|
|
2012-09-28 06:02:57 +00:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "gTimeService",
|
|
|
|
"@mozilla.org/time/timeservice;1",
|
|
|
|
"nsITimeService");
|
|
|
|
|
2013-01-24 06:42:07 +00:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "gSystemWorkerManager",
|
|
|
|
"@mozilla.org/telephony/system-worker-manager;1",
|
|
|
|
"nsISystemWorkerManager");
|
|
|
|
|
2014-06-03 14:15:25 +00:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "gTelephonyService",
|
|
|
|
"@mozilla.org/telephony/telephonyservice;1",
|
|
|
|
"nsIGonkTelephonyService");
|
2013-09-07 06:19:57 +00:00
|
|
|
|
2014-02-10 11:55:22 +00:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "gMobileConnectionService",
|
|
|
|
"@mozilla.org/mobileconnection/mobileconnectionservice;1",
|
2014-09-21 07:24:42 +00:00
|
|
|
"nsIGonkMobileConnectionService");
|
2014-02-10 11:55:22 +00:00
|
|
|
|
2014-08-13 10:28:34 +00:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "gCellBroadcastService",
|
|
|
|
"@mozilla.org/cellbroadcast/gonkservice;1",
|
|
|
|
"nsIGonkCellBroadcastService");
|
|
|
|
|
2014-10-24 03:33:01 +00:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "gSmsMessenger",
|
|
|
|
"@mozilla.org/ril/system-messenger-helper;1",
|
|
|
|
"nsISmsMessenger");
|
|
|
|
|
2014-01-13 02:44:33 +00:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "WAP", function() {
|
2013-09-07 11:09:54 +00:00
|
|
|
let wap = {};
|
|
|
|
Cu.import("resource://gre/modules/WapPushManager.js", wap);
|
|
|
|
return wap;
|
|
|
|
});
|
|
|
|
|
2014-01-13 02:44:33 +00:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "PhoneNumberUtils", function() {
|
2013-09-07 11:09:54 +00:00
|
|
|
let ns = {};
|
|
|
|
Cu.import("resource://gre/modules/PhoneNumberUtils.jsm", ns);
|
|
|
|
return ns.PhoneNumberUtils;
|
|
|
|
});
|
|
|
|
|
2014-01-13 02:44:33 +00:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "gMessageManager", function() {
|
2013-09-07 11:32:23 +00:00
|
|
|
return {
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIMessageListener,
|
|
|
|
Ci.nsIObserver]),
|
|
|
|
|
|
|
|
ril: null,
|
|
|
|
|
|
|
|
// Manage message targets in terms of topic. Only the authorized and
|
|
|
|
// registered contents can receive related messages.
|
|
|
|
targetsByTopic: {},
|
|
|
|
topics: [],
|
|
|
|
|
|
|
|
targetMessageQueue: [],
|
|
|
|
ready: false,
|
|
|
|
|
2014-01-13 02:44:40 +00:00
|
|
|
init: function(ril) {
|
2013-09-07 11:32:23 +00:00
|
|
|
this.ril = ril;
|
|
|
|
|
2013-10-24 08:14:59 +00:00
|
|
|
Services.obs.addObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
|
2013-09-07 11:32:23 +00:00
|
|
|
Services.obs.addObserver(this, kSysMsgListenerReadyObserverTopic, false);
|
|
|
|
this._registerMessageListeners();
|
|
|
|
},
|
|
|
|
|
2014-01-13 02:44:40 +00:00
|
|
|
_shutdown: function() {
|
2013-09-07 11:32:23 +00:00
|
|
|
this.ril = null;
|
|
|
|
|
2013-10-24 08:14:59 +00:00
|
|
|
Services.obs.removeObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
|
2013-09-07 11:32:23 +00:00
|
|
|
this._unregisterMessageListeners();
|
|
|
|
},
|
|
|
|
|
2014-01-13 02:44:40 +00:00
|
|
|
_registerMessageListeners: function() {
|
2013-09-07 11:32:23 +00:00
|
|
|
ppmm.addMessageListener("child-process-shutdown", this);
|
|
|
|
for (let msgName of RIL_IPC_ICCMANAGER_MSG_NAMES) {
|
|
|
|
ppmm.addMessageListener(msgName, this);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-01-13 02:44:40 +00:00
|
|
|
_unregisterMessageListeners: function() {
|
2013-09-07 11:32:23 +00:00
|
|
|
ppmm.removeMessageListener("child-process-shutdown", this);
|
|
|
|
for (let msgName of RIL_IPC_ICCMANAGER_MSG_NAMES) {
|
|
|
|
ppmm.removeMessageListener(msgName, this);
|
|
|
|
}
|
|
|
|
ppmm = null;
|
|
|
|
},
|
|
|
|
|
2014-01-13 02:44:40 +00:00
|
|
|
_registerMessageTarget: function(topic, target) {
|
2013-09-07 11:32:23 +00:00
|
|
|
let targets = this.targetsByTopic[topic];
|
|
|
|
if (!targets) {
|
|
|
|
targets = this.targetsByTopic[topic] = [];
|
|
|
|
let list = this.topics;
|
|
|
|
if (list.indexOf(topic) == -1) {
|
|
|
|
list.push(topic);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (targets.indexOf(target) != -1) {
|
|
|
|
if (DEBUG) debug("Already registered this target!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
targets.push(target);
|
|
|
|
if (DEBUG) debug("Registered " + topic + " target: " + target);
|
|
|
|
},
|
|
|
|
|
2014-01-13 02:44:40 +00:00
|
|
|
_unregisterMessageTarget: function(topic, target) {
|
2013-09-07 11:32:23 +00:00
|
|
|
if (topic == null) {
|
|
|
|
// Unregister the target for every topic when no topic is specified.
|
|
|
|
for (let type of this.topics) {
|
|
|
|
this._unregisterMessageTarget(type, target);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unregister the target for a specified topic.
|
|
|
|
let targets = this.targetsByTopic[topic];
|
|
|
|
if (!targets) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let index = targets.indexOf(target);
|
|
|
|
if (index != -1) {
|
|
|
|
targets.splice(index, 1);
|
|
|
|
if (DEBUG) debug("Unregistered " + topic + " target: " + target);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-01-13 02:44:40 +00:00
|
|
|
_enqueueTargetMessage: function(topic, message, options) {
|
2013-09-07 11:32:23 +00:00
|
|
|
let msg = { topic : topic,
|
|
|
|
message : message,
|
|
|
|
options : options };
|
2013-11-28 10:10:38 +00:00
|
|
|
// Remove previous queued message with the same message type and client Id
|
|
|
|
// , only one message per (message type + client Id) is allowed in queue.
|
2013-09-07 11:32:23 +00:00
|
|
|
let messageQueue = this.targetMessageQueue;
|
|
|
|
for(let i = 0; i < messageQueue.length; i++) {
|
2013-11-28 10:10:38 +00:00
|
|
|
if (messageQueue[i].message === message &&
|
|
|
|
messageQueue[i].options.clientId === options.clientId) {
|
2013-09-07 11:32:23 +00:00
|
|
|
messageQueue.splice(i, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
messageQueue.push(msg);
|
|
|
|
},
|
|
|
|
|
2014-01-13 02:44:40 +00:00
|
|
|
_sendTargetMessage: function(topic, message, options) {
|
2013-09-07 11:32:23 +00:00
|
|
|
if (!this.ready) {
|
|
|
|
this._enqueueTargetMessage(topic, message, options);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let targets = this.targetsByTopic[topic];
|
|
|
|
if (!targets) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let target of targets) {
|
|
|
|
target.sendAsyncMessage(message, options);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-01-13 02:44:40 +00:00
|
|
|
_resendQueuedTargetMessage: function() {
|
2013-09-07 11:32:23 +00:00
|
|
|
this.ready = true;
|
|
|
|
|
|
|
|
// Here uses this._sendTargetMessage() to resend message, which will
|
|
|
|
// enqueue message if listener is not ready.
|
|
|
|
// So only resend after listener is ready, or it will cause infinate loop and
|
|
|
|
// hang the system.
|
|
|
|
|
|
|
|
// Dequeue and resend messages.
|
|
|
|
for each (let msg in this.targetMessageQueue) {
|
|
|
|
this._sendTargetMessage(msg.topic, msg.message, msg.options);
|
|
|
|
}
|
|
|
|
this.targetMessageQueue = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nsIMessageListener interface methods.
|
|
|
|
*/
|
|
|
|
|
2014-01-13 02:44:40 +00:00
|
|
|
receiveMessage: function(msg) {
|
2013-09-07 11:32:23 +00:00
|
|
|
if (DEBUG) debug("Received '" + msg.name + "' message from content process");
|
|
|
|
if (msg.name == "child-process-shutdown") {
|
|
|
|
// By the time we receive child-process-shutdown, the child process has
|
|
|
|
// already forgotten its permissions so we need to unregister the target
|
|
|
|
// for every permission.
|
|
|
|
this._unregisterMessageTarget(null, msg.target);
|
2013-09-13 22:12:30 +00:00
|
|
|
return null;
|
2013-09-07 11:32:23 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 11:55:22 +00:00
|
|
|
if (RIL_IPC_ICCMANAGER_MSG_NAMES.indexOf(msg.name) != -1) {
|
2013-09-07 11:32:23 +00:00
|
|
|
if (!msg.target.assertPermission("mobileconnection")) {
|
|
|
|
if (DEBUG) {
|
|
|
|
debug("IccManager message " + msg.name +
|
|
|
|
" from a content process with no 'mobileconnection' privileges.");
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (DEBUG) debug("Ignoring unknown message type: " + msg.name);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (msg.name) {
|
|
|
|
case "RIL:RegisterIccMsg":
|
|
|
|
this._registerMessageTarget("icc", msg.target);
|
2013-09-13 22:12:30 +00:00
|
|
|
return null;
|
2013-09-07 11:32:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let clientId = msg.json.clientId || 0;
|
|
|
|
let radioInterface = this.ril.getRadioInterface(clientId);
|
|
|
|
if (!radioInterface) {
|
|
|
|
if (DEBUG) debug("No such radio interface: " + clientId);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return radioInterface.receiveMessage(msg);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nsIObserver interface methods.
|
|
|
|
*/
|
|
|
|
|
2014-01-13 02:44:40 +00:00
|
|
|
observe: function(subject, topic, data) {
|
2013-09-07 11:32:23 +00:00
|
|
|
switch (topic) {
|
|
|
|
case kSysMsgListenerReadyObserverTopic:
|
|
|
|
Services.obs.removeObserver(this, kSysMsgListenerReadyObserverTopic);
|
|
|
|
this._resendQueuedTargetMessage();
|
|
|
|
break;
|
2013-10-24 08:14:59 +00:00
|
|
|
case NS_XPCOM_SHUTDOWN_OBSERVER_ID:
|
2013-09-07 11:32:23 +00:00
|
|
|
this._shutdown();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-01-13 02:44:40 +00:00
|
|
|
sendIccMessage: function(message, clientId, data) {
|
2013-09-07 11:32:23 +00:00
|
|
|
this._sendTargetMessage("icc", message, {
|
|
|
|
clientId: clientId,
|
|
|
|
data: data
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2013-07-02 09:36:40 +00:00
|
|
|
});
|
2011-12-05 07:58:27 +00:00
|
|
|
|
2014-01-13 02:44:33 +00:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "gRadioEnabledController", function() {
|
2014-02-14 09:42:32 +00:00
|
|
|
let _ril = null;
|
2014-02-10 11:55:22 +00:00
|
|
|
let _pendingMessages = []; // For queueing "setRadioEnabled" message.
|
2014-02-14 09:42:32 +00:00
|
|
|
let _isProcessingPending = false;
|
|
|
|
let _timer = null;
|
|
|
|
let _request = null;
|
|
|
|
let _deactivatingDeferred = {};
|
|
|
|
let _initializedCardState = {};
|
|
|
|
let _allCardStateInitialized = !RILQUIRKS_RADIO_OFF_WO_CARD;
|
2013-11-21 14:09:14 +00:00
|
|
|
|
2014-02-14 09:42:32 +00:00
|
|
|
return {
|
2014-01-13 02:44:40 +00:00
|
|
|
init: function(ril) {
|
2014-02-14 09:42:32 +00:00
|
|
|
_ril = ril;
|
2013-11-21 14:09:14 +00:00
|
|
|
},
|
|
|
|
|
2014-02-14 09:42:32 +00:00
|
|
|
receiveCardState: function(clientId) {
|
|
|
|
if (_allCardStateInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DEBUG) debug("RadioControl: receive cardState from " + clientId);
|
|
|
|
_initializedCardState[clientId] = true;
|
|
|
|
if (Object.keys(_initializedCardState).length == _ril.numRadioInterfaces) {
|
|
|
|
_allCardStateInitialized = true;
|
|
|
|
this._startProcessingPending();
|
2013-11-21 14:09:14 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-02-10 11:55:22 +00:00
|
|
|
setRadioEnabled: function(clientId, data, callback) {
|
|
|
|
if (DEBUG) debug("setRadioEnabled: " + clientId + ": " + JSON.stringify(data));
|
|
|
|
let message = {
|
|
|
|
clientId: clientId,
|
|
|
|
data: data,
|
|
|
|
callback: callback
|
|
|
|
};
|
|
|
|
_pendingMessages.push(message);
|
2014-02-14 09:42:32 +00:00
|
|
|
this._startProcessingPending();
|
|
|
|
},
|
|
|
|
|
2013-11-21 14:09:14 +00:00
|
|
|
isDeactivatingDataCalls: function() {
|
2014-02-14 09:42:32 +00:00
|
|
|
return _request !== null;
|
2013-11-21 14:09:14 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
finishDeactivatingDataCalls: function(clientId) {
|
2014-02-14 09:42:32 +00:00
|
|
|
if (DEBUG) debug("RadioControl: finishDeactivatingDataCalls: " + clientId);
|
|
|
|
let deferred = _deactivatingDeferred[clientId];
|
2013-11-21 14:09:14 +00:00
|
|
|
if (deferred) {
|
|
|
|
deferred.resolve();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-02-10 11:55:22 +00:00
|
|
|
notifyRadioStateChanged: function(clientId, radioState) {
|
|
|
|
gMobileConnectionService.notifyRadioStateChanged(clientId, radioState);
|
|
|
|
},
|
|
|
|
|
2014-02-14 09:42:32 +00:00
|
|
|
_startProcessingPending: function() {
|
|
|
|
if (!_isProcessingPending) {
|
|
|
|
if (DEBUG) debug("RadioControl: start dequeue");
|
|
|
|
_isProcessingPending = true;
|
|
|
|
this._processNextMessage();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-11-21 14:09:14 +00:00
|
|
|
_processNextMessage: function() {
|
2014-02-14 09:42:32 +00:00
|
|
|
if (_pendingMessages.length === 0 || !_allCardStateInitialized) {
|
|
|
|
if (DEBUG) debug("RadioControl: stop dequeue");
|
|
|
|
_isProcessingPending = false;
|
2013-11-21 14:09:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-14 09:42:32 +00:00
|
|
|
let msg = _pendingMessages.shift();
|
2013-11-21 14:09:14 +00:00
|
|
|
this._handleMessage(msg);
|
|
|
|
},
|
|
|
|
|
2014-01-15 14:40:49 +00:00
|
|
|
_getNumCards: function() {
|
|
|
|
let numCards = 0;
|
2014-02-14 09:42:32 +00:00
|
|
|
for (let i = 0, N = _ril.numRadioInterfaces; i < N; ++i) {
|
2014-01-15 14:40:49 +00:00
|
|
|
if (this._isCardPresentAtClient(i)) {
|
|
|
|
numCards++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return numCards;
|
|
|
|
},
|
|
|
|
|
|
|
|
_isCardPresentAtClient: function(clientId) {
|
2014-02-14 09:42:32 +00:00
|
|
|
let cardState = _ril.getRadioInterface(clientId).rilContext.cardState;
|
2014-09-03 11:31:00 +00:00
|
|
|
return cardState !== Ci.nsIIccProvider.CARD_STATE_UNDETECTED &&
|
|
|
|
cardState !== Ci.nsIIccProvider.CARD_STATE_UNKNOWN;
|
2014-01-15 14:40:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_isRadioAbleToEnableAtClient: function(clientId, numCards) {
|
|
|
|
if (!RILQUIRKS_RADIO_OFF_WO_CARD) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We could only turn on the radio for clientId if
|
|
|
|
// 1. a SIM card is presented or
|
|
|
|
// 2. it is the default clientId and there is no any SIM card at any client.
|
|
|
|
|
|
|
|
if (this._isCardPresentAtClient(clientId)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
numCards = numCards == null ? this._getNumCards() : numCards;
|
|
|
|
if (clientId === HW_DEFAULT_CLIENT_ID && numCards === 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2014-09-21 07:24:43 +00:00
|
|
|
_isValidStateForSetRadioEnabled: function(radioState) {
|
2014-10-24 09:12:35 +00:00
|
|
|
return radioState == Ci.nsIMobileConnection.MOBILE_RADIO_STATE_ENABLED ||
|
|
|
|
radioState == Ci.nsIMobileConnection.MOBILE_RADIO_STATE_DISABLED;
|
2014-02-10 11:55:22 +00:00
|
|
|
},
|
|
|
|
|
2014-09-21 07:24:43 +00:00
|
|
|
_isDummyForSetRadioEnabled: function(radioState, data) {
|
2014-10-24 09:12:35 +00:00
|
|
|
return (radioState == Ci.nsIMobileConnection.MOBILE_RADIO_STATE_ENABLED &&
|
|
|
|
data.enabled) ||
|
|
|
|
(radioState == Ci.nsIMobileConnection.MOBILE_RADIO_STATE_DISABLED &&
|
|
|
|
!data.enabled);
|
2014-02-10 11:55:22 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_handleMessage: function(message) {
|
|
|
|
if (DEBUG) debug("RadioControl: handleMessage: " + JSON.stringify(message));
|
|
|
|
let clientId = message.clientId || 0;
|
2014-09-21 07:24:43 +00:00
|
|
|
let connection =
|
|
|
|
gMobileConnectionService.getItemByServiceId(clientId);
|
|
|
|
let radioState = connection && connection.radioState;
|
2013-11-21 14:09:14 +00:00
|
|
|
|
2014-09-21 07:24:43 +00:00
|
|
|
if (!this._isValidStateForSetRadioEnabled(radioState)) {
|
2014-02-10 11:55:22 +00:00
|
|
|
message.data.errorMsg = "InvalidStateError";
|
|
|
|
message.callback(message.data);
|
2013-11-21 14:09:14 +00:00
|
|
|
this._processNextMessage();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-21 07:24:43 +00:00
|
|
|
if (this._isDummyForSetRadioEnabled(radioState, message.data)) {
|
2014-02-10 11:55:22 +00:00
|
|
|
message.callback(message.data);
|
2013-11-21 14:09:14 +00:00
|
|
|
this._processNextMessage();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-10 11:55:22 +00:00
|
|
|
if (message.data.enabled) {
|
2014-01-15 14:40:49 +00:00
|
|
|
if (this._isRadioAbleToEnableAtClient(clientId)) {
|
2014-02-10 11:55:22 +00:00
|
|
|
this._setRadioEnabledInternal(message);
|
2014-01-15 14:40:49 +00:00
|
|
|
} else {
|
|
|
|
// Not really do it but respond success.
|
2014-02-10 11:55:22 +00:00
|
|
|
message.callback(message.data);
|
2014-01-15 14:40:49 +00:00
|
|
|
}
|
|
|
|
|
2013-11-21 14:09:14 +00:00
|
|
|
this._processNextMessage();
|
|
|
|
} else {
|
2014-02-10 11:55:22 +00:00
|
|
|
_request = this._setRadioEnabledInternal.bind(this, message);
|
2013-11-21 14:09:14 +00:00
|
|
|
|
2014-02-06 04:31:53 +00:00
|
|
|
// In 2G network, modem takes 35+ seconds to process deactivate data
|
|
|
|
// call request if device has active voice call (please see bug 964974
|
|
|
|
// for more details). Therefore we should hangup all active voice calls
|
|
|
|
// first. And considering some DSDS architecture, toggling one radio may
|
|
|
|
// toggle both, so we send hangUpAll to all clients.
|
2014-02-14 09:42:32 +00:00
|
|
|
for (let i = 0, N = _ril.numRadioInterfaces; i < N; ++i) {
|
|
|
|
let iface = _ril.getRadioInterface(i);
|
2014-02-06 04:31:53 +00:00
|
|
|
iface.workerMessenger.send("hangUpAll");
|
|
|
|
}
|
|
|
|
|
2013-11-21 14:09:14 +00:00
|
|
|
// In some DSDS architecture with only one modem, toggling one radio may
|
|
|
|
// toggle both. Therefore, for safely turning off, we should first
|
|
|
|
// explicitly deactivate all data calls from all clients.
|
|
|
|
this._deactivateDataCalls().then(() => {
|
2014-02-14 09:42:32 +00:00
|
|
|
if (DEBUG) debug("RadioControl: deactivation done");
|
2013-11-21 14:09:14 +00:00
|
|
|
this._executeRequest();
|
|
|
|
});
|
|
|
|
|
|
|
|
this._createTimer();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-02-10 11:55:22 +00:00
|
|
|
_setRadioEnabledInternal: function(message) {
|
|
|
|
let clientId = message.clientId || 0;
|
|
|
|
let enabled = message.data.enabled || false;
|
|
|
|
let radioInterface = _ril.getRadioInterface(clientId);
|
|
|
|
|
|
|
|
this.notifyRadioStateChanged(clientId,
|
2014-10-24 09:12:35 +00:00
|
|
|
enabled ? Ci.nsIMobileConnection.MOBILE_RADIO_STATE_ENABLING
|
|
|
|
: Ci.nsIMobileConnection.MOBILE_RADIO_STATE_DISABLING);
|
2014-02-10 11:55:22 +00:00
|
|
|
radioInterface.workerMessenger.send("setRadioEnabled", message.data,
|
|
|
|
(function(response) {
|
|
|
|
if (response.errorMsg) {
|
|
|
|
// Request fails. Rollback to the original radioState.
|
|
|
|
this.notifyRadioStateChanged(clientId,
|
2014-10-24 09:12:35 +00:00
|
|
|
enabled ? Ci.nsIMobileConnection.MOBILE_RADIO_STATE_DISABLED
|
|
|
|
: Ci.nsIMobileConnection.MOBILE_RADIO_STATE_ENABLED);
|
2014-02-10 11:55:22 +00:00
|
|
|
}
|
|
|
|
message.callback(response);
|
|
|
|
return false;
|
|
|
|
}).bind(this));
|
|
|
|
},
|
|
|
|
|
2013-11-21 14:09:14 +00:00
|
|
|
_deactivateDataCalls: function() {
|
2014-02-14 09:42:32 +00:00
|
|
|
if (DEBUG) debug("RadioControl: deactivating data calls...");
|
|
|
|
_deactivatingDeferred = {};
|
2013-11-21 14:09:14 +00:00
|
|
|
|
|
|
|
let promise = Promise.resolve();
|
2014-02-14 09:42:32 +00:00
|
|
|
for (let i = 0, N = _ril.numRadioInterfaces; i < N; ++i) {
|
2013-11-21 14:09:14 +00:00
|
|
|
promise = promise.then(this._deactivateDataCallsForClient(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
},
|
|
|
|
|
|
|
|
_deactivateDataCallsForClient: function(clientId) {
|
2014-02-14 09:42:32 +00:00
|
|
|
return function() {
|
|
|
|
let deferred = _deactivatingDeferred[clientId] = Promise.defer();
|
2013-12-03 06:18:32 +00:00
|
|
|
let dataConnectionHandler = gDataConnectionManager.getConnectionHandler(clientId);
|
|
|
|
dataConnectionHandler.deactivateDataCalls();
|
2013-11-21 14:09:14 +00:00
|
|
|
return deferred.promise;
|
2014-02-14 09:42:32 +00:00
|
|
|
};
|
2013-11-21 14:09:14 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_createTimer: function() {
|
2014-02-21 06:15:35 +00:00
|
|
|
if (!_timer) {
|
2014-02-14 09:42:32 +00:00
|
|
|
_timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
2013-11-21 14:09:14 +00:00
|
|
|
}
|
2014-02-14 09:42:32 +00:00
|
|
|
_timer.initWithCallback(this._executeRequest.bind(this),
|
|
|
|
RADIO_POWER_OFF_TIMEOUT,
|
|
|
|
Ci.nsITimer.TYPE_ONE_SHOT);
|
2013-11-21 14:09:14 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_cancelTimer: function() {
|
2014-02-14 09:42:32 +00:00
|
|
|
if (_timer) {
|
|
|
|
_timer.cancel();
|
2013-11-21 14:09:14 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_executeRequest: function() {
|
2014-02-14 09:42:32 +00:00
|
|
|
if (typeof _request === "function") {
|
|
|
|
if (DEBUG) debug("RadioControl: executeRequest");
|
2013-11-21 14:09:14 +00:00
|
|
|
this._cancelTimer();
|
2014-02-14 09:42:32 +00:00
|
|
|
_request();
|
|
|
|
_request = null;
|
2013-11-21 14:09:14 +00:00
|
|
|
}
|
2013-12-13 16:46:23 +00:00
|
|
|
this._processNextMessage();
|
2014-01-15 14:40:49 +00:00
|
|
|
},
|
2013-11-21 14:09:14 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2013-08-22 09:18:13 +00:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "gDataConnectionManager", function () {
|
|
|
|
return {
|
2013-12-03 06:18:32 +00:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
|
|
|
|
Ci.nsISettingsServiceCallback]),
|
2013-08-22 09:18:13 +00:00
|
|
|
|
|
|
|
_connectionHandlers: null,
|
|
|
|
|
2013-12-03 06:18:32 +00:00
|
|
|
// Flag to determine the data state to start with when we boot up. It
|
|
|
|
// corresponds to the 'ril.data.enabled' setting from the UI.
|
|
|
|
_dataEnabled: false,
|
|
|
|
|
|
|
|
// Flag to record the default client id for data call. It corresponds to
|
|
|
|
// the 'ril.data.defaultServiceId' setting from the UI.
|
|
|
|
_dataDefaultClientId: -1,
|
|
|
|
|
|
|
|
// Flag to record the current default client id for data call.
|
|
|
|
// It differs from _dataDefaultClientId in that it is set only when
|
|
|
|
// the switch of client id process is done.
|
|
|
|
_currentDataClientId: -1,
|
|
|
|
|
|
|
|
// Pending function to execute when we are notified that another data call has
|
|
|
|
// been disconnected.
|
|
|
|
_pendingDataCallRequest: null,
|
|
|
|
|
2013-08-22 09:18:13 +00:00
|
|
|
debug: function(s) {
|
|
|
|
dump("-*- DataConnectionManager: " + s + "\n");
|
|
|
|
},
|
|
|
|
|
|
|
|
init: function(ril) {
|
|
|
|
if (!ril) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._connectionHandlers = [];
|
|
|
|
for (let clientId = 0; clientId < ril.numRadioInterfaces; clientId++) {
|
|
|
|
let radioInterface = ril.getRadioInterface(clientId);
|
|
|
|
this._connectionHandlers.push(
|
|
|
|
new DataConnectionHandler(clientId, radioInterface));
|
|
|
|
}
|
|
|
|
|
2013-12-03 06:18:32 +00:00
|
|
|
let lock = gSettingsService.createLock();
|
|
|
|
// Read the APN data from the settings DB.
|
|
|
|
lock.get("ril.data.apnSettings", this);
|
|
|
|
// Read the data enabled setting from DB.
|
|
|
|
lock.get("ril.data.enabled", this);
|
|
|
|
lock.get("ril.data.roaming_enabled", this);
|
|
|
|
// Read the default client id for data call.
|
|
|
|
lock.get("ril.data.defaultServiceId", this);
|
|
|
|
|
2013-08-22 09:18:13 +00:00
|
|
|
Services.obs.addObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
|
2013-12-03 06:18:32 +00:00
|
|
|
Services.obs.addObserver(this, kMozSettingsChangedObserverTopic, false);
|
2013-08-22 09:18:13 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getConnectionHandler: function(clientId) {
|
|
|
|
return this._connectionHandlers[clientId];
|
|
|
|
},
|
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
isSwitchingDataClientId: function() {
|
|
|
|
return this._pendingDataCallRequest !== null;
|
|
|
|
},
|
|
|
|
|
|
|
|
notifyDataCallStateChange: function(clientId) {
|
|
|
|
if (!this.isSwitchingDataClientId() ||
|
|
|
|
clientId != this._currentDataClientId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let connHandler = this._connectionHandlers[this._currentDataClientId];
|
|
|
|
if (connHandler.allDataDisconnected() &&
|
|
|
|
typeof this._pendingDataCallRequest === "function") {
|
|
|
|
if (DEBUG) {
|
2014-08-07 10:38:21 +00:00
|
|
|
this.debug("All data calls disconnected, process pending data settings.");
|
2014-05-27 00:08:00 +00:00
|
|
|
}
|
|
|
|
this._pendingDataCallRequest();
|
|
|
|
this._pendingDataCallRequest = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-12-03 06:18:32 +00:00
|
|
|
_handleDataClientIdChange: function(newDefault) {
|
|
|
|
if (this._dataDefaultClientId === newDefault) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._dataDefaultClientId = newDefault;
|
|
|
|
|
2014-08-07 10:38:21 +00:00
|
|
|
// This is to handle boot up stage.
|
2013-12-03 06:18:32 +00:00
|
|
|
if (this._currentDataClientId == -1) {
|
|
|
|
this._currentDataClientId = this._dataDefaultClientId;
|
|
|
|
let connHandler = this._connectionHandlers[this._currentDataClientId];
|
|
|
|
let radioInterface = connHandler.radioInterface;
|
2014-05-05 07:12:14 +00:00
|
|
|
if (RILQUIRKS_DATA_REGISTRATION_ON_DEMAND ||
|
|
|
|
RILQUIRKS_SUBSCRIPTION_CONTROL) {
|
2013-12-03 06:18:32 +00:00
|
|
|
radioInterface.setDataRegistration(true);
|
|
|
|
}
|
|
|
|
if (this._dataEnabled) {
|
|
|
|
let settings = connHandler.dataCallSettings;
|
|
|
|
settings.oldEnabled = settings.enabled;
|
|
|
|
settings.enabled = true;
|
|
|
|
connHandler.updateRILNetworkInterface();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let oldConnHandler = this._connectionHandlers[this._currentDataClientId];
|
|
|
|
let oldIface = oldConnHandler.radioInterface;
|
|
|
|
let oldSettings = oldConnHandler.dataCallSettings;
|
|
|
|
let newConnHandler = this._connectionHandlers[this._dataDefaultClientId];
|
|
|
|
let newIface = newConnHandler.radioInterface;
|
|
|
|
let newSettings = newConnHandler.dataCallSettings;
|
|
|
|
|
2014-08-07 10:38:21 +00:00
|
|
|
let applyPendingDataSettings = (function() {
|
2014-05-05 07:12:14 +00:00
|
|
|
if (RILQUIRKS_DATA_REGISTRATION_ON_DEMAND ||
|
|
|
|
RILQUIRKS_SUBSCRIPTION_CONTROL) {
|
2014-08-07 10:38:21 +00:00
|
|
|
oldIface.setDataRegistration(false)
|
|
|
|
.then(() => {
|
|
|
|
if (this._dataEnabled) {
|
|
|
|
newSettings.oldEnabled = newSettings.enabled;
|
|
|
|
newSettings.enabled = true;
|
|
|
|
}
|
|
|
|
this._currentDataClientId = this._dataDefaultClientId;
|
|
|
|
return newIface.setDataRegistration(true);
|
|
|
|
})
|
|
|
|
.then(() => newConnHandler.updateRILNetworkInterface());
|
|
|
|
return;
|
2013-12-03 06:18:32 +00:00
|
|
|
}
|
|
|
|
|
2014-08-07 10:38:21 +00:00
|
|
|
if (this._dataEnabled) {
|
2013-12-03 06:18:32 +00:00
|
|
|
newSettings.oldEnabled = newSettings.enabled;
|
2014-08-07 10:38:21 +00:00
|
|
|
newSettings.enabled = true;
|
|
|
|
}
|
|
|
|
this._currentDataClientId = this._dataDefaultClientId;
|
|
|
|
newConnHandler.updateRILNetworkInterface();
|
|
|
|
}).bind(this);
|
2013-12-03 06:18:32 +00:00
|
|
|
|
2014-08-07 10:38:21 +00:00
|
|
|
if (this._dataEnabled) {
|
|
|
|
oldSettings.oldEnabled = oldSettings.enabled;
|
|
|
|
oldSettings.enabled = false;
|
|
|
|
}
|
2013-12-03 06:18:32 +00:00
|
|
|
|
2014-11-24 02:15:25 +00:00
|
|
|
if (oldConnHandler.deactivateDataCalls()) {
|
2014-08-07 10:38:21 +00:00
|
|
|
this._pendingDataCallRequest = applyPendingDataSettings;
|
2013-12-03 06:18:32 +00:00
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("_handleDataClientIdChange: existing data call(s) active" +
|
|
|
|
", wait for them to get disconnected.");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-07 10:38:21 +00:00
|
|
|
applyPendingDataSettings();
|
2013-12-03 06:18:32 +00:00
|
|
|
},
|
|
|
|
|
2013-08-22 09:18:13 +00:00
|
|
|
_shutdown: function() {
|
|
|
|
for (let handler of this._connectionHandlers) {
|
|
|
|
handler.shutdown();
|
|
|
|
}
|
|
|
|
this._connectionHandlers = null;
|
|
|
|
Services.obs.removeObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
|
2013-12-03 06:18:32 +00:00
|
|
|
Services.obs.removeObserver(this, kMozSettingsChangedObserverTopic);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nsISettingsServiceCallback
|
|
|
|
*/
|
|
|
|
handle: function(name, result) {
|
|
|
|
switch(name) {
|
|
|
|
case "ril.data.apnSettings":
|
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("'ril.data.apnSettings' is now " +
|
|
|
|
JSON.stringify(result));
|
|
|
|
}
|
|
|
|
if (!result) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (let clientId in this._connectionHandlers) {
|
|
|
|
let handler = this._connectionHandlers[clientId];
|
|
|
|
let apnSetting = result[clientId];
|
|
|
|
if (handler && apnSetting) {
|
|
|
|
handler.updateApnSettings(apnSetting);
|
|
|
|
handler.updateRILNetworkInterface();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "ril.data.enabled":
|
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("'ril.data.enabled' is now " + result);
|
|
|
|
}
|
|
|
|
if (this._dataEnabled === result) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
this._dataEnabled = result;
|
|
|
|
|
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("Default id for data call: " + this._dataDefaultClientId);
|
|
|
|
}
|
|
|
|
if (this._dataDefaultClientId === -1) {
|
|
|
|
// We haven't got the default id for data from db.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
let connHandler = this._connectionHandlers[this._dataDefaultClientId];
|
|
|
|
let settings = connHandler.dataCallSettings;
|
|
|
|
settings.oldEnabled = settings.enabled;
|
|
|
|
settings.enabled = result;
|
|
|
|
connHandler.updateRILNetworkInterface();
|
|
|
|
break;
|
|
|
|
case "ril.data.roaming_enabled":
|
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("'ril.data.roaming_enabled' is now " + result);
|
|
|
|
this.debug("Default id for data call: " + this._dataDefaultClientId);
|
|
|
|
}
|
2014-04-08 18:55:00 +00:00
|
|
|
for (let clientId = 0; clientId < this._connectionHandlers.length; clientId++) {
|
|
|
|
let connHandler = this._connectionHandlers[clientId];
|
2013-12-03 06:18:32 +00:00
|
|
|
let settings = connHandler.dataCallSettings;
|
2014-04-08 18:55:00 +00:00
|
|
|
settings.roamingEnabled = Array.isArray(result) ? result[clientId] : result;
|
2013-12-03 06:18:32 +00:00
|
|
|
}
|
|
|
|
if (this._dataDefaultClientId === -1) {
|
|
|
|
// We haven't got the default id for data from db.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
this._connectionHandlers[this._dataDefaultClientId].updateRILNetworkInterface();
|
|
|
|
break;
|
|
|
|
case "ril.data.defaultServiceId":
|
|
|
|
result = result || 0;
|
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("'ril.data.defaultServiceId' is now " + result);
|
|
|
|
}
|
|
|
|
this._handleDataClientIdChange(result);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
handleError: function(errorMessage) {
|
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("There was an error while reading RIL settings.");
|
|
|
|
}
|
2013-08-22 09:18:13 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nsIObserver interface methods.
|
|
|
|
*/
|
|
|
|
observe: function(subject, topic, data) {
|
|
|
|
switch (topic) {
|
2013-12-03 06:18:32 +00:00
|
|
|
case kMozSettingsChangedObserverTopic:
|
2014-09-16 17:15:16 +00:00
|
|
|
if ("wrappedJSObject" in subject) {
|
|
|
|
subject = subject.wrappedJSObject;
|
|
|
|
}
|
|
|
|
this.handle(subject.key, subject.value);
|
2013-12-03 06:18:32 +00:00
|
|
|
break;
|
2013-08-22 09:18:13 +00:00
|
|
|
case NS_XPCOM_SHUTDOWN_OBSERVER_ID:
|
|
|
|
this._shutdown();
|
|
|
|
break;
|
|
|
|
}
|
2013-12-03 06:18:32 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
// 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 = {
|
2014-09-19 07:53:05 +00:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIIccInfo]),
|
2014-08-18 07:15:16 +00:00
|
|
|
|
2014-09-19 07:53:05 +00:00
|
|
|
// nsIIccInfo
|
2014-08-18 07:15:16 +00:00
|
|
|
|
2013-12-03 06:18:32 +00:00
|
|
|
iccType: null,
|
|
|
|
iccid: null,
|
|
|
|
mcc: null,
|
|
|
|
mnc: null,
|
|
|
|
spn: null,
|
|
|
|
isDisplayNetworkNameRequired: null,
|
|
|
|
isDisplaySpnRequired: null
|
|
|
|
};
|
|
|
|
|
|
|
|
function GsmIccInfo() {}
|
|
|
|
GsmIccInfo.prototype = {
|
|
|
|
__proto__: IccInfo.prototype,
|
2014-09-19 07:53:05 +00:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIGsmIccInfo,
|
|
|
|
Ci.nsIIccInfo]),
|
2013-12-03 06:18:32 +00:00
|
|
|
|
2014-09-19 07:53:05 +00:00
|
|
|
// nsIGsmIccInfo
|
2013-12-03 06:18:32 +00:00
|
|
|
|
|
|
|
msisdn: null
|
|
|
|
};
|
|
|
|
|
|
|
|
function CdmaIccInfo() {}
|
|
|
|
CdmaIccInfo.prototype = {
|
|
|
|
__proto__: IccInfo.prototype,
|
2014-09-19 07:53:05 +00:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsICdmaIccInfo,
|
|
|
|
Ci.nsIIccInfo]),
|
2013-12-03 06:18:32 +00:00
|
|
|
|
2014-09-19 07:53:05 +00:00
|
|
|
// nsICdmaIccInfo
|
2013-12-03 06:18:32 +00:00
|
|
|
|
2014-04-07 07:29:04 +00:00
|
|
|
mdn: null,
|
|
|
|
prlVersion: 0
|
2013-12-03 06:18:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function DataConnectionHandler(clientId, radioInterface) {
|
|
|
|
// Initial owning attributes.
|
|
|
|
this.clientId = clientId;
|
|
|
|
this.radioInterface = radioInterface;
|
|
|
|
this.dataCallSettings = {
|
|
|
|
oldEnabled: false,
|
|
|
|
enabled: false,
|
|
|
|
roamingEnabled: false
|
|
|
|
};
|
2014-05-27 00:08:00 +00:00
|
|
|
this._dataCalls = [];
|
|
|
|
|
|
|
|
// This map is used to collect all the apn types and its corresponding
|
|
|
|
// RILNetworkInterface.
|
|
|
|
this.dataNetworkInterfaces = new Map();
|
2013-12-03 06:18:32 +00:00
|
|
|
}
|
|
|
|
DataConnectionHandler.prototype = {
|
|
|
|
clientId: 0,
|
|
|
|
radioInterface: null,
|
|
|
|
// Data calls setting.
|
|
|
|
dataCallSettings: null,
|
2014-05-27 00:08:00 +00:00
|
|
|
dataNetworkInterfaces: null,
|
|
|
|
_dataCalls: null,
|
2013-12-03 06:18:32 +00:00
|
|
|
|
|
|
|
// Apn settings to be setup after data call are cleared.
|
|
|
|
_pendingApnSettings: null,
|
|
|
|
|
|
|
|
debug: function(s) {
|
|
|
|
dump("-*- DataConnectionHandler[" + this.clientId + "]: " + s + "\n");
|
|
|
|
},
|
|
|
|
|
|
|
|
shutdown: function() {
|
|
|
|
// Shutdown all RIL network interfaces
|
2014-05-27 00:08:00 +00:00
|
|
|
this.dataNetworkInterfaces.forEach(function(networkInterface) {
|
|
|
|
gNetworkManager.unregisterNetworkInterface(networkInterface);
|
|
|
|
networkInterface.shutdown();
|
|
|
|
networkInterface = null;
|
|
|
|
});
|
|
|
|
this.dataNetworkInterfaces.clear();
|
|
|
|
this._dataCalls = [];
|
2013-12-03 06:18:32 +00:00
|
|
|
this.clientId = null;
|
|
|
|
this.radioInterface = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if we get all necessary APN data.
|
|
|
|
*/
|
|
|
|
_validateApnSetting: function(apnSetting) {
|
|
|
|
return (apnSetting &&
|
|
|
|
apnSetting.apn &&
|
|
|
|
apnSetting.types &&
|
|
|
|
apnSetting.types.length);
|
|
|
|
},
|
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
_convertApnType: function(apnType) {
|
|
|
|
switch(apnType) {
|
|
|
|
case "default":
|
2014-11-25 01:44:33 +00:00
|
|
|
return NETWORK_TYPE_MOBILE;
|
2014-05-27 00:08:00 +00:00
|
|
|
case "mms":
|
2014-11-25 01:44:33 +00:00
|
|
|
return NETWORK_TYPE_MOBILE_MMS;
|
2014-05-27 00:08:00 +00:00
|
|
|
case "supl":
|
2014-11-25 01:44:33 +00:00
|
|
|
return NETWORK_TYPE_MOBILE_SUPL;
|
2014-05-27 00:08:00 +00:00
|
|
|
case "ims":
|
2014-11-25 01:44:33 +00:00
|
|
|
return NETWORK_TYPE_MOBILE_IMS;
|
2014-05-27 00:08:00 +00:00
|
|
|
case "dun":
|
2014-11-25 01:44:33 +00:00
|
|
|
return NETWORK_TYPE_MOBILE_DUN;
|
2014-05-27 00:08:00 +00:00
|
|
|
default:
|
2014-11-25 01:44:33 +00:00
|
|
|
return NETWORK_TYPE_UNKNOWN;
|
2014-05-27 00:08:00 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-10-08 18:24:00 +00:00
|
|
|
_compareDataCallOptions: function(dataCall, newDataCall) {
|
|
|
|
return dataCall.apnProfile.apn == newDataCall.apn &&
|
|
|
|
dataCall.apnProfile.user == newDataCall.user &&
|
2014-10-13 15:12:47 +00:00
|
|
|
dataCall.apnProfile.password == newDataCall.passwd &&
|
2014-10-08 18:24:00 +00:00
|
|
|
dataCall.chappap == newDataCall.chappap &&
|
|
|
|
dataCall.pdptype == newDataCall.pdptype;
|
|
|
|
},
|
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
_deliverDataCallMessage: function(name, args) {
|
|
|
|
for (let i = 0; i < this._dataCalls.length; i++) {
|
|
|
|
let datacall = this._dataCalls[i];
|
2014-10-08 18:24:00 +00:00
|
|
|
// Send message only to the DataCall that matches the data call options.
|
2014-05-27 00:08:00 +00:00
|
|
|
// Currently, args always contain only one datacall info.
|
2014-10-08 18:24:00 +00:00
|
|
|
if (!this._compareDataCallOptions(datacall, args[0])) {
|
2014-05-27 00:08:00 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Do not deliver message to DataCall that contains cid but mistmaches
|
|
|
|
// with the cid in the current message.
|
2014-10-08 18:24:00 +00:00
|
|
|
if (args[0].cid !== undefined && datacall.linkInfo.cid != null &&
|
2014-05-27 00:08:00 +00:00
|
|
|
args[0].cid != datacall.linkInfo.cid) {
|
2013-12-03 06:18:32 +00:00
|
|
|
continue;
|
|
|
|
}
|
2014-05-27 00:08:00 +00:00
|
|
|
|
2013-12-03 06:18:32 +00:00
|
|
|
try {
|
2014-05-27 00:08:00 +00:00
|
|
|
let handler = datacall[name];
|
2014-03-29 07:18:13 +00:00
|
|
|
if (typeof handler !== "function") {
|
|
|
|
throw new Error("No handler for " + name);
|
|
|
|
}
|
2014-05-27 00:08:00 +00:00
|
|
|
handler.apply(datacall, args);
|
2013-12-03 06:18:32 +00:00
|
|
|
} catch (e) {
|
|
|
|
if (DEBUG) {
|
2014-05-27 00:08:00 +00:00
|
|
|
this.debug("Handler for " + name + " threw an exception: " + e);
|
2013-12-03 06:18:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function will do the following steps:
|
|
|
|
* 1. Clear the cached APN settings in the RIL.
|
|
|
|
* 2. Combine APN, user name, and password as the key of |byApn| object to
|
|
|
|
* refer to the corresponding APN setting.
|
|
|
|
* 3. Use APN type as the index of |byType| object to refer to the
|
|
|
|
* corresponding APN setting.
|
|
|
|
* 4. Create RilNetworkInterface for each APN setting created at step 2.
|
|
|
|
*/
|
|
|
|
_setupApnSettings: function(newApnSettings) {
|
|
|
|
if (!newApnSettings) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (DEBUG) this.debug("setupApnSettings: " + JSON.stringify(newApnSettings));
|
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
// Shutdown all network interfaces and clear data calls.
|
|
|
|
this.dataNetworkInterfaces.forEach(function(networkInterface) {
|
|
|
|
gNetworkManager.unregisterNetworkInterface(networkInterface);
|
|
|
|
networkInterface.shutdown();
|
|
|
|
networkInterface = null;
|
|
|
|
});
|
|
|
|
this.dataNetworkInterfaces.clear();
|
|
|
|
this._dataCalls = [];
|
2013-12-03 06:18:32 +00:00
|
|
|
|
|
|
|
// Cache the APN settings by APNs and by types in the RIL.
|
|
|
|
for (let inputApnSetting of newApnSettings) {
|
|
|
|
if (!this._validateApnSetting(inputApnSetting)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
// Use APN type as the key of dataNetworkInterfaces to refer to the
|
|
|
|
// corresponding RILNetworkInterface.
|
|
|
|
for (let i = 0; i < inputApnSetting.types.length; i++) {
|
|
|
|
let apnType = inputApnSetting.types[i];
|
|
|
|
let networkType = this._convertApnType(apnType);
|
2014-11-25 01:44:33 +00:00
|
|
|
if (networkType === NETWORK_TYPE_UNKNOWN) {
|
2014-05-27 00:08:00 +00:00
|
|
|
if (DEBUG) this.debug("Invalid apn type: " + apnType);
|
|
|
|
continue;
|
|
|
|
}
|
2013-12-03 06:18:32 +00:00
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
if (DEBUG) this.debug("Preparing RILNetworkInterface for type: " + apnType);
|
|
|
|
// Create DataCall for RILNetworkInterface or reuse one that is shareable.
|
|
|
|
let dataCall;
|
|
|
|
for (let i = 0; i < this._dataCalls.length; i++) {
|
|
|
|
if (this._dataCalls[i].canHandleApn(inputApnSetting)) {
|
|
|
|
if (DEBUG) this.debug("Found shareable DataCall, reusing it.");
|
|
|
|
dataCall = this._dataCalls[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-12-03 06:18:32 +00:00
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
if (!dataCall) {
|
|
|
|
if (DEBUG) this.debug("No shareable DataCall found, creating one.");
|
|
|
|
dataCall = new DataCall(this.clientId, inputApnSetting);
|
|
|
|
this._dataCalls.push(dataCall);
|
|
|
|
}
|
2013-12-03 06:18:32 +00:00
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
try {
|
|
|
|
let networkInterface = new RILNetworkInterface(this, networkType,
|
|
|
|
inputApnSetting,
|
|
|
|
dataCall);
|
|
|
|
gNetworkManager.registerNetworkInterface(networkInterface);
|
2014-11-25 01:44:33 +00:00
|
|
|
this.dataNetworkInterfaces.set(networkType, networkInterface);
|
2014-05-27 00:08:00 +00:00
|
|
|
} catch (e) {
|
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("Error setting up RILNetworkInterface for type " +
|
|
|
|
apnType + ": " + e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-12-03 06:18:32 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if all data is disconnected.
|
|
|
|
*/
|
|
|
|
allDataDisconnected: function() {
|
2014-05-27 00:08:00 +00:00
|
|
|
for (let i = 0; i < this._dataCalls.length; i++) {
|
|
|
|
let dataCall = this._dataCalls[i];
|
|
|
|
if (dataCall.state != RIL.GECKO_NETWORK_STATE_UNKNOWN &&
|
|
|
|
dataCall.state != RIL.GECKO_NETWORK_STATE_DISCONNECTED) {
|
2013-12-03 06:18:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
updateApnSettings: function(newApnSettings) {
|
|
|
|
if (!newApnSettings) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (this._pendingApnSettings) {
|
|
|
|
// Change of apn settings in process, just update to the newest.
|
|
|
|
this._pengingApnSettings = newApnSettings;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let isDeactivatingDataCalls = false;
|
2014-05-27 00:08:00 +00:00
|
|
|
this.dataNetworkInterfaces.forEach(function(networkInterface) {
|
|
|
|
// Clear all existing connections.
|
|
|
|
if (networkInterface.state == RIL.GECKO_NETWORK_STATE_CONNECTED) {
|
|
|
|
networkInterface.disconnect();
|
|
|
|
isDeactivatingDataCalls = true;
|
2013-12-03 06:18:32 +00:00
|
|
|
}
|
2014-05-27 00:08:00 +00:00
|
|
|
});
|
|
|
|
|
2013-12-03 06:18:32 +00:00
|
|
|
if (isDeactivatingDataCalls) {
|
|
|
|
// Defer apn settings setup until all data calls are cleared.
|
|
|
|
this._pendingApnSettings = newApnSettings;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._setupApnSettings(newApnSettings);
|
|
|
|
},
|
|
|
|
|
|
|
|
updateRILNetworkInterface: function() {
|
2014-11-25 01:44:33 +00:00
|
|
|
let networkInterface = this.dataNetworkInterfaces.get(NETWORK_TYPE_MOBILE);
|
2014-05-27 00:08:00 +00:00
|
|
|
if (!networkInterface) {
|
2013-12-03 06:18:32 +00:00
|
|
|
if (DEBUG) {
|
2014-05-27 00:08:00 +00:00
|
|
|
this.debug("No network interface for default data.");
|
2013-12-03 06:18:32 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-21 07:24:43 +00:00
|
|
|
let connection =
|
|
|
|
gMobileConnectionService.getItemByServiceId(this.clientId);
|
|
|
|
|
2013-12-03 06:18:32 +00:00
|
|
|
// This check avoids data call connection if the radio is not ready
|
|
|
|
// yet after toggling off airplane mode.
|
2014-09-21 07:24:43 +00:00
|
|
|
let radioState = connection && connection.radioState;
|
2014-10-24 09:12:35 +00:00
|
|
|
if (radioState != Ci.nsIMobileConnection.MOBILE_RADIO_STATE_ENABLED) {
|
2013-12-03 06:18:32 +00:00
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("RIL is not ready for data connection: radio's not ready");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We only watch at "ril.data.enabled" flag changes for connecting or
|
|
|
|
// disconnecting the data call. If the value of "ril.data.enabled" is
|
|
|
|
// true and any of the remaining flags change the setting application
|
|
|
|
// should turn this flag to false and then to true in order to reload
|
|
|
|
// the new values and reconnect the data call.
|
|
|
|
if (this.dataCallSettings.oldEnabled === this.dataCallSettings.enabled) {
|
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("No changes for ril.data.enabled flag. Nothing to do.");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-21 07:24:43 +00:00
|
|
|
let dataInfo = connection && connection.data;
|
2013-12-03 06:18:32 +00:00
|
|
|
let isRegistered =
|
2014-09-21 07:24:43 +00:00
|
|
|
dataInfo &&
|
2013-12-03 06:18:32 +00:00
|
|
|
dataInfo.state == RIL.GECKO_MOBILE_CONNECTION_STATE_REGISTERED;
|
|
|
|
let haveDataConnection =
|
2014-09-21 07:24:43 +00:00
|
|
|
dataInfo &&
|
2013-12-03 06:18:32 +00:00
|
|
|
dataInfo.type != RIL.GECKO_MOBILE_CONNECTION_STATE_UNKNOWN;
|
|
|
|
if (!isRegistered || !haveDataConnection) {
|
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("RIL is not ready for data connection: Phone's not " +
|
|
|
|
"registered or doesn't have data connection.");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let wifi_active = false;
|
|
|
|
if (gNetworkManager.active &&
|
2014-11-25 01:44:33 +00:00
|
|
|
gNetworkManager.active.type == NETWORK_TYPE_WIFI) {
|
2013-12-03 06:18:32 +00:00
|
|
|
wifi_active = true;
|
|
|
|
}
|
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
let defaultDataCallConnected = networkInterface.connected;
|
|
|
|
|
|
|
|
// We have moved part of the decision making into DataCall, the rest will be
|
|
|
|
// moved after Bug 904514 - [meta] NetworkManager enhancement.
|
|
|
|
if (networkInterface.enabled &&
|
2013-12-03 06:18:32 +00:00
|
|
|
(!this.dataCallSettings.enabled ||
|
|
|
|
(dataInfo.roaming && !this.dataCallSettings.roamingEnabled))) {
|
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("Data call settings: disconnect data call.");
|
|
|
|
}
|
2014-05-27 00:08:00 +00:00
|
|
|
networkInterface.disconnect();
|
2013-12-03 06:18:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-10 10:14:03 +00:00
|
|
|
if (networkInterface.enabled && wifi_active) {
|
2013-12-03 06:18:32 +00:00
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("Disconnect data call when Wifi is connected.");
|
|
|
|
}
|
2014-05-27 00:08:00 +00:00
|
|
|
networkInterface.disconnect();
|
2013-12-03 06:18:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-10 10:14:03 +00:00
|
|
|
if (!this.dataCallSettings.enabled || defaultDataCallConnected) {
|
2013-12-03 06:18:32 +00:00
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("Data call settings: nothing to do.");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (dataInfo.roaming && !this.dataCallSettings.roamingEnabled) {
|
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("We're roaming, but data roaming is disabled.");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (wifi_active) {
|
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("Don't connect data call when Wifi is connected.");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (this._pendingApnSettings) {
|
|
|
|
if (DEBUG) this.debug("We're changing apn settings, ignore any changes.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-21 07:24:43 +00:00
|
|
|
if (gRadioEnabledController.isDeactivatingDataCalls()) {
|
2013-12-03 06:18:32 +00:00
|
|
|
// We're changing the radio power currently, ignore any changes.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("Data call settings: connect data call.");
|
|
|
|
}
|
2014-05-27 00:08:00 +00:00
|
|
|
networkInterface.connect();
|
2013-12-03 06:18:32 +00:00
|
|
|
},
|
|
|
|
|
2014-11-25 01:44:33 +00:00
|
|
|
_isMobileNetworkType: function(networkType) {
|
|
|
|
if (networkType === NETWORK_TYPE_MOBILE ||
|
|
|
|
networkType === NETWORK_TYPE_MOBILE_MMS ||
|
|
|
|
networkType === NETWORK_TYPE_MOBILE_SUPL ||
|
|
|
|
networkType === NETWORK_TYPE_MOBILE_IMS ||
|
|
|
|
networkType === NETWORK_TYPE_MOBILE_DUN) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
getDataCallStateByType: function(networkType) {
|
|
|
|
if (!this._isMobileNetworkType(networkType)) {
|
|
|
|
if (DEBUG) this.debug(networkType + " is not a mobile network type!");
|
|
|
|
throw Cr.NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
let networkInterface = this.dataNetworkInterfaces.get(networkType);
|
2014-05-27 00:08:00 +00:00
|
|
|
if (!networkInterface) {
|
|
|
|
return RIL.GECKO_NETWORK_STATE_UNKNOWN;
|
2013-12-03 06:18:32 +00:00
|
|
|
}
|
2014-05-27 00:08:00 +00:00
|
|
|
return networkInterface.state;
|
2013-12-03 06:18:32 +00:00
|
|
|
},
|
|
|
|
|
2014-11-25 01:44:33 +00:00
|
|
|
setupDataCallByType: function(networkType) {
|
2013-12-03 06:18:32 +00:00
|
|
|
if (DEBUG) {
|
2014-11-25 01:44:33 +00:00
|
|
|
this.debug("setupDataCallByType: " + networkType);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this._isMobileNetworkType(networkType)) {
|
|
|
|
if (DEBUG) this.debug(networkType + " is not a mobile network type!");
|
|
|
|
throw Cr.NS_ERROR_INVALID_ARG;
|
2013-12-03 06:18:32 +00:00
|
|
|
}
|
2014-11-25 01:44:33 +00:00
|
|
|
|
|
|
|
let networkInterface = this.dataNetworkInterfaces.get(networkType);
|
2014-05-27 00:08:00 +00:00
|
|
|
if (!networkInterface) {
|
2013-12-03 06:18:32 +00:00
|
|
|
if (DEBUG) {
|
2014-11-25 01:44:33 +00:00
|
|
|
this.debug("No network interface for type: " + networkType);
|
2013-12-03 06:18:32 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
networkInterface.connect();
|
2013-12-03 06:18:32 +00:00
|
|
|
},
|
|
|
|
|
2014-11-25 01:44:33 +00:00
|
|
|
deactivateDataCallByType: function(networkType) {
|
2013-12-03 06:18:32 +00:00
|
|
|
if (DEBUG) {
|
2014-11-25 01:44:33 +00:00
|
|
|
this.debug("deactivateDataCallByType: " + networkType);
|
2013-12-03 06:18:32 +00:00
|
|
|
}
|
2014-11-25 01:44:33 +00:00
|
|
|
|
|
|
|
if (!this._isMobileNetworkType(networkType)) {
|
|
|
|
if (DEBUG) this.debug(networkType + " is not a mobile network type!");
|
|
|
|
throw Cr.NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
let networkInterface = this.dataNetworkInterfaces.get(networkType);
|
2014-05-27 00:08:00 +00:00
|
|
|
if (!networkInterface) {
|
2013-12-03 06:18:32 +00:00
|
|
|
if (DEBUG) {
|
2014-11-25 01:44:33 +00:00
|
|
|
this.debug("No network interface for type: " + networkType);
|
2013-12-03 06:18:32 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
networkInterface.disconnect();
|
2013-12-03 06:18:32 +00:00
|
|
|
},
|
2013-10-24 08:15:06 +00:00
|
|
|
|
2013-12-03 06:18:32 +00:00
|
|
|
deactivateDataCalls: function() {
|
|
|
|
let dataDisconnecting = false;
|
2014-05-27 00:08:00 +00:00
|
|
|
this.dataNetworkInterfaces.forEach(function(networkInterface) {
|
2014-11-24 02:15:25 +00:00
|
|
|
if (networkInterface.enabled) {
|
|
|
|
if (networkInterface.state == RIL.GECKO_NETWORK_STATE_CONNECTED) {
|
|
|
|
dataDisconnecting = true;
|
|
|
|
}
|
2014-05-27 00:08:00 +00:00
|
|
|
networkInterface.disconnect();
|
2013-12-03 06:18:32 +00:00
|
|
|
}
|
2014-05-27 00:08:00 +00:00
|
|
|
});
|
2013-10-15 02:42:49 +00:00
|
|
|
|
2013-12-03 06:18:32 +00:00
|
|
|
// No data calls exist. It's safe to proceed the pending radio power off
|
|
|
|
// request.
|
|
|
|
if (gRadioEnabledController.isDeactivatingDataCalls() && !dataDisconnecting) {
|
|
|
|
gRadioEnabledController.finishDeactivatingDataCalls(this.clientId);
|
|
|
|
}
|
2014-11-24 02:15:25 +00:00
|
|
|
|
|
|
|
return dataDisconnecting;
|
2013-12-03 06:18:32 +00:00
|
|
|
},
|
2013-10-15 02:42:49 +00:00
|
|
|
|
2013-12-03 06:18:32 +00:00
|
|
|
/**
|
|
|
|
* Handle data errors.
|
|
|
|
*/
|
|
|
|
handleDataCallError: function(message) {
|
|
|
|
// Notify data call error only for data APN
|
2014-11-25 01:44:33 +00:00
|
|
|
let networkInterface = this.dataNetworkInterfaces.get(NETWORK_TYPE_MOBILE);
|
2014-05-27 00:08:00 +00:00
|
|
|
if (networkInterface && networkInterface.enabled) {
|
2014-10-08 18:24:00 +00:00
|
|
|
let dataCall = networkInterface.dataCall;
|
|
|
|
// If there is a cid, compare cid; otherwise it is probably an error on
|
|
|
|
// data call setup.
|
|
|
|
if (message.cid !== undefined) {
|
|
|
|
if (message.cid == dataCall.linkInfo.cid) {
|
|
|
|
gMobileConnectionService.notifyDataError(this.clientId, message);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (this._compareDataCallOptions(dataCall, message)) {
|
|
|
|
gMobileConnectionService.notifyDataError(this.clientId, message);
|
|
|
|
}
|
2013-12-03 06:18:32 +00:00
|
|
|
}
|
|
|
|
}
|
2013-10-15 02:42:49 +00:00
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
this._deliverDataCallMessage("dataCallError", [message]);
|
2013-12-03 06:18:32 +00:00
|
|
|
},
|
2013-10-15 02:42:49 +00:00
|
|
|
|
2013-12-03 06:18:32 +00:00
|
|
|
/**
|
|
|
|
* Handle data call state changes.
|
|
|
|
*/
|
|
|
|
handleDataCallState: function(datacall) {
|
2014-05-27 00:08:00 +00:00
|
|
|
this._deliverDataCallMessage("dataCallStateChanged", [datacall]);
|
2013-08-22 09:18:13 +00:00
|
|
|
|
2013-12-03 06:18:32 +00:00
|
|
|
// Process pending radio power off request after all data calls
|
|
|
|
// are disconnected.
|
2014-05-27 00:04:00 +00:00
|
|
|
if (datacall.state == RIL.GECKO_NETWORK_STATE_DISCONNECTED &&
|
2013-12-03 06:18:32 +00:00
|
|
|
this.allDataDisconnected()) {
|
|
|
|
if (gRadioEnabledController.isDeactivatingDataCalls()) {
|
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("All data connections are disconnected.");
|
|
|
|
}
|
|
|
|
gRadioEnabledController.finishDeactivatingDataCalls(this.clientId);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._pendingApnSettings) {
|
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("Setup pending apn settings.");
|
|
|
|
}
|
|
|
|
this._setupApnSettings(this._pendingApnSettings);
|
|
|
|
this._pendingApnSettings = null;
|
|
|
|
this.updateRILNetworkInterface();
|
|
|
|
}
|
2014-05-27 00:08:00 +00:00
|
|
|
|
|
|
|
if (gDataConnectionManager.isSwitchingDataClientId()) {
|
|
|
|
gDataConnectionManager.notifyDataCallStateChange(this.clientId);
|
|
|
|
}
|
2013-12-03 06:18:32 +00:00
|
|
|
}
|
2013-08-22 09:18:13 +00:00
|
|
|
},
|
|
|
|
};
|
2013-07-02 09:36:40 +00:00
|
|
|
|
2013-08-22 09:18:13 +00:00
|
|
|
function RadioInterfaceLayer() {
|
2014-02-17 11:35:12 +00:00
|
|
|
let workerMessenger = new WorkerMessenger();
|
|
|
|
workerMessenger.init();
|
2014-05-20 22:50:00 +00:00
|
|
|
this.setWorkerDebugFlag = workerMessenger.setDebugFlag.bind(workerMessenger);
|
2014-02-17 11:35:12 +00:00
|
|
|
|
2013-07-02 09:36:37 +00:00
|
|
|
let numIfaces = this.numRadioInterfaces;
|
2014-01-23 08:44:20 +00:00
|
|
|
if (DEBUG) debug(numIfaces + " interfaces");
|
2013-07-02 09:36:37 +00:00
|
|
|
this.radioInterfaces = [];
|
|
|
|
for (let clientId = 0; clientId < numIfaces; clientId++) {
|
2014-02-17 11:35:03 +00:00
|
|
|
this.radioInterfaces.push(new RadioInterface(clientId, workerMessenger));
|
2013-07-02 09:36:37 +00:00
|
|
|
}
|
2013-12-20 20:56:35 +00:00
|
|
|
|
|
|
|
Services.obs.addObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
|
2014-05-20 22:50:00 +00:00
|
|
|
Services.prefs.addObserver(kPrefRilDebuggingEnabled, this, false);
|
2013-08-22 09:18:13 +00:00
|
|
|
|
|
|
|
gMessageManager.init(this);
|
|
|
|
gRadioEnabledController.init(this);
|
|
|
|
gDataConnectionManager.init(this);
|
2013-07-02 09:36:37 +00:00
|
|
|
}
|
|
|
|
RadioInterfaceLayer.prototype = {
|
|
|
|
|
|
|
|
classID: RADIOINTERFACELAYER_CID,
|
|
|
|
classInfo: XPCOMUtils.generateCI({classID: RADIOINTERFACELAYER_CID,
|
|
|
|
classDescription: "RadioInterfaceLayer",
|
|
|
|
interfaces: [Ci.nsIRadioInterfaceLayer]}),
|
|
|
|
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIRadioInterfaceLayer,
|
|
|
|
Ci.nsIObserver]),
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nsIObserver interface methods.
|
|
|
|
*/
|
|
|
|
|
2014-01-13 02:44:40 +00:00
|
|
|
observe: function(subject, topic, data) {
|
2013-12-20 20:56:35 +00:00
|
|
|
switch (topic) {
|
|
|
|
case NS_XPCOM_SHUTDOWN_OBSERVER_ID:
|
2013-12-03 06:18:32 +00:00
|
|
|
for (let radioInterface of this.radioInterfaces) {
|
|
|
|
radioInterface.shutdown();
|
2013-12-20 20:56:35 +00:00
|
|
|
}
|
2013-12-03 06:18:32 +00:00
|
|
|
this.radioInterfaces = null;
|
|
|
|
Services.obs.removeObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
|
2013-12-20 20:56:35 +00:00
|
|
|
break;
|
2014-05-20 22:50:00 +00:00
|
|
|
|
|
|
|
case NS_PREFBRANCH_PREFCHANGE_TOPIC_ID:
|
|
|
|
if (data === kPrefRilDebuggingEnabled) {
|
|
|
|
updateDebugFlag();
|
|
|
|
this.setWorkerDebugFlag(DEBUG);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-07-02 09:36:37 +00:00
|
|
|
},
|
2013-06-07 07:32:20 +00:00
|
|
|
|
2013-07-02 09:36:37 +00:00
|
|
|
/**
|
|
|
|
* nsIRadioInterfaceLayer interface methods.
|
|
|
|
*/
|
|
|
|
|
2014-01-13 02:44:40 +00:00
|
|
|
getRadioInterface: function(clientId) {
|
2013-07-02 09:36:37 +00:00
|
|
|
return this.radioInterfaces[clientId];
|
2013-11-02 10:17:35 +00:00
|
|
|
},
|
|
|
|
|
2014-07-02 07:47:00 +00:00
|
|
|
getClientIdForEmergencyCall: function() {
|
|
|
|
for (let cid = 0; cid < this.numRadioInterfaces; ++cid) {
|
|
|
|
if (gRadioEnabledController._isRadioAbleToEnableAtClient(cid)) {
|
|
|
|
return cid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
},
|
|
|
|
|
2014-01-13 02:44:40 +00:00
|
|
|
setMicrophoneMuted: function(muted) {
|
2013-11-27 07:45:31 +00:00
|
|
|
for (let clientId = 0; clientId < this.numRadioInterfaces; clientId++) {
|
|
|
|
let radioInterface = this.radioInterfaces[clientId];
|
|
|
|
radioInterface.workerMessenger.send("setMute", { muted: muted });
|
|
|
|
}
|
2013-07-02 09:36:37 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(RadioInterfaceLayer.prototype,
|
2014-01-13 02:44:33 +00:00
|
|
|
"numRadioInterfaces", function() {
|
2013-07-02 09:36:37 +00:00
|
|
|
try {
|
2013-10-24 08:15:06 +00:00
|
|
|
return Services.prefs.getIntPref(kPrefRilNumRadioInterfaces);
|
|
|
|
} catch(e) {}
|
2013-09-30 09:24:54 +00:00
|
|
|
|
|
|
|
return 1;
|
2013-07-02 09:36:37 +00:00
|
|
|
});
|
|
|
|
|
2014-02-17 11:35:03 +00:00
|
|
|
function WorkerMessenger() {
|
2013-08-13 12:14:10 +00:00
|
|
|
// Initial owning attributes.
|
2014-02-17 11:35:03 +00:00
|
|
|
this.radioInterfaces = [];
|
2013-08-13 12:14:10 +00:00
|
|
|
this.tokenCallbackMap = {};
|
|
|
|
|
|
|
|
this.worker = new ChromeWorker("resource://gre/modules/ril_worker.js");
|
|
|
|
this.worker.onerror = this.onerror.bind(this);
|
|
|
|
this.worker.onmessage = this.onmessage.bind(this);
|
|
|
|
}
|
|
|
|
WorkerMessenger.prototype = {
|
2014-02-17 11:35:03 +00:00
|
|
|
radioInterfaces: null,
|
2013-08-13 12:14:10 +00:00
|
|
|
worker: null,
|
|
|
|
|
|
|
|
// This gets incremented each time we send out a message.
|
|
|
|
token: 1,
|
|
|
|
|
|
|
|
// Maps tokens we send out with messages to the message callback.
|
|
|
|
tokenCallbackMap: null,
|
|
|
|
|
2014-02-17 11:35:02 +00:00
|
|
|
init: function() {
|
|
|
|
let options = {
|
|
|
|
debug: DEBUG,
|
|
|
|
quirks: {
|
|
|
|
callstateExtraUint32:
|
|
|
|
libcutils.property_get("ro.moz.ril.callstate_extra_int", "false") === "true",
|
|
|
|
v5Legacy:
|
|
|
|
libcutils.property_get("ro.moz.ril.v5_legacy", "true") === "true",
|
|
|
|
requestUseDialEmergencyCall:
|
|
|
|
libcutils.property_get("ro.moz.ril.dial_emergency_call", "false") === "true",
|
|
|
|
simAppStateExtraFields:
|
|
|
|
libcutils.property_get("ro.moz.ril.simstate_extra_field", "false") === "true",
|
|
|
|
extraUint2ndCall:
|
|
|
|
libcutils.property_get("ro.moz.ril.extra_int_2nd_call", "false") == "true",
|
|
|
|
haveQueryIccLockRetryCount:
|
|
|
|
libcutils.property_get("ro.moz.ril.query_icc_count", "false") == "true",
|
|
|
|
sendStkProfileDownload:
|
|
|
|
libcutils.property_get("ro.moz.ril.send_stk_profile_dl", "false") == "true",
|
2014-05-05 07:12:14 +00:00
|
|
|
dataRegistrationOnDemand: RILQUIRKS_DATA_REGISTRATION_ON_DEMAND,
|
|
|
|
subscriptionControl: RILQUIRKS_SUBSCRIPTION_CONTROL
|
2014-06-24 10:32:41 +00:00
|
|
|
}
|
2014-02-17 11:35:02 +00:00
|
|
|
};
|
|
|
|
|
2014-02-17 11:35:03 +00:00
|
|
|
this.send(null, "setInitialOptions", options);
|
|
|
|
},
|
|
|
|
|
2014-05-20 22:50:00 +00:00
|
|
|
setDebugFlag: function(aDebug) {
|
|
|
|
let options = { debug: aDebug };
|
|
|
|
this.send(null, "setDebugFlag", options);
|
|
|
|
},
|
|
|
|
|
2014-02-17 11:35:03 +00:00
|
|
|
debug: function(aClientId, aMessage) {
|
|
|
|
// We use the same debug subject with RadioInterface's here.
|
|
|
|
dump("-*- RadioInterface[" + aClientId + "]: " + aMessage + "\n");
|
2014-02-17 11:35:02 +00:00
|
|
|
},
|
|
|
|
|
2014-01-13 02:44:40 +00:00
|
|
|
onerror: function(event) {
|
2013-08-13 12:14:10 +00:00
|
|
|
if (DEBUG) {
|
2014-02-17 11:35:03 +00:00
|
|
|
this.debug("X", "Got an error: " + event.filename + ":" +
|
2013-08-13 12:14:10 +00:00
|
|
|
event.lineno + ": " + event.message + "\n");
|
|
|
|
}
|
|
|
|
event.preventDefault();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process the incoming message from the RIL worker.
|
|
|
|
*/
|
2014-01-13 02:44:40 +00:00
|
|
|
onmessage: function(event) {
|
2013-08-13 12:14:10 +00:00
|
|
|
let message = event.data;
|
2014-02-17 11:35:03 +00:00
|
|
|
let clientId = message.rilMessageClientId;
|
|
|
|
if (clientId === null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-13 12:14:10 +00:00
|
|
|
if (DEBUG) {
|
2014-02-17 11:35:03 +00:00
|
|
|
this.debug(clientId, "Received message from worker: " + JSON.stringify(message));
|
2013-08-13 12:14:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let token = message.rilMessageToken;
|
|
|
|
if (token == null) {
|
|
|
|
// That's an unsolicited message. Pass to RadioInterface directly.
|
2014-02-17 11:35:03 +00:00
|
|
|
let radioInterface = this.radioInterfaces[clientId];
|
|
|
|
radioInterface.handleUnsolicitedWorkerMessage(message);
|
2013-08-13 12:14:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let callback = this.tokenCallbackMap[message.rilMessageToken];
|
|
|
|
if (!callback) {
|
2014-02-17 11:35:03 +00:00
|
|
|
if (DEBUG) this.debug(clientId, "Ignore orphan token: " + message.rilMessageToken);
|
2013-08-13 12:14:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let keep = false;
|
|
|
|
try {
|
|
|
|
keep = callback(message);
|
|
|
|
} catch(e) {
|
2014-02-17 11:35:03 +00:00
|
|
|
if (DEBUG) this.debug(clientId, "callback throws an exception: " + e);
|
2013-08-13 12:14:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!keep) {
|
|
|
|
delete this.tokenCallbackMap[message.rilMessageToken];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-02-17 11:35:03 +00:00
|
|
|
registerClient: function(aClientId, aRadioInterface) {
|
|
|
|
if (DEBUG) this.debug(aClientId, "Starting RIL Worker");
|
|
|
|
|
|
|
|
// Keep a reference so that we can dispatch unsolicited messages to it.
|
|
|
|
this.radioInterfaces[aClientId] = aRadioInterface;
|
|
|
|
|
|
|
|
this.send(null, "registerClient", { clientId: aClientId });
|
|
|
|
gSystemWorkerManager.registerRilWorker(aClientId, this.worker);
|
|
|
|
},
|
|
|
|
|
2013-08-13 12:14:10 +00:00
|
|
|
/**
|
|
|
|
* Send arbitrary message to worker.
|
|
|
|
*
|
|
|
|
* @param rilMessageType
|
|
|
|
* A text message type.
|
|
|
|
* @param message [optional]
|
|
|
|
* An optional message object to send.
|
|
|
|
* @param callback [optional]
|
|
|
|
* An optional callback function which is called when worker replies
|
2013-11-21 14:09:14 +00:00
|
|
|
* with an message containing a "rilMessageToken" attribute of the
|
2013-08-13 12:14:10 +00:00
|
|
|
* same value we passed. This callback function accepts only one
|
|
|
|
* parameter -- the reply from worker. It also returns a boolean
|
|
|
|
* value true to keep current token-callback mapping and wait for
|
|
|
|
* another worker reply, or false to remove the mapping.
|
|
|
|
*/
|
2014-02-17 11:35:03 +00:00
|
|
|
send: function(clientId, rilMessageType, message, callback) {
|
2013-08-13 12:14:10 +00:00
|
|
|
message = message || {};
|
|
|
|
|
2014-02-17 11:35:03 +00:00
|
|
|
message.rilMessageClientId = clientId;
|
2013-08-13 12:14:10 +00:00
|
|
|
message.rilMessageToken = this.token;
|
|
|
|
this.token++;
|
|
|
|
|
|
|
|
if (callback) {
|
|
|
|
// Only create the map if callback is provided. For sending a request
|
|
|
|
// and intentionally leaving the callback undefined, that reply will
|
|
|
|
// be dropped in |this.onmessage| because of that orphan token.
|
|
|
|
//
|
|
|
|
// For sending a request that never replied at all, we're fine with this
|
|
|
|
// because no callback shall be passed and we leave nothing to be cleaned
|
|
|
|
// up later.
|
|
|
|
this.tokenCallbackMap[message.rilMessageToken] = callback;
|
|
|
|
}
|
|
|
|
|
|
|
|
message.rilMessageType = rilMessageType;
|
|
|
|
this.worker.postMessage(message);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send message to worker and return worker reply to RILContentHelper.
|
|
|
|
*
|
|
|
|
* @param msg
|
|
|
|
* A message object from ppmm.
|
|
|
|
* @param rilMessageType
|
|
|
|
* A text string for worker message type.
|
|
|
|
* @param ipcType [optinal]
|
2013-11-21 14:09:14 +00:00
|
|
|
* A text string for ipc message type. "msg.name" if omitted.
|
2013-08-13 12:14:10 +00:00
|
|
|
*
|
|
|
|
* @TODO: Bug 815526 - deprecate RILContentHelper.
|
|
|
|
*/
|
2014-02-17 11:35:03 +00:00
|
|
|
sendWithIPCMessage: function(clientId, msg, rilMessageType, ipcType) {
|
|
|
|
this.send(clientId, rilMessageType, msg.json.data, (function(reply) {
|
2013-08-13 12:14:10 +00:00
|
|
|
ipcType = ipcType || msg.name;
|
2013-09-30 00:56:00 +00:00
|
|
|
msg.target.sendAsyncMessage(ipcType, {
|
2014-02-17 11:35:03 +00:00
|
|
|
clientId: clientId,
|
2013-09-30 00:56:00 +00:00
|
|
|
data: reply
|
|
|
|
});
|
2013-08-13 12:14:10 +00:00
|
|
|
return false;
|
2013-09-30 00:56:00 +00:00
|
|
|
}).bind(this));
|
2013-08-13 12:14:10 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-02-17 11:35:03 +00:00
|
|
|
function RadioInterface(aClientId, aWorkerMessenger) {
|
2014-02-17 11:35:02 +00:00
|
|
|
this.clientId = aClientId;
|
2014-02-17 11:35:03 +00:00
|
|
|
this.workerMessenger = {
|
|
|
|
send: aWorkerMessenger.send.bind(aWorkerMessenger, aClientId),
|
|
|
|
sendWithIPCMessage:
|
|
|
|
aWorkerMessenger.sendWithIPCMessage.bind(aWorkerMessenger, aClientId),
|
|
|
|
};
|
|
|
|
aWorkerMessenger.registerClient(aClientId, this);
|
2013-07-02 09:36:37 +00:00
|
|
|
|
2012-06-13 02:46:41 +00:00
|
|
|
this.rilContext = {
|
2014-09-03 11:31:00 +00:00
|
|
|
cardState: Ci.nsIIccProvider.CARD_STATE_UNKNOWN,
|
2013-01-10 16:18:54 +00:00
|
|
|
iccInfo: null,
|
2014-02-10 11:55:22 +00:00
|
|
|
imsi: null
|
2011-12-07 06:57:19 +00:00
|
|
|
};
|
2012-05-24 05:12:07 +00:00
|
|
|
|
2013-08-08 09:29:42 +00:00
|
|
|
this.operatorInfo = {};
|
|
|
|
|
2012-09-07 18:05:08 +00:00
|
|
|
let lock = gSettingsService.createLock();
|
2012-05-24 05:12:07 +00:00
|
|
|
|
2013-11-21 14:09:14 +00:00
|
|
|
// Read the "time.clock.automatic-update.enabled" setting to see if
|
2013-06-22 14:22:05 +00:00
|
|
|
// we need to adjust the system clock time by NITZ or SNTP.
|
2013-10-24 08:14:59 +00:00
|
|
|
lock.get(kSettingsClockAutoUpdateEnabled, this);
|
2012-09-28 06:02:57 +00:00
|
|
|
|
2013-11-21 14:09:14 +00:00
|
|
|
// Read the "time.timezone.automatic-update.enabled" setting to see if
|
2013-06-22 14:22:05 +00:00
|
|
|
// we need to adjust the system timezone by NITZ.
|
2013-10-24 08:14:59 +00:00
|
|
|
lock.get(kSettingsTimezoneAutoUpdateEnabled, this);
|
2013-06-22 14:22:05 +00:00
|
|
|
|
|
|
|
// Set "time.clock.automatic-update.available" to false when starting up.
|
|
|
|
this.setClockAutoUpdateAvailable(false);
|
|
|
|
|
|
|
|
// Set "time.timezone.automatic-update.available" to false when starting up.
|
|
|
|
this.setTimezoneAutoUpdateAvailable(false);
|
2013-01-25 10:06:24 +00:00
|
|
|
|
2012-04-24 20:46:42 +00:00
|
|
|
Services.obs.addObserver(this, kMozSettingsChangedObserverTopic, false);
|
2012-10-23 07:15:53 +00:00
|
|
|
Services.obs.addObserver(this, kSysClockChangeObserverTopic, false);
|
2013-06-06 07:28:59 +00:00
|
|
|
Services.obs.addObserver(this, kScreenStateChangedTopic, false);
|
2012-04-19 21:33:25 +00:00
|
|
|
|
2014-03-10 03:36:42 +00:00
|
|
|
Services.obs.addObserver(this, kNetworkConnStateChangedTopic, false);
|
2013-09-07 11:09:54 +00:00
|
|
|
|
|
|
|
this.portAddressedSmsApps = {};
|
|
|
|
this.portAddressedSmsApps[WAP.WDP_PORT_PUSH] = this.handleSmsWdpPortPush.bind(this);
|
2013-06-22 14:22:05 +00:00
|
|
|
|
2014-03-12 16:27:00 +00:00
|
|
|
this._receivedSmsSegmentsMap = {};
|
|
|
|
|
2013-06-22 14:22:05 +00:00
|
|
|
this._sntp = new Sntp(this.setClockBySntp.bind(this),
|
2013-11-21 14:09:14 +00:00
|
|
|
Services.prefs.getIntPref("network.sntp.maxRetryCount"),
|
|
|
|
Services.prefs.getIntPref("network.sntp.refreshPeriod"),
|
|
|
|
Services.prefs.getIntPref("network.sntp.timeout"),
|
|
|
|
Services.prefs.getCharPref("network.sntp.pools").split(";"),
|
|
|
|
Services.prefs.getIntPref("network.sntp.port"));
|
2011-12-05 07:58:27 +00:00
|
|
|
}
|
2013-06-22 14:22:05 +00:00
|
|
|
|
2013-07-02 09:36:37 +00:00
|
|
|
RadioInterface.prototype = {
|
2011-12-05 07:58:27 +00:00
|
|
|
|
2013-07-02 09:36:37 +00:00
|
|
|
classID: RADIOINTERFACE_CID,
|
|
|
|
classInfo: XPCOMUtils.generateCI({classID: RADIOINTERFACE_CID,
|
|
|
|
classDescription: "RadioInterface",
|
|
|
|
interfaces: [Ci.nsIRadioInterface]}),
|
2011-12-05 07:58:27 +00:00
|
|
|
|
2013-07-02 09:36:37 +00:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIRadioInterface,
|
2012-05-24 05:12:07 +00:00
|
|
|
Ci.nsIObserver,
|
|
|
|
Ci.nsISettingsServiceCallback]),
|
2011-12-05 07:58:27 +00:00
|
|
|
|
2014-02-17 11:35:03 +00:00
|
|
|
// A private wrapped WorkerMessenger instance.
|
2013-08-13 12:14:10 +00:00
|
|
|
workerMessenger: null,
|
|
|
|
|
2014-01-13 02:44:40 +00:00
|
|
|
debug: function(s) {
|
2013-07-02 09:36:58 +00:00
|
|
|
dump("-*- RadioInterface[" + this.clientId + "]: " + s + "\n");
|
|
|
|
},
|
|
|
|
|
2013-12-03 06:18:32 +00:00
|
|
|
shutdown: function() {
|
|
|
|
// Release the CPU wake lock for handling the received SMS.
|
|
|
|
this._releaseSmsHandledWakeLock();
|
|
|
|
|
|
|
|
Services.obs.removeObserver(this, kMozSettingsChangedObserverTopic);
|
|
|
|
Services.obs.removeObserver(this, kSysClockChangeObserverTopic);
|
|
|
|
Services.obs.removeObserver(this, kScreenStateChangedTopic);
|
2014-03-10 03:36:42 +00:00
|
|
|
Services.obs.removeObserver(this, kNetworkConnStateChangedTopic);
|
2013-12-03 06:18:32 +00:00
|
|
|
},
|
|
|
|
|
2013-08-08 09:29:42 +00:00
|
|
|
/**
|
|
|
|
* A utility function to copy objects. The srcInfo may contain
|
2013-11-21 14:09:14 +00:00
|
|
|
* "rilMessageType", should ignore it.
|
2013-08-08 09:29:42 +00:00
|
|
|
*/
|
2014-01-13 02:44:40 +00:00
|
|
|
updateInfo: function(srcInfo, destInfo) {
|
2013-08-08 09:29:42 +00:00
|
|
|
for (let key in srcInfo) {
|
2013-11-21 14:09:14 +00:00
|
|
|
if (key === "rilMessageType") {
|
2013-08-08 09:29:42 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
destInfo[key] = srcInfo[key];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-08-09 04:27:19 +00:00
|
|
|
/**
|
|
|
|
* A utility function to compare objects. The srcInfo may contain
|
2013-11-21 14:09:14 +00:00
|
|
|
* "rilMessageType", should ignore it.
|
2013-08-09 04:27:19 +00:00
|
|
|
*/
|
2014-01-13 02:44:40 +00:00
|
|
|
isInfoChanged: function(srcInfo, destInfo) {
|
2013-08-09 04:27:19 +00:00
|
|
|
if (!destInfo) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let key in srcInfo) {
|
2013-11-21 14:09:14 +00:00
|
|
|
if (key === "rilMessageType") {
|
2013-08-09 04:27:19 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (srcInfo[key] !== destInfo[key]) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2012-04-19 21:33:25 +00:00
|
|
|
/**
|
|
|
|
* Process a message from the content process.
|
|
|
|
*/
|
2014-01-13 02:44:40 +00:00
|
|
|
receiveMessage: function(msg) {
|
2012-04-19 21:33:25 +00:00
|
|
|
switch (msg.name) {
|
2012-06-13 02:46:41 +00:00
|
|
|
case "RIL:GetRilContext":
|
2012-04-19 21:33:25 +00:00
|
|
|
// This message is sync.
|
2012-06-13 02:46:41 +00:00
|
|
|
return this.rilContext;
|
2013-04-11 07:12:09 +00:00
|
|
|
case "RIL:GetCardLockState":
|
2013-08-13 12:14:13 +00:00
|
|
|
this.workerMessenger.sendWithIPCMessage(msg, "iccGetCardLockState",
|
2014-10-28 11:48:12 +00:00
|
|
|
"RIL:GetCardLockResult");
|
2012-04-12 04:01:49 +00:00
|
|
|
break;
|
|
|
|
case "RIL:UnlockCardLock":
|
2013-08-13 12:14:13 +00:00
|
|
|
this.workerMessenger.sendWithIPCMessage(msg, "iccUnlockCardLock",
|
2014-10-28 11:48:12 +00:00
|
|
|
"RIL:SetUnlockCardLockResult");
|
2012-04-12 04:01:49 +00:00
|
|
|
break;
|
|
|
|
case "RIL:SetCardLock":
|
2013-08-13 12:14:13 +00:00
|
|
|
this.workerMessenger.sendWithIPCMessage(msg, "iccSetCardLock",
|
2014-10-28 11:48:12 +00:00
|
|
|
"RIL:SetUnlockCardLockResult");
|
2012-04-12 04:01:49 +00:00
|
|
|
break;
|
Bug 875710: Added getCardLockRetryCount to nsIIccProvider, r=vyang, sr=mounir
This patch adds getCardLockRetryCount to nsIIccProvider and its
implementations. This method allows callers to query the number
of remaining tries for unlocking a SIM-card lock. Supported locks
are 'pin', 'puk', 'pin2', 'puk2', 'nck', 'cck', and 'spck'. The
call returns a DOM request that returns the retry count in its
success handler, or signals an appropriate error.
Reading the retry count is an optional feature and may not be
supported for all lock types. In this case the DOM request receives
and error with the name GECKO_ERROR_NOT_SUPPORTED. For an invalid
lock type, the error name is GECKO_ERROR_GENERIC_FAILURE.
getCardLockRetryCount replaces retryCount in nsIDOMMobileConnection,
which is now deprecated.
--HG--
extra : rebase_source : d1d11612f836652dca85f7c701f09e7af962e3b7
2013-07-09 14:06:05 +00:00
|
|
|
case "RIL:GetCardLockRetryCount":
|
2013-08-13 12:14:13 +00:00
|
|
|
this.workerMessenger.sendWithIPCMessage(msg, "iccGetCardLockRetryCount",
|
|
|
|
"RIL:CardLockRetryCount");
|
Bug 875710: Added getCardLockRetryCount to nsIIccProvider, r=vyang, sr=mounir
This patch adds getCardLockRetryCount to nsIIccProvider and its
implementations. This method allows callers to query the number
of remaining tries for unlocking a SIM-card lock. Supported locks
are 'pin', 'puk', 'pin2', 'puk2', 'nck', 'cck', and 'spck'. The
call returns a DOM request that returns the retry count in its
success handler, or signals an appropriate error.
Reading the retry count is an optional feature and may not be
supported for all lock types. In this case the DOM request receives
and error with the name GECKO_ERROR_NOT_SUPPORTED. For an invalid
lock type, the error name is GECKO_ERROR_GENERIC_FAILURE.
getCardLockRetryCount replaces retryCount in nsIDOMMobileConnection,
which is now deprecated.
--HG--
extra : rebase_source : d1d11612f836652dca85f7c701f09e7af962e3b7
2013-07-09 14:06:05 +00:00
|
|
|
break;
|
2012-04-10 12:04:27 +00:00
|
|
|
case "RIL:SendStkResponse":
|
2013-08-13 12:14:13 +00:00
|
|
|
this.workerMessenger.send("sendStkTerminalResponse", msg.json.data);
|
2012-04-10 12:04:27 +00:00
|
|
|
break;
|
|
|
|
case "RIL:SendStkMenuSelection":
|
2013-08-13 12:14:13 +00:00
|
|
|
this.workerMessenger.send("sendStkMenuSelection", msg.json.data);
|
2012-04-10 12:04:27 +00:00
|
|
|
break;
|
2012-11-28 08:16:20 +00:00
|
|
|
case "RIL:SendStkTimerExpiration":
|
2013-08-13 12:14:13 +00:00
|
|
|
this.workerMessenger.send("sendStkTimerExpiration", msg.json.data);
|
2012-11-28 08:16:20 +00:00
|
|
|
break;
|
2012-09-11 02:34:36 +00:00
|
|
|
case "RIL:SendStkEventDownload":
|
2013-08-13 12:14:13 +00:00
|
|
|
this.workerMessenger.send("sendStkEventDownload", msg.json.data);
|
2012-09-11 02:34:36 +00:00
|
|
|
break;
|
2013-02-25 09:27:26 +00:00
|
|
|
case "RIL:IccOpenChannel":
|
2013-08-13 12:14:13 +00:00
|
|
|
this.workerMessenger.sendWithIPCMessage(msg, "iccOpenChannel");
|
2013-02-25 09:27:26 +00:00
|
|
|
break;
|
|
|
|
case "RIL:IccCloseChannel":
|
2013-08-13 12:14:13 +00:00
|
|
|
this.workerMessenger.sendWithIPCMessage(msg, "iccCloseChannel");
|
2013-02-25 09:27:26 +00:00
|
|
|
break;
|
|
|
|
case "RIL:IccExchangeAPDU":
|
2013-08-13 12:14:13 +00:00
|
|
|
this.workerMessenger.sendWithIPCMessage(msg, "iccExchangeAPDU");
|
2013-02-25 09:27:26 +00:00
|
|
|
break;
|
2013-03-06 02:51:40 +00:00
|
|
|
case "RIL:ReadIccContacts":
|
2013-08-13 12:14:13 +00:00
|
|
|
this.workerMessenger.sendWithIPCMessage(msg, "readICCContacts");
|
2013-03-06 02:51:40 +00:00
|
|
|
break;
|
2013-03-25 03:09:01 +00:00
|
|
|
case "RIL:UpdateIccContact":
|
2013-08-13 12:14:13 +00:00
|
|
|
this.workerMessenger.sendWithIPCMessage(msg, "updateICCContact");
|
2012-10-09 10:07:11 +00:00
|
|
|
break;
|
2014-01-27 18:22:00 +00:00
|
|
|
case "RIL:MatchMvno":
|
|
|
|
this.matchMvno(msg.target, msg.json.data);
|
|
|
|
break;
|
2012-04-19 21:33:25 +00:00
|
|
|
}
|
2013-09-13 22:12:30 +00:00
|
|
|
return null;
|
2012-04-19 21:33:25 +00:00
|
|
|
},
|
|
|
|
|
2014-01-13 02:44:40 +00:00
|
|
|
handleUnsolicitedWorkerMessage: function(message) {
|
2013-12-03 06:18:32 +00:00
|
|
|
let connHandler = gDataConnectionManager.getConnectionHandler(this.clientId);
|
2012-08-06 21:28:03 +00:00
|
|
|
switch (message.rilMessageType) {
|
2014-10-16 21:40:00 +00:00
|
|
|
case "audioStateChanged":
|
|
|
|
gTelephonyService.notifyAudioStateChanged(this.clientId, message.state);
|
|
|
|
break;
|
2012-11-28 01:28:43 +00:00
|
|
|
case "callRing":
|
2014-06-03 14:15:25 +00:00
|
|
|
gTelephonyService.notifyCallRing();
|
2012-11-28 01:28:43 +00:00
|
|
|
break;
|
2012-01-09 22:28:47 +00:00
|
|
|
case "callStateChange":
|
2014-06-03 14:15:25 +00:00
|
|
|
gTelephonyService.notifyCallStateChanged(this.clientId, message.call);
|
2012-01-09 22:28:47 +00:00
|
|
|
break;
|
|
|
|
case "callDisconnected":
|
2014-06-03 14:15:25 +00:00
|
|
|
gTelephonyService.notifyCallDisconnected(this.clientId, message.call);
|
2012-01-09 22:28:47 +00:00
|
|
|
break;
|
2013-07-06 10:40:58 +00:00
|
|
|
case "conferenceCallStateChanged":
|
2014-06-03 14:15:25 +00:00
|
|
|
gTelephonyService.notifyConferenceCallStateChanged(message.state);
|
2013-07-06 10:40:58 +00:00
|
|
|
break;
|
2013-07-30 09:24:43 +00:00
|
|
|
case "cdmaCallWaiting":
|
2014-10-15 06:51:00 +00:00
|
|
|
gTelephonyService.notifyCdmaCallWaiting(this.clientId,
|
|
|
|
message.waitingCall);
|
2013-07-30 09:24:43 +00:00
|
|
|
break;
|
2013-08-05 20:28:31 +00:00
|
|
|
case "suppSvcNotification":
|
2014-06-03 14:15:25 +00:00
|
|
|
gTelephonyService.notifySupplementaryService(this.clientId,
|
2014-02-10 11:55:22 +00:00
|
|
|
message.callIndex,
|
|
|
|
message.notification);
|
2013-08-05 20:28:31 +00:00
|
|
|
break;
|
2014-10-15 06:51:00 +00:00
|
|
|
case "ussdreceived":
|
|
|
|
gTelephonyService.notifyUssdReceived(this.clientId, message.message,
|
|
|
|
message.sessionEnded);
|
|
|
|
break;
|
2013-12-03 06:18:32 +00:00
|
|
|
case "datacallerror":
|
|
|
|
connHandler.handleDataCallError(message);
|
|
|
|
break;
|
|
|
|
case "datacallstatechange":
|
2014-03-29 07:18:16 +00:00
|
|
|
let addresses = [];
|
|
|
|
for (let i = 0; i < message.addresses.length; i++) {
|
|
|
|
let [address, prefixLength] = message.addresses[i].split("/");
|
|
|
|
// From AOSP hardware/ril/include/telephony/ril.h, that address prefix
|
|
|
|
// is said to be OPTIONAL, but we never met such case before.
|
|
|
|
addresses.push({
|
|
|
|
address: address,
|
|
|
|
prefixLength: prefixLength ? parseInt(prefixLength, 10) : 0
|
|
|
|
});
|
2013-12-03 06:18:32 +00:00
|
|
|
}
|
2014-03-29 07:18:16 +00:00
|
|
|
message.addresses = addresses;
|
2013-12-03 06:18:32 +00:00
|
|
|
connHandler.handleDataCallState(message);
|
|
|
|
break;
|
2013-08-14 12:50:36 +00:00
|
|
|
case "emergencyCbModeChange":
|
2014-02-10 11:55:22 +00:00
|
|
|
gMobileConnectionService.notifyEmergencyCallbackModeChanged(this.clientId,
|
|
|
|
message);
|
2013-08-14 12:50:36 +00:00
|
|
|
break;
|
2012-06-19 22:52:06 +00:00
|
|
|
case "networkinfochanged":
|
2014-02-10 11:55:22 +00:00
|
|
|
gMobileConnectionService.notifyNetworkInfoChanged(this.clientId,
|
|
|
|
message);
|
|
|
|
connHandler.updateRILNetworkInterface();
|
2012-06-19 22:52:06 +00:00
|
|
|
break;
|
|
|
|
case "networkselectionmodechange":
|
2014-02-10 11:55:22 +00:00
|
|
|
gMobileConnectionService.notifyNetworkSelectModeChanged(this.clientId,
|
|
|
|
message.mode);
|
2012-06-19 22:52:06 +00:00
|
|
|
break;
|
2012-03-19 22:49:27 +00:00
|
|
|
case "voiceregistrationstatechange":
|
2014-02-10 11:55:22 +00:00
|
|
|
gMobileConnectionService.notifyVoiceInfoChanged(this.clientId, message);
|
2012-02-10 19:27:23 +00:00
|
|
|
break;
|
2012-03-19 22:49:27 +00:00
|
|
|
case "dataregistrationstatechange":
|
2014-02-10 11:55:22 +00:00
|
|
|
gMobileConnectionService.notifyDataInfoChanged(this.clientId, message);
|
|
|
|
connHandler.updateRILNetworkInterface();
|
2012-02-10 19:27:23 +00:00
|
|
|
break;
|
2011-12-05 07:58:27 +00:00
|
|
|
case "signalstrengthchange":
|
2014-02-10 11:55:22 +00:00
|
|
|
gMobileConnectionService.notifySignalStrengthChanged(this.clientId,
|
|
|
|
message);
|
2011-12-05 07:58:27 +00:00
|
|
|
break;
|
|
|
|
case "operatorchange":
|
2014-02-10 11:55:22 +00:00
|
|
|
gMobileConnectionService.notifyOperatorChanged(this.clientId, message);
|
2011-12-05 07:58:27 +00:00
|
|
|
break;
|
2013-08-27 12:25:54 +00:00
|
|
|
case "otastatuschange":
|
2014-02-10 11:55:22 +00:00
|
|
|
gMobileConnectionService.notifyOtaStatusChanged(this.clientId, message.status);
|
2013-08-27 12:25:54 +00:00
|
|
|
break;
|
2011-12-07 06:57:19 +00:00
|
|
|
case "radiostatechange":
|
2014-02-10 11:55:22 +00:00
|
|
|
// gRadioEnabledController should know the radio state for each client,
|
|
|
|
// so notify gRadioEnabledController here.
|
|
|
|
gRadioEnabledController.notifyRadioStateChanged(this.clientId,
|
|
|
|
message.radioState);
|
|
|
|
break;
|
2011-12-05 07:58:27 +00:00
|
|
|
case "cardstatechange":
|
2012-06-13 02:46:41 +00:00
|
|
|
this.rilContext.cardState = message.cardState;
|
2014-02-14 09:42:32 +00:00
|
|
|
gRadioEnabledController.receiveCardState(this.clientId);
|
2013-05-22 09:32:18 +00:00
|
|
|
gMessageManager.sendIccMessage("RIL:CardStateChanged",
|
|
|
|
this.clientId, message);
|
2011-12-05 07:58:27 +00:00
|
|
|
break;
|
2011-12-24 05:02:52 +00:00
|
|
|
case "sms-received":
|
2014-03-12 16:27:00 +00:00
|
|
|
this.handleSmsMultipart(message);
|
|
|
|
break;
|
2012-12-04 02:40:47 +00:00
|
|
|
case "cellbroadcast-received":
|
2014-08-13 10:28:34 +00:00
|
|
|
this.handleCellbroadcastMessageReceived(message);
|
2012-12-04 02:40:47 +00:00
|
|
|
break;
|
2012-03-09 04:16:06 +00:00
|
|
|
case "nitzTime":
|
2012-09-28 06:02:57 +00:00
|
|
|
this.handleNitzTime(message);
|
2012-03-09 04:16:06 +00:00
|
|
|
break;
|
2012-04-18 10:07:29 +00:00
|
|
|
case "iccinfochange":
|
2013-03-25 03:09:01 +00:00
|
|
|
this.handleIccInfoChange(message);
|
2012-03-17 14:23:17 +00:00
|
|
|
break;
|
2013-01-11 09:20:12 +00:00
|
|
|
case "iccimsi":
|
|
|
|
this.rilContext.imsi = message.imsi;
|
|
|
|
break;
|
2012-07-21 00:19:38 +00:00
|
|
|
case "iccmbdn":
|
2013-03-25 03:09:01 +00:00
|
|
|
this.handleIccMbdn(message);
|
2012-07-21 00:19:38 +00:00
|
|
|
break;
|
2013-12-06 09:35:13 +00:00
|
|
|
case "iccmwis":
|
2014-09-26 05:00:25 +00:00
|
|
|
this.handleIccMwis(message.mwi);
|
2013-12-06 09:35:13 +00:00
|
|
|
break;
|
2012-04-10 12:04:27 +00:00
|
|
|
case "stkcommand":
|
|
|
|
this.handleStkProactiveCommand(message);
|
|
|
|
break;
|
|
|
|
case "stksessionend":
|
2013-07-02 09:36:40 +00:00
|
|
|
gMessageManager.sendIccMessage("RIL:StkSessionEnd", this.clientId, null);
|
2012-04-10 12:04:27 +00:00
|
|
|
break;
|
2013-09-10 16:48:19 +00:00
|
|
|
case "cdma-info-rec-received":
|
2014-10-03 06:23:41 +00:00
|
|
|
this.handleCdmaInformationRecords(message.records);
|
2013-09-10 16:48:19 +00:00
|
|
|
break;
|
2012-01-09 22:28:47 +00:00
|
|
|
default:
|
2012-08-06 21:28:03 +00:00
|
|
|
throw new Error("Don't know about this message type: " +
|
|
|
|
message.rilMessageType);
|
2011-12-05 07:58:27 +00:00
|
|
|
}
|
2012-01-09 22:28:47 +00:00
|
|
|
},
|
|
|
|
|
2013-10-15 02:42:49 +00:00
|
|
|
/**
|
|
|
|
* Get phone number from iccInfo.
|
|
|
|
*
|
|
|
|
* If the icc card is gsm card, the phone number is in msisdn.
|
2014-09-19 07:53:05 +00:00
|
|
|
* @see nsIGsmIccInfo
|
2013-10-15 02:42:49 +00:00
|
|
|
*
|
|
|
|
* Otherwise, the phone number is in mdn.
|
2014-09-19 07:53:05 +00:00
|
|
|
* @see nsICdmaIccInfo
|
2013-10-15 02:42:49 +00:00
|
|
|
*/
|
2014-01-13 02:44:40 +00:00
|
|
|
getPhoneNumber: function() {
|
2013-09-07 11:09:54 +00:00
|
|
|
let iccInfo = this.rilContext.iccInfo;
|
2013-10-15 02:42:49 +00:00
|
|
|
|
|
|
|
if (!iccInfo) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// After moving SMS code out of RadioInterfaceLayer, we could use
|
2014-09-19 07:53:05 +00:00
|
|
|
// |iccInfo instanceof Ci.nsIGsmIccInfo| here.
|
2013-10-15 02:42:49 +00:00
|
|
|
// TODO: Bug 873351 - B2G SMS: move SMS code out of RadioInterfaceLayer to
|
|
|
|
// SmsService
|
|
|
|
let number = (iccInfo instanceof GsmIccInfo) ? iccInfo.msisdn : iccInfo.mdn;
|
2013-09-07 11:09:54 +00:00
|
|
|
|
|
|
|
// Workaround an xpconnect issue with undefined string objects.
|
|
|
|
// See bug 808220
|
|
|
|
if (number === undefined || number === "undefined") {
|
|
|
|
return null;
|
|
|
|
}
|
2013-11-02 10:17:25 +00:00
|
|
|
|
2013-09-07 11:09:54 +00:00
|
|
|
return number;
|
|
|
|
},
|
|
|
|
|
2013-11-02 10:17:25 +00:00
|
|
|
/**
|
|
|
|
* A utility function to get the ICC ID of the SIM card (if installed).
|
|
|
|
*/
|
2014-01-13 02:44:40 +00:00
|
|
|
getIccId: function() {
|
2013-11-02 10:17:25 +00:00
|
|
|
let iccInfo = this.rilContext.iccInfo;
|
|
|
|
|
2014-03-05 03:10:46 +00:00
|
|
|
if (!iccInfo) {
|
2013-11-02 10:17:25 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
let iccId = iccInfo.iccid;
|
|
|
|
|
|
|
|
// Workaround an xpconnect issue with undefined string objects.
|
|
|
|
// See bug 808220
|
|
|
|
if (iccId === undefined || iccId === "undefined") {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return iccId;
|
|
|
|
},
|
|
|
|
|
2014-01-27 18:22:00 +00:00
|
|
|
// Matches the mvnoData pattern with imsi. Characters 'x' and 'X' are skipped
|
|
|
|
// and not compared. E.g., if the mvnoData passed is '310260x10xxxxxx',
|
|
|
|
// then the function returns true only if imsi has the same first 6 digits,
|
|
|
|
// 8th and 9th digit.
|
|
|
|
isImsiMatches: function(mvnoData) {
|
|
|
|
let imsi = this.rilContext.imsi;
|
|
|
|
|
|
|
|
// This should not be an error, but a mismatch.
|
|
|
|
if (mvnoData.length > imsi.length) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let i = 0; i < mvnoData.length; i++) {
|
|
|
|
let c = mvnoData[i];
|
|
|
|
if ((c !== 'x') && (c !== 'X') && (c !== imsi[i])) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
matchMvno: function(target, message) {
|
|
|
|
if (DEBUG) this.debug("matchMvno: " + JSON.stringify(message));
|
|
|
|
|
|
|
|
if (!message || !message.mvnoType || !message.mvnoData) {
|
|
|
|
message.errorMsg = RIL.GECKO_ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!message.errorMsg) {
|
2014-07-01 00:09:00 +00:00
|
|
|
switch (message.mvnoType) {
|
|
|
|
case "imsi":
|
|
|
|
if (!this.rilContext.imsi) {
|
|
|
|
message.errorMsg = RIL.GECKO_ERROR_GENERIC_FAILURE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
message.result = this.isImsiMatches(message.mvnoData);
|
|
|
|
break;
|
|
|
|
case "spn":
|
|
|
|
let spn = this.rilContext.iccInfo && this.rilContext.iccInfo.spn;
|
|
|
|
if (!spn) {
|
|
|
|
message.errorMsg = RIL.GECKO_ERROR_GENERIC_FAILURE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
message.result = spn == message.mvnoData;
|
|
|
|
break;
|
2014-07-18 03:41:37 +00:00
|
|
|
case "gid":
|
|
|
|
this.workerMessenger.send("getGID1", null, (function(response) {
|
|
|
|
let gid = response.gid1;
|
|
|
|
let mvnoDataLength = message.mvnoData.length;
|
|
|
|
|
|
|
|
if (!gid) {
|
|
|
|
message.errorMsg = RIL.GECKO_ERROR_GENERIC_FAILURE;
|
|
|
|
} else if (mvnoDataLength > gid.length) {
|
|
|
|
message.result = false;
|
|
|
|
} else {
|
|
|
|
message.result =
|
|
|
|
gid.substring(0, mvnoDataLength).toLowerCase() ==
|
|
|
|
message.mvnoData.toLowerCase();
|
|
|
|
}
|
|
|
|
|
|
|
|
target.sendAsyncMessage("RIL:MatchMvno", {
|
|
|
|
clientId: this.clientId,
|
|
|
|
data: message
|
|
|
|
});
|
|
|
|
}).bind(this));
|
|
|
|
return;
|
2014-07-01 00:09:00 +00:00
|
|
|
default:
|
|
|
|
message.errorMsg = RIL.GECKO_ERROR_MODE_NOT_SUPPORTED;
|
|
|
|
}
|
2014-01-27 18:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
target.sendAsyncMessage("RIL:MatchMvno", {
|
|
|
|
clientId: this.clientId,
|
|
|
|
data: message
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-12-03 06:18:32 +00:00
|
|
|
setDataRegistration: function(attach) {
|
2014-08-07 10:38:21 +00:00
|
|
|
let deferred = Promise.defer();
|
|
|
|
this.workerMessenger.send("setDataRegistration",
|
|
|
|
{attach: attach},
|
|
|
|
(function(response) {
|
|
|
|
// Always resolve to proceed with the following steps.
|
|
|
|
deferred.resolve(response.errorMsg ? response.errorMsg : null);
|
|
|
|
}).bind(this));
|
|
|
|
|
|
|
|
return deferred.promise;
|
2013-12-03 06:18:32 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TODO: Bug 911713 - B2G NetworkManager: Move policy control logic to
|
|
|
|
* NetworkManager
|
|
|
|
*/
|
|
|
|
updateRILNetworkInterface: function() {
|
|
|
|
let connHandler = gDataConnectionManager.getConnectionHandler(this.clientId);
|
|
|
|
connHandler.updateRILNetworkInterface();
|
2012-08-01 14:54:04 +00:00
|
|
|
},
|
|
|
|
|
2013-09-07 11:09:54 +00:00
|
|
|
/**
|
|
|
|
* Handle WDP port push PDU. Constructor WDP bearer information and deliver
|
|
|
|
* to WapPushManager.
|
|
|
|
*
|
|
|
|
* @param message
|
|
|
|
* A SMS message.
|
|
|
|
*/
|
2014-01-13 02:44:40 +00:00
|
|
|
handleSmsWdpPortPush: function(message) {
|
2013-09-07 11:09:54 +00:00
|
|
|
if (message.encoding != RIL.PDU_DCS_MSG_CODING_8BITS_ALPHABET) {
|
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("Got port addressed SMS but not encoded in 8-bit alphabet." +
|
|
|
|
" Drop!");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let options = {
|
|
|
|
bearer: WAP.WDP_BEARER_GSM_SMS_GSM_MSISDN,
|
|
|
|
sourceAddress: message.sender,
|
2014-03-12 16:27:00 +00:00
|
|
|
sourcePort: message.originatorPort,
|
2013-09-07 11:09:54 +00:00
|
|
|
destinationAddress: this.rilContext.iccInfo.msisdn,
|
2014-03-12 16:27:00 +00:00
|
|
|
destinationPort: message.destinationPort,
|
2013-11-02 10:17:35 +00:00
|
|
|
serviceId: this.clientId
|
2013-09-07 11:09:54 +00:00
|
|
|
};
|
|
|
|
WAP.WapPushManager.receiveWdpPDU(message.fullData, message.fullData.length,
|
|
|
|
0, options);
|
|
|
|
},
|
|
|
|
|
2014-10-24 03:33:01 +00:00
|
|
|
_convertSmsMessageClass: function(aMessageClass) {
|
|
|
|
let index = RIL.GECKO_SMS_MESSAGE_CLASSES.indexOf(aMessageClass);
|
|
|
|
|
|
|
|
if (index < 0) {
|
|
|
|
throw new Error("Invalid MessageClass: " + aMessageClass);
|
|
|
|
}
|
|
|
|
|
|
|
|
return index;
|
|
|
|
},
|
|
|
|
|
|
|
|
_convertSmsDelivery: function(aDelivery) {
|
|
|
|
let index = [DOM_MOBILE_MESSAGE_DELIVERY_RECEIVED,
|
|
|
|
DOM_MOBILE_MESSAGE_DELIVERY_SENDING,
|
|
|
|
DOM_MOBILE_MESSAGE_DELIVERY_SENT,
|
|
|
|
DOM_MOBILE_MESSAGE_DELIVERY_ERROR].indexOf(aDelivery);
|
|
|
|
|
|
|
|
if (index < 0) {
|
|
|
|
throw new Error("Invalid Delivery: " + aDelivery);
|
|
|
|
}
|
|
|
|
|
|
|
|
return index;
|
|
|
|
},
|
|
|
|
|
|
|
|
_convertSmsDeliveryStatus: function(aDeliveryStatus) {
|
|
|
|
let index = [RIL.GECKO_SMS_DELIVERY_STATUS_NOT_APPLICABLE,
|
|
|
|
RIL.GECKO_SMS_DELIVERY_STATUS_SUCCESS,
|
|
|
|
RIL.GECKO_SMS_DELIVERY_STATUS_PENDING,
|
|
|
|
RIL.GECKO_SMS_DELIVERY_STATUS_ERROR].indexOf(aDeliveryStatus);
|
|
|
|
|
|
|
|
if (index < 0) {
|
|
|
|
throw new Error("Invalid DeliveryStatus: " + aDeliveryStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
return index;
|
|
|
|
},
|
|
|
|
|
2013-09-07 11:09:54 +00:00
|
|
|
/**
|
|
|
|
* A helper to broadcast the system message to launch registered apps
|
|
|
|
* like Costcontrol, Notification and Message app... etc.
|
|
|
|
*
|
|
|
|
* @param aName
|
|
|
|
* The system message name.
|
|
|
|
* @param aDomMessage
|
|
|
|
* The nsIDOMMozSmsMessage object.
|
|
|
|
*/
|
2014-10-24 03:33:01 +00:00
|
|
|
broadcastSmsSystemMessage: function(aNotificationType, aDomMessage) {
|
|
|
|
if (DEBUG) this.debug("Broadcasting the SMS system message: " + aNotificationType);
|
2013-09-07 11:09:54 +00:00
|
|
|
|
|
|
|
// Sadly we cannot directly broadcast the aDomMessage object
|
|
|
|
// because the system message mechamism will rewrap the object
|
|
|
|
// based on the content window, which needs to know the properties.
|
2014-10-24 03:33:01 +00:00
|
|
|
try {
|
|
|
|
gSmsMessenger.notifySms(aNotificationType,
|
|
|
|
aDomMessage.id,
|
|
|
|
aDomMessage.threadId,
|
|
|
|
aDomMessage.iccId,
|
|
|
|
this._convertSmsDelivery(
|
|
|
|
aDomMessage.delivery),
|
|
|
|
this._convertSmsDeliveryStatus(
|
|
|
|
aDomMessage.deliveryStatus),
|
|
|
|
aDomMessage.sender,
|
|
|
|
aDomMessage.receiver,
|
|
|
|
aDomMessage.body,
|
|
|
|
this._convertSmsMessageClass(
|
|
|
|
aDomMessage.messageClass),
|
|
|
|
aDomMessage.timestamp,
|
|
|
|
aDomMessage.sentTimestamp,
|
|
|
|
aDomMessage.deliveryTimestamp,
|
|
|
|
aDomMessage.read);
|
|
|
|
} catch (e) {
|
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("Failed to broadcastSmsSystemMessage: " + e);
|
|
|
|
}
|
|
|
|
}
|
2013-09-07 11:09:54 +00:00
|
|
|
},
|
|
|
|
|
2013-10-28 06:07:28 +00:00
|
|
|
// The following attributes/functions are used for acquiring/releasing the
|
|
|
|
// CPU wake lock when the RIL handles the received SMS. Note that we need
|
|
|
|
// a timer to bound the lock's life cycle to avoid exhausting the battery.
|
2013-09-10 13:51:47 +00:00
|
|
|
_smsHandledWakeLock: null,
|
|
|
|
_smsHandledWakeLockTimer: null,
|
2013-10-28 06:07:28 +00:00
|
|
|
|
2014-03-12 16:27:00 +00:00
|
|
|
_acquireSmsHandledWakeLock: function() {
|
2013-09-10 13:51:47 +00:00
|
|
|
if (!this._smsHandledWakeLock) {
|
|
|
|
if (DEBUG) this.debug("Acquiring a CPU wake lock for handling SMS.");
|
|
|
|
this._smsHandledWakeLock = gPowerManagerService.newWakeLock("cpu");
|
|
|
|
}
|
|
|
|
if (!this._smsHandledWakeLockTimer) {
|
|
|
|
if (DEBUG) this.debug("Creating a timer for releasing the CPU wake lock.");
|
|
|
|
this._smsHandledWakeLockTimer =
|
|
|
|
Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
|
|
|
}
|
|
|
|
if (DEBUG) this.debug("Setting the timer for releasing the CPU wake lock.");
|
|
|
|
this._smsHandledWakeLockTimer
|
2013-10-28 06:07:28 +00:00
|
|
|
.initWithCallback(this._releaseSmsHandledWakeLock.bind(this),
|
2013-09-10 13:51:47 +00:00
|
|
|
SMS_HANDLED_WAKELOCK_TIMEOUT,
|
|
|
|
Ci.nsITimer.TYPE_ONE_SHOT);
|
2014-03-12 16:27:00 +00:00
|
|
|
},
|
2013-09-10 13:51:47 +00:00
|
|
|
|
2014-03-12 16:27:00 +00:00
|
|
|
_releaseSmsHandledWakeLock: function() {
|
|
|
|
if (DEBUG) this.debug("Releasing the CPU wake lock for handling SMS.");
|
|
|
|
if (this._smsHandledWakeLockTimer) {
|
|
|
|
this._smsHandledWakeLockTimer.cancel();
|
|
|
|
}
|
|
|
|
if (this._smsHandledWakeLock) {
|
|
|
|
this._smsHandledWakeLock.unlock();
|
|
|
|
this._smsHandledWakeLock = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hash map for received multipart sms fragments. Messages are hashed with
|
|
|
|
* its sender address and concatenation reference number. Three additional
|
|
|
|
* attributes `segmentMaxSeq`, `receivedSegments`, `segments` are inserted.
|
|
|
|
*/
|
|
|
|
_receivedSmsSegmentsMap: null,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper for processing received multipart SMS.
|
|
|
|
*
|
|
|
|
* @return null for handled segments, and an object containing full message
|
|
|
|
* body/data once all segments are received.
|
|
|
|
*/
|
|
|
|
_processReceivedSmsSegment: function(aSegment) {
|
|
|
|
|
|
|
|
// Directly replace full message body for single SMS.
|
|
|
|
if (!(aSegment.segmentMaxSeq && (aSegment.segmentMaxSeq > 1))) {
|
|
|
|
if (aSegment.encoding == RIL.PDU_DCS_MSG_CODING_8BITS_ALPHABET) {
|
|
|
|
aSegment.fullData = aSegment.data;
|
|
|
|
} else {
|
|
|
|
aSegment.fullBody = aSegment.body;
|
|
|
|
}
|
|
|
|
return aSegment;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle Concatenation for Class 0 SMS
|
|
|
|
let hash = aSegment.sender + ":" +
|
|
|
|
aSegment.segmentRef + ":" +
|
|
|
|
aSegment.segmentMaxSeq;
|
|
|
|
let seq = aSegment.segmentSeq;
|
|
|
|
|
|
|
|
let options = this._receivedSmsSegmentsMap[hash];
|
|
|
|
if (!options) {
|
|
|
|
options = aSegment;
|
|
|
|
this._receivedSmsSegmentsMap[hash] = options;
|
|
|
|
|
|
|
|
options.receivedSegments = 0;
|
|
|
|
options.segments = [];
|
|
|
|
} else if (options.segments[seq]) {
|
|
|
|
// Duplicated segment?
|
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("Got duplicated segment no." + seq +
|
|
|
|
" of a multipart SMS: " + JSON.stringify(aSegment));
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.receivedSegments > 0) {
|
|
|
|
// Update received timestamp.
|
|
|
|
options.timestamp = aSegment.timestamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.encoding == RIL.PDU_DCS_MSG_CODING_8BITS_ALPHABET) {
|
|
|
|
options.segments[seq] = aSegment.data;
|
|
|
|
} else {
|
|
|
|
options.segments[seq] = aSegment.body;
|
|
|
|
}
|
|
|
|
options.receivedSegments++;
|
|
|
|
|
|
|
|
// The port information is only available in 1st segment for CDMA WAP Push.
|
|
|
|
// If the segments of a WAP Push are not received in sequence
|
|
|
|
// (e.g., SMS with seq == 1 is not the 1st segment received by the device),
|
|
|
|
// we have to retrieve the port information from 1st segment and
|
|
|
|
// save it into the cached options.
|
|
|
|
if (aSegment.teleservice === RIL.PDU_CDMA_MSG_TELESERIVCIE_ID_WAP
|
|
|
|
&& seq === 1) {
|
|
|
|
if (!options.originatorPort && aSegment.originatorPort) {
|
|
|
|
options.originatorPort = aSegment.originatorPort;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!options.destinationPort && aSegment.destinationPort) {
|
|
|
|
options.destinationPort = aSegment.destinationPort;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.receivedSegments < options.segmentMaxSeq) {
|
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("Got segment no." + seq + " of a multipart SMS: " +
|
|
|
|
JSON.stringify(options));
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove from map
|
|
|
|
delete this._receivedSmsSegmentsMap[hash];
|
|
|
|
|
|
|
|
// Rebuild full body
|
|
|
|
if (options.encoding == RIL.PDU_DCS_MSG_CODING_8BITS_ALPHABET) {
|
|
|
|
// Uint8Array doesn't have `concat`, so we have to merge all segements
|
|
|
|
// by hand.
|
|
|
|
let fullDataLen = 0;
|
|
|
|
for (let i = 1; i <= options.segmentMaxSeq; i++) {
|
|
|
|
fullDataLen += options.segments[i].length;
|
|
|
|
}
|
|
|
|
|
|
|
|
options.fullData = new Uint8Array(fullDataLen);
|
|
|
|
for (let d= 0, i = 1; i <= options.segmentMaxSeq; i++) {
|
|
|
|
let data = options.segments[i];
|
|
|
|
for (let j = 0; j < data.length; j++) {
|
|
|
|
options.fullData[d++] = data[j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
options.fullBody = options.segments.join("");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove handy fields after completing the concatenation.
|
|
|
|
delete options.receivedSegments;
|
|
|
|
delete options.segments;
|
|
|
|
|
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("Got full multipart SMS: " + JSON.stringify(options));
|
|
|
|
}
|
|
|
|
|
|
|
|
return options;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper to create Savable SmsSegment.
|
|
|
|
*/
|
|
|
|
_createSavableSmsSegment: function(aMessage) {
|
|
|
|
// We precisely define what data fields to be stored into
|
|
|
|
// DB here for better data migration.
|
|
|
|
let segment = {};
|
|
|
|
segment.messageType = aMessage.messageType;
|
|
|
|
segment.teleservice = aMessage.teleservice;
|
|
|
|
segment.SMSC = aMessage.SMSC;
|
|
|
|
segment.sentTimestamp = aMessage.sentTimestamp;
|
|
|
|
segment.timestamp = Date.now();
|
|
|
|
segment.sender = aMessage.sender;
|
|
|
|
segment.pid = aMessage.pid;
|
|
|
|
segment.encoding = aMessage.encoding;
|
|
|
|
segment.messageClass = aMessage.messageClass;
|
|
|
|
segment.iccId = this.getIccId();
|
|
|
|
if (aMessage.header) {
|
|
|
|
segment.segmentRef = aMessage.header.segmentRef;
|
|
|
|
segment.segmentSeq = aMessage.header.segmentSeq;
|
|
|
|
segment.segmentMaxSeq = aMessage.header.segmentMaxSeq;
|
|
|
|
segment.originatorPort = aMessage.header.originatorPort;
|
|
|
|
segment.destinationPort = aMessage.header.destinationPort;
|
|
|
|
}
|
|
|
|
segment.mwiPresent = (aMessage.mwi)? true: false;
|
|
|
|
segment.mwiDiscard = (segment.mwiPresent)? aMessage.mwi.discard: false;
|
|
|
|
segment.mwiMsgCount = (segment.mwiPresent)? aMessage.mwi.msgCount: 0;
|
|
|
|
segment.mwiActive = (segment.mwiPresent)? aMessage.mwi.active: false;
|
|
|
|
segment.serviceCategory = aMessage.serviceCategory;
|
|
|
|
segment.language = aMessage.language;
|
|
|
|
segment.data = aMessage.data;
|
|
|
|
segment.body = aMessage.body;
|
|
|
|
|
|
|
|
return segment;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper to purge complete message.
|
|
|
|
*
|
|
|
|
* We remove unnessary fields defined in _createSavableSmsSegment() after
|
|
|
|
* completing the concatenation.
|
|
|
|
*/
|
|
|
|
_purgeCompleteSmsMessage: function(aMessage) {
|
|
|
|
// Purge concatenation info
|
|
|
|
delete aMessage.segmentRef;
|
|
|
|
delete aMessage.segmentSeq;
|
|
|
|
delete aMessage.segmentMaxSeq;
|
|
|
|
|
|
|
|
// Purge partial message body
|
|
|
|
delete aMessage.data;
|
|
|
|
delete aMessage.body;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* handle concatenation of received SMS.
|
|
|
|
*/
|
|
|
|
handleSmsMultipart: function(aMessage) {
|
|
|
|
if (DEBUG) this.debug("handleSmsMultipart: " + JSON.stringify(aMessage));
|
|
|
|
|
|
|
|
this._acquireSmsHandledWakeLock();
|
|
|
|
|
|
|
|
let segment = this._createSavableSmsSegment(aMessage);
|
|
|
|
|
|
|
|
let isMultipart = (segment.segmentMaxSeq && (segment.segmentMaxSeq > 1));
|
|
|
|
let messageClass = segment.messageClass;
|
|
|
|
|
|
|
|
let handleReceivedAndAck = function(aRvOfIncompleteMsg, aCompleteMessage) {
|
|
|
|
if (aCompleteMessage) {
|
|
|
|
this._purgeCompleteSmsMessage(aCompleteMessage);
|
|
|
|
if (this.handleSmsReceived(aCompleteMessage)) {
|
|
|
|
this.sendAckSms(Cr.NS_OK, aCompleteMessage);
|
|
|
|
}
|
|
|
|
// else Ack will be sent after further process in handleSmsReceived.
|
|
|
|
} else {
|
|
|
|
this.sendAckSms(aRvOfIncompleteMsg, segment);
|
|
|
|
}
|
|
|
|
}.bind(this);
|
|
|
|
|
|
|
|
// No need to access SmsSegmentStore for Class 0 SMS and Single SMS.
|
|
|
|
if (!isMultipart ||
|
|
|
|
(messageClass == RIL.GECKO_SMS_MESSAGE_CLASSES[RIL.PDU_DCS_MSG_CLASS_0])) {
|
|
|
|
// `When a mobile terminated message is class 0 and the MS has the
|
|
|
|
// capability of displaying short messages, the MS shall display the
|
|
|
|
// message immediately and send an acknowledgement to the SC when the
|
|
|
|
// message has successfully reached the MS irrespective of whether
|
|
|
|
// there is memory available in the (U)SIM or ME. The message shall
|
|
|
|
// not be automatically stored in the (U)SIM or ME.`
|
|
|
|
// ~ 3GPP 23.038 clause 4
|
|
|
|
|
|
|
|
handleReceivedAndAck(Cr.NS_OK, // ACK OK For Incomplete Class 0
|
|
|
|
this._processReceivedSmsSegment(segment));
|
|
|
|
} else {
|
|
|
|
gMobileMessageDatabaseService
|
|
|
|
.saveSmsSegment(segment, function notifyResult(aRv, aCompleteMessage) {
|
|
|
|
handleReceivedAndAck(aRv, // Ack according to the result after saving
|
|
|
|
aCompleteMessage);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
portAddressedSmsApps: null,
|
|
|
|
handleSmsReceived: function(message) {
|
|
|
|
if (DEBUG) this.debug("handleSmsReceived: " + JSON.stringify(message));
|
|
|
|
|
|
|
|
if (message.messageType == RIL.PDU_CDMA_MSG_TYPE_BROADCAST) {
|
2014-08-13 10:28:34 +00:00
|
|
|
this.handleCellbroadcastMessageReceived(message);
|
2014-03-12 16:27:00 +00:00
|
|
|
return true;
|
2013-09-07 11:09:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Dispatch to registered handler if application port addressing is
|
|
|
|
// available. Note that the destination port can possibly be zero when
|
|
|
|
// representing a UDP/TCP port.
|
2014-03-12 16:27:00 +00:00
|
|
|
if (message.destinationPort != null) {
|
|
|
|
let handler = this.portAddressedSmsApps[message.destinationPort];
|
2013-09-07 11:09:54 +00:00
|
|
|
if (handler) {
|
|
|
|
handler(message);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (message.encoding == RIL.PDU_DCS_MSG_CODING_8BITS_ALPHABET) {
|
|
|
|
// Don't know how to handle binary data yet.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
message.type = "sms";
|
|
|
|
message.sender = message.sender || null;
|
2013-10-15 02:42:49 +00:00
|
|
|
message.receiver = this.getPhoneNumber();
|
2013-09-07 11:09:54 +00:00
|
|
|
message.body = message.fullBody = message.fullBody || null;
|
|
|
|
|
|
|
|
if (gSmsService.isSilentNumber(message.sender)) {
|
|
|
|
message.id = -1;
|
|
|
|
message.threadId = 0;
|
|
|
|
message.delivery = DOM_MOBILE_MESSAGE_DELIVERY_RECEIVED;
|
|
|
|
message.deliveryStatus = RIL.GECKO_SMS_DELIVERY_STATUS_SUCCESS;
|
|
|
|
message.read = false;
|
|
|
|
|
|
|
|
let domMessage =
|
|
|
|
gMobileMessageService.createSmsMessage(message.id,
|
|
|
|
message.threadId,
|
2013-11-02 10:17:25 +00:00
|
|
|
message.iccId,
|
2013-09-07 11:09:54 +00:00
|
|
|
message.delivery,
|
|
|
|
message.deliveryStatus,
|
|
|
|
message.sender,
|
|
|
|
message.receiver,
|
|
|
|
message.body,
|
|
|
|
message.messageClass,
|
|
|
|
message.timestamp,
|
2013-09-23 02:31:32 +00:00
|
|
|
message.sentTimestamp,
|
2013-11-01 12:00:55 +00:00
|
|
|
0,
|
2013-09-07 11:09:54 +00:00
|
|
|
message.read);
|
|
|
|
|
|
|
|
Services.obs.notifyObservers(domMessage,
|
|
|
|
kSilentSmsReceivedObserverTopic,
|
|
|
|
null);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-03-12 16:27:00 +00:00
|
|
|
if (message.mwiPresent) {
|
|
|
|
let mwi = {
|
|
|
|
discard: message.mwiDiscard,
|
|
|
|
msgCount: message.mwiMsgCount,
|
|
|
|
active: message.mwiActive
|
|
|
|
};
|
|
|
|
this.workerMessenger.send("updateMwis", { mwi: mwi });
|
|
|
|
|
2013-09-07 11:09:54 +00:00
|
|
|
mwi.returnNumber = message.sender;
|
|
|
|
mwi.returnMessage = message.fullBody;
|
2014-09-26 05:00:25 +00:00
|
|
|
this.handleIccMwis(mwi);
|
2013-12-06 03:18:17 +00:00
|
|
|
|
|
|
|
// Dicarded MWI comes without text body.
|
|
|
|
// Hence, we discard it here after notifying the MWI status.
|
2014-03-12 16:27:00 +00:00
|
|
|
if (message.mwiDiscard) {
|
2013-12-06 03:18:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-09-07 11:09:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let notifyReceived = function notifyReceived(rv, domMessage) {
|
|
|
|
let success = Components.isSuccessCode(rv);
|
|
|
|
|
2014-03-12 16:27:00 +00:00
|
|
|
this.sendAckSms(rv, message);
|
2013-09-07 11:09:54 +00:00
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
// At this point we could send a message to content to notify the user
|
|
|
|
// that storing an incoming SMS failed, most likely due to a full disk.
|
|
|
|
if (DEBUG) {
|
2013-11-26 18:58:41 +00:00
|
|
|
this.debug("Could not store SMS, error code " + rv);
|
2013-09-07 11:09:54 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-24 03:33:01 +00:00
|
|
|
this.broadcastSmsSystemMessage(
|
|
|
|
Ci.nsISmsMessenger.NOTIFICATION_TYPE_RECEIVED, domMessage);
|
2013-09-07 11:09:54 +00:00
|
|
|
Services.obs.notifyObservers(domMessage, kSmsReceivedObserverTopic, null);
|
|
|
|
}.bind(this);
|
|
|
|
|
|
|
|
if (message.messageClass != RIL.GECKO_SMS_MESSAGE_CLASSES[RIL.PDU_DCS_MSG_CLASS_0]) {
|
2013-11-26 18:58:41 +00:00
|
|
|
gMobileMessageDatabaseService.saveReceivedMessage(message,
|
|
|
|
notifyReceived);
|
2013-09-07 11:09:54 +00:00
|
|
|
} else {
|
|
|
|
message.id = -1;
|
|
|
|
message.threadId = 0;
|
|
|
|
message.delivery = DOM_MOBILE_MESSAGE_DELIVERY_RECEIVED;
|
|
|
|
message.deliveryStatus = RIL.GECKO_SMS_DELIVERY_STATUS_SUCCESS;
|
|
|
|
message.read = false;
|
|
|
|
|
|
|
|
let domMessage =
|
|
|
|
gMobileMessageService.createSmsMessage(message.id,
|
|
|
|
message.threadId,
|
2013-11-02 10:17:25 +00:00
|
|
|
message.iccId,
|
2013-09-07 11:09:54 +00:00
|
|
|
message.delivery,
|
|
|
|
message.deliveryStatus,
|
|
|
|
message.sender,
|
|
|
|
message.receiver,
|
|
|
|
message.body,
|
|
|
|
message.messageClass,
|
|
|
|
message.timestamp,
|
2013-09-23 02:31:32 +00:00
|
|
|
message.sentTimestamp,
|
2013-11-01 12:00:55 +00:00
|
|
|
0,
|
2013-09-07 11:09:54 +00:00
|
|
|
message.read);
|
|
|
|
|
|
|
|
notifyReceived(Cr.NS_OK, domMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
// SMS ACK will be sent in notifyReceived. Return false here.
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2014-03-12 16:27:00 +00:00
|
|
|
/**
|
|
|
|
* Handle ACK response of received SMS.
|
|
|
|
*/
|
|
|
|
sendAckSms: function(aRv, aMessage) {
|
|
|
|
if (aMessage.messageClass === RIL.GECKO_SMS_MESSAGE_CLASSES[RIL.PDU_DCS_MSG_CLASS_2]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let result = RIL.PDU_FCS_OK;
|
|
|
|
if (!Components.isSuccessCode(aRv)) {
|
|
|
|
if (DEBUG) this.debug("Failed to handle received sms: " + aRv);
|
|
|
|
result = (aRv === Cr.NS_ERROR_FILE_NO_DEVICE_SPACE)
|
|
|
|
? RIL.PDU_FCS_MEMORY_CAPACITY_EXCEEDED
|
|
|
|
: RIL.PDU_FCS_UNSPECIFIED;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.workerMessenger.send("ackSMS", { result: result });
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-01-25 10:06:24 +00:00
|
|
|
/**
|
2013-06-22 14:22:05 +00:00
|
|
|
* Set the setting value of "time.clock.automatic-update.available".
|
|
|
|
*/
|
2014-01-13 02:44:40 +00:00
|
|
|
setClockAutoUpdateAvailable: function(value) {
|
2014-08-28 04:01:31 +00:00
|
|
|
gSettingsService.createLock().set(kSettingsClockAutoUpdateAvailable, value, null);
|
2013-06-22 14:22:05 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the setting value of "time.timezone.automatic-update.available".
|
2013-01-25 10:06:24 +00:00
|
|
|
*/
|
2014-01-13 02:44:40 +00:00
|
|
|
setTimezoneAutoUpdateAvailable: function(value) {
|
2014-08-28 04:01:31 +00:00
|
|
|
gSettingsService.createLock().set(kSettingsTimezoneAutoUpdateAvailable, value, null);
|
2013-01-25 10:06:24 +00:00
|
|
|
},
|
|
|
|
|
2012-09-28 06:02:57 +00:00
|
|
|
/**
|
2013-06-22 14:22:05 +00:00
|
|
|
* Set the system clock by NITZ.
|
2012-09-28 06:02:57 +00:00
|
|
|
*/
|
2014-01-13 02:44:40 +00:00
|
|
|
setClockByNitz: function(message) {
|
2012-09-28 06:02:57 +00:00
|
|
|
// To set the system clock time. Note that there could be a time diff
|
|
|
|
// between when the NITZ was received and when the time is actually set.
|
|
|
|
gTimeService.set(
|
|
|
|
message.networkTimeInMS + (Date.now() - message.receiveTimeInMS));
|
2013-06-22 14:22:05 +00:00
|
|
|
},
|
2012-09-28 06:02:57 +00:00
|
|
|
|
2013-06-22 14:22:05 +00:00
|
|
|
/**
|
|
|
|
* Set the system time zone by NITZ.
|
|
|
|
*/
|
2014-01-13 02:44:40 +00:00
|
|
|
setTimezoneByNitz: function(message) {
|
2012-09-28 06:02:57 +00:00
|
|
|
// To set the sytem timezone. Note that we need to convert the time zone
|
|
|
|
// value to a UTC repesentation string in the format of "UTC(+/-)hh:mm".
|
2013-10-15 08:43:53 +00:00
|
|
|
// Ex, time zone -480 is "UTC+08:00"; time zone 630 is "UTC-10:30".
|
2012-09-28 06:02:57 +00:00
|
|
|
//
|
|
|
|
// We can unapply the DST correction if we want the raw time zone offset:
|
|
|
|
// message.networkTimeZoneInMinutes -= message.networkDSTInMinutes;
|
|
|
|
if (message.networkTimeZoneInMinutes != (new Date()).getTimezoneOffset()) {
|
|
|
|
let absTimeZoneInMinutes = Math.abs(message.networkTimeZoneInMinutes);
|
|
|
|
let timeZoneStr = "UTC";
|
2013-10-15 08:43:53 +00:00
|
|
|
timeZoneStr += (message.networkTimeZoneInMinutes > 0 ? "-" : "+");
|
2012-09-28 06:02:57 +00:00
|
|
|
timeZoneStr += ("0" + Math.floor(absTimeZoneInMinutes / 60)).slice(-2);
|
|
|
|
timeZoneStr += ":";
|
|
|
|
timeZoneStr += ("0" + absTimeZoneInMinutes % 60).slice(-2);
|
|
|
|
gSettingsService.createLock().set("time.timezone", timeZoneStr, null);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-10-23 07:15:53 +00:00
|
|
|
/**
|
|
|
|
* Handle the NITZ message.
|
|
|
|
*/
|
2014-01-13 02:44:40 +00:00
|
|
|
handleNitzTime: function(message) {
|
2013-01-25 10:06:24 +00:00
|
|
|
// Got the NITZ info received from the ril_worker.
|
2013-06-22 14:22:05 +00:00
|
|
|
this.setClockAutoUpdateAvailable(true);
|
|
|
|
this.setTimezoneAutoUpdateAvailable(true);
|
2013-01-25 10:06:24 +00:00
|
|
|
|
2012-10-23 07:15:53 +00:00
|
|
|
// Cache the latest NITZ message whenever receiving it.
|
|
|
|
this._lastNitzMessage = message;
|
|
|
|
|
2013-06-22 14:22:05 +00:00
|
|
|
// Set the received NITZ clock if the setting is enabled.
|
|
|
|
if (this._clockAutoUpdateEnabled) {
|
|
|
|
this.setClockByNitz(message);
|
|
|
|
}
|
|
|
|
// Set the received NITZ timezone if the setting is enabled.
|
|
|
|
if (this._timezoneAutoUpdateEnabled) {
|
|
|
|
this.setTimezoneByNitz(message);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the system clock by SNTP.
|
|
|
|
*/
|
2014-01-13 02:44:40 +00:00
|
|
|
setClockBySntp: function(offset) {
|
2013-06-22 14:22:05 +00:00
|
|
|
// Got the SNTP info.
|
|
|
|
this.setClockAutoUpdateAvailable(true);
|
|
|
|
if (!this._clockAutoUpdateEnabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (this._lastNitzMessage) {
|
2014-01-23 08:44:20 +00:00
|
|
|
if (DEBUG) debug("SNTP: NITZ available, discard SNTP");
|
2013-06-22 14:22:05 +00:00
|
|
|
return;
|
2012-10-23 07:15:53 +00:00
|
|
|
}
|
2013-06-22 14:22:05 +00:00
|
|
|
gTimeService.set(Date.now() + offset);
|
2012-10-23 07:15:53 +00:00
|
|
|
},
|
|
|
|
|
2014-01-13 02:44:40 +00:00
|
|
|
handleIccMbdn: function(message) {
|
2014-09-26 05:00:25 +00:00
|
|
|
let service = Cc["@mozilla.org/voicemail/voicemailservice;1"]
|
|
|
|
.getService(Ci.nsIGonkVoicemailService);
|
|
|
|
service.notifyInfoChanged(this.clientId, message.number, message.alphaId);
|
|
|
|
},
|
2012-11-23 04:09:01 +00:00
|
|
|
|
2014-09-26 05:00:25 +00:00
|
|
|
handleIccMwis: function(mwi) {
|
|
|
|
let service = Cc["@mozilla.org/voicemail/voicemailservice;1"]
|
|
|
|
.getService(Ci.nsIGonkVoicemailService);
|
|
|
|
service.notifyStatusChanged(this.clientId, mwi.active, mwi.msgCount,
|
|
|
|
mwi.returnNumber, mwi.returnMessage);
|
2012-11-23 04:09:01 +00:00
|
|
|
},
|
|
|
|
|
2014-01-13 02:44:40 +00:00
|
|
|
handleIccInfoChange: function(message) {
|
2013-10-15 02:42:49 +00:00
|
|
|
let oldSpn = this.rilContext.iccInfo ? this.rilContext.iccInfo.spn : null;
|
2013-01-10 16:18:54 +00:00
|
|
|
|
2014-08-18 07:15:16 +00:00
|
|
|
if (!message || !message.iccid) {
|
2013-10-15 02:42:49 +00:00
|
|
|
// Card is not detected, clear iccInfo to null.
|
|
|
|
this.rilContext.iccInfo = null;
|
|
|
|
} else {
|
|
|
|
if (!this.rilContext.iccInfo) {
|
|
|
|
if (message.iccType === "ruim" || message.iccType === "csim") {
|
|
|
|
this.rilContext.iccInfo = new CdmaIccInfo();
|
2014-08-18 07:15:16 +00:00
|
|
|
} else if (message.iccType === "sim" || message.iccType === "usim") {
|
2013-10-15 02:42:49 +00:00
|
|
|
this.rilContext.iccInfo = new GsmIccInfo();
|
2014-08-18 07:15:16 +00:00
|
|
|
} else {
|
|
|
|
this.rilContext.iccInfo = new IccInfo();
|
2013-10-15 02:42:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.isInfoChanged(message, this.rilContext.iccInfo)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.updateInfo(message, this.rilContext.iccInfo);
|
2012-09-03 21:43:59 +00:00
|
|
|
}
|
2013-10-15 02:42:49 +00:00
|
|
|
|
2012-09-03 21:43:59 +00:00
|
|
|
// RIL:IccInfoChanged corresponds to a DOM event that gets fired only
|
2013-08-12 06:59:17 +00:00
|
|
|
// when iccInfo has changed.
|
2013-05-30 11:14:39 +00:00
|
|
|
gMessageManager.sendIccMessage("RIL:IccInfoChanged",
|
2013-08-12 06:59:17 +00:00
|
|
|
this.clientId,
|
2014-08-18 07:15:16 +00:00
|
|
|
message.iccid ? message : null);
|
2013-01-04 08:44:20 +00:00
|
|
|
|
2014-09-21 07:24:42 +00:00
|
|
|
// In bug 864489, icc related code will be move to gonk IccProvider, we may
|
|
|
|
// need a better way to notify icc change to MobileConnectionService.
|
2014-02-10 11:55:22 +00:00
|
|
|
gMobileConnectionService.notifyIccChanged(this.clientId,
|
|
|
|
message.iccid || null);
|
|
|
|
|
2013-07-18 20:17:41 +00:00
|
|
|
// Update lastKnownSimMcc.
|
|
|
|
if (message.mcc) {
|
|
|
|
try {
|
|
|
|
Services.prefs.setCharPref("ril.lastKnownSimMcc",
|
|
|
|
message.mcc.toString());
|
|
|
|
} catch (e) {}
|
|
|
|
}
|
|
|
|
|
2013-05-03 01:37:51 +00:00
|
|
|
// Update lastKnownHomeNetwork.
|
|
|
|
if (message.mcc && message.mnc) {
|
2014-02-10 11:55:22 +00:00
|
|
|
let lastKnownHomeNetwork = message.mcc + "-" + message.mnc;
|
2014-06-27 04:01:06 +00:00
|
|
|
// Append spn information if available.
|
|
|
|
if (message.spn) {
|
2014-02-10 11:55:22 +00:00
|
|
|
lastKnownHomeNetwork += "-" + message.spn;
|
2014-06-27 04:01:06 +00:00
|
|
|
}
|
2014-02-10 11:55:22 +00:00
|
|
|
|
|
|
|
gMobileConnectionService.notifyLastHomeNetworkChanged(this.clientId,
|
|
|
|
lastKnownHomeNetwork);
|
2013-05-03 01:37:51 +00:00
|
|
|
}
|
|
|
|
|
2013-01-04 08:44:20 +00:00
|
|
|
// If spn becomes available, we should check roaming again.
|
2013-01-08 12:40:00 +00:00
|
|
|
if (!oldSpn && message.spn) {
|
2014-02-10 11:55:22 +00:00
|
|
|
gMobileConnectionService.notifySpnAvailable(this.clientId);
|
2013-01-04 08:44:20 +00:00
|
|
|
}
|
2012-09-03 21:43:59 +00:00
|
|
|
},
|
|
|
|
|
2014-01-13 02:44:40 +00:00
|
|
|
handleStkProactiveCommand: function(message) {
|
2013-07-02 09:36:58 +00:00
|
|
|
if (DEBUG) this.debug("handleStkProactiveCommand " + JSON.stringify(message));
|
2013-11-25 10:10:34 +00:00
|
|
|
let iccId = this.rilContext.iccInfo && this.rilContext.iccInfo.iccid;
|
|
|
|
if (iccId) {
|
2014-11-25 09:45:35 +00:00
|
|
|
gSystemMessenger.broadcastMessage("icc-stkcommand",
|
|
|
|
{iccId: iccId,
|
|
|
|
command: message});
|
2013-11-25 10:10:34 +00:00
|
|
|
}
|
2013-07-02 09:36:40 +00:00
|
|
|
gMessageManager.sendIccMessage("RIL:StkCommand", this.clientId, message);
|
2012-04-10 12:04:27 +00:00
|
|
|
},
|
|
|
|
|
2014-09-23 10:27:03 +00:00
|
|
|
_convertCbGsmGeographicalScope: function(aGeographicalScope) {
|
|
|
|
return (aGeographicalScope != null)
|
|
|
|
? aGeographicalScope
|
|
|
|
: Ci.nsICellBroadcastService.GSM_GEOGRAPHICAL_SCOPE_INVALID;
|
|
|
|
},
|
|
|
|
|
|
|
|
_convertCbMessageClass: function(aMessageClass) {
|
|
|
|
let index = RIL.GECKO_SMS_MESSAGE_CLASSES.indexOf(aMessageClass);
|
|
|
|
return (index != -1)
|
|
|
|
? index
|
2014-10-24 05:18:26 +00:00
|
|
|
: Ci.nsICellBroadcastService.GSM_MESSAGE_CLASS_NORMAL;
|
2014-09-23 10:27:03 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_convertCbEtwsWarningType: function(aWarningType) {
|
|
|
|
return (aWarningType != null)
|
|
|
|
? aWarningType
|
|
|
|
: Ci.nsICellBroadcastService.GSM_ETWS_WARNING_INVALID;
|
|
|
|
},
|
|
|
|
|
2014-08-13 10:28:34 +00:00
|
|
|
handleCellbroadcastMessageReceived: function(aMessage) {
|
|
|
|
let etwsInfo = aMessage.etws;
|
|
|
|
let hasEtwsInfo = etwsInfo != null;
|
|
|
|
let serviceCategory = (aMessage.serviceCategory)
|
|
|
|
? aMessage.serviceCategory
|
|
|
|
: Ci.nsICellBroadcastService.CDMA_SERVICE_CATEGORY_INVALID;
|
|
|
|
|
|
|
|
gCellBroadcastService
|
|
|
|
.notifyMessageReceived(this.clientId,
|
2014-09-23 10:27:03 +00:00
|
|
|
this._convertCbGsmGeographicalScope(aMessage.geographicalScope),
|
2014-08-13 10:28:34 +00:00
|
|
|
aMessage.messageCode,
|
|
|
|
aMessage.messageId,
|
|
|
|
aMessage.language,
|
|
|
|
aMessage.fullBody,
|
2014-09-23 10:27:03 +00:00
|
|
|
this._convertCbMessageClass(aMessage.messageClass),
|
2014-09-15 09:44:46 +00:00
|
|
|
Date.now(),
|
2014-08-13 10:28:34 +00:00
|
|
|
serviceCategory,
|
|
|
|
hasEtwsInfo,
|
2014-09-23 10:27:03 +00:00
|
|
|
(hasEtwsInfo)
|
|
|
|
? this._convertCbEtwsWarningType(etwsInfo.warningType)
|
|
|
|
: Ci.nsICellBroadcastService.GSM_ETWS_WARNING_INVALID,
|
2014-08-13 10:28:34 +00:00
|
|
|
hasEtwsInfo ? etwsInfo.emergencyUserAlert : false,
|
|
|
|
hasEtwsInfo ? etwsInfo.popup : false);
|
|
|
|
},
|
|
|
|
|
2014-10-03 06:23:41 +00:00
|
|
|
handleCdmaInformationRecords: function(aRecords) {
|
|
|
|
if (DEBUG) this.debug("cdma-info-rec-received: " + JSON.stringify(aRecords));
|
|
|
|
|
|
|
|
let clientId = this.clientId;
|
|
|
|
|
|
|
|
aRecords.forEach(function(aRecord) {
|
|
|
|
if (aRecord.display) {
|
|
|
|
gMobileConnectionService
|
|
|
|
.notifyCdmaInfoRecDisplay(clientId, aRecord.display);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aRecord.calledNumber) {
|
|
|
|
gMobileConnectionService
|
|
|
|
.notifyCdmaInfoRecCalledPartyNumber(clientId,
|
|
|
|
aRecord.calledNumber.type,
|
|
|
|
aRecord.calledNumber.plan,
|
|
|
|
aRecord.calledNumber.number,
|
|
|
|
aRecord.calledNumber.pi,
|
|
|
|
aRecord.calledNumber.si);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aRecord.callingNumber) {
|
|
|
|
gMobileConnectionService
|
|
|
|
.notifyCdmaInfoRecCallingPartyNumber(clientId,
|
|
|
|
aRecord.callingNumber.type,
|
|
|
|
aRecord.callingNumber.plan,
|
|
|
|
aRecord.callingNumber.number,
|
|
|
|
aRecord.callingNumber.pi,
|
|
|
|
aRecord.callingNumber.si);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aRecord.connectedNumber) {
|
|
|
|
gMobileConnectionService
|
|
|
|
.notifyCdmaInfoRecConnectedPartyNumber(clientId,
|
|
|
|
aRecord.connectedNumber.type,
|
|
|
|
aRecord.connectedNumber.plan,
|
|
|
|
aRecord.connectedNumber.number,
|
|
|
|
aRecord.connectedNumber.pi,
|
|
|
|
aRecord.connectedNumber.si);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aRecord.signal) {
|
|
|
|
gMobileConnectionService
|
|
|
|
.notifyCdmaInfoRecSignal(clientId,
|
|
|
|
aRecord.signal.type,
|
|
|
|
aRecord.signal.alertPitch,
|
|
|
|
aRecord.signal.signal);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aRecord.redirect) {
|
|
|
|
gMobileConnectionService
|
|
|
|
.notifyCdmaInfoRecRedirectingNumber(clientId,
|
|
|
|
aRecord.redirect.type,
|
|
|
|
aRecord.redirect.plan,
|
|
|
|
aRecord.redirect.number,
|
|
|
|
aRecord.redirect.pi,
|
|
|
|
aRecord.redirect.si,
|
|
|
|
aRecord.redirect.reason);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aRecord.lineControl) {
|
|
|
|
gMobileConnectionService
|
|
|
|
.notifyCdmaInfoRecLineControl(clientId,
|
|
|
|
aRecord.lineControl.polarityIncluded,
|
|
|
|
aRecord.lineControl.toggle,
|
|
|
|
aRecord.lineControl.reverse,
|
|
|
|
aRecord.lineControl.powerDenial);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aRecord.clirCause) {
|
|
|
|
gMobileConnectionService
|
|
|
|
.notifyCdmaInfoRecClir(clientId,
|
|
|
|
aRecord.clirCause);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aRecord.audioControl) {
|
|
|
|
gMobileConnectionService
|
|
|
|
.notifyCdmaInfoRecAudioControl(clientId,
|
|
|
|
aRecord.audioControl.upLink,
|
|
|
|
aRecord.audioControl.downLink);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-04-19 21:33:25 +00:00
|
|
|
// nsIObserver
|
2012-03-12 23:45:57 +00:00
|
|
|
|
2014-01-13 02:44:40 +00:00
|
|
|
observe: function(subject, topic, data) {
|
2012-04-24 20:46:42 +00:00
|
|
|
switch (topic) {
|
|
|
|
case kMozSettingsChangedObserverTopic:
|
2014-09-16 17:15:16 +00:00
|
|
|
if ("wrappedJSObject" in subject) {
|
|
|
|
subject = subject.wrappedJSObject;
|
|
|
|
}
|
|
|
|
this.handleSettingsChange(subject.key, subject.value, subject.isInternalChange);
|
2012-04-24 20:46:42 +00:00
|
|
|
break;
|
2012-10-23 07:15:53 +00:00
|
|
|
case kSysClockChangeObserverTopic:
|
2013-06-22 14:22:05 +00:00
|
|
|
let offset = parseInt(data, 10);
|
2012-10-23 07:15:53 +00:00
|
|
|
if (this._lastNitzMessage) {
|
2013-06-22 14:22:05 +00:00
|
|
|
this._lastNitzMessage.receiveTimeInMS += offset;
|
|
|
|
}
|
|
|
|
this._sntp.updateOffset(offset);
|
|
|
|
break;
|
2014-03-10 03:36:42 +00:00
|
|
|
case kNetworkConnStateChangedTopic:
|
2013-06-22 14:22:05 +00:00
|
|
|
let network = subject.QueryInterface(Ci.nsINetworkInterface);
|
2013-10-29 08:13:06 +00:00
|
|
|
if (network.state != Ci.nsINetworkInterface.NETWORK_STATE_CONNECTED) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// SNTP can only update when we have mobile or Wifi connections.
|
2014-11-25 01:44:33 +00:00
|
|
|
if (network.type != NETWORK_TYPE_WIFI &&
|
|
|
|
network.type != NETWORK_TYPE_MOBILE) {
|
2013-10-29 08:13:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the network comes from RIL, make sure the RIL service is matched.
|
|
|
|
if (subject instanceof Ci.nsIRilNetworkInterface) {
|
|
|
|
network = subject.QueryInterface(Ci.nsIRilNetworkInterface);
|
|
|
|
if (network.serviceId != this.clientId) {
|
|
|
|
return;
|
2013-06-22 14:22:05 +00:00
|
|
|
}
|
2012-10-23 07:15:53 +00:00
|
|
|
}
|
2013-10-29 08:13:06 +00:00
|
|
|
|
|
|
|
// SNTP won't update unless the SNTP is already expired.
|
|
|
|
if (this._sntp.isExpired()) {
|
|
|
|
this._sntp.request();
|
|
|
|
}
|
2012-04-24 20:46:42 +00:00
|
|
|
break;
|
2013-06-06 07:28:59 +00:00
|
|
|
case kScreenStateChangedTopic:
|
2013-08-14 10:11:47 +00:00
|
|
|
this.workerMessenger.send("setScreenState", { on: (data === "on") });
|
2013-06-06 07:28:59 +00:00
|
|
|
break;
|
2012-04-19 21:33:25 +00:00
|
|
|
}
|
2012-03-12 23:45:57 +00:00
|
|
|
},
|
|
|
|
|
2013-06-22 14:22:05 +00:00
|
|
|
// Flag to determine whether to update system clock automatically. It
|
2013-11-21 14:09:14 +00:00
|
|
|
// corresponds to the "time.clock.automatic-update.enabled" setting.
|
2013-06-22 14:22:05 +00:00
|
|
|
_clockAutoUpdateEnabled: null,
|
|
|
|
|
|
|
|
// Flag to determine whether to update system timezone automatically. It
|
2013-11-21 14:09:14 +00:00
|
|
|
// corresponds to the "time.clock.automatic-update.enabled" setting.
|
2013-06-22 14:22:05 +00:00
|
|
|
_timezoneAutoUpdateEnabled: null,
|
2012-09-28 13:08:04 +00:00
|
|
|
|
2012-10-23 07:15:53 +00:00
|
|
|
// Remember the last NITZ message so that we can set the time based on
|
|
|
|
// the network immediately when users enable network-based time.
|
|
|
|
_lastNitzMessage: null,
|
|
|
|
|
2013-06-22 14:22:05 +00:00
|
|
|
// Object that handles SNTP.
|
|
|
|
_sntp: null,
|
|
|
|
|
2012-12-04 02:41:39 +00:00
|
|
|
// Cell Broadcast settings values.
|
2014-04-03 08:33:56 +00:00
|
|
|
_cellBroadcastSearchList: null,
|
2012-12-04 02:41:39 +00:00
|
|
|
|
2014-08-28 04:01:31 +00:00
|
|
|
handleSettingsChange: function(aName, aResult, aIsInternalSetting) {
|
2013-01-25 10:06:24 +00:00
|
|
|
// Don't allow any content processes to modify the setting
|
2013-06-22 14:22:05 +00:00
|
|
|
// "time.clock.automatic-update.available" except for the chrome process.
|
2013-10-24 08:14:59 +00:00
|
|
|
if (aName === kSettingsClockAutoUpdateAvailable &&
|
2014-08-28 04:01:31 +00:00
|
|
|
!aIsInternalSetting) {
|
2013-06-22 14:22:05 +00:00
|
|
|
let isClockAutoUpdateAvailable = this._lastNitzMessage !== null ||
|
|
|
|
this._sntp.isAvailable();
|
|
|
|
if (aResult !== isClockAutoUpdateAvailable) {
|
2014-01-23 08:44:20 +00:00
|
|
|
if (DEBUG) {
|
|
|
|
debug("Content processes cannot modify 'time.clock.automatic-update.available'. Restore!");
|
|
|
|
}
|
2013-06-22 14:22:05 +00:00
|
|
|
// Restore the setting to the current value.
|
|
|
|
this.setClockAutoUpdateAvailable(isClockAutoUpdateAvailable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't allow any content processes to modify the setting
|
|
|
|
// "time.timezone.automatic-update.available" except for the chrome
|
|
|
|
// process.
|
2013-10-24 08:14:59 +00:00
|
|
|
if (aName === kSettingsTimezoneAutoUpdateAvailable &&
|
2014-08-28 04:01:31 +00:00
|
|
|
!aIsInternalSetting) {
|
2013-06-22 14:22:05 +00:00
|
|
|
let isTimezoneAutoUpdateAvailable = this._lastNitzMessage !== null;
|
|
|
|
if (aResult !== isTimezoneAutoUpdateAvailable) {
|
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("Content processes cannot modify 'time.timezone.automatic-update.available'. Restore!");
|
|
|
|
}
|
|
|
|
// Restore the setting to the current value.
|
|
|
|
this.setTimezoneAutoUpdateAvailable(isTimezoneAutoUpdateAvailable);
|
2013-07-02 09:36:58 +00:00
|
|
|
}
|
2013-01-25 10:06:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.handle(aName, aResult);
|
|
|
|
},
|
|
|
|
|
2012-09-28 06:02:57 +00:00
|
|
|
// nsISettingsServiceCallback
|
2014-01-13 02:44:40 +00:00
|
|
|
handle: function(aName, aResult) {
|
2012-08-01 14:54:04 +00:00
|
|
|
switch(aName) {
|
2013-10-24 08:14:59 +00:00
|
|
|
case kSettingsClockAutoUpdateEnabled:
|
2013-06-22 14:22:05 +00:00
|
|
|
this._clockAutoUpdateEnabled = aResult;
|
|
|
|
if (!this._clockAutoUpdateEnabled) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the latest cached NITZ time if it's available.
|
|
|
|
if (this._lastNitzMessage) {
|
|
|
|
this.setClockByNitz(this._lastNitzMessage);
|
|
|
|
} else if (gNetworkManager.active && gNetworkManager.active.state ==
|
|
|
|
Ci.nsINetworkInterface.NETWORK_STATE_CONNECTED) {
|
|
|
|
// Set the latest cached SNTP time if it's available.
|
|
|
|
if (!this._sntp.isExpired()) {
|
|
|
|
this.setClockBySntp(this._sntp.getOffset());
|
|
|
|
} else {
|
|
|
|
// Or refresh the SNTP.
|
|
|
|
this._sntp.request();
|
|
|
|
}
|
2014-02-18 14:41:36 +00:00
|
|
|
} else {
|
|
|
|
// Set a sane minimum time.
|
|
|
|
let buildTime = libcutils.property_get("ro.build.date.utc", "0") * 1000;
|
|
|
|
let file = FileUtils.File("/system/b2g/b2g");
|
|
|
|
if (file.lastModifiedTime > buildTime) {
|
|
|
|
buildTime = file.lastModifiedTime;
|
|
|
|
}
|
|
|
|
if (buildTime > Date.now()) {
|
|
|
|
gTimeService.set(buildTime);
|
|
|
|
}
|
2013-06-22 14:22:05 +00:00
|
|
|
}
|
|
|
|
break;
|
2013-10-24 08:14:59 +00:00
|
|
|
case kSettingsTimezoneAutoUpdateEnabled:
|
2013-06-22 14:22:05 +00:00
|
|
|
this._timezoneAutoUpdateEnabled = aResult;
|
2012-10-23 07:15:53 +00:00
|
|
|
|
2013-06-22 14:22:05 +00:00
|
|
|
if (this._timezoneAutoUpdateEnabled) {
|
|
|
|
// Apply the latest cached NITZ for timezone if it's available.
|
|
|
|
if (this._timezoneAutoUpdateEnabled && this._lastNitzMessage) {
|
|
|
|
this.setTimezoneByNitz(this._lastNitzMessage);
|
|
|
|
}
|
2012-10-23 07:15:53 +00:00
|
|
|
}
|
2012-09-28 06:02:57 +00:00
|
|
|
break;
|
2013-06-10 02:41:14 +00:00
|
|
|
}
|
2012-05-24 05:12:07 +00:00
|
|
|
},
|
2012-09-05 09:36:01 +00:00
|
|
|
|
2014-01-13 02:44:40 +00:00
|
|
|
handleError: function(aErrorMessage) {
|
2013-12-03 06:18:32 +00:00
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("There was an error while reading RIL settings.");
|
|
|
|
}
|
2012-05-24 05:12:07 +00:00
|
|
|
},
|
|
|
|
|
2013-07-02 09:36:37 +00:00
|
|
|
// nsIRadioInterface
|
2011-12-05 07:58:27 +00:00
|
|
|
|
2012-06-13 02:46:41 +00:00
|
|
|
rilContext: null,
|
2011-12-05 07:58:27 +00:00
|
|
|
|
2013-09-07 11:09:54 +00:00
|
|
|
/**
|
|
|
|
* List of tuples of national language identifier pairs.
|
|
|
|
*
|
|
|
|
* TODO: Support static/runtime settings, see bug 733331.
|
|
|
|
*/
|
|
|
|
enabledGsmTableTuples: [
|
|
|
|
[RIL.PDU_NL_IDENTIFIER_DEFAULT, RIL.PDU_NL_IDENTIFIER_DEFAULT],
|
|
|
|
],
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Use 16-bit reference number for concatenated outgoint messages.
|
|
|
|
*
|
|
|
|
* TODO: Support static/runtime settings, see bug 733331.
|
|
|
|
*/
|
|
|
|
segmentRef16Bit: false,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get valid SMS concatenation reference number.
|
|
|
|
*/
|
|
|
|
_segmentRef: 0,
|
|
|
|
get nextSegmentRef() {
|
|
|
|
let ref = this._segmentRef++;
|
|
|
|
|
|
|
|
this._segmentRef %= (this.segmentRef16Bit ? 65535 : 255);
|
|
|
|
|
|
|
|
// 0 is not a valid SMS concatenation reference number.
|
|
|
|
return ref + 1;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate encoded length using specified locking/single shift table
|
|
|
|
*
|
|
|
|
* @param message
|
|
|
|
* message string to be encoded.
|
|
|
|
* @param langTable
|
|
|
|
* locking shift table string.
|
|
|
|
* @param langShiftTable
|
|
|
|
* single shift table string.
|
|
|
|
* @param strict7BitEncoding
|
|
|
|
* Optional. Enable Latin characters replacement with corresponding
|
|
|
|
* ones in GSM SMS 7-bit default alphabet.
|
|
|
|
*
|
|
|
|
* @return encoded length in septets.
|
|
|
|
*
|
|
|
|
* @note that the algorithm used in this function must match exactly with
|
|
|
|
* GsmPDUHelper#writeStringAsSeptets.
|
|
|
|
*/
|
2014-01-13 02:44:40 +00:00
|
|
|
_countGsm7BitSeptets: function(message, langTable, langShiftTable, strict7BitEncoding) {
|
2013-09-07 11:09:54 +00:00
|
|
|
let length = 0;
|
|
|
|
for (let msgIndex = 0; msgIndex < message.length; msgIndex++) {
|
|
|
|
let c = message.charAt(msgIndex);
|
|
|
|
if (strict7BitEncoding) {
|
|
|
|
c = RIL.GSM_SMS_STRICT_7BIT_CHARMAP[c] || c;
|
|
|
|
}
|
|
|
|
|
|
|
|
let septet = langTable.indexOf(c);
|
|
|
|
|
|
|
|
// According to 3GPP TS 23.038, section 6.1.1 General notes, "The
|
|
|
|
// characters marked '1)' are not used but are displayed as a space."
|
|
|
|
if (septet == RIL.PDU_NL_EXTENDED_ESCAPE) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (septet >= 0) {
|
|
|
|
length++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
septet = langShiftTable.indexOf(c);
|
|
|
|
if (septet < 0) {
|
|
|
|
if (!strict7BitEncoding) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bug 816082, when strict7BitEncoding is enabled, we should replace
|
|
|
|
// characters that can't be encoded with GSM 7-Bit alphabets with '*'.
|
2013-11-21 14:09:14 +00:00
|
|
|
c = "*";
|
2013-09-07 11:09:54 +00:00
|
|
|
if (langTable.indexOf(c) >= 0) {
|
|
|
|
length++;
|
|
|
|
} else if (langShiftTable.indexOf(c) >= 0) {
|
|
|
|
length += 2;
|
|
|
|
} else {
|
|
|
|
// We can't even encode a '*' character with current configuration.
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// According to 3GPP TS 23.038 B.2, "This code represents a control
|
|
|
|
// character and therefore must not be used for language specific
|
|
|
|
// characters."
|
|
|
|
if (septet == RIL.PDU_NL_RESERVED_CONTROL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The character is not found in locking shfit table, but could be
|
|
|
|
// encoded as <escape><char> with single shift table. Note that it's
|
|
|
|
// still possible for septet to has the value of PDU_NL_EXTENDED_ESCAPE,
|
|
|
|
// but we can display it as a space in this case as said in previous
|
|
|
|
// comment.
|
|
|
|
length += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return length;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate user data length of specified message string encoded in GSM 7Bit
|
|
|
|
* alphabets.
|
|
|
|
*
|
|
|
|
* @param message
|
|
|
|
* a message string to be encoded.
|
|
|
|
* @param strict7BitEncoding
|
|
|
|
* Optional. Enable Latin characters replacement with corresponding
|
|
|
|
* ones in GSM SMS 7-bit default alphabet.
|
|
|
|
*
|
|
|
|
* @return null or an options object with attributes `dcs`,
|
|
|
|
* `userDataHeaderLength`, `encodedFullBodyLength`, `langIndex`,
|
|
|
|
* `langShiftIndex`, `segmentMaxSeq` set.
|
|
|
|
*
|
|
|
|
* @see #_calculateUserDataLength().
|
|
|
|
*/
|
2014-01-13 02:44:40 +00:00
|
|
|
_calculateUserDataLength7Bit: function(message, strict7BitEncoding) {
|
2013-09-07 11:09:54 +00:00
|
|
|
let options = null;
|
|
|
|
let minUserDataSeptets = Number.MAX_VALUE;
|
|
|
|
for (let i = 0; i < this.enabledGsmTableTuples.length; i++) {
|
|
|
|
let [langIndex, langShiftIndex] = this.enabledGsmTableTuples[i];
|
|
|
|
|
|
|
|
const langTable = RIL.PDU_NL_LOCKING_SHIFT_TABLES[langIndex];
|
|
|
|
const langShiftTable = RIL.PDU_NL_SINGLE_SHIFT_TABLES[langShiftIndex];
|
|
|
|
|
|
|
|
let bodySeptets = this._countGsm7BitSeptets(message,
|
|
|
|
langTable,
|
|
|
|
langShiftTable,
|
|
|
|
strict7BitEncoding);
|
|
|
|
if (bodySeptets < 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
let headerLen = 0;
|
|
|
|
if (langIndex != RIL.PDU_NL_IDENTIFIER_DEFAULT) {
|
|
|
|
headerLen += 3; // IEI + len + langIndex
|
|
|
|
}
|
|
|
|
if (langShiftIndex != RIL.PDU_NL_IDENTIFIER_DEFAULT) {
|
|
|
|
headerLen += 3; // IEI + len + langShiftIndex
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate full user data length, note the extra byte is for header len
|
|
|
|
let headerSeptets = Math.ceil((headerLen ? headerLen + 1 : 0) * 8 / 7);
|
|
|
|
let segmentSeptets = RIL.PDU_MAX_USER_DATA_7BIT;
|
|
|
|
if ((bodySeptets + headerSeptets) > segmentSeptets) {
|
|
|
|
headerLen += this.segmentRef16Bit ? 6 : 5;
|
|
|
|
headerSeptets = Math.ceil((headerLen + 1) * 8 / 7);
|
|
|
|
segmentSeptets -= headerSeptets;
|
|
|
|
}
|
|
|
|
|
|
|
|
let segments = Math.ceil(bodySeptets / segmentSeptets);
|
|
|
|
let userDataSeptets = bodySeptets + headerSeptets * segments;
|
|
|
|
if (userDataSeptets >= minUserDataSeptets) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
minUserDataSeptets = userDataSeptets;
|
|
|
|
|
|
|
|
options = {
|
|
|
|
dcs: RIL.PDU_DCS_MSG_CODING_7BITS_ALPHABET,
|
|
|
|
encodedFullBodyLength: bodySeptets,
|
|
|
|
userDataHeaderLength: headerLen,
|
|
|
|
langIndex: langIndex,
|
|
|
|
langShiftIndex: langShiftIndex,
|
|
|
|
segmentMaxSeq: segments,
|
|
|
|
segmentChars: segmentSeptets,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return options;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate user data length of specified message string encoded in UCS2.
|
|
|
|
*
|
|
|
|
* @param message
|
|
|
|
* a message string to be encoded.
|
|
|
|
*
|
|
|
|
* @return an options object with attributes `dcs`, `userDataHeaderLength`,
|
|
|
|
* `encodedFullBodyLength`, `segmentMaxSeq` set.
|
|
|
|
*
|
|
|
|
* @see #_calculateUserDataLength().
|
|
|
|
*/
|
2014-01-13 02:44:40 +00:00
|
|
|
_calculateUserDataLengthUCS2: function(message) {
|
2013-09-07 11:09:54 +00:00
|
|
|
let bodyChars = message.length;
|
|
|
|
let headerLen = 0;
|
|
|
|
let headerChars = Math.ceil((headerLen ? headerLen + 1 : 0) / 2);
|
|
|
|
let segmentChars = RIL.PDU_MAX_USER_DATA_UCS2;
|
|
|
|
if ((bodyChars + headerChars) > segmentChars) {
|
|
|
|
headerLen += this.segmentRef16Bit ? 6 : 5;
|
|
|
|
headerChars = Math.ceil((headerLen + 1) / 2);
|
|
|
|
segmentChars -= headerChars;
|
|
|
|
}
|
|
|
|
|
|
|
|
let segments = Math.ceil(bodyChars / segmentChars);
|
|
|
|
|
|
|
|
return {
|
|
|
|
dcs: RIL.PDU_DCS_MSG_CODING_16BITS_ALPHABET,
|
|
|
|
encodedFullBodyLength: bodyChars * 2,
|
|
|
|
userDataHeaderLength: headerLen,
|
|
|
|
segmentMaxSeq: segments,
|
|
|
|
segmentChars: segmentChars,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate user data length and its encoding.
|
|
|
|
*
|
|
|
|
* @param message
|
|
|
|
* a message string to be encoded.
|
|
|
|
* @param strict7BitEncoding
|
|
|
|
* Optional. Enable Latin characters replacement with corresponding
|
|
|
|
* ones in GSM SMS 7-bit default alphabet.
|
|
|
|
*
|
|
|
|
* @return an options object with some or all of following attributes set:
|
|
|
|
*
|
|
|
|
* @param dcs
|
|
|
|
* Data coding scheme. One of the PDU_DCS_MSG_CODING_*BITS_ALPHABET
|
|
|
|
* constants.
|
|
|
|
* @param userDataHeaderLength
|
|
|
|
* Length of embedded user data header, in bytes. The whole header
|
|
|
|
* size will be userDataHeaderLength + 1; 0 for no header.
|
|
|
|
* @param encodedFullBodyLength
|
|
|
|
* Length of the message body when encoded with the given DCS. For
|
|
|
|
* UCS2, in bytes; for 7-bit, in septets.
|
|
|
|
* @param langIndex
|
|
|
|
* Table index used for normal 7-bit encoded character lookup.
|
|
|
|
* @param langShiftIndex
|
|
|
|
* Table index used for escaped 7-bit encoded character lookup.
|
|
|
|
* @param segmentMaxSeq
|
|
|
|
* Max sequence number of a multi-part messages, or 1 for single one.
|
|
|
|
* This number might not be accurate for a multi-part message until
|
|
|
|
* it's processed by #_fragmentText() again.
|
|
|
|
*/
|
2014-01-13 02:44:40 +00:00
|
|
|
_calculateUserDataLength: function(message, strict7BitEncoding) {
|
2013-09-07 11:09:54 +00:00
|
|
|
let options = this._calculateUserDataLength7Bit(message, strict7BitEncoding);
|
|
|
|
if (!options) {
|
|
|
|
options = this._calculateUserDataLengthUCS2(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DEBUG) this.debug("_calculateUserDataLength: " + JSON.stringify(options));
|
|
|
|
return options;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fragment GSM 7-Bit encodable string for transmission.
|
|
|
|
*
|
|
|
|
* @param text
|
|
|
|
* text string to be fragmented.
|
|
|
|
* @param langTable
|
|
|
|
* locking shift table string.
|
|
|
|
* @param langShiftTable
|
|
|
|
* single shift table string.
|
|
|
|
* @param segmentSeptets
|
|
|
|
* Number of available spetets per segment.
|
|
|
|
* @param strict7BitEncoding
|
|
|
|
* Optional. Enable Latin characters replacement with corresponding
|
|
|
|
* ones in GSM SMS 7-bit default alphabet.
|
|
|
|
*
|
|
|
|
* @return an array of objects. See #_fragmentText() for detailed definition.
|
|
|
|
*/
|
2014-01-13 02:44:40 +00:00
|
|
|
_fragmentText7Bit: function(text, langTable, langShiftTable, segmentSeptets, strict7BitEncoding) {
|
2013-09-07 11:09:54 +00:00
|
|
|
let ret = [];
|
|
|
|
let body = "", len = 0;
|
2014-01-18 14:13:35 +00:00
|
|
|
// If the message is empty, we only push the empty message to ret.
|
|
|
|
if (text.length === 0) {
|
|
|
|
ret.push({
|
|
|
|
body: text,
|
|
|
|
encodedBodyLength: text.length,
|
|
|
|
});
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-09-07 11:09:54 +00:00
|
|
|
for (let i = 0, inc = 0; i < text.length; i++) {
|
|
|
|
let c = text.charAt(i);
|
|
|
|
if (strict7BitEncoding) {
|
|
|
|
c = RIL.GSM_SMS_STRICT_7BIT_CHARMAP[c] || c;
|
|
|
|
}
|
|
|
|
|
|
|
|
let septet = langTable.indexOf(c);
|
|
|
|
if (septet == RIL.PDU_NL_EXTENDED_ESCAPE) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (septet >= 0) {
|
|
|
|
inc = 1;
|
|
|
|
} else {
|
|
|
|
septet = langShiftTable.indexOf(c);
|
|
|
|
if (septet == RIL.PDU_NL_RESERVED_CONTROL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
inc = 2;
|
|
|
|
if (septet < 0) {
|
|
|
|
if (!strict7BitEncoding) {
|
|
|
|
throw new Error("Given text cannot be encoded with GSM 7-bit Alphabet!");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bug 816082, when strict7BitEncoding is enabled, we should replace
|
|
|
|
// characters that can't be encoded with GSM 7-Bit alphabets with '*'.
|
2013-11-21 14:09:14 +00:00
|
|
|
c = "*";
|
2013-09-07 11:09:54 +00:00
|
|
|
if (langTable.indexOf(c) >= 0) {
|
|
|
|
inc = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((len + inc) > segmentSeptets) {
|
|
|
|
ret.push({
|
|
|
|
body: body,
|
|
|
|
encodedBodyLength: len,
|
|
|
|
});
|
|
|
|
body = c;
|
|
|
|
len = inc;
|
|
|
|
} else {
|
|
|
|
body += c;
|
|
|
|
len += inc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len) {
|
|
|
|
ret.push({
|
|
|
|
body: body,
|
|
|
|
encodedBodyLength: len,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fragment UCS2 encodable string for transmission.
|
|
|
|
*
|
|
|
|
* @param text
|
|
|
|
* text string to be fragmented.
|
|
|
|
* @param segmentChars
|
|
|
|
* Number of available characters per segment.
|
|
|
|
*
|
|
|
|
* @return an array of objects. See #_fragmentText() for detailed definition.
|
|
|
|
*/
|
2014-01-13 02:44:40 +00:00
|
|
|
_fragmentTextUCS2: function(text, segmentChars) {
|
2013-09-07 11:09:54 +00:00
|
|
|
let ret = [];
|
2014-01-18 14:13:35 +00:00
|
|
|
// If the message is empty, we only push the empty message to ret.
|
|
|
|
if (text.length === 0) {
|
|
|
|
ret.push({
|
|
|
|
body: text,
|
|
|
|
encodedBodyLength: text.length,
|
|
|
|
});
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-09-07 11:09:54 +00:00
|
|
|
for (let offset = 0; offset < text.length; offset += segmentChars) {
|
|
|
|
let str = text.substr(offset, segmentChars);
|
|
|
|
ret.push({
|
|
|
|
body: str,
|
|
|
|
encodedBodyLength: str.length * 2,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fragment string for transmission.
|
|
|
|
*
|
|
|
|
* Fragment input text string into an array of objects that contains
|
|
|
|
* attributes `body`, substring for this segment, `encodedBodyLength`,
|
|
|
|
* length of the encoded segment body in septets.
|
|
|
|
*
|
|
|
|
* @param text
|
|
|
|
* Text string to be fragmented.
|
|
|
|
* @param options
|
|
|
|
* Optional pre-calculated option object. The output array will be
|
|
|
|
* stored at options.segments if there are multiple segments.
|
|
|
|
* @param strict7BitEncoding
|
|
|
|
* Optional. Enable Latin characters replacement with corresponding
|
|
|
|
* ones in GSM SMS 7-bit default alphabet.
|
|
|
|
*
|
|
|
|
* @return Populated options object.
|
|
|
|
*/
|
2014-01-13 02:44:40 +00:00
|
|
|
_fragmentText: function(text, options, strict7BitEncoding) {
|
2013-09-07 11:09:54 +00:00
|
|
|
if (!options) {
|
|
|
|
options = this._calculateUserDataLength(text, strict7BitEncoding);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.dcs == RIL.PDU_DCS_MSG_CODING_7BITS_ALPHABET) {
|
|
|
|
const langTable = RIL.PDU_NL_LOCKING_SHIFT_TABLES[options.langIndex];
|
|
|
|
const langShiftTable = RIL.PDU_NL_SINGLE_SHIFT_TABLES[options.langShiftIndex];
|
|
|
|
options.segments = this._fragmentText7Bit(text,
|
|
|
|
langTable, langShiftTable,
|
|
|
|
options.segmentChars,
|
|
|
|
strict7BitEncoding);
|
|
|
|
} else {
|
|
|
|
options.segments = this._fragmentTextUCS2(text,
|
|
|
|
options.segmentChars);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Re-sync options.segmentMaxSeq with actual length of returning array.
|
|
|
|
options.segmentMaxSeq = options.segments.length;
|
|
|
|
|
|
|
|
return options;
|
|
|
|
},
|
|
|
|
|
2014-01-13 02:44:40 +00:00
|
|
|
getSegmentInfoForText: function(text, request) {
|
2013-09-07 11:09:54 +00:00
|
|
|
let strict7BitEncoding;
|
|
|
|
try {
|
|
|
|
strict7BitEncoding = Services.prefs.getBoolPref("dom.sms.strict7BitEncoding");
|
|
|
|
} catch (e) {
|
|
|
|
strict7BitEncoding = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
let options = this._fragmentText(text, null, strict7BitEncoding);
|
|
|
|
let charsInLastSegment;
|
|
|
|
if (options.segmentMaxSeq) {
|
|
|
|
let lastSegment = options.segments[options.segmentMaxSeq - 1];
|
|
|
|
charsInLastSegment = lastSegment.encodedBodyLength;
|
|
|
|
if (options.dcs == RIL.PDU_DCS_MSG_CODING_16BITS_ALPHABET) {
|
|
|
|
// In UCS2 encoding, encodedBodyLength is in octets.
|
|
|
|
charsInLastSegment /= 2;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
charsInLastSegment = 0;
|
|
|
|
}
|
|
|
|
|
2014-08-04 09:01:36 +00:00
|
|
|
request.notifySegmentInfoForTextGot(options.segmentMaxSeq,
|
|
|
|
options.segmentChars,
|
|
|
|
options.segmentChars - charsInLastSegment);
|
2013-09-07 11:09:54 +00:00
|
|
|
},
|
|
|
|
|
2014-01-13 02:44:40 +00:00
|
|
|
getSmscAddress: function(request) {
|
2013-09-16 02:12:40 +00:00
|
|
|
this.workerMessenger.send("getSmscAddress",
|
|
|
|
null,
|
|
|
|
(function(response) {
|
|
|
|
if (!response.errorMsg) {
|
|
|
|
request.notifyGetSmscAddress(response.smscAddress);
|
|
|
|
} else {
|
2014-08-22 07:28:02 +00:00
|
|
|
request.notifyGetSmscAddressFailed(Ci.nsIMobileMessageCallback.NOT_FOUND_ERROR);
|
2013-09-16 02:12:40 +00:00
|
|
|
}
|
|
|
|
}).bind(this));
|
|
|
|
},
|
|
|
|
|
2014-01-13 02:44:40 +00:00
|
|
|
sendSMS: function(number, message, silent, request) {
|
2013-09-07 11:09:54 +00:00
|
|
|
let strict7BitEncoding;
|
|
|
|
try {
|
|
|
|
strict7BitEncoding = Services.prefs.getBoolPref("dom.sms.strict7BitEncoding");
|
|
|
|
} catch (e) {
|
|
|
|
strict7BitEncoding = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
let options = this._fragmentText(message, null, strict7BitEncoding);
|
|
|
|
options.number = PhoneNumberUtils.normalize(number);
|
|
|
|
let requestStatusReport;
|
|
|
|
try {
|
|
|
|
requestStatusReport =
|
|
|
|
Services.prefs.getBoolPref("dom.sms.requestStatusReport");
|
|
|
|
} catch (e) {
|
|
|
|
requestStatusReport = true;
|
|
|
|
}
|
|
|
|
options.requestStatusReport = requestStatusReport && !silent;
|
|
|
|
if (options.segmentMaxSeq > 1) {
|
|
|
|
options.segmentRef16Bit = this.segmentRef16Bit;
|
|
|
|
options.segmentRef = this.nextSegmentRef;
|
|
|
|
}
|
|
|
|
|
|
|
|
let notifyResult = (function notifyResult(rv, domMessage) {
|
2014-02-20 04:21:11 +00:00
|
|
|
if (!Components.isSuccessCode(rv)) {
|
|
|
|
if (DEBUG) this.debug("Error! Fail to save sending message! rv = " + rv);
|
|
|
|
request.notifySendMessageFailed(
|
2014-04-28 05:28:12 +00:00
|
|
|
gMobileMessageDatabaseService.translateCrErrorToMessageCallbackError(rv),
|
|
|
|
domMessage);
|
2014-02-20 04:21:11 +00:00
|
|
|
Services.obs.notifyObservers(domMessage, kSmsFailedObserverTopic, null);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-07 11:09:54 +00:00
|
|
|
if (!silent) {
|
|
|
|
Services.obs.notifyObservers(domMessage, kSmsSendingObserverTopic, null);
|
|
|
|
}
|
|
|
|
|
2014-09-21 07:24:43 +00:00
|
|
|
let connection =
|
|
|
|
gMobileConnectionService.getItemByServiceId(this.clientId);
|
2013-09-07 11:09:54 +00:00
|
|
|
// If the radio is disabled or the SIM card is not ready, just directly
|
|
|
|
// return with the corresponding error code.
|
|
|
|
let errorCode;
|
2014-09-21 07:24:43 +00:00
|
|
|
let radioState = connection && connection.radioState;
|
2013-09-07 11:09:54 +00:00
|
|
|
if (!PhoneNumberUtils.isPlainPhoneNumber(options.number)) {
|
|
|
|
if (DEBUG) this.debug("Error! Address is invalid when sending SMS: " +
|
|
|
|
options.number);
|
|
|
|
errorCode = Ci.nsIMobileMessageCallback.INVALID_ADDRESS_ERROR;
|
2014-10-24 09:12:35 +00:00
|
|
|
} else if (radioState == Ci.nsIMobileConnection.MOBILE_RADIO_STATE_UNKNOWN ||
|
|
|
|
radioState == Ci.nsIMobileConnection.MOBILE_RADIO_STATE_DISABLED) {
|
2013-09-07 11:09:54 +00:00
|
|
|
if (DEBUG) this.debug("Error! Radio is disabled when sending SMS.");
|
|
|
|
errorCode = Ci.nsIMobileMessageCallback.RADIO_DISABLED_ERROR;
|
2014-09-03 11:31:00 +00:00
|
|
|
} else if (this.rilContext.cardState != Ci.nsIIccProvider.CARD_STATE_READY) {
|
2013-09-07 11:09:54 +00:00
|
|
|
if (DEBUG) this.debug("Error! SIM card is not ready when sending SMS.");
|
|
|
|
errorCode = Ci.nsIMobileMessageCallback.NO_SIM_CARD_ERROR;
|
|
|
|
}
|
|
|
|
if (errorCode) {
|
|
|
|
if (silent) {
|
2014-04-28 05:28:12 +00:00
|
|
|
request.notifySendMessageFailed(errorCode, domMessage);
|
2013-09-07 11:09:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gMobileMessageDatabaseService
|
|
|
|
.setMessageDeliveryByMessageId(domMessage.id,
|
|
|
|
null,
|
|
|
|
DOM_MOBILE_MESSAGE_DELIVERY_ERROR,
|
|
|
|
RIL.GECKO_SMS_DELIVERY_STATUS_ERROR,
|
|
|
|
null,
|
|
|
|
function notifyResult(rv, domMessage) {
|
|
|
|
// TODO bug 832140 handle !Components.isSuccessCode(rv)
|
2014-04-28 05:28:12 +00:00
|
|
|
request.notifySendMessageFailed(errorCode, domMessage);
|
2013-09-07 11:09:54 +00:00
|
|
|
Services.obs.notifyObservers(domMessage, kSmsFailedObserverTopic, null);
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Keep current SMS message info for sent/delivered notifications
|
|
|
|
let context = {
|
|
|
|
request: request,
|
|
|
|
sms: domMessage,
|
|
|
|
requestStatusReport: options.requestStatusReport,
|
|
|
|
silent: silent
|
|
|
|
};
|
|
|
|
|
|
|
|
// This is the entry point starting to send SMS.
|
|
|
|
this.workerMessenger.send("sendSMS", options,
|
|
|
|
(function(context, response) {
|
|
|
|
if (response.errorMsg) {
|
|
|
|
// Failed to send SMS out.
|
|
|
|
let error = Ci.nsIMobileMessageCallback.UNKNOWN_ERROR;
|
|
|
|
switch (response.errorMsg) {
|
|
|
|
case RIL.ERROR_RADIO_NOT_AVAILABLE:
|
|
|
|
error = Ci.nsIMobileMessageCallback.NO_SIGNAL_ERROR;
|
|
|
|
break;
|
2013-09-09 13:48:07 +00:00
|
|
|
case RIL.ERROR_FDN_CHECK_FAILURE:
|
|
|
|
error = Ci.nsIMobileMessageCallback.FDN_CHECK_ERROR;
|
|
|
|
break;
|
2013-09-07 11:09:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (context.silent) {
|
2014-04-28 05:28:12 +00:00
|
|
|
// There is no way to modify nsIDOMMozSmsMessage attributes as they
|
|
|
|
// are read only so we just create a new sms instance to send along
|
|
|
|
// with the notification.
|
|
|
|
let sms = context.sms;
|
|
|
|
context.request.notifySendMessageFailed(
|
|
|
|
error,
|
|
|
|
gMobileMessageService.createSmsMessage(sms.id,
|
|
|
|
sms.threadId,
|
|
|
|
sms.iccId,
|
|
|
|
DOM_MOBILE_MESSAGE_DELIVERY_ERROR,
|
|
|
|
RIL.GECKO_SMS_DELIVERY_STATUS_ERROR,
|
|
|
|
sms.sender,
|
|
|
|
sms.receiver,
|
|
|
|
sms.body,
|
|
|
|
sms.messageClass,
|
|
|
|
sms.timestamp,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
sms.read));
|
2013-09-07 11:09:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
gMobileMessageDatabaseService
|
|
|
|
.setMessageDeliveryByMessageId(context.sms.id,
|
|
|
|
null,
|
|
|
|
DOM_MOBILE_MESSAGE_DELIVERY_ERROR,
|
|
|
|
RIL.GECKO_SMS_DELIVERY_STATUS_ERROR,
|
|
|
|
null,
|
|
|
|
function notifyResult(rv, domMessage) {
|
|
|
|
// TODO bug 832140 handle !Components.isSuccessCode(rv)
|
2014-04-28 05:28:12 +00:00
|
|
|
context.request.notifySendMessageFailed(error, domMessage);
|
2013-09-07 11:09:54 +00:00
|
|
|
Services.obs.notifyObservers(domMessage, kSmsFailedObserverTopic, null);
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
} // End of send failure.
|
|
|
|
|
|
|
|
if (response.deliveryStatus) {
|
|
|
|
// Message delivery.
|
|
|
|
gMobileMessageDatabaseService
|
|
|
|
.setMessageDeliveryByMessageId(context.sms.id,
|
|
|
|
null,
|
|
|
|
context.sms.delivery,
|
|
|
|
response.deliveryStatus,
|
|
|
|
null,
|
2013-11-01 14:45:57 +00:00
|
|
|
(function notifyResult(rv, domMessage) {
|
2013-09-07 11:09:54 +00:00
|
|
|
// TODO bug 832140 handle !Components.isSuccessCode(rv)
|
2013-11-01 09:55:54 +00:00
|
|
|
|
|
|
|
let topic = (response.deliveryStatus ==
|
|
|
|
RIL.GECKO_SMS_DELIVERY_STATUS_SUCCESS)
|
2013-09-07 11:09:54 +00:00
|
|
|
? kSmsDeliverySuccessObserverTopic
|
|
|
|
: kSmsDeliveryErrorObserverTopic;
|
2013-11-01 09:55:54 +00:00
|
|
|
|
2013-11-21 14:09:14 +00:00
|
|
|
// Broadcasting a "sms-delivery-success" system message to open apps.
|
2013-11-01 09:55:54 +00:00
|
|
|
if (topic == kSmsDeliverySuccessObserverTopic) {
|
2014-10-24 03:33:01 +00:00
|
|
|
this.broadcastSmsSystemMessage(
|
|
|
|
Ci.nsISmsMessenger.NOTIFICATION_TYPE_DELIVERY_SUCCESS, domMessage);
|
2013-11-01 09:55:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Notifying observers the delivery status is updated.
|
2013-09-07 11:09:54 +00:00
|
|
|
Services.obs.notifyObservers(domMessage, topic, null);
|
2013-11-01 14:45:57 +00:00
|
|
|
}).bind(this));
|
2013-09-07 11:09:54 +00:00
|
|
|
|
|
|
|
// Send transaction has ended completely.
|
|
|
|
return false;
|
|
|
|
} // End of message delivery.
|
|
|
|
|
|
|
|
// Message sent.
|
|
|
|
if (context.silent) {
|
2013-11-01 12:00:55 +00:00
|
|
|
// There is no way to modify nsIDOMMozSmsMessage attributes as they
|
|
|
|
// are read only so we just create a new sms instance to send along
|
|
|
|
// with the notification.
|
2013-09-07 11:09:54 +00:00
|
|
|
let sms = context.sms;
|
|
|
|
context.request.notifyMessageSent(
|
|
|
|
gMobileMessageService.createSmsMessage(sms.id,
|
|
|
|
sms.threadId,
|
2013-11-02 10:17:25 +00:00
|
|
|
sms.iccId,
|
2013-09-07 11:09:54 +00:00
|
|
|
DOM_MOBILE_MESSAGE_DELIVERY_SENT,
|
|
|
|
sms.deliveryStatus,
|
|
|
|
sms.sender,
|
|
|
|
sms.receiver,
|
|
|
|
sms.body,
|
|
|
|
sms.messageClass,
|
|
|
|
sms.timestamp,
|
2013-09-23 02:31:32 +00:00
|
|
|
Date.now(),
|
2013-11-01 12:00:55 +00:00
|
|
|
0,
|
2013-09-07 11:09:54 +00:00
|
|
|
sms.read));
|
|
|
|
// We don't wait for SMS-DELIVER-REPORT for silent one.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
gMobileMessageDatabaseService
|
|
|
|
.setMessageDeliveryByMessageId(context.sms.id,
|
|
|
|
null,
|
|
|
|
DOM_MOBILE_MESSAGE_DELIVERY_SENT,
|
|
|
|
context.sms.deliveryStatus,
|
|
|
|
null,
|
|
|
|
(function notifyResult(rv, domMessage) {
|
|
|
|
// TODO bug 832140 handle !Components.isSuccessCode(rv)
|
|
|
|
|
|
|
|
if (context.requestStatusReport) {
|
|
|
|
context.sms = domMessage;
|
|
|
|
}
|
|
|
|
|
2014-10-24 03:33:01 +00:00
|
|
|
this.broadcastSmsSystemMessage(
|
|
|
|
Ci.nsISmsMessenger.NOTIFICATION_TYPE_SENT, domMessage);
|
2013-09-07 11:09:54 +00:00
|
|
|
context.request.notifyMessageSent(domMessage);
|
|
|
|
Services.obs.notifyObservers(domMessage, kSmsSentObserverTopic, null);
|
|
|
|
}).bind(this));
|
|
|
|
|
|
|
|
// Only keep current context if we have requested for delivery report.
|
|
|
|
return context.requestStatusReport;
|
|
|
|
}).bind(this, context)); // End of |workerMessenger.send| callback.
|
|
|
|
}).bind(this); // End of DB saveSendingMessage callback.
|
|
|
|
|
|
|
|
let sendingMessage = {
|
|
|
|
type: "sms",
|
2013-10-15 02:42:49 +00:00
|
|
|
sender: this.getPhoneNumber(),
|
2013-09-07 11:09:54 +00:00
|
|
|
receiver: number,
|
|
|
|
body: message,
|
|
|
|
deliveryStatusRequested: options.requestStatusReport,
|
2013-11-02 10:17:25 +00:00
|
|
|
timestamp: Date.now(),
|
|
|
|
iccId: this.getIccId()
|
2013-09-07 11:09:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (silent) {
|
|
|
|
let delivery = DOM_MOBILE_MESSAGE_DELIVERY_SENDING;
|
2013-09-23 02:31:32 +00:00
|
|
|
let deliveryStatus = RIL.GECKO_SMS_DELIVERY_STATUS_PENDING;
|
2013-09-07 11:09:54 +00:00
|
|
|
let domMessage =
|
|
|
|
gMobileMessageService.createSmsMessage(-1, // id
|
|
|
|
0, // threadId
|
2013-11-02 10:17:25 +00:00
|
|
|
sendingMessage.iccId,
|
2013-09-07 11:09:54 +00:00
|
|
|
delivery,
|
|
|
|
deliveryStatus,
|
|
|
|
sendingMessage.sender,
|
|
|
|
sendingMessage.receiver,
|
|
|
|
sendingMessage.body,
|
|
|
|
"normal", // message class
|
|
|
|
sendingMessage.timestamp,
|
2013-11-01 12:00:55 +00:00
|
|
|
0,
|
2013-09-23 02:31:32 +00:00
|
|
|
0,
|
2013-09-07 11:09:54 +00:00
|
|
|
false);
|
|
|
|
notifyResult(Cr.NS_OK, domMessage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-21 14:09:14 +00:00
|
|
|
let id = gMobileMessageDatabaseService.saveSendingMessage(
|
|
|
|
sendingMessage, notifyResult);
|
2013-09-07 11:09:54 +00:00
|
|
|
},
|
|
|
|
|
2013-12-03 06:18:32 +00:00
|
|
|
// TODO: Bug 928861 - B2G NetworkManager: Provide a more generic function
|
|
|
|
// for connecting
|
2014-11-25 01:44:33 +00:00
|
|
|
setupDataCallByType: function(networkType) {
|
2013-12-03 06:18:32 +00:00
|
|
|
let connHandler = gDataConnectionManager.getConnectionHandler(this.clientId);
|
2014-11-25 01:44:33 +00:00
|
|
|
connHandler.setupDataCallByType(networkType);
|
2013-06-28 01:46:00 +00:00
|
|
|
},
|
2013-01-23 04:05:34 +00:00
|
|
|
|
2013-12-03 06:18:32 +00:00
|
|
|
// TODO: Bug 928861 - B2G NetworkManager: Provide a more generic function
|
|
|
|
// for connecting
|
2014-11-25 01:44:33 +00:00
|
|
|
deactivateDataCallByType: function(networkType) {
|
2013-12-03 06:18:32 +00:00
|
|
|
let connHandler = gDataConnectionManager.getConnectionHandler(this.clientId);
|
2014-11-25 01:44:33 +00:00
|
|
|
connHandler.deactivateDataCallByType(networkType);
|
2013-06-28 01:46:00 +00:00
|
|
|
},
|
|
|
|
|
2013-12-03 06:18:32 +00:00
|
|
|
// TODO: Bug 904514 - [meta] NetworkManager enhancement
|
2014-11-25 01:44:33 +00:00
|
|
|
getDataCallStateByType: function(networkType) {
|
2013-12-03 06:18:32 +00:00
|
|
|
let connHandler = gDataConnectionManager.getConnectionHandler(this.clientId);
|
2014-11-25 01:44:33 +00:00
|
|
|
return connHandler.getDataCallStateByType(networkType);
|
2012-09-26 12:57:37 +00:00
|
|
|
},
|
|
|
|
|
2014-01-13 02:44:44 +00:00
|
|
|
sendWorkerMessage: function(rilMessageType, message, callback) {
|
2014-02-10 11:55:22 +00:00
|
|
|
// Special handler for setRadioEnabled.
|
|
|
|
if (rilMessageType === "setRadioEnabled") {
|
|
|
|
// Forward it to gRadioEnabledController.
|
|
|
|
gRadioEnabledController.setRadioEnabled(this.clientId, message,
|
|
|
|
callback.handleResponse);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-21 09:46:58 +00:00
|
|
|
if (callback) {
|
|
|
|
this.workerMessenger.send(rilMessageType, message, function(response) {
|
|
|
|
return callback.handleResponse(response);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.workerMessenger.send(rilMessageType, message);
|
|
|
|
}
|
2014-06-24 23:27:00 +00:00
|
|
|
},
|
2012-04-12 04:01:49 +00:00
|
|
|
};
|
2012-03-12 23:46:08 +00:00
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
function DataCall(clientId, apnSetting) {
|
|
|
|
this.clientId = clientId;
|
|
|
|
this.apnProfile = {
|
|
|
|
apn: apnSetting.apn,
|
|
|
|
user: apnSetting.user,
|
|
|
|
password: apnSetting.password,
|
|
|
|
authType: apnSetting.authtype,
|
|
|
|
protocol: apnSetting.protocol,
|
|
|
|
roaming_protocol: apnSetting.roaming_protocol
|
|
|
|
};
|
|
|
|
this.linkInfo = {
|
|
|
|
cid: null,
|
|
|
|
ifname: null,
|
|
|
|
ips: [],
|
|
|
|
prefixLengths: [],
|
|
|
|
dnses: [],
|
|
|
|
gateways: []
|
|
|
|
};
|
|
|
|
this.state = RIL.GECKO_NETWORK_STATE_UNKNOWN;
|
|
|
|
this.requestedNetworkIfaces = [];
|
2012-09-26 12:52:21 +00:00
|
|
|
}
|
2012-03-12 23:46:08 +00:00
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
DataCall.prototype = {
|
2012-06-01 21:09:59 +00:00
|
|
|
/**
|
|
|
|
* Standard values for the APN connection retry process
|
|
|
|
* Retry funcion: time(secs) = A * numer_of_retries^2 + B
|
|
|
|
*/
|
|
|
|
NETWORK_APNRETRY_FACTOR: 8,
|
|
|
|
NETWORK_APNRETRY_ORIGIN: 3,
|
|
|
|
NETWORK_APNRETRY_MAXRETRIES: 10,
|
|
|
|
|
|
|
|
// Event timer for connection retries
|
|
|
|
timer: null,
|
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
// APN failed connections. Retry counter
|
|
|
|
apnRetryCounter: 0,
|
2013-11-02 10:17:58 +00:00
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
// Array to hold RILNetworkInterfaces that requested this DataCall.
|
|
|
|
requestedNetworkIfaces: null,
|
|
|
|
|
2014-10-08 18:24:00 +00:00
|
|
|
// Holds the pdp type sent to ril worker.
|
|
|
|
pdptype: null,
|
|
|
|
|
|
|
|
// Holds the authentication type sent to ril worker.
|
|
|
|
chappap: null,
|
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
dataCallError: function(message) {
|
2014-11-24 02:15:25 +00:00
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("Data call error on APN " + message.apn + ": " +
|
|
|
|
message.errorMsg + " (" + message.status + "), retry time: " +
|
|
|
|
message.suggestedRetryTime);
|
|
|
|
}
|
2014-05-27 00:08:00 +00:00
|
|
|
this.state = RIL.GECKO_NETWORK_STATE_DISCONNECTED;
|
2014-11-24 02:15:25 +00:00
|
|
|
|
|
|
|
if (this.requestedNetworkIfaces.length === 0) {
|
|
|
|
if (DEBUG) this.debug("This DataCall is not requested anymore.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For suggestedRetryTime, the value of INT32_MAX(0x7fffffff) means no retry.
|
|
|
|
if (message.suggestedRetryTime === INT32_MAX ||
|
|
|
|
this.isPermanentFail(message.status, message.errorMsg)) {
|
|
|
|
if (DEBUG) this.debug("Data call error: no retry needed.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.retry(message.suggestedRetryTime);
|
2014-05-27 00:08:00 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
dataCallStateChanged: function(datacall) {
|
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("Data call ID: " + datacall.cid + ", interface name: " +
|
|
|
|
datacall.ifname + ", APN name: " + datacall.apn + ", state: " +
|
|
|
|
datacall.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.state == datacall.state &&
|
|
|
|
datacall.state != RIL.GECKO_NETWORK_STATE_CONNECTED) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (datacall.state) {
|
|
|
|
case RIL.GECKO_NETWORK_STATE_CONNECTED:
|
|
|
|
if (this.state == RIL.GECKO_NETWORK_STATE_CONNECTING) {
|
2014-11-24 02:15:25 +00:00
|
|
|
this.apnRetryCounter = 0;
|
2014-05-27 00:08:00 +00:00
|
|
|
this.linkInfo.cid = datacall.cid;
|
|
|
|
|
|
|
|
if (this.requestedNetworkIfaces.length === 0) {
|
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("State is connected, but no network interface requested" +
|
|
|
|
" this DataCall");
|
|
|
|
}
|
|
|
|
this.deactivate();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.linkInfo.ifname = datacall.ifname;
|
|
|
|
for (let entry of datacall.addresses) {
|
|
|
|
this.linkInfo.ips.push(entry.address);
|
|
|
|
this.linkInfo.prefixLengths.push(entry.prefixLength);
|
|
|
|
}
|
|
|
|
this.linkInfo.gateways = datacall.gateways.slice();
|
|
|
|
this.linkInfo.dnses = datacall.dnses.slice();
|
|
|
|
|
|
|
|
} else if (this.state == RIL.GECKO_NETWORK_STATE_CONNECTED) {
|
|
|
|
// configuration changed.
|
|
|
|
let changed = false;
|
|
|
|
if (this.linkInfo.ips.length != datacall.addresses.length) {
|
|
|
|
changed = true;
|
|
|
|
this.linkInfo.ips = [];
|
|
|
|
this.linkInfo.prefixLengths = [];
|
|
|
|
for (let entry of datacall.addresses) {
|
|
|
|
this.linkInfo.ips.push(entry.address);
|
|
|
|
this.linkInfo.prefixLengths.push(entry.prefixLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let reduceFunc = function(aRhs, aChanged, aElement, aIndex) {
|
|
|
|
return aChanged || (aElement != aRhs[aIndex]);
|
|
|
|
};
|
|
|
|
for (let field of ["gateways", "dnses"]) {
|
|
|
|
let lhs = this.linkInfo[field], rhs = datacall[field];
|
|
|
|
if (lhs.length != rhs.length ||
|
|
|
|
lhs.reduce(reduceFunc.bind(null, rhs), false)) {
|
|
|
|
changed = true;
|
|
|
|
this.linkInfo[field] = rhs.slice();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!changed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RIL.GECKO_NETWORK_STATE_DISCONNECTED:
|
|
|
|
case RIL.GECKO_NETWORK_STATE_UNKNOWN:
|
|
|
|
if (this.state == RIL.GECKO_NETWORK_STATE_CONNECTED) {
|
|
|
|
// Notify first on unexpected data call disconnection.
|
|
|
|
this.state = datacall.state;
|
|
|
|
for (let i = 0; i < this.requestedNetworkIfaces.length; i++) {
|
|
|
|
this.requestedNetworkIfaces[i].notifyRILNetworkInterface();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.reset();
|
|
|
|
|
|
|
|
if (this.requestedNetworkIfaces.length > 0) {
|
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("State is disconnected/unknown, but this DataCall is" +
|
|
|
|
" requested.");
|
|
|
|
}
|
|
|
|
this.setup();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.state = datacall.state;
|
|
|
|
for (let i = 0; i < this.requestedNetworkIfaces.length; i++) {
|
|
|
|
this.requestedNetworkIfaces[i].notifyRILNetworkInterface();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Helpers
|
|
|
|
|
|
|
|
debug: function(s) {
|
|
|
|
dump("-*- DataCall[" + this.clientId + ":" + this.apnProfile.apn + "]: " +
|
|
|
|
s + "\n");
|
|
|
|
},
|
|
|
|
|
|
|
|
get connected() {
|
|
|
|
return this.state == RIL.GECKO_NETWORK_STATE_CONNECTED;
|
|
|
|
},
|
|
|
|
|
2014-11-24 02:15:25 +00:00
|
|
|
isPermanentFail: function(dataFailCause, errorMsg) {
|
|
|
|
// Check ril.h for 'no retry' data call fail causes.
|
|
|
|
if (errorMsg === RIL.GECKO_ERROR_RADIO_NOT_AVAILABLE ||
|
|
|
|
errorMsg === RIL.GECKO_ERROR_INVALID_PARAMETER ||
|
|
|
|
dataFailCause === RIL.DATACALL_FAIL_OPERATOR_BARRED ||
|
|
|
|
dataFailCause === RIL.DATACALL_FAIL_MISSING_UKNOWN_APN ||
|
|
|
|
dataFailCause === RIL.DATACALL_FAIL_UNKNOWN_PDP_ADDRESS_TYPE ||
|
|
|
|
dataFailCause === RIL.DATACALL_FAIL_USER_AUTHENTICATION ||
|
|
|
|
dataFailCause === RIL.DATACALL_FAIL_ACTIVATION_REJECT_GGSN ||
|
|
|
|
dataFailCause === RIL.DATACALL_FAIL_SERVICE_OPTION_NOT_SUPPORTED ||
|
|
|
|
dataFailCause === RIL.DATACALL_FAIL_SERVICE_OPTION_NOT_SUBSCRIBED ||
|
|
|
|
dataFailCause === RIL.DATACALL_FAIL_NSAPI_IN_USE ||
|
|
|
|
dataFailCause === RIL.DATACALL_FAIL_ONLY_IPV4_ALLOWED ||
|
|
|
|
dataFailCause === RIL.DATACALL_FAIL_ONLY_IPV6_ALLOWED ||
|
|
|
|
dataFailCause === RIL.DATACALL_FAIL_PROTOCOL_ERRORS ||
|
|
|
|
dataFailCause === RIL.DATACALL_FAIL_RADIO_POWER_OFF ||
|
|
|
|
dataFailCause === RIL.DATACALL_FAIL_TETHERED_CALL_ACTIVE) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
inRequestedTypes: function(type) {
|
|
|
|
for (let i = 0; i < this.requestedNetworkIfaces.length; i++) {
|
|
|
|
if (this.requestedNetworkIfaces[i].type == type) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
canHandleApn: function(apnSetting) {
|
2014-10-08 18:24:00 +00:00
|
|
|
let isIdentical = this.apnProfile.apn == apnSetting.apn &&
|
|
|
|
(this.apnProfile.user || '') == (apnSetting.user || '') &&
|
|
|
|
(this.apnProfile.password || '') == (apnSetting.password || '') &&
|
|
|
|
(this.apnProfile.authType || '') == (apnSetting.authtype || '');
|
|
|
|
|
|
|
|
if (RILQUIRKS_HAVE_IPV6) {
|
|
|
|
isIdentical = isIdentical &&
|
|
|
|
(this.apnProfile.protocol || '') == (apnSetting.protocol || '') &&
|
|
|
|
(this.apnProfile.roaming_protocol || '') == (apnSetting.roaming_protocol || '');
|
|
|
|
}
|
|
|
|
|
|
|
|
return isIdentical;
|
2014-05-27 00:08:00 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
reset: function() {
|
|
|
|
this.linkInfo.cid = null;
|
|
|
|
this.linkInfo.ifname = null;
|
|
|
|
this.linkInfo.ips = [];
|
|
|
|
this.linkInfo.prefixLengths = [];
|
|
|
|
this.linkInfo.dnses = [];
|
|
|
|
this.linkInfo.gateways = [];
|
|
|
|
|
|
|
|
this.state = RIL.GECKO_NETWORK_STATE_UNKNOWN;
|
2014-10-08 18:24:00 +00:00
|
|
|
|
|
|
|
this.chappap = null;
|
|
|
|
this.pdptype = null;
|
2014-05-27 00:08:00 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
connect: function(networkInterface) {
|
|
|
|
if (DEBUG) this.debug("connect: " + networkInterface.type);
|
|
|
|
|
|
|
|
if (this.requestedNetworkIfaces.indexOf(networkInterface) == -1) {
|
|
|
|
this.requestedNetworkIfaces.push(networkInterface);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.state == RIL.GECKO_NETWORK_STATE_CONNECTING ||
|
|
|
|
this.state == RIL.GECKO_NETWORK_STATE_DISCONNECTING) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (this.state == RIL.GECKO_NETWORK_STATE_CONNECTED) {
|
2014-09-26 08:03:00 +00:00
|
|
|
// This needs to run asynchronously, to behave the same way as the case of
|
|
|
|
// non-shared apn, see bug 1059110.
|
|
|
|
Services.tm.currentThread.dispatch(function(state) {
|
|
|
|
// Do not notify if state changed while this event was being dispatched,
|
|
|
|
// the state probably was notified already or need not to be notified.
|
|
|
|
if (networkInterface.state == state) {
|
|
|
|
networkInterface.notifyRILNetworkInterface();
|
|
|
|
}
|
|
|
|
}.bind(null, RIL.GECKO_NETWORK_STATE_CONNECTED), Ci.nsIEventTarget.DISPATCH_NORMAL);
|
2014-05-27 00:08:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If retry mechanism is running on background, stop it since we are going
|
|
|
|
// to setup data call now.
|
|
|
|
if (this.timer) {
|
|
|
|
this.timer.cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setup();
|
|
|
|
},
|
|
|
|
|
|
|
|
setup: function() {
|
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("Going to set up data connection with APN " +
|
|
|
|
this.apnProfile.apn);
|
|
|
|
}
|
|
|
|
|
2014-09-21 07:24:43 +00:00
|
|
|
let connection =
|
|
|
|
gMobileConnectionService.getItemByServiceId(this.clientId);
|
|
|
|
let dataInfo = connection && connection.data;
|
|
|
|
if (dataInfo == null ||
|
|
|
|
dataInfo.state != RIL.GECKO_MOBILE_CONNECTION_STATE_REGISTERED ||
|
2014-05-27 00:08:00 +00:00
|
|
|
dataInfo.type == RIL.GECKO_MOBILE_CONNECTION_STATE_UNKNOWN) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let radioTechType = dataInfo.type;
|
|
|
|
let radioTechnology = RIL.GECKO_RADIO_TECH.indexOf(radioTechType);
|
2014-10-08 18:24:00 +00:00
|
|
|
let authType = RIL.RIL_DATACALL_AUTH_TO_GECKO.indexOf(this.apnProfile.authType);
|
2014-05-27 00:08:00 +00:00
|
|
|
// Use the default authType if the value in database is invalid.
|
|
|
|
// For the case that user might not select the authentication type.
|
|
|
|
if (authType == -1) {
|
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("Invalid authType " + this.apnProfile.authtype);
|
|
|
|
}
|
|
|
|
authType = RIL.RIL_DATACALL_AUTH_TO_GECKO.indexOf(RIL.GECKO_DATACALL_AUTH_DEFAULT);
|
|
|
|
}
|
2014-10-08 18:24:00 +00:00
|
|
|
this.chappap = authType;
|
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
let pdpType = RIL.GECKO_DATACALL_PDP_TYPE_IP;
|
|
|
|
if (RILQUIRKS_HAVE_IPV6) {
|
2014-02-10 11:55:22 +00:00
|
|
|
pdpType = !dataInfo.roaming
|
2014-05-27 00:08:00 +00:00
|
|
|
? this.apnProfile.protocol
|
|
|
|
: this.apnProfile.roaming_protocol;
|
|
|
|
if (RIL.RIL_DATACALL_PDP_TYPES.indexOf(pdpType) < 0) {
|
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("Invalid pdpType '" + pdpType + "', using '" +
|
|
|
|
RIL.GECKO_DATACALL_PDP_TYPE_DEFAULT + "'");
|
|
|
|
}
|
|
|
|
pdpType = RIL.GECKO_DATACALL_PDP_TYPE_DEFAULT;
|
|
|
|
}
|
|
|
|
}
|
2014-10-08 18:24:00 +00:00
|
|
|
this.pdptype = pdpType;
|
2014-09-21 07:24:43 +00:00
|
|
|
|
|
|
|
let radioInterface = this.gRIL.getRadioInterface(this.clientId);
|
2014-05-27 00:08:00 +00:00
|
|
|
radioInterface.sendWorkerMessage("setupDataCall", {
|
|
|
|
radioTech: radioTechnology,
|
|
|
|
apn: this.apnProfile.apn,
|
|
|
|
user: this.apnProfile.user,
|
|
|
|
passwd: this.apnProfile.password,
|
|
|
|
chappap: authType,
|
|
|
|
pdptype: pdpType
|
|
|
|
});
|
|
|
|
this.state = RIL.GECKO_NETWORK_STATE_CONNECTING;
|
|
|
|
},
|
|
|
|
|
2014-11-24 02:15:25 +00:00
|
|
|
retry: function(suggestedRetryTime) {
|
2014-05-27 00:08:00 +00:00
|
|
|
let apnRetryTimer;
|
|
|
|
|
|
|
|
// We will retry the connection in increasing times
|
|
|
|
// based on the function: time = A * numer_of_retries^2 + B
|
|
|
|
if (this.apnRetryCounter >= this.NETWORK_APNRETRY_MAXRETRIES) {
|
|
|
|
this.apnRetryCounter = 0;
|
|
|
|
this.timer = null;
|
|
|
|
if (DEBUG) this.debug("Too many APN Connection retries - STOP retrying");
|
|
|
|
return;
|
|
|
|
}
|
2013-11-02 10:17:58 +00:00
|
|
|
|
2014-11-24 02:15:25 +00:00
|
|
|
// If there is a valid suggestedRetryTime, override the retry timer.
|
|
|
|
if (suggestedRetryTime !== undefined && suggestedRetryTime >= 0) {
|
|
|
|
apnRetryTimer = suggestedRetryTime / 1000;
|
|
|
|
} else {
|
|
|
|
apnRetryTimer = this.NETWORK_APNRETRY_FACTOR *
|
|
|
|
(this.apnRetryCounter * this.apnRetryCounter) +
|
|
|
|
this.NETWORK_APNRETRY_ORIGIN;
|
|
|
|
}
|
2014-05-27 00:08:00 +00:00
|
|
|
this.apnRetryCounter++;
|
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("Data call - APN Connection Retry Timer (secs-counter): " +
|
|
|
|
apnRetryTimer + "-" + this.apnRetryCounter);
|
2013-06-28 01:46:00 +00:00
|
|
|
}
|
2014-05-27 00:08:00 +00:00
|
|
|
|
|
|
|
if (this.timer == null) {
|
|
|
|
// Event timer for connection retries
|
|
|
|
this.timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
2013-06-28 01:46:00 +00:00
|
|
|
}
|
2014-05-27 00:08:00 +00:00
|
|
|
this.timer.initWithCallback(this, apnRetryTimer * 1000,
|
|
|
|
Ci.nsITimer.TYPE_ONE_SHOT);
|
|
|
|
},
|
|
|
|
|
|
|
|
disconnect: function(networkInterface) {
|
|
|
|
if (DEBUG) this.debug("disconnect: " + networkInterface.type);
|
|
|
|
let index = this.requestedNetworkIfaces.indexOf(networkInterface);
|
|
|
|
if (index != -1) {
|
|
|
|
this.requestedNetworkIfaces.splice(index, 1);
|
|
|
|
|
|
|
|
if (this.state == RIL.GECKO_NETWORK_STATE_DISCONNECTED ||
|
|
|
|
this.state == RIL.GECKO_NETWORK_STATE_UNKNOWN) {
|
|
|
|
if (this.timer) {
|
|
|
|
this.timer.cancel();
|
|
|
|
}
|
|
|
|
this.reset();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Notify the DISCONNECTED event immediately after network interface is
|
|
|
|
// removed from requestedNetworkIfaces, to make the DataCall, shared or
|
|
|
|
// not, to have the same behavior.
|
2014-09-26 08:03:00 +00:00
|
|
|
Services.tm.currentThread.dispatch(function(state) {
|
|
|
|
// Do not notify if state changed while this event was being dispatched,
|
|
|
|
// the state probably was notified already or need not to be notified.
|
|
|
|
if (networkInterface.state == state) {
|
|
|
|
networkInterface.notifyRILNetworkInterface();
|
|
|
|
}
|
|
|
|
}.bind(null, RIL.GECKO_NETWORK_STATE_DISCONNECTED), Ci.nsIEventTarget.DISPATCH_NORMAL);
|
2013-06-28 01:46:00 +00:00
|
|
|
}
|
2014-05-27 00:08:00 +00:00
|
|
|
|
|
|
|
// Only deactivate data call if no more network interface needs this
|
|
|
|
// DataCall and if state is CONNECTED, for other states, we simply remove
|
|
|
|
// the network interface from requestedNetworkIfaces.
|
|
|
|
if (this.requestedNetworkIfaces.length > 0 ||
|
|
|
|
this.state != RIL.GECKO_NETWORK_STATE_CONNECTED) {
|
|
|
|
return;
|
2014-02-25 16:08:00 +00:00
|
|
|
}
|
2014-05-27 00:08:00 +00:00
|
|
|
|
|
|
|
this.deactivate();
|
|
|
|
},
|
|
|
|
|
|
|
|
deactivate: function() {
|
|
|
|
let reason = RIL.DATACALL_DEACTIVATE_NO_REASON;
|
|
|
|
if (DEBUG) {
|
|
|
|
this.debug("Going to disconnet data connection cid " + this.linkInfo.cid);
|
2014-02-28 10:04:59 +00:00
|
|
|
}
|
2014-05-27 00:08:00 +00:00
|
|
|
let radioInterface = this.gRIL.getRadioInterface(this.clientId);
|
|
|
|
radioInterface.sendWorkerMessage("deactivateDataCall", {
|
|
|
|
cid: this.linkInfo.cid,
|
|
|
|
reason: reason
|
|
|
|
});
|
|
|
|
this.state = RIL.GECKO_NETWORK_STATE_DISCONNECTING;
|
|
|
|
},
|
2014-02-28 10:04:59 +00:00
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
// Entry method for timer events. Used to reconnect to a failed APN
|
|
|
|
notify: function(timer) {
|
|
|
|
this.setup();
|
2013-06-28 01:46:00 +00:00
|
|
|
},
|
2012-04-19 21:33:25 +00:00
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
shutdown: function() {
|
|
|
|
if (this.timer) {
|
|
|
|
this.timer.cancel();
|
|
|
|
this.timer = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function RILNetworkInterface(dataConnectionHandler, type, apnSetting, dataCall) {
|
|
|
|
if (!dataCall) {
|
|
|
|
throw new Error("No dataCall for RILNetworkInterface: " + type);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.dataConnectionHandler = dataConnectionHandler;
|
|
|
|
this.type = type;
|
|
|
|
this.apnSetting = apnSetting;
|
|
|
|
this.dataCall = dataCall;
|
|
|
|
|
|
|
|
this.enabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
RILNetworkInterface.prototype = {
|
|
|
|
classID: RILNETWORKINTERFACE_CID,
|
|
|
|
classInfo: XPCOMUtils.generateCI({classID: RILNETWORKINTERFACE_CID,
|
|
|
|
classDescription: "RILNetworkInterface",
|
|
|
|
interfaces: [Ci.nsINetworkInterface,
|
|
|
|
Ci.nsIRilNetworkInterface]}),
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsINetworkInterface,
|
|
|
|
Ci.nsIRilNetworkInterface]),
|
|
|
|
|
|
|
|
// Hold reference to DataCall object which is determined at initilization.
|
|
|
|
dataCall: null,
|
|
|
|
|
|
|
|
// If this RILNetworkInterface type is enabled or not.
|
|
|
|
enabled: null,
|
2012-04-19 21:33:25 +00:00
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
/**
|
|
|
|
* nsINetworkInterface Implementation
|
|
|
|
*/
|
2012-08-14 01:54:42 +00:00
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
get state() {
|
|
|
|
if (!this.dataCall.inRequestedTypes(this.type)) {
|
|
|
|
return Ci.nsINetworkInterface.NETWORK_STATE_DISCONNECTED;
|
|
|
|
}
|
|
|
|
return this.dataCall.state;
|
|
|
|
},
|
2012-08-14 01:54:42 +00:00
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
type: null,
|
2012-08-14 01:54:42 +00:00
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
get name() {
|
|
|
|
return this.dataCall.linkInfo.ifname;
|
|
|
|
},
|
2012-08-14 01:54:42 +00:00
|
|
|
|
2013-07-12 04:44:22 +00:00
|
|
|
get httpProxyHost() {
|
2013-11-21 14:09:14 +00:00
|
|
|
return this.apnSetting.proxy || "";
|
2013-07-12 04:44:22 +00:00
|
|
|
},
|
2012-08-01 14:55:43 +00:00
|
|
|
|
2013-07-12 04:44:22 +00:00
|
|
|
get httpProxyPort() {
|
2013-11-21 14:09:14 +00:00
|
|
|
return this.apnSetting.port || "";
|
2013-07-12 04:44:22 +00:00
|
|
|
},
|
2012-08-01 14:55:43 +00:00
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
getAddresses: function(ips, prefixLengths) {
|
|
|
|
let linkInfo = this.dataCall.linkInfo;
|
|
|
|
|
|
|
|
ips.value = linkInfo.ips.slice();
|
|
|
|
prefixLengths.value = linkInfo.prefixLengths.slice();
|
|
|
|
|
|
|
|
return linkInfo.ips.length;
|
|
|
|
},
|
|
|
|
|
|
|
|
getGateways: function(count) {
|
|
|
|
let linkInfo = this.dataCall.linkInfo;
|
|
|
|
|
|
|
|
if (count) {
|
|
|
|
count.value = linkInfo.gateways.length;
|
|
|
|
}
|
|
|
|
return linkInfo.gateways.slice();
|
|
|
|
},
|
|
|
|
|
|
|
|
getDnses: function(count) {
|
|
|
|
let linkInfo = this.dataCall.linkInfo;
|
|
|
|
|
|
|
|
if (count) {
|
|
|
|
count.value = linkInfo.dnses.length;
|
|
|
|
}
|
|
|
|
return linkInfo.dnses.slice();
|
|
|
|
},
|
|
|
|
|
2013-11-02 10:17:58 +00:00
|
|
|
/**
|
|
|
|
* nsIRilNetworkInterface Implementation
|
|
|
|
*/
|
|
|
|
|
2013-10-22 10:43:03 +00:00
|
|
|
get serviceId() {
|
2013-12-03 06:18:32 +00:00
|
|
|
return this.dataConnectionHandler.clientId;
|
2013-10-22 10:43:03 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
get iccId() {
|
2013-12-03 06:18:32 +00:00
|
|
|
let iccInfo = this.dataConnectionHandler.radioInterface.rilContext.iccInfo;
|
2013-10-22 10:43:03 +00:00
|
|
|
return iccInfo && iccInfo.iccid;
|
|
|
|
},
|
|
|
|
|
2013-11-02 10:17:58 +00:00
|
|
|
get mmsc() {
|
2014-11-25 01:44:33 +00:00
|
|
|
if (this.type != NETWORK_TYPE_MOBILE_MMS) {
|
2013-11-02 10:17:58 +00:00
|
|
|
if (DEBUG) this.debug("Error! Only MMS network can get MMSC.");
|
|
|
|
throw Cr.NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
let mmsc = this.apnSetting.mmsc;
|
|
|
|
if (!mmsc) {
|
|
|
|
try {
|
|
|
|
mmsc = Services.prefs.getCharPref("ril.mms.mmsc");
|
|
|
|
} catch (e) {
|
|
|
|
mmsc = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return mmsc;
|
|
|
|
},
|
|
|
|
|
|
|
|
get mmsProxy() {
|
2014-11-25 01:44:33 +00:00
|
|
|
if (this.type != NETWORK_TYPE_MOBILE_MMS) {
|
2013-11-02 10:17:58 +00:00
|
|
|
if (DEBUG) this.debug("Error! Only MMS network can get MMS proxy.");
|
|
|
|
throw Cr.NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
let proxy = this.apnSetting.mmsproxy;
|
|
|
|
if (!proxy) {
|
|
|
|
try {
|
|
|
|
proxy = Services.prefs.getCharPref("ril.mms.mmsproxy");
|
|
|
|
} catch (e) {
|
|
|
|
proxy = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return proxy;
|
|
|
|
},
|
|
|
|
|
|
|
|
get mmsPort() {
|
2014-11-25 01:44:33 +00:00
|
|
|
if (this.type != NETWORK_TYPE_MOBILE_MMS) {
|
2013-11-02 10:17:58 +00:00
|
|
|
if (DEBUG) this.debug("Error! Only MMS network can get MMS port.");
|
|
|
|
throw Cr.NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
let port = this.apnSetting.mmsport;
|
|
|
|
if (!port) {
|
|
|
|
try {
|
|
|
|
port = Services.prefs.getIntPref("ril.mms.mmsport");
|
|
|
|
} catch (e) {
|
|
|
|
port = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return port;
|
|
|
|
},
|
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
// Helpers
|
2014-05-27 00:03:00 +00:00
|
|
|
|
2014-01-13 02:44:40 +00:00
|
|
|
debug: function(s) {
|
2013-12-03 06:18:32 +00:00
|
|
|
dump("-*- RILNetworkInterface[" + this.dataConnectionHandler.clientId + ":" +
|
2013-07-02 09:36:58 +00:00
|
|
|
this.type + "]: " + s + "\n");
|
|
|
|
},
|
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
apnSetting: null,
|
|
|
|
|
|
|
|
get connected() {
|
|
|
|
return this.state == Ci.nsINetworkInterface.NETWORK_STATE_CONNECTED;
|
2012-09-26 12:52:21 +00:00
|
|
|
},
|
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
notifyRILNetworkInterface: function() {
|
2013-07-02 09:36:58 +00:00
|
|
|
if (DEBUG) {
|
2014-05-27 00:08:00 +00:00
|
|
|
this.debug("notifyRILNetworkInterface type: " + this.type + ", state: " +
|
|
|
|
this.state);
|
2012-03-12 23:46:08 +00:00
|
|
|
}
|
2013-09-18 10:07:14 +00:00
|
|
|
|
2014-07-29 08:44:26 +00:00
|
|
|
gNetworkManager.updateNetworkInterface(this);
|
2012-03-12 23:46:08 +00:00
|
|
|
},
|
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
connect: function() {
|
|
|
|
this.enabled = true;
|
2013-06-28 01:46:00 +00:00
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
this.dataCall.connect(this);
|
2013-06-28 01:46:00 +00:00
|
|
|
},
|
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
disconnect: function() {
|
|
|
|
if (!this.enabled) {
|
2012-09-26 12:57:37 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-05-27 00:08:00 +00:00
|
|
|
this.enabled = false;
|
2012-09-26 12:57:37 +00:00
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
this.dataCall.disconnect(this);
|
2012-06-01 21:09:59 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
shutdown: function() {
|
2014-05-27 00:08:00 +00:00
|
|
|
this.dataCall.shutdown();
|
|
|
|
this.dataCall = null;
|
2012-06-01 21:09:59 +00:00
|
|
|
}
|
|
|
|
|
2012-03-12 23:46:08 +00:00
|
|
|
};
|
|
|
|
|
2014-05-27 00:08:00 +00:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(DataCall.prototype, "gRIL",
|
|
|
|
"@mozilla.org/ril;1",
|
|
|
|
"nsIRadioInterfaceLayer");
|
|
|
|
|
2012-10-31 16:13:28 +00:00
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([RadioInterfaceLayer]);
|