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.
|
|
|
|
*/
|
2012-04-19 21:33:25 +00:00
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2012-04-12 04:01:49 +00:00
|
|
|
Cu.import("resource://gre/modules/DOMRequestHelper.jsm");
|
2012-04-19 21:33:25 +00:00
|
|
|
|
|
|
|
var RIL = {};
|
|
|
|
Cu.import("resource://gre/modules/ril_consts.js", RIL);
|
|
|
|
|
2012-06-19 22:52:06 +00:00
|
|
|
// set to true to in ril_consts.js to see debug messages
|
2012-11-14 10:25:35 +00:00
|
|
|
var DEBUG = RIL.DEBUG_CONTENT_HELPER;
|
|
|
|
|
|
|
|
// Read debug setting from pref
|
|
|
|
try {
|
|
|
|
let debugPref = Services.prefs.getBoolPref("ril.debugging.enabled");
|
|
|
|
DEBUG = RIL.DEBUG_CONTENT_HELPER || debugPref;
|
|
|
|
} catch (e) {};
|
2012-04-19 21:33:25 +00:00
|
|
|
|
|
|
|
const RILCONTENTHELPER_CID =
|
|
|
|
Components.ID("{472816e1-1fd6-4405-996c-806f9ea68174}");
|
2012-09-03 21:43:59 +00:00
|
|
|
const MOBILEICCINFO_CID =
|
|
|
|
Components.ID("{8649c12f-f8f4-4664-bbdd-7d115c23e2a7}");
|
2012-04-19 21:33:25 +00:00
|
|
|
const MOBILECONNECTIONINFO_CID =
|
|
|
|
Components.ID("{a35cfd39-2d93-4489-ac7d-396475dacb27}");
|
2012-06-12 21:05:50 +00:00
|
|
|
const MOBILENETWORKINFO_CID =
|
2012-06-01 21:10:39 +00:00
|
|
|
Components.ID("{a6c8416c-09b4-46d1-bf29-6520d677d085}");
|
2012-08-16 01:36:56 +00:00
|
|
|
const MOBILECELLINFO_CID =
|
|
|
|
Components.ID("{5e809018-68c0-4c54-af0b-2a9b8f748c45}");
|
2012-07-19 03:27:08 +00:00
|
|
|
const VOICEMAILSTATUS_CID=
|
|
|
|
Components.ID("{5467f2eb-e214-43ea-9b89-67711241ec8e}");
|
2012-10-31 13:58:39 +00:00
|
|
|
const MOBILECFINFO_CID=
|
|
|
|
Components.ID("{a4756f16-e728-4d9f-8baa-8464f894888a}");
|
2012-12-04 02:40:47 +00:00
|
|
|
const CELLBROADCASTMESSAGE_CID =
|
|
|
|
Components.ID("{29474c96-3099-486f-bb4a-3c9a1da834e4}");
|
|
|
|
const CELLBROADCASTETWSINFO_CID =
|
|
|
|
Components.ID("{59f176ee-9dcd-4005-9d47-f6be0cd08e17}");
|
2012-04-19 21:33:25 +00:00
|
|
|
|
|
|
|
const RIL_IPC_MSG_NAMES = [
|
|
|
|
"RIL:CardStateChanged",
|
2012-09-03 21:43:59 +00:00
|
|
|
"RIL:IccInfoChanged",
|
2012-04-19 21:33:25 +00:00
|
|
|
"RIL:VoiceInfoChanged",
|
|
|
|
"RIL:DataInfoChanged",
|
2012-04-24 15:44:42 +00:00
|
|
|
"RIL:EnumerateCalls",
|
2012-06-01 21:10:39 +00:00
|
|
|
"RIL:GetAvailableNetworks",
|
2012-06-19 22:52:06 +00:00
|
|
|
"RIL:NetworkSelectionModeChanged",
|
|
|
|
"RIL:SelectNetwork",
|
|
|
|
"RIL:SelectNetworkAuto",
|
2012-04-24 15:44:42 +00:00
|
|
|
"RIL:CallStateChanged",
|
2012-07-19 03:27:08 +00:00
|
|
|
"RIL:VoicemailNotification",
|
2012-11-23 04:09:01 +00:00
|
|
|
"RIL:VoicemailInfoChanged",
|
2012-05-15 04:13:06 +00:00
|
|
|
"RIL:CallError",
|
2012-08-15 16:49:12 +00:00
|
|
|
"RIL:CardLockResult",
|
2012-10-05 14:08:55 +00:00
|
|
|
"RIL:USSDReceived",
|
|
|
|
"RIL:SendMMI:Return:OK",
|
|
|
|
"RIL:SendMMI:Return:KO",
|
|
|
|
"RIL:CancelMMI:Return:OK",
|
|
|
|
"RIL:CancelMMI:Return:KO",
|
2012-04-10 12:04:27 +00:00
|
|
|
"RIL:StkCommand",
|
2012-09-25 19:22:38 +00:00
|
|
|
"RIL:StkSessionEnd",
|
2012-10-31 13:58:39 +00:00
|
|
|
"RIL:DataError",
|
|
|
|
"RIL:SetCallForwardingOption",
|
2012-12-04 02:40:47 +00:00
|
|
|
"RIL:GetCallForwardingOption",
|
|
|
|
"RIL:CellBroadcastReceived"
|
2012-04-19 21:33:25 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
const kVoiceChangedTopic = "mobile-connection-voice-changed";
|
|
|
|
const kDataChangedTopic = "mobile-connection-data-changed";
|
|
|
|
const kCardStateChangedTopic = "mobile-connection-cardstate-changed";
|
2012-09-03 21:43:59 +00:00
|
|
|
const kIccInfoChangedTopic = "mobile-connection-iccinfo-changed";
|
2012-06-09 21:07:18 +00:00
|
|
|
const kUssdReceivedTopic = "mobile-connection-ussd-received";
|
2012-04-10 12:04:27 +00:00
|
|
|
const kStkCommandTopic = "icc-manager-stk-command";
|
|
|
|
const kStkSessionEndTopic = "icc-manager-stk-session-end";
|
2012-09-25 19:22:38 +00:00
|
|
|
const kDataErrorTopic = "mobile-connection-data-error";
|
2012-10-03 06:51:53 +00:00
|
|
|
const kIccCardLockErrorTopic = "mobile-connection-icccardlock-error";
|
2012-04-19 21:33:25 +00:00
|
|
|
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
|
|
|
|
"@mozilla.org/childprocessmessagemanager;1",
|
2012-08-27 14:13:02 +00:00
|
|
|
"nsISyncMessageSender");
|
2012-04-19 21:33:25 +00:00
|
|
|
|
2012-08-17 03:46:34 +00:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "gUUIDGenerator",
|
|
|
|
"@mozilla.org/uuid-generator;1",
|
|
|
|
"nsIUUIDGenerator");
|
|
|
|
|
2012-09-10 03:54:49 +00:00
|
|
|
function MobileICCCardLockResult(options) {
|
|
|
|
this.lockType = options.lockType;
|
|
|
|
this.enabled = options.enabled;
|
|
|
|
this.retryCount = options.retryCount;
|
|
|
|
this.success = options.success;
|
|
|
|
};
|
|
|
|
MobileICCCardLockResult.prototype = {
|
|
|
|
__exposedProps__ : {lockType: 'r',
|
|
|
|
enabled: 'r',
|
|
|
|
retryCount: 'r',
|
|
|
|
success: 'r'}
|
|
|
|
};
|
|
|
|
|
2012-12-13 00:57:11 +00:00
|
|
|
function MobileICCInfo() {
|
|
|
|
try {
|
|
|
|
this.lastKnownMcc = Services.prefs.getIntPref("ril.lastKnownMcc");
|
|
|
|
} catch (e) {}
|
|
|
|
};
|
2012-09-03 21:43:59 +00:00
|
|
|
MobileICCInfo.prototype = {
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMMozMobileICCInfo]),
|
|
|
|
classID: MOBILEICCINFO_CID,
|
|
|
|
classInfo: XPCOMUtils.generateCI({
|
|
|
|
classID: MOBILEICCINFO_CID,
|
|
|
|
classDescription: "MobileICCInfo",
|
|
|
|
flags: Ci.nsIClassInfo.DOM_OBJECT,
|
|
|
|
interfaces: [Ci.nsIDOMMozMobileICCInfo]
|
|
|
|
}),
|
|
|
|
|
|
|
|
// nsIDOMMozMobileICCInfo
|
|
|
|
|
2012-09-14 10:30:44 +00:00
|
|
|
iccid: null,
|
2012-09-03 21:43:59 +00:00
|
|
|
mcc: 0,
|
2012-12-13 00:57:11 +00:00
|
|
|
lastKnownMcc: 0,
|
2012-10-23 06:54:51 +00:00
|
|
|
mnc: 0,
|
|
|
|
spn: null,
|
2012-11-23 04:09:01 +00:00
|
|
|
msisdn: null
|
|
|
|
};
|
|
|
|
|
2012-12-26 10:49:08 +00:00
|
|
|
function VoicemailInfo() {}
|
|
|
|
VoicemailInfo.prototype = {
|
2012-11-23 04:09:01 +00:00
|
|
|
number: null,
|
|
|
|
displayName: null
|
2012-09-03 21:43:59 +00:00
|
|
|
};
|
|
|
|
|
2012-04-19 21:33:25 +00:00
|
|
|
function MobileConnectionInfo() {}
|
|
|
|
MobileConnectionInfo.prototype = {
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMMozMobileConnectionInfo]),
|
|
|
|
classID: MOBILECONNECTIONINFO_CID,
|
|
|
|
classInfo: XPCOMUtils.generateCI({
|
|
|
|
classID: MOBILECONNECTIONINFO_CID,
|
|
|
|
classDescription: "MobileConnectionInfo",
|
|
|
|
flags: Ci.nsIClassInfo.DOM_OBJECT,
|
|
|
|
interfaces: [Ci.nsIDOMMozMobileConnectionInfo]
|
|
|
|
}),
|
|
|
|
|
|
|
|
// nsIDOMMozMobileConnectionInfo
|
|
|
|
|
|
|
|
connected: false,
|
2012-08-07 19:11:48 +00:00
|
|
|
state: null,
|
2012-04-19 21:33:25 +00:00
|
|
|
emergencyCallsOnly: false,
|
|
|
|
roaming: false,
|
2012-06-12 21:05:50 +00:00
|
|
|
network: null,
|
2012-08-16 01:36:56 +00:00
|
|
|
cell: null,
|
2012-04-19 21:33:25 +00:00
|
|
|
type: null,
|
|
|
|
signalStrength: null,
|
|
|
|
relSignalStrength: null
|
|
|
|
};
|
|
|
|
|
2012-06-12 21:05:50 +00:00
|
|
|
function MobileNetworkInfo() {}
|
|
|
|
MobileNetworkInfo.prototype = {
|
2012-09-10 03:54:49 +00:00
|
|
|
__exposedProps__ : {shortName: 'r',
|
|
|
|
longName: 'r',
|
|
|
|
mcc: 'r',
|
|
|
|
mnc: 'r',
|
|
|
|
state: 'r'},
|
|
|
|
|
2012-06-12 21:05:50 +00:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMMozMobileNetworkInfo]),
|
|
|
|
classID: MOBILENETWORKINFO_CID,
|
2012-06-01 21:10:39 +00:00
|
|
|
classInfo: XPCOMUtils.generateCI({
|
2012-06-12 21:05:50 +00:00
|
|
|
classID: MOBILENETWORKINFO_CID,
|
|
|
|
classDescription: "MobileNetworkInfo",
|
2012-06-01 21:10:39 +00:00
|
|
|
flags: Ci.nsIClassInfo.DOM_OBJECT,
|
2012-06-12 21:05:50 +00:00
|
|
|
interfaces: [Ci.nsIDOMMozMobileNetworkInfo]
|
2012-06-01 21:10:39 +00:00
|
|
|
}),
|
|
|
|
|
2012-06-12 21:05:50 +00:00
|
|
|
// nsIDOMMozMobileNetworkInfo
|
2012-06-01 21:10:39 +00:00
|
|
|
|
|
|
|
shortName: null,
|
|
|
|
longName: null,
|
|
|
|
mcc: 0,
|
|
|
|
mnc: 0,
|
|
|
|
state: null
|
|
|
|
};
|
2012-04-19 21:33:25 +00:00
|
|
|
|
2012-08-16 01:36:56 +00:00
|
|
|
function MobileCellInfo() {}
|
|
|
|
MobileCellInfo.prototype = {
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMMozMobileCellInfo]),
|
|
|
|
classID: MOBILECELLINFO_CID,
|
|
|
|
classInfo: XPCOMUtils.generateCI({
|
|
|
|
classID: MOBILECELLINFO_CID,
|
|
|
|
classDescription: "MobileCellInfo",
|
|
|
|
flags: Ci.nsIClassInfo.DOM_OBJECT,
|
|
|
|
interfaces: [Ci.nsIDOMMozMobileCellInfo]
|
|
|
|
}),
|
|
|
|
|
|
|
|
// nsIDOMMozMobileCellInfo
|
|
|
|
|
|
|
|
gsmLocationAreaCode: null,
|
|
|
|
gsmCellId: null
|
|
|
|
};
|
|
|
|
|
2012-07-19 03:27:08 +00:00
|
|
|
function VoicemailStatus() {}
|
|
|
|
VoicemailStatus.prototype = {
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMMozVoicemailStatus]),
|
|
|
|
classID: VOICEMAILSTATUS_CID,
|
|
|
|
classInfo: XPCOMUtils.generateCI({
|
|
|
|
classID: VOICEMAILSTATUS_CID,
|
|
|
|
classDescription: "VoicemailStatus",
|
|
|
|
flags: Ci.nsIClassInfo.DOM_OBJECT,
|
|
|
|
interfaces: [Ci.nsIDOMMozVoicemailStatus]
|
|
|
|
}),
|
|
|
|
|
|
|
|
// nsIDOMMozVoicemailStatus
|
|
|
|
|
|
|
|
hasMessages: false,
|
|
|
|
messageCount: Ci.nsIDOMMozVoicemailStatus.MESSAGE_COUNT_UNKNOWN,
|
|
|
|
returnNumber: null,
|
|
|
|
returnMessage: null
|
|
|
|
};
|
|
|
|
|
2012-10-31 13:58:39 +00:00
|
|
|
function MobileCFInfo() {}
|
|
|
|
MobileCFInfo.prototype = {
|
|
|
|
__exposedProps__ : {active: 'r',
|
|
|
|
action: 'r',
|
|
|
|
reason: 'r',
|
|
|
|
number: 'r',
|
2012-12-03 09:30:59 +00:00
|
|
|
timeSeconds: 'r',
|
|
|
|
serviceClass: 'r'},
|
2012-10-31 13:58:39 +00:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMMozMobileCFInfo]),
|
|
|
|
classID: MOBILECFINFO_CID,
|
|
|
|
classInfo: XPCOMUtils.generateCI({
|
|
|
|
classID: MOBILECFINFO_CID,
|
|
|
|
classDescription: "MobileCFInfo",
|
|
|
|
flags: Ci.nsIClassInfo.DOM_OBJECT,
|
|
|
|
interfaces: [Ci.nsIDOMMozMobileCFInfo]
|
|
|
|
}),
|
|
|
|
|
|
|
|
// nsIDOMMozMobileCFInfo
|
|
|
|
|
|
|
|
active: false,
|
|
|
|
action: -1,
|
|
|
|
reason: -1,
|
|
|
|
number: null,
|
2012-12-03 09:30:59 +00:00
|
|
|
timeSeconds: 0,
|
|
|
|
serviceClass: -1
|
2012-10-31 13:58:39 +00:00
|
|
|
};
|
|
|
|
|
2012-12-04 02:40:47 +00:00
|
|
|
function CellBroadcastMessage(pdu) {
|
|
|
|
this.geographicalScope = RIL.CB_GSM_GEOGRAPHICAL_SCOPE_NAMES[pdu.geographicalScope];
|
|
|
|
this.messageCode = pdu.messageCode;
|
|
|
|
this.messageId = pdu.messageId;
|
|
|
|
this.language = pdu.language;
|
|
|
|
this.body = pdu.fullBody;
|
|
|
|
this.messageClass = pdu.messageClass;
|
|
|
|
this.timestamp = new Date(pdu.timestamp);
|
|
|
|
|
|
|
|
if (pdu.etws != null) {
|
|
|
|
this.etws = new CellBroadcastEtwsInfo(pdu.etws);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CellBroadcastMessage.prototype = {
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMMozCellBroadcastMessage]),
|
|
|
|
classID: CELLBROADCASTMESSAGE_CID,
|
|
|
|
classInfo: XPCOMUtils.generateCI({
|
|
|
|
classID: CELLBROADCASTMESSAGE_CID,
|
|
|
|
classDescription: "CellBroadcastMessage",
|
|
|
|
flags: Ci.nsIClassInfo.DOM_OBJECT,
|
|
|
|
interfaces: [Ci.nsIDOMMozCellBroadcastMessage]
|
|
|
|
}),
|
|
|
|
|
|
|
|
// nsIDOMMozCellBroadcastMessage
|
|
|
|
|
|
|
|
geographicalScope: null,
|
|
|
|
messageCode: null,
|
|
|
|
messageId: null,
|
|
|
|
language: null,
|
|
|
|
body: null,
|
|
|
|
messageClass: null,
|
|
|
|
timestamp: null,
|
|
|
|
|
|
|
|
etws: null
|
|
|
|
};
|
|
|
|
|
|
|
|
function CellBroadcastEtwsInfo(etwsInfo) {
|
|
|
|
if (etwsInfo.warningType != null) {
|
|
|
|
this.warningType = RIL.CB_ETWS_WARNING_TYPE_NAMES[etwsInfo.warningType];
|
|
|
|
}
|
|
|
|
this.emergencyUserAlert = etwsInfo.emergencyUserAlert;
|
|
|
|
this.popup = etwsInfo.popup;
|
|
|
|
}
|
|
|
|
CellBroadcastEtwsInfo.prototype = {
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMMozCellBroadcastEtwsInfo]),
|
|
|
|
classID: CELLBROADCASTETWSINFO_CID,
|
|
|
|
classInfo: XPCOMUtils.generateCI({
|
|
|
|
classID: CELLBROADCASTETWSINFO_CID,
|
|
|
|
classDescription: "CellBroadcastEtwsInfo",
|
|
|
|
flags: Ci.nsIClassInfo.DOM_OBJECT,
|
|
|
|
interfaces: [Ci.nsIDOMMozCellBroadcastEtwsInfo]
|
|
|
|
}),
|
|
|
|
|
|
|
|
// nsIDOMMozCellBroadcastEtwsInfo
|
|
|
|
|
|
|
|
warningType: null,
|
|
|
|
emergencyUserAlert: null,
|
|
|
|
popup: null
|
|
|
|
};
|
|
|
|
|
2012-04-19 21:33:25 +00:00
|
|
|
function RILContentHelper() {
|
2012-09-03 21:43:59 +00:00
|
|
|
this.iccInfo = new MobileICCInfo();
|
2012-04-19 21:33:25 +00:00
|
|
|
this.voiceConnectionInfo = new MobileConnectionInfo();
|
|
|
|
this.dataConnectionInfo = new MobileConnectionInfo();
|
2012-12-26 10:49:08 +00:00
|
|
|
this.voicemailInfo = new VoicemailInfo();
|
2012-04-19 21:33:25 +00:00
|
|
|
|
2012-04-12 04:01:49 +00:00
|
|
|
this.initRequests();
|
|
|
|
this.initMessageListener(RIL_IPC_MSG_NAMES);
|
2012-04-19 21:33:25 +00:00
|
|
|
Services.obs.addObserver(this, "xpcom-shutdown", false);
|
|
|
|
|
2012-07-24 07:15:25 +00:00
|
|
|
// Request initial context.
|
2012-08-27 14:13:02 +00:00
|
|
|
let rilContext = cpmm.sendSyncMessage("RIL:GetRilContext")[0];
|
2012-06-12 21:05:50 +00:00
|
|
|
|
2012-07-24 07:15:25 +00:00
|
|
|
if (!rilContext) {
|
|
|
|
debug("Received null rilContext from chrome process.");
|
2012-04-19 21:33:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-07-24 07:15:25 +00:00
|
|
|
this.cardState = rilContext.cardState;
|
2012-09-03 21:43:59 +00:00
|
|
|
this.updateICCInfo(rilContext.icc, this.iccInfo);
|
2012-07-24 07:15:25 +00:00
|
|
|
this.updateConnectionInfo(rilContext.voice, this.voiceConnectionInfo);
|
|
|
|
this.updateConnectionInfo(rilContext.data, this.dataConnectionInfo);
|
2012-04-19 21:33:25 +00:00
|
|
|
}
|
2012-06-12 21:05:50 +00:00
|
|
|
|
2012-04-19 21:33:25 +00:00
|
|
|
RILContentHelper.prototype = {
|
2012-04-12 04:01:49 +00:00
|
|
|
__proto__: DOMRequestIpcHelper.prototype,
|
|
|
|
|
2012-04-19 21:33:25 +00:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIMobileConnectionProvider,
|
|
|
|
Ci.nsIRILContentHelper,
|
|
|
|
Ci.nsIObserver]),
|
|
|
|
classID: RILCONTENTHELPER_CID,
|
|
|
|
classInfo: XPCOMUtils.generateCI({classID: RILCONTENTHELPER_CID,
|
|
|
|
classDescription: "RILContentHelper",
|
|
|
|
interfaces: [Ci.nsIMobileConnectionProvider,
|
|
|
|
Ci.nsIRILContentHelper]}),
|
|
|
|
|
2012-11-23 04:09:01 +00:00
|
|
|
updateVoicemailInfo: function updateVoicemailInfo(srcInfo, destInfo) {
|
|
|
|
for (let key in srcInfo) {
|
|
|
|
destInfo[key] = srcInfo[key];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-09-03 21:43:59 +00:00
|
|
|
updateICCInfo: function updateICCInfo(srcInfo, destInfo) {
|
2012-09-14 10:30:44 +00:00
|
|
|
for (let key in srcInfo) {
|
|
|
|
destInfo[key] = srcInfo[key];
|
2012-12-13 00:57:11 +00:00
|
|
|
if (key === 'mcc') {
|
|
|
|
destInfo['lastKnownMcc'] = srcInfo[key];
|
|
|
|
}
|
2012-09-14 10:30:44 +00:00
|
|
|
}
|
2012-09-03 21:43:59 +00:00
|
|
|
},
|
|
|
|
|
2012-06-12 21:05:50 +00:00
|
|
|
updateConnectionInfo: function updateConnectionInfo(srcInfo, destInfo) {
|
|
|
|
for (let key in srcInfo) {
|
2012-08-16 01:36:56 +00:00
|
|
|
if ((key != "network") && (key != "cell")) {
|
2012-06-12 21:05:50 +00:00
|
|
|
destInfo[key] = srcInfo[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-16 01:36:56 +00:00
|
|
|
let srcCell = srcInfo.cell;
|
|
|
|
if (!srcCell) {
|
|
|
|
destInfo.cell = null;
|
|
|
|
} else {
|
|
|
|
let cell = destInfo.cell;
|
|
|
|
if (!cell) {
|
|
|
|
cell = destInfo.cell = new MobileCellInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
cell.gsmLocationAreaCode = srcCell.gsmLocationAreaCode;
|
|
|
|
cell.gsmCellId = srcCell.gsmCellId;
|
|
|
|
}
|
|
|
|
|
2012-06-12 21:05:50 +00:00
|
|
|
let srcNetwork = srcInfo.network;
|
|
|
|
if (!srcNetwork) {
|
|
|
|
destInfo.network= null;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let network = destInfo.network;
|
|
|
|
if (!network) {
|
|
|
|
network = destInfo.network = new MobileNetworkInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
network.longName = srcNetwork.longName;
|
|
|
|
network.shortName = srcNetwork.shortName;
|
|
|
|
network.mnc = srcNetwork.mnc;
|
|
|
|
network.mcc = srcNetwork.mcc;
|
|
|
|
},
|
|
|
|
|
2012-04-19 21:33:25 +00:00
|
|
|
// nsIRILContentHelper
|
|
|
|
|
2012-09-03 21:43:59 +00:00
|
|
|
cardState: RIL.GECKO_CARDSTATE_UNAVAILABLE,
|
|
|
|
iccInfo: null,
|
|
|
|
voiceConnectionInfo: null,
|
|
|
|
dataConnectionInfo: null,
|
2012-06-19 22:52:06 +00:00
|
|
|
networkSelectionMode: RIL.GECKO_NETWORK_SELECTION_UNKNOWN,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The network that is currently trying to be selected (or "automatic").
|
|
|
|
* This helps ensure that only one network is selected at a time.
|
|
|
|
*/
|
|
|
|
_selectingNetwork: null,
|
2012-04-19 21:33:25 +00:00
|
|
|
|
|
|
|
getNetworks: function getNetworks(window) {
|
2012-06-01 21:10:39 +00:00
|
|
|
if (window == null) {
|
|
|
|
throw Components.Exception("Can't get window object",
|
|
|
|
Cr.NS_ERROR_UNEXPECTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
let request = Services.DOMRequest.createRequest(window);
|
|
|
|
let requestId = this.getRequestId(request);
|
|
|
|
|
2012-08-17 03:46:34 +00:00
|
|
|
cpmm.sendAsyncMessage("RIL:GetAvailableNetworks", {requestId: requestId});
|
2012-06-01 21:10:39 +00:00
|
|
|
return request;
|
2012-04-19 21:33:25 +00:00
|
|
|
},
|
|
|
|
|
2012-06-19 22:52:06 +00:00
|
|
|
selectNetwork: function selectNetwork(window, network) {
|
|
|
|
if (window == null) {
|
|
|
|
throw Components.Exception("Can't get window object",
|
|
|
|
Cr.NS_ERROR_UNEXPECTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._selectingNetwork) {
|
|
|
|
throw new Error("Already selecting a network: " + this._selectingNetwork);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!network) {
|
|
|
|
throw new Error("Invalid network provided: " + network);
|
|
|
|
}
|
|
|
|
|
|
|
|
let mnc = network.mnc;
|
|
|
|
if (!mnc) {
|
|
|
|
throw new Error("Invalid network MNC: " + mnc);
|
|
|
|
}
|
|
|
|
|
|
|
|
let mcc = network.mcc;
|
|
|
|
if (!mcc) {
|
|
|
|
throw new Error("Invalid network MCC: " + mcc);
|
|
|
|
}
|
|
|
|
|
|
|
|
let request = Services.DOMRequest.createRequest(window);
|
|
|
|
let requestId = this.getRequestId(request);
|
|
|
|
|
|
|
|
if (this.networkSelectionMode == RIL.GECKO_NETWORK_SELECTION_MANUAL
|
|
|
|
&& this.voiceConnectionInfo.network === network) {
|
|
|
|
|
|
|
|
// Already manually selected this network, so schedule
|
|
|
|
// onsuccess to be fired on the next tick
|
|
|
|
this.dispatchFireRequestSuccess(requestId, null);
|
|
|
|
return request;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._selectingNetwork = network;
|
|
|
|
|
|
|
|
cpmm.sendAsyncMessage("RIL:SelectNetwork", {
|
|
|
|
requestId: requestId,
|
|
|
|
mnc: mnc,
|
|
|
|
mcc: mcc
|
|
|
|
});
|
|
|
|
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
|
|
|
selectNetworkAutomatically: function selectNetworkAutomatically(window) {
|
|
|
|
|
|
|
|
if (window == null) {
|
|
|
|
throw Components.Exception("Can't get window object",
|
|
|
|
Cr.NS_ERROR_UNEXPECTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._selectingNetwork) {
|
|
|
|
throw new Error("Already selecting a network: " + this._selectingNetwork);
|
|
|
|
}
|
|
|
|
|
|
|
|
let request = Services.DOMRequest.createRequest(window);
|
|
|
|
let requestId = this.getRequestId(request);
|
|
|
|
|
|
|
|
if (this.networkSelectionMode == RIL.GECKO_NETWORK_SELECTION_AUTOMATIC) {
|
|
|
|
// Already using automatic selection mode, so schedule
|
|
|
|
// onsuccess to be be fired on the next tick
|
|
|
|
this.dispatchFireRequestSuccess(requestId, null);
|
|
|
|
return request;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._selectingNetwork = "automatic";
|
2012-08-17 03:46:34 +00:00
|
|
|
cpmm.sendAsyncMessage("RIL:SelectNetworkAuto", {requestId: requestId});
|
2012-06-19 22:52:06 +00:00
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2012-04-12 04:01:49 +00:00
|
|
|
getCardLock: function getCardLock(window, lockType) {
|
|
|
|
if (window == null) {
|
|
|
|
throw Components.Exception("Can't get window object",
|
|
|
|
Cr.NS_ERROR_UNEXPECTED);
|
|
|
|
}
|
|
|
|
let request = Services.DOMRequest.createRequest(window);
|
|
|
|
let requestId = this.getRequestId(request);
|
|
|
|
cpmm.sendAsyncMessage("RIL:GetCardLock", {lockType: lockType, requestId: requestId});
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
|
|
|
unlockCardLock: function unlockCardLock(window, info) {
|
|
|
|
if (window == null) {
|
|
|
|
throw Components.Exception("Can't get window object",
|
|
|
|
Cr.NS_ERROR_UNEXPECTED);
|
|
|
|
}
|
|
|
|
let request = Services.DOMRequest.createRequest(window);
|
|
|
|
info.requestId = this.getRequestId(request);
|
|
|
|
cpmm.sendAsyncMessage("RIL:UnlockCardLock", info);
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
|
|
|
setCardLock: function setCardLock(window, info) {
|
|
|
|
if (window == null) {
|
|
|
|
throw Components.Exception("Can't get window object",
|
|
|
|
Cr.NS_ERROR_UNEXPECTED);
|
|
|
|
}
|
|
|
|
let request = Services.DOMRequest.createRequest(window);
|
|
|
|
info.requestId = this.getRequestId(request);
|
|
|
|
cpmm.sendAsyncMessage("RIL:SetCardLock", info);
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2012-10-05 14:08:55 +00:00
|
|
|
sendMMI: function sendMMI(window, mmi) {
|
|
|
|
debug("Sending MMI " + mmi);
|
2012-06-09 21:07:18 +00:00
|
|
|
if (!window) {
|
|
|
|
throw Components.Exception("Can't get window object",
|
|
|
|
Cr.NS_ERROR_EXPECTED);
|
|
|
|
}
|
|
|
|
let request = Services.DOMRequest.createRequest(window);
|
|
|
|
let requestId = this.getRequestId(request);
|
2012-10-05 14:08:55 +00:00
|
|
|
cpmm.sendAsyncMessage("RIL:SendMMI", {mmi: mmi, requestId: requestId});
|
2012-06-09 21:07:18 +00:00
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2012-10-05 14:08:55 +00:00
|
|
|
cancelMMI: function cancelMMI(window) {
|
|
|
|
debug("Cancel MMI");
|
2012-06-09 21:07:18 +00:00
|
|
|
if (!window) {
|
|
|
|
throw Components.Exception("Can't get window object",
|
|
|
|
Cr.NS_ERROR_UNEXPECTED);
|
|
|
|
}
|
|
|
|
let request = Services.DOMRequest.createRequest(window);
|
|
|
|
let requestId = this.getRequestId(request);
|
2012-10-05 14:08:55 +00:00
|
|
|
cpmm.sendAsyncMessage("RIL:CancelMMI", {requestId: requestId});
|
2012-06-09 21:07:18 +00:00
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2012-08-29 22:09:12 +00:00
|
|
|
sendStkResponse: function sendStkResponse(window, command, response) {
|
2012-04-10 12:04:27 +00:00
|
|
|
if (window == null) {
|
|
|
|
throw Components.Exception("Can't get window object",
|
|
|
|
Cr.NS_ERROR_UNEXPECTED);
|
|
|
|
}
|
2012-08-29 22:09:12 +00:00
|
|
|
response.command = command;
|
2012-04-10 12:04:27 +00:00
|
|
|
cpmm.sendAsyncMessage("RIL:SendStkResponse", response);
|
|
|
|
},
|
|
|
|
|
|
|
|
sendStkMenuSelection: function sendStkMenuSelection(window,
|
|
|
|
itemIdentifier,
|
|
|
|
helpRequested) {
|
|
|
|
if (window == null) {
|
|
|
|
throw Components.Exception("Can't get window object",
|
|
|
|
Cr.NS_ERROR_UNEXPECTED);
|
|
|
|
}
|
|
|
|
cpmm.sendAsyncMessage("RIL:SendStkMenuSelection", {itemIdentifier: itemIdentifier,
|
|
|
|
helpRequested: helpRequested});
|
|
|
|
},
|
|
|
|
|
2012-11-28 08:16:20 +00:00
|
|
|
sendStkTimerExpiration: function sendStkTimerExpiration(window,
|
|
|
|
timer) {
|
|
|
|
if (window == null) {
|
|
|
|
throw Components.Exception("Can't get window object",
|
|
|
|
Cr.NS_ERROR_UNEXPECTED);
|
|
|
|
}
|
|
|
|
cpmm.sendAsyncMessage("RIL:SendStkTimerExpiration", {timer: timer});
|
|
|
|
},
|
|
|
|
|
2012-09-11 02:34:36 +00:00
|
|
|
sendStkEventDownload: function sendStkEventDownload(window,
|
|
|
|
event) {
|
|
|
|
if (window == null) {
|
|
|
|
throw Components.Exception("Can't get window object",
|
|
|
|
Cr.NS_ERROR_UNEXPECTED);
|
|
|
|
}
|
|
|
|
cpmm.sendAsyncMessage("RIL:SendStkEventDownload", {event: event});
|
|
|
|
},
|
|
|
|
|
2012-10-31 13:58:39 +00:00
|
|
|
getCallForwardingOption: function getCallForwardingOption(window, reason) {
|
|
|
|
if (window == null) {
|
|
|
|
throw Components.Exception("Can't get window object",
|
|
|
|
Cr.NS_ERROR_UNEXPECTED);
|
|
|
|
}
|
|
|
|
let request = Services.DOMRequest.createRequest(window);
|
|
|
|
let requestId = this.getRequestId(request);
|
|
|
|
|
|
|
|
if (!this._isValidCFReason(reason)){
|
|
|
|
this.dispatchFireRequestError(requestId, "Invalid call forwarding reason.");
|
|
|
|
return request;
|
|
|
|
}
|
|
|
|
|
|
|
|
cpmm.sendAsyncMessage("RIL:GetCallForwardingOption", {
|
|
|
|
requestId: requestId,
|
|
|
|
reason: reason
|
|
|
|
});
|
|
|
|
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
|
|
|
setCallForwardingOption: function setCallForwardingOption(window, cfInfo) {
|
|
|
|
if (window == null) {
|
|
|
|
throw Components.Exception("Can't get window object",
|
|
|
|
Cr.NS_ERROR_UNEXPECTED);
|
|
|
|
}
|
|
|
|
let request = Services.DOMRequest.createRequest(window);
|
|
|
|
let requestId = this.getRequestId(request);
|
|
|
|
|
|
|
|
if (!cfInfo ||
|
|
|
|
!this._isValidCFReason(cfInfo.reason) ||
|
|
|
|
!this._isValidCFAction(cfInfo.action)){
|
|
|
|
this.dispatchFireRequestError(requestId, "Invalid call forwarding rule definition.");
|
|
|
|
return request;
|
|
|
|
}
|
|
|
|
|
|
|
|
cpmm.sendAsyncMessage("RIL:SetCallForwardingOption", {
|
|
|
|
requestId: requestId,
|
|
|
|
active: cfInfo.active,
|
|
|
|
action: cfInfo.action,
|
|
|
|
reason: cfInfo.reason,
|
|
|
|
number: cfInfo.number,
|
|
|
|
timeSeconds: cfInfo.timeSeconds
|
|
|
|
});
|
|
|
|
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2012-04-24 15:44:42 +00:00
|
|
|
_telephonyCallbacks: null,
|
2012-07-19 03:27:08 +00:00
|
|
|
_voicemailCallbacks: null,
|
|
|
|
_enumerateTelephonyCallbacks: null,
|
2012-04-24 15:44:42 +00:00
|
|
|
|
2012-07-19 03:27:08 +00:00
|
|
|
voicemailStatus: null,
|
2012-12-26 10:49:08 +00:00
|
|
|
|
|
|
|
getVoicemailInfo: function getVoicemailInfo() {
|
|
|
|
// Get voicemail infomation by IPC only on first time.
|
|
|
|
this.getVoicemailInfo = function getVoicemailInfo() {
|
|
|
|
return this.voicemailInfo;
|
|
|
|
};
|
|
|
|
|
|
|
|
let voicemailInfo = cpmm.sendSyncMessage("RIL:GetVoicemailInfo")[0];
|
|
|
|
if (voicemailInfo) {
|
|
|
|
this.updateVoicemailInfo(voicemailInfo, this.voicemailInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.voicemailInfo;
|
|
|
|
},
|
2012-11-23 04:09:01 +00:00
|
|
|
get voicemailNumber() {
|
2012-12-26 10:49:08 +00:00
|
|
|
return this.getVoicemailInfo().number;
|
2012-11-23 04:09:01 +00:00
|
|
|
},
|
|
|
|
get voicemailDisplayName() {
|
2012-12-26 10:49:08 +00:00
|
|
|
return this.getVoicemailInfo().displayName;
|
2012-11-23 04:09:01 +00:00
|
|
|
},
|
2012-07-19 03:27:08 +00:00
|
|
|
|
|
|
|
registerCallback: function registerCallback(callbackType, callback) {
|
|
|
|
let callbacks = this[callbackType];
|
|
|
|
if (!callbacks) {
|
|
|
|
callbacks = this[callbackType] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (callbacks.indexOf(callback) != -1) {
|
|
|
|
throw new Error("Already registered this callback!");
|
2012-04-24 15:44:42 +00:00
|
|
|
}
|
2012-07-19 03:27:08 +00:00
|
|
|
|
|
|
|
callbacks.push(callback);
|
|
|
|
if (DEBUG) debug("Registered " + callbackType + " callback: " + callback);
|
2012-04-24 15:44:42 +00:00
|
|
|
},
|
|
|
|
|
2012-07-19 03:27:08 +00:00
|
|
|
unregisterCallback: function unregisterCallback(callbackType, callback) {
|
|
|
|
let callbacks = this[callbackType];
|
|
|
|
if (!callbacks) {
|
2012-04-24 15:44:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-07-19 03:27:08 +00:00
|
|
|
|
|
|
|
let index = callbacks.indexOf(callback);
|
2012-04-24 15:44:42 +00:00
|
|
|
if (index != -1) {
|
2012-07-19 03:27:08 +00:00
|
|
|
callbacks.splice(index, 1);
|
|
|
|
if (DEBUG) debug("Unregistered telephony callback: " + callback);
|
2012-04-24 15:44:42 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-07-19 03:27:08 +00:00
|
|
|
registerTelephonyCallback: function registerTelephonyCallback(callback) {
|
|
|
|
this.registerCallback("_telephonyCallbacks", callback);
|
|
|
|
},
|
|
|
|
|
|
|
|
unregisterTelephonyCallback: function unregisteTelephonyCallback(callback) {
|
|
|
|
this.unregisterCallback("_telephonyCallbacks", callback);
|
|
|
|
},
|
|
|
|
|
|
|
|
registerVoicemailCallback: function registerVoicemailCallback(callback) {
|
|
|
|
this.registerCallback("_voicemailCallbacks", callback);
|
|
|
|
},
|
|
|
|
|
|
|
|
unregisterVoicemailCallback: function unregisteVoicemailCallback(callback) {
|
|
|
|
this.unregisterCallback("_voicemailCallbacks", callback);
|
|
|
|
},
|
|
|
|
|
2012-12-04 02:40:47 +00:00
|
|
|
registerCellBroadcastCallback: function registerCellBroadcastCallback(callback) {
|
|
|
|
this.registerCallback("_cellBroadcastCallbacks", callback);
|
|
|
|
},
|
|
|
|
|
|
|
|
unregisterCellBroadcastCallback: function unregisterCellBroadcastCallback(callback) {
|
|
|
|
this.unregisterCallback("_cellBroadcastCallbacks", callback);
|
|
|
|
},
|
|
|
|
|
2012-10-09 10:07:11 +00:00
|
|
|
registerTelephonyMsg: function registerTelephonyMsg() {
|
|
|
|
debug("Registering for telephony-related messages");
|
|
|
|
cpmm.sendAsyncMessage("RIL:RegisterTelephonyMsg");
|
|
|
|
},
|
|
|
|
|
|
|
|
registerMobileConnectionMsg: function registerMobileConnectionMsg() {
|
|
|
|
debug("Registering for mobile connection-related messages");
|
|
|
|
cpmm.sendAsyncMessage("RIL:RegisterMobileConnectionMsg");
|
|
|
|
},
|
|
|
|
|
|
|
|
registerVoicemailMsg: function registerVoicemailMsg() {
|
|
|
|
debug("Registering for voicemail-related messages");
|
|
|
|
cpmm.sendAsyncMessage("RIL:RegisterVoicemailMsg");
|
|
|
|
},
|
|
|
|
|
2012-12-04 02:40:47 +00:00
|
|
|
registerCellBroadcastMsg: function registerCellBroadcastMsg() {
|
|
|
|
debug("Registering for Cell Broadcast related messages");
|
|
|
|
cpmm.sendAsyncMessage("RIL:RegisterCellBroadcastMsg");
|
|
|
|
},
|
|
|
|
|
2012-04-24 15:44:42 +00:00
|
|
|
enumerateCalls: function enumerateCalls(callback) {
|
|
|
|
debug("Requesting enumeration of calls for callback: " + callback);
|
2012-08-17 03:46:34 +00:00
|
|
|
// We need 'requestId' to meet the 'RILContentHelper <--> RadioInterfaceLayer'
|
|
|
|
// protocol.
|
|
|
|
let requestId = this._getRandomId();
|
|
|
|
cpmm.sendAsyncMessage("RIL:EnumerateCalls", {requestId: requestId});
|
2012-10-30 09:24:31 +00:00
|
|
|
if (!this._enumerateTelephonyCallbacks) {
|
|
|
|
this._enumerateTelephonyCallbacks = [];
|
2012-04-24 15:44:42 +00:00
|
|
|
}
|
2012-10-30 09:24:31 +00:00
|
|
|
this._enumerateTelephonyCallbacks.push(callback);
|
2012-04-24 15:44:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
startTone: function startTone(dtmfChar) {
|
|
|
|
debug("Sending Tone for " + dtmfChar);
|
|
|
|
cpmm.sendAsyncMessage("RIL:StartTone", dtmfChar);
|
|
|
|
},
|
|
|
|
|
|
|
|
stopTone: function stopTone() {
|
|
|
|
debug("Stopping Tone");
|
|
|
|
cpmm.sendAsyncMessage("RIL:StopTone");
|
|
|
|
},
|
|
|
|
|
|
|
|
dial: function dial(number) {
|
|
|
|
debug("Dialing " + number);
|
|
|
|
cpmm.sendAsyncMessage("RIL:Dial", number);
|
|
|
|
},
|
|
|
|
|
2012-07-20 12:08:24 +00:00
|
|
|
dialEmergency: function dialEmergency(number) {
|
|
|
|
debug("Dialing emergency " + number);
|
|
|
|
cpmm.sendAsyncMessage("RIL:DialEmergency", number);
|
|
|
|
},
|
|
|
|
|
2012-04-24 15:44:42 +00:00
|
|
|
hangUp: function hangUp(callIndex) {
|
|
|
|
debug("Hanging up call no. " + callIndex);
|
|
|
|
cpmm.sendAsyncMessage("RIL:HangUp", callIndex);
|
|
|
|
},
|
|
|
|
|
|
|
|
answerCall: function answerCall(callIndex) {
|
|
|
|
cpmm.sendAsyncMessage("RIL:AnswerCall", callIndex);
|
|
|
|
},
|
|
|
|
|
|
|
|
rejectCall: function rejectCall(callIndex) {
|
|
|
|
cpmm.sendAsyncMessage("RIL:RejectCall", callIndex);
|
|
|
|
},
|
|
|
|
|
|
|
|
holdCall: function holdCall(callIndex) {
|
|
|
|
cpmm.sendAsyncMessage("RIL:HoldCall", callIndex);
|
|
|
|
},
|
|
|
|
|
|
|
|
resumeCall: function resumeCall(callIndex) {
|
|
|
|
cpmm.sendAsyncMessage("RIL:ResumeCall", callIndex);
|
|
|
|
},
|
|
|
|
|
|
|
|
get microphoneMuted() {
|
|
|
|
return cpmm.sendSyncMessage("RIL:GetMicrophoneMuted")[0];
|
|
|
|
},
|
|
|
|
|
|
|
|
set microphoneMuted(value) {
|
|
|
|
cpmm.sendAsyncMessage("RIL:SetMicrophoneMuted", value);
|
|
|
|
},
|
|
|
|
|
|
|
|
get speakerEnabled() {
|
|
|
|
return cpmm.sendSyncMessage("RIL:GetSpeakerEnabled")[0];
|
|
|
|
},
|
|
|
|
|
|
|
|
set speakerEnabled(value) {
|
|
|
|
cpmm.sendAsyncMessage("RIL:SetSpeakerEnabled", value);
|
|
|
|
},
|
|
|
|
|
2012-04-19 21:33:25 +00:00
|
|
|
// nsIObserver
|
|
|
|
|
|
|
|
observe: function observe(subject, topic, data) {
|
|
|
|
if (topic == "xpcom-shutdown") {
|
2012-04-12 04:01:49 +00:00
|
|
|
this.removeMessageListener();
|
2012-04-19 21:33:25 +00:00
|
|
|
Services.obs.removeObserver(this, "xpcom-shutdown");
|
|
|
|
cpmm = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-08-27 14:13:02 +00:00
|
|
|
// nsIMessageListener
|
2012-04-19 21:33:25 +00:00
|
|
|
|
2012-06-12 21:05:50 +00:00
|
|
|
fireRequestSuccess: function fireRequestSuccess(requestId, result) {
|
|
|
|
let request = this.takeRequest(requestId);
|
|
|
|
if (!request) {
|
|
|
|
if (DEBUG) {
|
2012-06-19 22:52:06 +00:00
|
|
|
debug("not firing success for id: " + requestId +
|
|
|
|
", result: " + JSON.stringify(result));
|
2012-06-12 21:05:50 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DEBUG) {
|
2012-06-19 22:52:06 +00:00
|
|
|
debug("fire request success, id: " + requestId +
|
|
|
|
", result: " + JSON.stringify(result));
|
2012-06-12 21:05:50 +00:00
|
|
|
}
|
|
|
|
Services.DOMRequest.fireSuccess(request, result);
|
|
|
|
},
|
|
|
|
|
2012-06-19 22:52:06 +00:00
|
|
|
dispatchFireRequestSuccess: function dispatchFireRequestSuccess(requestId, result) {
|
|
|
|
let currentThread = Services.tm.currentThread;
|
|
|
|
|
|
|
|
currentThread.dispatch(this.fireRequestSuccess.bind(this, requestId, result),
|
|
|
|
Ci.nsIThread.DISPATCH_NORMAL);
|
|
|
|
},
|
|
|
|
|
2012-06-12 21:05:50 +00:00
|
|
|
fireRequestError: function fireRequestError(requestId, error) {
|
|
|
|
let request = this.takeRequest(requestId);
|
|
|
|
if (!request) {
|
|
|
|
if (DEBUG) {
|
2012-06-19 22:52:06 +00:00
|
|
|
debug("not firing error for id: " + requestId +
|
|
|
|
", error: " + JSON.stringify(error));
|
2012-06-12 21:05:50 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DEBUG) {
|
2012-06-19 22:52:06 +00:00
|
|
|
debug("fire request error, id: " + requestId +
|
|
|
|
", result: " + JSON.stringify(error));
|
2012-06-12 21:05:50 +00:00
|
|
|
}
|
|
|
|
Services.DOMRequest.fireError(request, error);
|
|
|
|
},
|
|
|
|
|
2012-10-31 13:58:39 +00:00
|
|
|
dispatchFireRequestError: function dispatchFireRequestError(requestId, error) {
|
|
|
|
let currentThread = Services.tm.currentThread;
|
|
|
|
|
|
|
|
currentThread.dispatch(this.fireRequestError.bind(this, requestId, error),
|
|
|
|
Ci.nsIThread.DISPATCH_NORMAL);
|
|
|
|
},
|
|
|
|
|
2012-04-19 21:33:25 +00:00
|
|
|
receiveMessage: function receiveMessage(msg) {
|
2012-04-12 04:01:49 +00:00
|
|
|
let request;
|
2012-04-19 21:33:25 +00:00
|
|
|
debug("Received message '" + msg.name + "': " + JSON.stringify(msg.json));
|
|
|
|
switch (msg.name) {
|
|
|
|
case "RIL:CardStateChanged":
|
|
|
|
if (this.cardState != msg.json.cardState) {
|
|
|
|
this.cardState = msg.json.cardState;
|
|
|
|
Services.obs.notifyObservers(null, kCardStateChangedTopic, null);
|
|
|
|
}
|
|
|
|
break;
|
2012-09-03 21:43:59 +00:00
|
|
|
case "RIL:IccInfoChanged":
|
|
|
|
this.updateICCInfo(msg.json, this.iccInfo);
|
2012-12-13 00:57:11 +00:00
|
|
|
if (this.iccInfo.mcc) {
|
2013-01-04 16:27:29 +00:00
|
|
|
try {
|
|
|
|
Services.prefs.setIntPref("ril.lastKnownMcc", this.iccInfo.mcc);
|
|
|
|
} catch (e) {}
|
2012-12-13 00:57:11 +00:00
|
|
|
}
|
2012-09-03 21:43:59 +00:00
|
|
|
Services.obs.notifyObservers(null, kIccInfoChangedTopic, null);
|
|
|
|
break;
|
2012-04-19 21:33:25 +00:00
|
|
|
case "RIL:VoiceInfoChanged":
|
2012-06-12 21:05:50 +00:00
|
|
|
this.updateConnectionInfo(msg.json, this.voiceConnectionInfo);
|
2012-04-19 21:33:25 +00:00
|
|
|
Services.obs.notifyObservers(null, kVoiceChangedTopic, null);
|
|
|
|
break;
|
|
|
|
case "RIL:DataInfoChanged":
|
2012-06-12 21:05:50 +00:00
|
|
|
this.updateConnectionInfo(msg.json, this.dataConnectionInfo);
|
2012-04-19 21:33:25 +00:00
|
|
|
Services.obs.notifyObservers(null, kDataChangedTopic, null);
|
|
|
|
break;
|
2012-04-24 15:44:42 +00:00
|
|
|
case "RIL:EnumerateCalls":
|
2012-08-17 03:46:34 +00:00
|
|
|
this.handleEnumerateCalls(msg.json.calls);
|
2012-04-24 15:44:42 +00:00
|
|
|
break;
|
2012-06-01 21:10:39 +00:00
|
|
|
case "RIL:GetAvailableNetworks":
|
|
|
|
this.handleGetAvailableNetworks(msg.json);
|
|
|
|
break;
|
2012-06-19 22:52:06 +00:00
|
|
|
case "RIL:NetworkSelectionModeChanged":
|
|
|
|
this.networkSelectionMode = msg.json.mode;
|
|
|
|
break;
|
|
|
|
case "RIL:SelectNetwork":
|
|
|
|
this.handleSelectNetwork(msg.json,
|
|
|
|
RIL.GECKO_NETWORK_SELECTION_MANUAL);
|
|
|
|
break;
|
|
|
|
case "RIL:SelectNetworkAuto":
|
|
|
|
this.handleSelectNetwork(msg.json,
|
|
|
|
RIL.GECKO_NETWORK_SELECTION_AUTOMATIC);
|
|
|
|
break;
|
2012-04-24 15:44:42 +00:00
|
|
|
case "RIL:CallStateChanged":
|
2012-07-19 03:27:08 +00:00
|
|
|
this._deliverCallback("_telephonyCallbacks",
|
|
|
|
"callStateChanged",
|
|
|
|
[msg.json.callIndex, msg.json.state,
|
|
|
|
msg.json.number, msg.json.isActive]);
|
2012-05-15 04:13:06 +00:00
|
|
|
break;
|
|
|
|
case "RIL:CallError":
|
2012-07-19 03:27:08 +00:00
|
|
|
this._deliverCallback("_telephonyCallbacks",
|
|
|
|
"notifyError",
|
|
|
|
[msg.json.callIndex,
|
|
|
|
msg.json.error]);
|
|
|
|
break;
|
|
|
|
case "RIL:VoicemailNotification":
|
|
|
|
this.handleVoicemailNotification(msg.json);
|
2012-06-01 21:10:39 +00:00
|
|
|
break;
|
2012-11-23 04:09:01 +00:00
|
|
|
case "RIL:VoicemailInfoChanged":
|
|
|
|
this.updateVoicemailInfo(msg.json, this.voicemailInfo);
|
2012-07-21 00:19:38 +00:00
|
|
|
break;
|
2012-08-15 16:49:12 +00:00
|
|
|
case "RIL:CardLockResult":
|
|
|
|
if (msg.json.success) {
|
2012-09-10 03:54:49 +00:00
|
|
|
let result = new MobileICCCardLockResult(msg.json);
|
|
|
|
this.fireRequestSuccess(msg.json.requestId, result);
|
2012-08-15 16:49:12 +00:00
|
|
|
} else {
|
2012-10-03 06:51:53 +00:00
|
|
|
if (msg.json.rilMessageType == "iccSetCardLock" ||
|
|
|
|
msg.json.rilMessageType == "iccUnlockCardLock") {
|
|
|
|
let result = JSON.stringify({lockType: msg.json.lockType,
|
|
|
|
retryCount: msg.json.retryCount});
|
|
|
|
Services.obs.notifyObservers(null, kIccCardLockErrorTopic,
|
|
|
|
result);
|
|
|
|
}
|
|
|
|
this.fireRequestError(msg.json.requestId, msg.json.errorMsg);
|
2012-08-15 16:49:12 +00:00
|
|
|
}
|
2012-04-12 04:01:49 +00:00
|
|
|
break;
|
2012-10-05 14:08:55 +00:00
|
|
|
case "RIL:USSDReceived":
|
2012-10-17 11:17:19 +00:00
|
|
|
let res = JSON.stringify({message: msg.json.message,
|
|
|
|
sessionEnded: msg.json.sessionEnded});
|
|
|
|
Services.obs.notifyObservers(null, kUssdReceivedTopic, res);
|
2012-06-09 21:07:18 +00:00
|
|
|
break;
|
2012-10-05 14:08:55 +00:00
|
|
|
case "RIL:SendMMI:Return:OK":
|
|
|
|
case "RIL:CancelMMI:Return:OK":
|
2012-11-07 22:13:48 +00:00
|
|
|
this.handleSendCancelMMIOK(msg.json);
|
2012-06-09 21:07:18 +00:00
|
|
|
break;
|
2012-10-05 14:08:55 +00:00
|
|
|
case "RIL:SendMMI:Return:KO":
|
|
|
|
case "RIL:CancelMMI:Return:KO":
|
2012-06-09 21:07:18 +00:00
|
|
|
request = this.takeRequest(msg.json.requestId);
|
|
|
|
if (request) {
|
|
|
|
Services.DOMRequest.fireError(request, msg.json.errorMsg);
|
|
|
|
}
|
|
|
|
break;
|
2012-04-10 12:04:27 +00:00
|
|
|
case "RIL:StkCommand":
|
|
|
|
let jsonString = JSON.stringify(msg.json);
|
|
|
|
Services.obs.notifyObservers(null, kStkCommandTopic, jsonString);
|
|
|
|
break;
|
|
|
|
case "RIL:StkSessionEnd":
|
|
|
|
Services.obs.notifyObservers(null, kStkSessionEndTopic, null);
|
2012-09-25 19:22:38 +00:00
|
|
|
break;
|
|
|
|
case "RIL:DataError":
|
|
|
|
this.updateConnectionInfo(msg.json, this.dataConnectionInfo);
|
|
|
|
Services.obs.notifyObservers(null, kDataErrorTopic, msg.json.error);
|
|
|
|
break;
|
2012-10-31 13:58:39 +00:00
|
|
|
case "RIL:GetCallForwardingOption":
|
|
|
|
this.handleGetCallForwardingOption(msg.json);
|
|
|
|
break;
|
|
|
|
case "RIL:SetCallForwardingOption":
|
|
|
|
this.handleSetCallForwardingOption(msg.json);
|
|
|
|
break;
|
2012-12-04 02:40:47 +00:00
|
|
|
case "RIL:CellBroadcastReceived":
|
|
|
|
let message = new CellBroadcastMessage(msg.json);
|
|
|
|
this._deliverCallback("_cellBroadcastCallbacks",
|
|
|
|
"notifyMessageReceived",
|
|
|
|
[message]);
|
|
|
|
break;
|
2012-04-24 15:44:42 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-05-15 04:13:06 +00:00
|
|
|
handleEnumerateCalls: function handleEnumerateCalls(calls) {
|
|
|
|
debug("handleEnumerateCalls: " + JSON.stringify(calls));
|
2012-10-30 09:24:31 +00:00
|
|
|
let callback = this._enumerateTelephonyCallbacks.shift();
|
2012-04-24 15:44:42 +00:00
|
|
|
for (let i in calls) {
|
|
|
|
let call = calls[i];
|
|
|
|
let keepGoing;
|
|
|
|
try {
|
|
|
|
keepGoing =
|
|
|
|
callback.enumerateCallState(call.callIndex, call.state, call.number,
|
2012-05-15 04:13:06 +00:00
|
|
|
call.isActive);
|
2012-04-24 15:44:42 +00:00
|
|
|
} catch (e) {
|
|
|
|
debug("callback handler for 'enumerateCallState' threw an " +
|
|
|
|
" exception: " + e);
|
|
|
|
keepGoing = true;
|
|
|
|
}
|
|
|
|
if (!keepGoing) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-06-01 21:10:39 +00:00
|
|
|
handleGetAvailableNetworks: function handleGetAvailableNetworks(message) {
|
|
|
|
debug("handleGetAvailableNetworks: " + JSON.stringify(message));
|
|
|
|
|
|
|
|
let requestId = message.requestId;
|
|
|
|
let request = this.takeRequest(requestId);
|
|
|
|
if (!request) {
|
|
|
|
debug("no DOMRequest found with request ID: " + requestId);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (message.error) {
|
|
|
|
debug("Received error from getAvailableNetworks: " + message.error);
|
|
|
|
Services.DOMRequest.fireError(request, message.error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let networks = message.networks;
|
|
|
|
for (let i = 0; i < networks.length; i++) {
|
|
|
|
let network = networks[i];
|
2012-06-12 21:05:50 +00:00
|
|
|
let info = new MobileNetworkInfo();
|
2012-06-01 21:10:39 +00:00
|
|
|
|
|
|
|
for (let key in network) {
|
|
|
|
info[key] = network[key];
|
|
|
|
}
|
|
|
|
|
|
|
|
networks[i] = info;
|
|
|
|
}
|
|
|
|
|
|
|
|
Services.DOMRequest.fireSuccess(request, networks);
|
|
|
|
},
|
|
|
|
|
2012-06-19 22:52:06 +00:00
|
|
|
handleSelectNetwork: function handleSelectNetwork(message, mode) {
|
|
|
|
this._selectingNetwork = null;
|
|
|
|
this.networkSelectionMode = mode;
|
|
|
|
|
|
|
|
if (message.error) {
|
|
|
|
this.fireRequestError(message.requestId, message.error);
|
|
|
|
} else {
|
|
|
|
this.fireRequestSuccess(message.requestId, null);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-07-19 03:27:08 +00:00
|
|
|
handleVoicemailNotification: function handleVoicemailNotification(message) {
|
|
|
|
let changed = false;
|
|
|
|
if (!this.voicemailStatus) {
|
|
|
|
this.voicemailStatus = new VoicemailStatus();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.voicemailStatus.hasMessages != message.active) {
|
|
|
|
changed = true;
|
|
|
|
this.voicemailStatus.hasMessages = message.active;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.voicemailStatus.messageCount != message.msgCount) {
|
|
|
|
changed = true;
|
|
|
|
this.voicemailStatus.messageCount = message.msgCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.voicemailStatus.returnNumber != message.returnNumber) {
|
|
|
|
changed = true;
|
|
|
|
this.voicemailStatus.returnNumber = message.returnNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.voicemailStatus.returnMessage != message.returnMessage) {
|
|
|
|
changed = true;
|
|
|
|
this.voicemailStatus.returnMessage = message.returnMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changed) {
|
|
|
|
this._deliverCallback("_voicemailCallbacks",
|
|
|
|
"voicemailNotification",
|
|
|
|
[this.voicemailStatus]);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-11-07 22:13:48 +00:00
|
|
|
_cfRulesToMobileCfInfo: function _cfRulesToMobileCfInfo(rules) {
|
|
|
|
for (let i = 0; i < rules.length; i++) {
|
|
|
|
let rule = rules[i];
|
|
|
|
let info = new MobileCFInfo();
|
|
|
|
|
|
|
|
for (let key in rule) {
|
|
|
|
info[key] = rule[key];
|
|
|
|
}
|
|
|
|
|
|
|
|
rules[i] = info;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-10-31 13:58:39 +00:00
|
|
|
handleGetCallForwardingOption: function handleGetCallForwardingOption(message) {
|
|
|
|
let requestId = message.requestId;
|
|
|
|
let request = this.takeRequest(requestId);
|
|
|
|
if (!request) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!message.success) {
|
|
|
|
Services.DOMRequest.fireError(request, message.errorMsg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-07 22:13:48 +00:00
|
|
|
this._cfRulesToMobileCfInfo(message.rules);
|
|
|
|
Services.DOMRequest.fireSuccess(request, message.rules);
|
2012-10-31 13:58:39 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
handleSetCallForwardingOption: function handleSetCallForwardingOption(message) {
|
|
|
|
let requestId = message.requestId;
|
|
|
|
let request = this.takeRequest(requestId);
|
|
|
|
if (!request) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!message.success) {
|
|
|
|
Services.DOMRequest.fireError(request, message.errorMsg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Services.DOMRequest.fireSuccess(request, null);
|
|
|
|
},
|
|
|
|
|
2012-11-07 22:13:48 +00:00
|
|
|
handleSendCancelMMIOK: function handleSendCancelMMIOK(message) {
|
|
|
|
let request = this.takeRequest(message.requestId);
|
|
|
|
if (!request) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// MMI query call forwarding options request returns a set of rules that
|
|
|
|
// will be exposed in the form of an array of nsIDOMMozMobileCFInfo
|
|
|
|
// instances.
|
|
|
|
if (message.success && message.rules) {
|
|
|
|
this._cfRulesToMobileCfInfo(message.rules);
|
|
|
|
message.result = message.rules;
|
|
|
|
}
|
|
|
|
|
|
|
|
Services.DOMRequest.fireSuccess(request, message.result);
|
|
|
|
},
|
|
|
|
|
2012-08-17 03:46:34 +00:00
|
|
|
_getRandomId: function _getRandomId() {
|
|
|
|
return gUUIDGenerator.generateUUID().toString();
|
|
|
|
},
|
|
|
|
|
2012-07-19 03:27:08 +00:00
|
|
|
_deliverCallback: function _deliverCallback(callbackType, name, args) {
|
|
|
|
let thisCallbacks = this[callbackType];
|
|
|
|
if (!thisCallbacks) {
|
2012-04-24 15:44:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-19 03:27:08 +00:00
|
|
|
let callbacks = thisCallbacks.slice();
|
2012-04-24 15:44:42 +00:00
|
|
|
for each (let callback in callbacks) {
|
2012-07-19 03:27:08 +00:00
|
|
|
if (thisCallbacks.indexOf(callback) == -1) {
|
2012-04-24 15:44:42 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
let handler = callback[name];
|
|
|
|
if (typeof handler != "function") {
|
|
|
|
throw new Error("No handler for " + name);
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
handler.apply(callback, args);
|
|
|
|
} catch (e) {
|
|
|
|
debug("callback handler for " + name + " threw an exception: " + e);
|
|
|
|
}
|
2012-04-19 21:33:25 +00:00
|
|
|
}
|
2012-10-31 13:58:39 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper for guarding us again invalid reason values for call forwarding.
|
|
|
|
*/
|
|
|
|
_isValidCFReason: function _isValidCFReason(reason) {
|
|
|
|
switch (reason) {
|
|
|
|
case Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_REASON_UNCONDITIONAL:
|
|
|
|
case Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_REASON_MOBILE_BUSY:
|
|
|
|
case Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_REASON_NO_REPLY:
|
|
|
|
case Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_REASON_NOT_REACHABLE:
|
|
|
|
case Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_REASON_ALL_CALL_FORWARDING:
|
|
|
|
case Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_REASON_ALL_CONDITIONAL_CALL_FORWARDING:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper for guarding us again invalid action values for call forwarding.
|
|
|
|
*/
|
|
|
|
_isValidCFAction: function _isValidCFAction(action) {
|
|
|
|
switch (action) {
|
|
|
|
case Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_ACTION_DISABLE:
|
|
|
|
case Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_ACTION_ENABLE:
|
|
|
|
case Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_ACTION_REGISTRATION:
|
|
|
|
case Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_ACTION_ERASURE:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2012-07-19 03:27:08 +00:00
|
|
|
}
|
2012-04-19 21:33:25 +00:00
|
|
|
};
|
|
|
|
|
2012-10-31 16:13:28 +00:00
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([RILContentHelper]);
|
2012-04-19 21:33:25 +00:00
|
|
|
|
|
|
|
let debug;
|
|
|
|
if (DEBUG) {
|
|
|
|
debug = function (s) {
|
|
|
|
dump("-*- RILContentHelper: " + s + "\n");
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
debug = function (s) {};
|
|
|
|
}
|