Bug 921918 - 4.b/4: Gonk RIL implementation. r=gene

This commit is contained in:
Vicamo Yang 2013-11-25 15:19:33 +08:00
parent d9367b47db
commit 0afd9d717f
4 changed files with 139 additions and 6 deletions

View File

@ -1504,6 +1504,13 @@ const MMS_PDU_TYPES = (function () {
"to",
"from",
"x-mms-read-status"]);
add(MMS_PDU_TYPE_READ_ORIG_IND, false, ["x-mms-message-type",
"x-mms-mms-version",
"message-id",
"to",
"from",
"date",
"x-mms-read-status"]);
return pdus;
})();

View File

@ -35,6 +35,8 @@ const kSmsReceivedObserverTopic = "sms-received";
const kSmsRetrievingObserverTopic = "sms-retrieving";
const kSmsDeliverySuccessObserverTopic = "sms-delivery-success";
const kSmsDeliveryErrorObserverTopic = "sms-delivery-error";
const kSmsReadSuccessObserverTopic = "sms-read-success";
const kSmsReadErrorObserverTopic = "sms-read-error";
const NS_XPCOM_SHUTDOWN_OBSERVER_ID = "xpcom-shutdown";
const kNetworkInterfaceStateChangedTopic = "network-interface-state-changed";
@ -1796,11 +1798,6 @@ MmsService.prototype = {
* The MMS message object.
*/
handleDeliveryIndication: function handleDeliveryIndication(aMsg) {
if (DEBUG) {
debug("handleDeliveryIndication: got delivery report" +
JSON.stringify(aMsg));
}
let headers = aMsg.headers;
let envelopeId = headers["message-id"];
let address = headers.to.address;
@ -1861,6 +1858,57 @@ MmsService.prototype = {
}).bind(this));
},
/**
* Handle incoming M-Read-Orig.ind PDU.
*
* @param aIndication
* The MMS message object.
*/
handleReadOriginateIndication:
function handleReadOriginateIndication(aIndication) {
let headers = aIndication.headers;
let envelopeId = headers["message-id"];
let address = headers.from.address;
let mmsReadStatus = headers["x-mms-read-status"];
if (DEBUG) {
debug("Start updating the read status for envelopeId: " + envelopeId +
", address: " + address + ", mmsReadStatus: " + mmsReadStatus);
}
// From OMA-TS-MMS_ENC-V1_3-20110913-A subclause 9.4 "X-Mms-Read-Status",
// in M-Read-Rec-Orig.ind the X-Mms-Read-Status could be
// MMS.MMS_READ_STATUS_{ READ, DELETED_WITHOUT_BEING_READ }.
let readStatus = mmsReadStatus == MMS.MMS_PDU_READ_STATUS_READ
? MMS.DOM_READ_STATUS_SUCCESS
: MMS.DOM_READ_STATUS_ERROR;
if (DEBUG) debug("Updating the read status to: " + readStatus);
gMobileMessageDatabaseService
.setMessageReadStatusByEnvelopeId(envelopeId, address, readStatus,
(function(aRv, aDomMessage) {
if (!Components.isSuccessCode(aRv)) {
// Notifying observers the read status is error.
Services.obs.notifyObservers(aDomMessage, kSmsReadSuccessObserverTopic, null);
return;
}
if (DEBUG) debug("Marking the read status is done.");
let topic;
if (mmsReadStatus == MMS.MMS_PDU_READ_STATUS_READ) {
topic = kSmsReadSuccessObserverTopic;
// Broadcasting a 'sms-read-success' system message to open apps.
this.broadcastMmsSystemMessage(topic, aDomMessage);
} else {
topic = kSmsReadErrorObserverTopic;
}
// Notifying observers the read status is updated.
Services.obs.notifyObservers(aDomMessage, topic, null);
}).bind(this));
},
/**
* A utility function to convert the MmsParameters dictionary object
* to a database-savable message.
@ -2362,6 +2410,9 @@ MmsService.prototype = {
case MMS.MMS_PDU_TYPE_DELIVERY_IND:
this.handleDeliveryIndication(msg);
break;
case MMS.MMS_PDU_TYPE_READ_ORIG_IND:
this.handleReadOriginateIndication(msg);
break;
default:
if (DEBUG) debug("Unsupported X-MMS-Message-Type: " + msg.type);
break;

View File

@ -1226,6 +1226,17 @@ MobileMessageDatabaseService.prototype = {
}
}
// For all sent and received MMS messages, we have to add their
// |readStatus| and |readTimestamp| attributes in |deliveryInfo| array.
let readReportRequested =
messageRecord.headers["x-mms-read-report"] || false;
for (let element of messageRecord.deliveryInfo) {
element.readStatus = readReportRequested
? MMS.DOM_READ_STATUS_PENDING
: MMS.DOM_READ_STATUS_NOT_APPLICABLE;
element.readTimestamp = 0;
}
cursor.update(messageRecord);
cursor.continue();
};
@ -2047,6 +2058,8 @@ MobileMessageDatabaseService.prototype = {
receiver: aMessage.phoneNumber,
deliveryStatus: aMessage.deliveryStatus,
deliveryTimestamp: 0,
readStatus: MMS.DOM_READ_STATUS_NOT_APPLICABLE,
readTimestamp: 0,
}];
delete aMessage.deliveryStatus;
@ -2100,12 +2113,18 @@ MobileMessageDatabaseService.prototype = {
}
return;
}
let readStatus = aMessage.headers["x-mms-read-report"]
? MMS.DOM_READ_STATUS_PENDING
: MMS.DOM_READ_STATUS_NOT_APPLICABLE;
aMessage.deliveryInfo = [];
for (let i = 0; i < receivers.length; i++) {
aMessage.deliveryInfo.push({
receiver: receivers[i],
deliveryStatus: deliveryStatus,
deliveryTimestamp: 0 });
deliveryTimestamp: 0,
readStatus: readStatus,
readTimestamp: 0,
});
}
}
@ -2143,6 +2162,57 @@ MobileMessageDatabaseService.prototype = {
aDeliveryStatus, null, aCallback);
},
setMessageReadStatusByEnvelopeId:
function setMessageReadStatusByEnvelopeId(aEnvelopeId, aReceiver,
aReadStatus, aCallback) {
if (DEBUG) {
debug("Setting message's read status by envelopeId = " + aEnvelopeId +
", receiver: " + aReceiver + ", readStatus: " + aReadStatus);
}
let self = this;
this.newTxnWithCallback(aCallback, function(aCapture, aMessageStore) {
let getRequest = aMessageStore.index("envelopeId").get(aEnvelopeId);
getRequest.onsuccess = function onsuccess(event) {
let messageRecord = event.target.result;
if (!messageRecord) {
if (DEBUG) debug("envelopeId '" + aEnvelopeId + "' not found");
throw Cr.NS_ERROR_FAILURE;
}
aCapture.messageRecord = messageRecord;
let isRecordUpdated = false;
self.forEachMatchedMmsDeliveryInfo(messageRecord.deliveryInfo,
aReceiver, function(aEntry) {
if (aEntry.readStatus == aReadStatus) {
return;
}
aEntry.readStatus = aReadStatus;
if (aReadStatus == MMS.DOM_READ_STATUS_SUCCESS) {
aEntry.readTimestamp = Date.now();
} else {
aEntry.readTimestamp = 0;
}
isRecordUpdated = true;
});
if (!isRecordUpdated) {
if (DEBUG) {
debug("The values of readStatus don't need to be updated.");
}
return;
}
if (DEBUG) {
debug("The readStatus is updated.");
}
aMessageStore.put(messageRecord);
};
});
},
getMessageRecordByTransactionId: function getMessageRecordByTransactionId(aTransactionId, aCallback) {
if (DEBUG) debug("Retrieving message with transaction ID " + aTransactionId);
let self = this;

View File

@ -118,6 +118,11 @@ this.MMS_MAX_TOTAL_RECIPIENTS = 20;
this.MMS_MAX_LENGTH_NAME_CONTENT_TYPE = 40;
this.MMS_MAX_LENGTH_MAILBOX_PORTION = 256;
this.DOM_READ_STATUS_NOT_APPLICABLE = "not-applicable";
this.DOM_READ_STATUS_SUCCESS = "success";
this.DOM_READ_STATUS_PENDING = "pending";
this.DOM_READ_STATUS_ERROR = "error";
this.ALL_CONST_SYMBOLS = undefined; // We want ALL_CONST_SYMBOLS to be exported.
this.ALL_CONST_SYMBOLS = Object.keys(this);