Bug 736697 - Part 4: handle SMS-STATUS-REPORT. r=philikon

This commit is contained in:
Vicamo Yang 2012-04-05 14:16:56 -07:00
Родитель d75add116e
Коммит bca7e88a78
2 изменённых файлов: 115 добавлений и 16 удалений

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

@ -58,6 +58,7 @@ const nsIAudioManager = Ci.nsIAudioManager;
const nsIRadioInterfaceLayer = Ci.nsIRadioInterfaceLayer;
const kSmsReceivedObserverTopic = "sms-received";
const kSmsDeliveredObserverTopic = "sms-delivered";
const DOM_SMS_DELIVERY_RECEIVED = "received";
const DOM_SMS_DELIVERY_SENT = "sent";
@ -151,6 +152,7 @@ function RadioInterfaceLayer() {
type: null,
msisdn: null,
};
this._sentSmsEnvelopes = {};
}
RadioInterfaceLayer.prototype = {
@ -257,6 +259,9 @@ RadioInterfaceLayer.prototype = {
case "sms-sent":
this.handleSmsSent(message);
return;
case "sms-delivered":
this.handleSmsDelivered(message);
return;
case "datacallstatechange":
this.handleDataCallState(message.datacall);
break;
@ -425,20 +430,61 @@ RadioInterfaceLayer.prototype = {
Services.obs.notifyObservers(sms, kSmsReceivedObserverTopic, null);
},
/**
* Local storage for sent SMS messages.
*/
_sentSmsEnvelopes: null,
createSmsEnvelope: function createSmsEnvelope(options) {
let i;
for (i = 1; this._sentSmsEnvelopes[i]; i++) {
// Do nothing.
}
debug("createSmsEnvelope: assigned " + i);
options.envelopeId = i;
this._sentSmsEnvelopes[i] = options;
},
handleSmsSent: function handleSmsSent(message) {
debug("handleSmsSent: " + JSON.stringify(message));
let options = this._sentSmsEnvelopes[message.envelopeId];
if (!options) {
return;
}
let timestamp = Date.now();
let id = gSmsDatabaseService.saveSentMessage(message.number,
message.fullBody,
let id = gSmsDatabaseService.saveSentMessage(options.number,
options.fullBody,
timestamp);
let sms = gSmsService.createSmsMessage(id,
DOM_SMS_DELIVERY_SENT,
null,
message.number,
message.fullBody,
options.number,
options.fullBody,
timestamp);
if (!options.requestStatusReport) {
// No more used if STATUS-REPORT not requested.
delete this._sentSmsEnvelopes[message.envelopeId];
} else {
options.sms = sms;
}
//TODO handle errors (bug 727319)
gSmsRequestManager.notifySmsSent(message.requestId, sms);
gSmsRequestManager.notifySmsSent(options.requestId, sms);
},
handleSmsDelivered: function handleSmsDelivered(message) {
debug("handleSmsDelivered: " + JSON.stringify(message));
let options = this._sentSmsEnvelopes[message.envelopeId];
if (!options) {
return;
}
delete this._sentSmsEnvelopes[message.envelopeId];
Services.obs.notifyObservers(options.sms, kSmsDeliveredObserverTopic, null);
},
/**
@ -921,6 +967,7 @@ RadioInterfaceLayer.prototype = {
options.number = number;
options.requestId = requestId;
options.processId = processId;
options.requestStatusReport = true;
this._fragmentText(message, options);
if (options.segmentMaxSeq > 1) {
@ -928,6 +975,9 @@ RadioInterfaceLayer.prototype = {
options.segmentRef = this.nextSegmentRef;
}
// Keep current SMS message info for sent/delivered notifications
this.createSmsEnvelope(options);
this.worker.postMessage(options);
},

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

@ -614,6 +614,11 @@ let RIL = {
*/
_receivedSmsSegmentsMap: {},
/**
* Outgoing messages waiting for SMS-STATUS-REPORT.
*/
_pendingSentSmsMap: {},
/**
* Mute or unmute the radio.
*/
@ -1545,6 +1550,25 @@ let RIL = {
return PDU_FCS_UNSPECIFIED;
}
let options = this._pendingSentSmsMap[message.messageRef];
if (!options) {
return PDU_FCS_OK;
}
delete this._pendingSentSmsMap[message.messageRef];
if ((options.segmentMaxSeq > 1)
&& (options.segmentSeq < options.segmentMaxSeq)) {
// Not last segment. Send next segment here.
this._processSentSmsSegment(options);
} else {
// Last segment delivered with success. Report it.
this.sendDOMMessage({
type: "sms-delivered",
envelopeId: options.envelopeId,
});
}
return PDU_FCS_OK;
},
@ -1601,6 +1625,19 @@ let RIL = {
return options;
},
/**
* Helper for processing sent multipart SMS.
*/
_processSentSmsSegment: function _processSentSmsSegment(options) {
// Setup attributes for sending next segment
let next = options.segmentSeq;
options.body = options.segments[next].body;
options.encodedBodyLength = options.segments[next].encodedBodyLength;
options.segmentSeq = next + 1;
this.sendSMS(options);
},
/**
* Handle incoming messages from the main UI thread.
*
@ -1866,20 +1903,25 @@ RIL[REQUEST_SEND_SMS] = function REQUEST_SEND_SMS(length, options) {
options.errorCode = Buf.readUint32();
//TODO handle errors (bug 727319)
if ((options.segmentMaxSeq > 1)
&& (options.segmentSeq < options.segmentMaxSeq)) {
// Setup attributes for sending next segment
let next = options.segmentSeq;
options.body = options.segments[next].body;
options.encodedBodyLength = options.segments[next].encodedBodyLength;
options.segmentSeq = next + 1;
this.sendSMS(options);
return;
if (options.requestStatusReport) {
this._pendingSentSmsMap[options.messageRef] = options;
}
options.type = "sms-sent";
this.sendDOMMessage(options);
if ((options.segmentMaxSeq > 1)
&& (options.segmentSeq < options.segmentMaxSeq)) {
// Not last segment
if (!options.requestStatusReport) {
// Status-Report not requested, send next segment here.
this._processSentSmsSegment(options);
}
} else {
// Last segment sent with success. Report it.
this.sendDOMMessage({
type: "sms-sent",
envelopeId: options.envelopeId,
});
}
};
RIL[REQUEST_SEND_SMS_EXPECT_MORE] = null;
@ -3058,6 +3100,8 @@ let GsmPDUHelper = {
* Table index used for normal 7-bit encoded character lookup.
* @param langShiftIndex
* Table index used for escaped 7-bit encoded character lookup.
* @param requestStatusReport
* Request status report.
*/
writeMessage: function writeMessage(options) {
if (DEBUG) {
@ -3144,6 +3188,11 @@ let GsmPDUHelper = {
// PDU type. MTI is set to SMS-SUBMIT
let firstOctet = PDU_MTI_SMS_SUBMIT;
// Status-Report-Request
if (options.requestStatusReport) {
firstOctet |= PDU_SRI_SRR;
}
// Validity period
if (validity) {
//TODO: not supported yet, OR with one of PDU_VPF_*