Bug 734145 - B2G RIL: Support USSD codes. Part 2: RIL. r=philikon

This commit is contained in:
Fernando Jiménez 2012-06-09 17:07:18 -04:00
parent 0a85d3d8ca
commit 5ecdfabb61
3 changed files with 146 additions and 6 deletions

View File

@ -36,11 +36,17 @@ const RIL_IPC_MSG_NAMES = [
"RIL:SetCardLock:Return:KO",
"RIL:UnlockCardLock:Return:OK",
"RIL:UnlockCardLock:Return:KO",
"RIL:UssdReceived",
"RIL:SendUssd:Return:OK",
"RIL:SendUssd:Return:KO",
"RIL:CancelUssd:Return:OK",
"RIL:CancelUssd:Return:KO"
];
const kVoiceChangedTopic = "mobile-connection-voice-changed";
const kDataChangedTopic = "mobile-connection-data-changed";
const kCardStateChangedTopic = "mobile-connection-cardstate-changed";
const kUssdReceivedTopic = "mobile-connection-ussd-received";
XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
"@mozilla.org/childprocessmessagemanager;1",
@ -175,6 +181,30 @@ RILContentHelper.prototype = {
return request;
},
sendUSSD: function sendUSSD(window, ussd) {
debug("Sending USSD " + ussd);
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);
cpmm.sendAsyncMessage("RIL:SendUSSD", {ussd: ussd, requestId: requestId});
return request;
},
cancelUSSD: function cancelUSSD(window) {
debug("Cancel USSD");
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);
cpmm.sendAsyncMessage("RIL:CancelUSSD", {requestId: requestId});
return request;
},
_telephonyCallbacks: null,
_enumerationTelephonyCallbacks: null,
@ -328,6 +358,24 @@ RILContentHelper.prototype = {
Services.DOMRequest.fireError(request, msg.json.errorMsg);
}
break;
case "RIL:UssdReceived":
Services.obs.notifyObservers(null, kUssdReceivedTopic,
msg.json.message);
break;
case "RIL:SendUssd:Return:OK":
case "RIL:CancelUssd:Return:OK":
request = this.takeRequest(msg.json.requestId);
if (request) {
Services.DOMRequest.fireSuccess(request, msg.json);
}
break;
case "RIL:SendUssd:Return:KO":
case "RIL:CancelUssd:Return:KO":
request = this.takeRequest(msg.json.requestId);
if (request) {
Services.DOMRequest.fireError(request, msg.json.errorMsg);
}
break;
}
},

View File

@ -47,7 +47,9 @@ const RIL_IPC_MSG_NAMES = [
"RIL:GetAvailableNetworks",
"RIL:GetCardLock",
"RIL:UnlockCardLock",
"RIL:SetCardLock"
"RIL:SetCardLock",
"RIL:SendUSSD",
"RIL:CancelUSSD"
];
XPCOMUtils.defineLazyServiceGetter(this, "gSmsService",
@ -256,6 +258,12 @@ RadioInterfaceLayer.prototype = {
case "RIL:SetCardLock":
this.setCardLock(msg.json);
break;
case "RIL:SendUSSD":
this.sendUSSD(msg.json);
break;
case "RIL:CancelUSSD":
this.cancelUSSD(msg.json);
break;
}
},
@ -375,6 +383,16 @@ RadioInterfaceLayer.prototype = {
case "celllocationchanged":
this.radioState.cell = message;
break;
case "ussdreceived":
debug("ussdreceived " + JSON.stringify(message));
this.handleUSSDReceived(message);
break;
case "sendussd":
this.handleSendUSSD(message);
break;
case "cancelussd":
this.handleCancelUSSD(message);
break;
default:
throw new Error("Don't know about this message type: " + message.type);
}
@ -790,6 +808,25 @@ RadioInterfaceLayer.prototype = {
ppmm.sendAsyncMessage("RIL:UnlockCardLock:Return:OK", message);
},
handleUSSDReceived: function handleUSSDReceived(ussd) {
debug("handleUSSDReceived " + JSON.stringify(ussd));
ppmm.sendAsyncMessage("RIL:UssdReceived", ussd);
},
handleSendUSSD: function handleSendUSSD(message) {
debug("handleSendUSSD " + JSON.stringify(message));
let messageType = message.success ? "RIL:SendUssd:Return:OK" :
"RIL:SendUssd:Return:KO";
ppmm.sendAsyncMessage(messageType, message);
},
handleCancelUSSD: function handleCancelUSSD(message) {
debug("handleCancelUSSD " + JSON.stringify(message));
let messageType = message.success ? "RIL:CancelUssd:Return:OK" :
"RIL:CancelUssd:Return:KO";
ppmm.sendAsyncMessage(messageType, message);
},
// nsIObserver
observe: function observe(subject, topic, data) {
@ -891,6 +928,18 @@ RadioInterfaceLayer.prototype = {
this.worker.postMessage({type: "getAvailableNetworks", requestId: requestId});
},
sendUSSD: function sendUSSD(message) {
debug("SendUSSD " + JSON.stringify(message));
message.type = "sendUSSD";
this.worker.postMessage(message);
},
cancelUSSD: function cancelUSSD(message) {
debug("Cancel pending USSD");
message.type = "cancelUSSD";
this.worker.postMessage(message);
},
get microphoneMuted() {
return gAudioManager.microphoneMuted;
},

View File

@ -1757,6 +1757,26 @@ let RIL = {
Buf.simpleRequest(REQUEST_LAST_CALL_FAIL_CAUSE, options);
},
/**
* Send USSD.
*
* @param ussd
* String containing the USSD code.
*
*/
sendUSSD: function sendUSSD(options) {
Buf.newParcel(REQUEST_SEND_USSD, options);
Buf.writeString(options.ussd);
Buf.sendParcel();
},
/**
* Cancel pending USSD.
*/
cancelUSSD: function cancelUSSD(options) {
Buf.simpleRequest(REQUEST_CANCEL_USSD, options);
},
/**
* Check a given number against the list of emergency numbers provided by the RIL.
*
@ -2943,8 +2963,22 @@ RIL[REQUEST_SIM_IO] = function REQUEST_SIM_IO(length, options) {
}
this._processICCIO(options);
};
RIL[REQUEST_SEND_USSD] = null;
RIL[REQUEST_CANCEL_USSD] = null;
RIL[REQUEST_SEND_USSD] = function REQUEST_SEND_USSD(length, options) {
if (DEBUG) {
debug("REQUEST_SEND_USSD " + JSON.stringify(options));
}
options.type = "sendussd";
options.success = options.rilRequestError == 0 ? true : false;
this.sendDOMMessage(options);
};
RIL[REQUEST_CANCEL_USSD] = function REQUEST_CANCEL_USSD(length, options) {
if (DEBUG) {
debug("REQUEST_CANCEL_USSD" + JSON.stringify(options));
}
options.type = "cancelussd";
options.success = options.rilRequestError == 0 ? true : false;
this.sendDOMMessage(options);
};
RIL[REQUEST_GET_CLIR] = null;
RIL[REQUEST_SET_CLIR] = null;
RIL[REQUEST_QUERY_CALL_FORWARD_STATUS] = null;
@ -3234,9 +3268,18 @@ RIL[UNSOLICITED_RESPONSE_NEW_SMS_ON_SIM] = function UNSOLICITED_RESPONSE_NEW_SMS
let info = Buf.readUint32List();
//TODO
};
RIL[UNSOLICITED_ON_USSD] = null;
RIL[UNSOLICITED_ON_USSD_REQUEST] = null;
RIL[UNSOLICITED_ON_USSD] = function UNSOLICITED_ON_USSD() {
let [typeCode, message] = Buf.readStringList();
if (DEBUG) {
debug("On USSD. Type Code: " + typeCode + " Message: " + message);
}
// Empty message should not be progressed to the DOM.
if (!message || message == "") {
return;
}
this.sendDOMMessage({type: "ussdreceived",
message: message});
};
RIL[UNSOLICITED_NITZ_TIME_RECEIVED] = function UNSOLICITED_NITZ_TIME_RECEIVED() {
let dateString = Buf.readString();