mtk内置的应用 mms就是包含发短信功能的apk,当然它还有彩信的功能。
mtk的mms应用发短信并没有使用 android的标准api ,而是使用了自家的个性化的方法。
关键发送代码所在的文件为:
packages\apps\Mms\src\com\android\mms\transaction\SmsSingleRecipientSender.java
其内容如下(关键函数使用红色加粗标记):
package com.android.mms.transaction;
import java.util.ArrayList;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.provider.Telephony.Mms;
import android.telephony.PhoneNumberUtils;
import android.telephony.SmsManager;
import android.util.Log;
import com.android.mms.LogTag;
import com.android.mms.MmsConfig;
import com.google.android.mms.MmsException;
import android.provider.Telephony.Sms;
import com.android.mms.data.Conversation;
import com.android.mms.ui.MessageUtils;
/// M:
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.telephony.SmsMessage;
import com.mediatek.encapsulation.android.telephony.gemini.EncapsulatedGeminiSmsManager;
import com.mediatek.encapsulation.android.telephony.EncapsulatedSmsManager;
import com.mediatek.encapsulation.com.android.internal.telephony.EncapsulatedPhone;
import com.android.mms.MmsApp;
import com.android.mms.ui.SmsPreferenceActivity;
import com.mediatek.encapsulation.com.mediatek.common.featureoption.EncapsulatedFeatureOption;
import com.mediatek.encapsulation.MmsLog;
import com.mediatek.encapsulation.android.telephony.EncapsulatedTelephony.SIMInfo;
public class SmsSingleRecipientSenderextends SmsMessageSender {
private final boolean mRequestDeliveryReport;
private String mDest;
private Uri mUri;
private static final String TAG = "SmsSingleRecipientSender";
public SmsSingleRecipientSender(Context context, String dest, String msgText, long threadId,
boolean requestDeliveryReport, Uri uri) {
super(context, null, msgText, threadId);
mRequestDeliveryReport = requestDeliveryReport;
mDest = dest;
mUri = uri;
}
public boolean sendMessage(long token) throws MmsException {
if (LogTag.DEBUG_SEND) {
Log.v(TAG, "sendMessage token: " + token);
}
/// M:Code analyze 001, convert sim id to slot id @{
int slotId = SIMInfo.getSlotById(mContext, mSimId);
MmsLog.d(MmsApp.TXN_TAG, "SmsSingleRecipientSender: sendMessage() simId=" + mSimId +"slotId=" + slotId);
if (mMessageText == null) {
// Don't try to send an empty message, and destination should be just
// one.
throw new MmsException("Null message body or have multiple destinations.");
}
/// M:Code analyze 002,add a variable to caculate the length of sms @{
int codingType = SmsMessage.ENCODING_UNKNOWN;
if (MmsConfig.getSmsEncodingTypeEnabled()) {
codingType = MessageUtils.getSmsEncodingType(mContext);
}
/// @}
//SmsManager smsManager = SmsManager.getDefault();
ArrayList<String> messages = null;
if ((MmsConfig.getEmailGateway() != null) && (Mms.isEmailAddress(mDest) || MessageUtils.isAlias(mDest))){
String msgText;
msgText = mDest + " " + mMessageText;
mDest = MmsConfig.getEmailGateway();
/// M:Code analyze 003,add a parameter codingType to caculate length of sms @{
messages = EncapsulatedSmsManager.divideMessage(msgText, codingType);
/// @}
} else {
/// M:Code analyze 003,add a parameter codingType to caculate length of sms @{
messages = EncapsulatedSmsManager.divideMessage(mMessageText, codingType);
/// @}
// remove spaces and dashes from destination number
// (e.g. "801 555 1212" -> "8015551212")
// (e.g. "+8211-123-4567" -> "+82111234567")
/// M:Code analyze 004, comment the line,using customized striping pattern to mDest @{
//mDest = PhoneNumberUtils.stripSeparators(mDest);
/** M: remove spaces from destination number (e.g. "801 555 1212" -> "8015551212") @{ */
mDest = mDest.replaceAll(" ", "");
mDest = mDest.replaceAll("-", "");
/// @}
mDest = Conversation.verifySingleRecipient(mContext, mThreadId, mDest);
}
int messageCount = messages.size();
/// M:
MmsLog.d(MmsApp.TXN_TAG, "SmsSingleRecipientSender: sendMessage(), Message Count=" + messageCount);
if (messageCount == 0) {
// Don't try to send an empty message.
throw new MmsException("SmsMessageSender.sendMessage: divideMessage returned " +
"empty messages. Original message is \"" + mMessageText + "\"");
}
boolean moved = Sms.moveMessageToFolder(mContext, mUri, Sms.MESSAGE_TYPE_OUTBOX, 0);
if (!moved) {
throw new MmsException("SmsMessageSender.sendMessage: couldn't move message " +
"to outbox: " + mUri);
}
if (LogTag.DEBUG_SEND) {
Log.v(TAG, "sendMessage mDest: " + mDest + " mRequestDeliveryReport: " +