Bug 814581 - Part 5/8: fix MobileMessage. r=gene

This commit is contained in:
Vicamo Yang 2013-07-02 17:36:47 +08:00
Родитель 71655e9ca4
Коммит 3e43e554bf
5 изменённых файлов: 54 добавлений и 47 удалений

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

@ -105,9 +105,11 @@ XPCOMUtils.defineLazyServiceGetter(this, "gUUIDGenerator",
"@mozilla.org/uuid-generator;1",
"nsIUUIDGenerator");
XPCOMUtils.defineLazyServiceGetter(this, "gRIL",
"@mozilla.org/ril;1",
"nsIRadioInterfaceLayer");
XPCOMUtils.defineLazyGetter(this, "gRadioInterface", function () {
let ril = Cc["@mozilla.org/ril;1"].getService(Ci["nsIRadioInterfaceLayer"]);
// TODO: Bug 854326 - B2G Multi-SIM: support multiple SIM cards for SMS/MMS
return ril.getRadioInterface(0);
});
XPCOMUtils.defineLazyServiceGetter(this, "gMobileMessageDatabaseService",
"@mozilla.org/mobilemessage/rilmobilemessagedatabaseservice;1",
@ -176,7 +178,7 @@ XPCOMUtils.defineLazyGetter(this, "gMmsConnection", function () {
onDisconnectTimerTimeout: function onDisconnectTimerTimeout() {
if (DEBUG) debug("onDisconnectTimerTimeout: deactivate the MMS data call.");
if (this.connected) {
gRIL.deactivateDataCallByType("mms");
gRadioInterface.deactivateDataCallByType("mms");
}
},
@ -207,7 +209,7 @@ XPCOMUtils.defineLazyGetter(this, "gMmsConnection", function () {
this.radioDisabled = false;
}
this.connected = gRIL.getDataCallStateByType("mms") ==
this.connected = gRadioInterface.getDataCallStateByType("mms") ==
Ci.nsINetworkInterface.NETWORK_STATE_CONNECTED;
},
@ -217,7 +219,7 @@ XPCOMUtils.defineLazyGetter(this, "gMmsConnection", function () {
* @return true if voice call is roaming.
*/
isVoiceRoaming: function isVoiceRoaming() {
let isRoaming = gRIL.rilContext.voice.roaming;
let isRoaming = gRadioInterface.rilContext.voice.roaming;
if (DEBUG) debug("isVoiceRoaming = " + isRoaming);
return isRoaming;
},
@ -241,7 +243,7 @@ XPCOMUtils.defineLazyGetter(this, "gMmsConnection", function () {
if (!this.connected) {
if (DEBUG) debug("acquire: buffer the MMS request and setup the MMS data call.");
this.pendingCallbacks.push(callback);
gRIL.setupDataCallByType("mms");
gRadioInterface.setupDataCallByType("mms");
// Set a timer to clear the buffered MMS requests if the
// MMS network fails to be connected within a time period.
@ -318,7 +320,7 @@ XPCOMUtils.defineLazyGetter(this, "gMmsConnection", function () {
switch (topic) {
case kNetworkInterfaceStateChangedTopic: {
this.connected =
gRIL.getDataCallStateByType("mms") ==
gRadioInterface.getDataCallStateByType("mms") ==
Ci.nsINetworkInterface.NETWORK_STATE_CONNECTED;
if (!this.connected) {
@ -1176,6 +1178,18 @@ MmsService.prototype = {
return config >= CONFIG_SEND_REPORT_DEFAULT_YES;
},
getMsisdn: function getMsisdn() {
let iccInfo = gRadioInterface.rilContext.iccInfo;
let number = iccInfo ? iccInfo.msisdn : null;
// Workaround an xpconnect issue with undefined string objects.
// See bug 808220
if (number === undefined || number === "undefined") {
return null;
}
return number;
},
/**
* Convert intermediate message to indexedDB savable object.
*
@ -1217,6 +1231,7 @@ MmsService.prototype = {
intermediate.sender = "anonymous";
}
intermediate.receivers = [];
intermediate.msisdn = this.getMsisdn();
return intermediate;
},
@ -1626,6 +1641,7 @@ MmsService.prototype = {
message["deliveryStatusRequested"] = true;
message["timestamp"] = Date.now();
message["receivers"] = receivers;
message["sender"] = this.getMsisdn();
if (DEBUG) debug("createSavableFromParams: message: " + JSON.stringify(message));
return message;
@ -1699,7 +1715,7 @@ MmsService.prototype = {
}
// For SIM card is not ready.
if (gRIL.rilContext.cardState != "ready") {
if (gRadioInterface.rilContext.cardState != "ready") {
if (DEBUG) debug("Error! SIM card is not ready when sending MMS.");
sendTransactionCb(aDomMessage,
Ci.nsIMobileMessageCallback.NO_SIM_CARD_ERROR);

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

@ -1103,18 +1103,6 @@ MobileMessageDatabaseService.prototype = {
return aMessageRecord.id;
},
getRilIccInfoMsisdn: function getRilIccInfoMsisdn() {
let iccInfo = this.mRIL.rilContext.iccInfo;
let number = iccInfo ? iccInfo.msisdn : null;
// Workaround an xpconnect issue with undefined string objects.
// See bug 808220
if (number === undefined || number === "undefined") {
return null;
}
return number;
},
/**
* nsIRilMobileMessageDatabaseService API
*/
@ -1133,13 +1121,8 @@ MobileMessageDatabaseService.prototype = {
}
return;
}
let self = this.getRilIccInfoMsisdn();
let threadParticipants = [aMessage.sender];
if (aMessage.type == "sms") {
// For some SIMs we cannot retrieve the vaild MSISDN (i.e. the user's own
// phone number), thus setting the SMS' receiver to be null.
aMessage.receiver = self;
} else if (aMessage.type == "mms" && !DISABLE_MMS_GROUPING_FOR_RECEIVING) {
if (aMessage.type == "mms" && !DISABLE_MMS_GROUPING_FOR_RECEIVING) {
let receivers = aMessage.receivers;
// If we don't want to disable the MMS grouping for receiving, we need to
// add the receivers (excluding the user's own number) to the participants
@ -1157,8 +1140,8 @@ MobileMessageDatabaseService.prototype = {
if (receivers.length >= 2) {
let isSuccess = false;
let slicedReceivers = receivers.slice();
if (self) {
let found = slicedReceivers.indexOf(self);
if (aMessage.msisdn) {
let found = slicedReceivers.indexOf(aMessage.msisdn);
if (found !== -1) {
isSuccess = true;
slicedReceivers.splice(found, 1);
@ -1232,9 +1215,6 @@ MobileMessageDatabaseService.prototype = {
}
}
// For some SIMs we cannot retrieve the vaild MSISDN (i.e. the user's own
// phone number), thus setting the message's sender to be null.
aMessage.sender = this.getRilIccInfoMsisdn();
let timestamp = aMessage.timestamp;
// Adding needed indexes and extra attributes for internal use.
@ -2342,10 +2322,6 @@ GetThreadsCursor.prototype = {
}
}
XPCOMUtils.defineLazyServiceGetter(MobileMessageDatabaseService.prototype, "mRIL",
"@mozilla.org/ril;1",
"nsIRadioInterfaceLayer");
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([MobileMessageDatabaseService]);
function debug() {

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

@ -16,8 +16,11 @@ NS_IMPL_ISUPPORTS1(SmsService, nsISmsService)
SmsService::SmsService()
{
mRIL = do_GetService("@mozilla.org/ril;1");
NS_WARN_IF_FALSE(mRIL, "This shouldn't fail!");
nsCOMPtr<nsIRadioInterfaceLayer> ril = do_GetService("@mozilla.org/ril;1");
if (ril) {
ril->GetRadioInterface(0, getter_AddRefs(mRadioInterface));
}
NS_WARN_IF_FALSE(mRadioInterface, "This shouldn't fail!");
}
NS_IMETHODIMP
@ -31,9 +34,9 @@ NS_IMETHODIMP
SmsService::GetSegmentInfoForText(const nsAString & aText,
nsIDOMMozSmsSegmentInfo** aResult)
{
NS_ENSURE_TRUE(mRIL, NS_ERROR_FAILURE);
NS_ENSURE_TRUE(mRadioInterface, NS_ERROR_FAILURE);
return mRIL->GetSegmentInfoForText(aText, aResult);
return mRadioInterface->GetSegmentInfoForText(aText, aResult);
}
NS_IMETHODIMP
@ -41,11 +44,9 @@ SmsService::Send(const nsAString& aNumber,
const nsAString& aMessage,
nsIMobileMessageCallback* aRequest)
{
if (!mRIL) {
return NS_OK;
}
mRIL->SendSMS(aNumber, aMessage, aRequest);
return NS_OK;
NS_ENSURE_TRUE(mRadioInterface, NS_ERROR_FAILURE);
return mRadioInterface->SendSMS(aNumber, aMessage, aRequest);
}
} // namespace mobilemessage

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

@ -21,7 +21,8 @@ public:
SmsService();
protected:
nsCOMPtr<nsIRadioInterfaceLayer> mRIL;
// TODO: Bug 854326 - B2G Multi-SIM: support multiple SIM cards for SMS/MMS
nsCOMPtr<nsIRadioInterface> mRadioInterface;
};
} // namespace mobilemessage

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

@ -1073,6 +1073,18 @@ RadioInterface.prototype = {
}
},
getMsisdn: function getMsisdn() {
let iccInfo = this.rilContext.iccInfo;
let number = iccInfo ? iccInfo.msisdn : null;
// Workaround an xpconnect issue with undefined string objects.
// See bug 808220
if (number === undefined || number === "undefined") {
return null;
}
return number;
},
updateNetworkInfo: function updateNetworkInfo(message) {
let voiceMessage = message[RIL.NETWORK_INFO_VOICE_REGISTRATION_STATE];
let dataMessage = message[RIL.NETWORK_INFO_DATA_REGISTRATION_STATE];
@ -1757,7 +1769,7 @@ RadioInterface.prototype = {
message.type = "sms";
message.sender = message.sender || null;
message.receiver = message.receiver || null;
message.receiver = this.getMsisdn();
message.body = message.fullBody = message.fullBody || null;
message.timestamp = Date.now();
@ -2984,6 +2996,7 @@ RadioInterface.prototype = {
let sendingMessage = {
type: "sms",
sender: this.getMsisdn(),
receiver: number,
body: message,
deliveryStatusRequested: options.requestStatusReport,