Bug 816564 - Silent SMS to Authenticate Device for Mobile Billing. Part 1: RIL. sr=vicamo

This commit is contained in:
Fernando Jiménez 2013-07-30 00:50:22 +02:00
Родитель 45b6d456ae
Коммит 75bd97c435
2 изменённых файлов: 131 добавлений и 47 удалений

Просмотреть файл

@ -51,6 +51,7 @@ const nsITelephonyProvider = Ci.nsITelephonyProvider;
const kNetworkInterfaceStateChangedTopic = "network-interface-state-changed";
const kSmsReceivedObserverTopic = "sms-received";
const kSilentSmsReceivedObserverTopic = "silent-sms-received";
const kSmsSendingObserverTopic = "sms-sending";
const kSmsSentObserverTopic = "sms-sent";
const kSmsFailedObserverTopic = "sms-failed";
@ -145,6 +146,10 @@ XPCOMUtils.defineLazyServiceGetter(this, "gMobileMessageService",
"@mozilla.org/mobilemessage/mobilemessageservice;1",
"nsIMobileMessageService");
XPCOMUtils.defineLazyServiceGetter(this, "gSmsService",
"@mozilla.org/sms/smsservice;1",
"nsISmsService");
XPCOMUtils.defineLazyServiceGetter(this, "gMobileMessageDatabaseService",
"@mozilla.org/mobilemessage/rilmobilemessagedatabaseservice;1",
"nsIRilMobileMessageDatabaseService");
@ -1888,6 +1893,31 @@ RadioInterface.prototype = {
message.body = message.fullBody = message.fullBody || null;
message.timestamp = Date.now();
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,
message.delivery,
message.deliveryStatus,
message.sender,
message.receiver,
message.body,
message.messageClass,
message.timestamp,
message.read);
Services.obs.notifyObservers(domMessage,
kSilentSmsReceivedObserverTopic,
null);
return true;
}
// TODO: Bug #768441
// For now we don't store indicators persistently. When the mwi.discard
// flag is false, we'll need to persist the indicator to EFmwis.
@ -1977,6 +2007,25 @@ RadioInterface.prototype = {
return;
}
if (options.silent) {
// 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 = options.sms;
options.request.notifyMessageSent(
gMobileMessageService.createSmsMessage(sms.id,
sms.threadId,
DOM_MOBILE_MESSAGE_DELIVERY_SENT,
sms.deliveryStatus,
sms.sender,
sms.receiver,
sms.body,
sms.messageClass,
sms.timestamp,
sms.read));
return;
}
gMobileMessageDatabaseService.setMessageDelivery(options.sms.id,
null,
DOM_MOBILE_MESSAGE_DELIVERY_SENT,
@ -2006,6 +2055,10 @@ RadioInterface.prototype = {
}
delete this._sentSmsEnvelopes[message.envelopeId];
if (options.silent) {
return;
}
gMobileMessageDatabaseService.setMessageDelivery(options.sms.id,
null,
options.sms.delivery,
@ -2035,6 +2088,11 @@ RadioInterface.prototype = {
break;
}
if (options.silent) {
options.request.notifySendMessageFailed(error);
return;
}
gMobileMessageDatabaseService.setMessageDelivery(options.sms.id,
null,
DOM_MOBILE_MESSAGE_DELIVERY_ERROR,
@ -3145,7 +3203,7 @@ RadioInterface.prototype = {
return result;
},
sendSMS: function sendSMS(number, message, request) {
sendSMS: function sendSMS(number, message, silent, request) {
let strict7BitEncoding;
try {
strict7BitEncoding = Services.prefs.getBoolPref("dom.sms.strict7BitEncoding");
@ -3169,6 +3227,57 @@ RadioInterface.prototype = {
options.segmentRef = this.nextSegmentRef;
}
let notifyResult = (function notifyResult(rv, domMessage) {
// TODO bug 832140 handle !Components.isSuccessCode(rv)
if (!silent) {
Services.obs.notifyObservers(domMessage, kSmsSendingObserverTopic, null);
}
// If the radio is disabled or the SIM card is not ready, just directly
// return with the corresponding error code.
let errorCode;
if (!PhoneNumberUtils.isPlainPhoneNumber(options.number)) {
if (DEBUG) this.debug("Error! Address is invalid when sending SMS: " +
options.number);
errorCode = Ci.nsIMobileMessageCallback.INVALID_ADDRESS_ERROR;
} else if (!this._radioEnabled) {
if (DEBUG) this.debug("Error! Radio is disabled when sending SMS.");
errorCode = Ci.nsIMobileMessageCallback.RADIO_DISABLED_ERROR;
} else if (this.rilContext.cardState != "ready") {
if (DEBUG) this.debug("Error! SIM card is not ready when sending SMS.");
errorCode = Ci.nsIMobileMessageCallback.NO_SIM_CARD_ERROR;
}
if (errorCode) {
if (silent) {
request.notifySendMessageFailed(errorCode);
return;
}
gMobileMessageDatabaseService
.setMessageDelivery(domMessage.id,
null,
DOM_MOBILE_MESSAGE_DELIVERY_ERROR,
RIL.GECKO_SMS_DELIVERY_STATUS_ERROR,
function notifyResult(rv, domMessage) {
// TODO bug 832140 handle !Components.isSuccessCode(rv)
request.notifySendMessageFailed(errorCode);
Services.obs.notifyObservers(domMessage, kSmsFailedObserverTopic, null);
});
return;
}
// Keep current SMS message info for sent/delivered notifications
options.envelopeId = this.createSmsEnvelope({
request: request,
sms: domMessage,
requestStatusReport: options.requestStatusReport,
silent: silent
});
// This is the entry point starting to send SMS.
this.worker.postMessage(options);
}).bind(this);
let sendingMessage = {
type: "sms",
sender: this.getMsisdn(),
@ -3178,52 +3287,26 @@ RadioInterface.prototype = {
timestamp: Date.now()
};
if (silent) {
let deliveryStatus = RIL.GECKO_SMS_DELIVERY_STATUS_PENDING;
let delivery = DOM_MOBILE_MESSAGE_DELIVERY_SENDING;
let domMessage =
gMobileMessageService.createSmsMessage(-1, // id
0, // threadId
delivery,
deliveryStatus,
sendingMessage.sender,
sendingMessage.receiver,
sendingMessage.body,
"normal", // message class
sendingMessage.timestamp,
false);
notifyResult(Cr.NS_OK, domMessage);
return;
}
let id = gMobileMessageDatabaseService.saveSendingMessage(
sendingMessage,
function notifyResult(rv, domMessage) {
// TODO bug 832140 handle !Components.isSuccessCode(rv)
Services.obs.notifyObservers(domMessage, kSmsSendingObserverTopic, null);
// If the radio is disabled or the SIM card is not ready, just directly
// return with the corresponding error code.
let errorCode;
if (!PhoneNumberUtils.isPlainPhoneNumber(options.number)) {
if (DEBUG) this.debug("Error! Address is invalid when sending SMS: " +
options.number);
errorCode = Ci.nsIMobileMessageCallback.INVALID_ADDRESS_ERROR;
} else if (!this._radioEnabled) {
if (DEBUG) this.debug("Error! Radio is disabled when sending SMS.");
errorCode = Ci.nsIMobileMessageCallback.RADIO_DISABLED_ERROR;
} else if (this.rilContext.cardState != "ready") {
if (DEBUG) this.debug("Error! SIM card is not ready when sending SMS.");
errorCode = Ci.nsIMobileMessageCallback.NO_SIM_CARD_ERROR;
}
if (errorCode) {
gMobileMessageDatabaseService
.setMessageDelivery(domMessage.id,
null,
DOM_MOBILE_MESSAGE_DELIVERY_ERROR,
RIL.GECKO_SMS_DELIVERY_STATUS_ERROR,
function notifyResult(rv, domMessage) {
// TODO bug 832140 handle !Components.isSuccessCode(rv)
request.notifySendMessageFailed(errorCode);
Services.obs.notifyObservers(domMessage, kSmsFailedObserverTopic, null);
});
return;
}
// Keep current SMS message info for sent/delivered notifications
options.envelopeId = this.createSmsEnvelope({
request: request,
sms: domMessage,
requestStatusReport: options.requestStatusReport
});
// This is the entry point starting to send SMS.
this.worker.postMessage(options);
}.bind(this));
sendingMessage, notifyResult);
},
registerDataCallCallback: function registerDataCallCallback(callback) {

Просмотреть файл

@ -79,7 +79,7 @@ interface nsIRilContext : nsISupports
readonly attribute nsIDOMMozMobileConnectionInfo data;
};
[scriptable, uuid(6dde3eaf-243d-4afa-abdb-95c94c2b1c7a)]
[scriptable, uuid(715c972b-97c5-48fd-a8b1-d50e6852153a)]
interface nsIRadioInterface : nsISupports
{
/**
@ -119,6 +119,7 @@ interface nsIRadioInterface : nsISupports
void sendSMS(in DOMString number,
in DOMString message,
in boolean silent,
in nsIMobileMessageCallback request);
};