diff options
46 files changed, 751 insertions, 780 deletions
diff --git a/res/layout/sub_select_item.xml b/res/layout/sub_select_item.xml index 0f83343a..1e4c7b15 100755 --- a/res/layout/sub_select_item.xml +++ b/res/layout/sub_select_item.xml @@ -21,7 +21,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" > - <com.android.internal.widget.SubscriptionView + <com.android.mms.ui.SubscriptionView android:id="@+id/subItem" android:layout_width="0dp" android:layout_height="match_parent" diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 0a1bd94a..8feafdcf 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -21,5 +21,6 @@ no subject string was delivered. --> <string-array name="empty_subject_strings"> <item>no subject</item> + <item>nosubject</item> </string-array> </resources> diff --git a/src/com/android/mms/LogTag.java b/src/com/android/mms/LogTag.java index 23212fe2..99fe3473 100644 --- a/src/com/android/mms/LogTag.java +++ b/src/com/android/mms/LogTag.java @@ -90,7 +90,7 @@ public class LogTag { Log.e(TAG, logFormat(format, args)); } - public static void dumpInternalTables(final Context context) { + public static void dumpInternalTables(final Context context, final int subId) { if (!ALLOW_DUMP_IN_LOGS) { return; } @@ -98,7 +98,7 @@ public class LogTag { public void run() { RecipientIdCache.canonicalTableDump(); RecipientIdCache.dump(); - Conversation.dumpThreadsTable(context); + Conversation.dumpThreadsTable(context, subId); Conversation.dump(); Conversation.dumpSmsTable(context); Contact.dump(); @@ -106,11 +106,12 @@ public class LogTag { }).start(); } - public static void warnPossibleRecipientMismatch(final String msg, final Activity activity) { + public static void warnPossibleRecipientMismatch(final String msg, final Activity activity, + final int subId) { Log.e(TAG, "WARNING!!!! " + msg, new RuntimeException()); if (SHOW_SEVERE_WARNING_DIALOG) { - dumpInternalTables(activity); + dumpInternalTables(activity, subId); activity.runOnUiThread(new Runnable() { public void run() { new AlertDialog.Builder(activity) diff --git a/src/com/android/mms/MmsApp.java b/src/com/android/mms/MmsApp.java index 990e49ab..6510004d 100644 --- a/src/com/android/mms/MmsApp.java +++ b/src/com/android/mms/MmsApp.java @@ -90,7 +90,6 @@ public class MmsApp extends Application { mPduLoaderManager = new PduLoaderManager(context); mThumbnailManager = new ThumbnailManager(context); - MmsConfig.init(this); Contact.init(this); DraftCache.init(this); Conversation.init(this); diff --git a/src/com/android/mms/MmsConfig.java b/src/com/android/mms/MmsConfig.java index 9f1f6c20..3750d751 100755 --- a/src/com/android/mms/MmsConfig.java +++ b/src/com/android/mms/MmsConfig.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 The Android Open Source Project + * Copyright (C) 2014 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,204 +16,125 @@ package com.android.mms; -import java.io.IOException; - -import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; - import android.content.Context; -import android.content.Intent; import android.content.SharedPreferences; -import android.content.res.XmlResourceParser; +import android.os.Bundle; import android.preference.PreferenceManager; import android.provider.Telephony; +import android.telephony.SmsManager; +import android.telephony.SubscriptionManager; +import android.telephony.TelephonyManager; import android.text.TextUtils; +import android.util.Base64; import android.util.Log; -import com.android.internal.telephony.TelephonyProperties; -import com.android.mms.ui.MessageUtils; -import com.android.mms.ui.MessagingPreferenceActivity; +import java.io.UnsupportedEncodingException; +import java.util.HashMap; public class MmsConfig { private static final String TAG = LogTag.TAG; - private static final boolean DEBUG = true; - private static final boolean LOCAL_LOGV = false; - - private static final String DEFAULT_HTTP_KEY_X_WAP_PROFILE = "x-wap-profile"; - private static final String DEFAULT_USER_AGENT = "Android-Mms/2.0"; - - private static String sMmsAppPackage; - - private static final String SMS_PROMO_DISMISSED_KEY = "sms_promo_dismissed_key"; - private static final int MAX_IMAGE_HEIGHT = 480; - private static final int MAX_IMAGE_WIDTH = 640; - private static final int MAX_TEXT_LENGTH = 2000; - - /** - * Whether to hide MMS functionality from the user (i.e. SMS only). - */ - private static boolean mTransIdEnabled = false; - private static int mMmsEnabled = 1; // default to true - private static int mMaxMessageSize = 300 * 1024; // default to 300k max size - private static String mUserAgent = DEFAULT_USER_AGENT; - private static String mUaProfTagName = DEFAULT_HTTP_KEY_X_WAP_PROFILE; - private static String mUaProfUrl = null; - private static String mHttpParams = null; - private static String mHttpParamsLine1Key = null; - private static String mEmailGateway = null; - private static int mMaxImageHeight = MAX_IMAGE_HEIGHT; // default value - private static int mMaxImageWidth = MAX_IMAGE_WIDTH; // default value - private static int mRecipientLimit = Integer.MAX_VALUE; // default value - private static int mDefaultSMSMessagesPerThread = 10000; // default value - private static int mDefaultMMSMessagesPerThread = 1000; // default value - private static int mMinMessageCountPerThread = 2; // default value - private static int mMaxMessageCountPerThread = 20000; // default value - private static int mHttpSocketTimeout = 60*1000; // default to 1 min - private static int mMinimumSlideElementDuration = 7; // default to 7 sec - private static boolean mNotifyWapMMSC = false; - private static boolean mAllowAttachAudio = true; - - // If mEnableMultipartSMS is true, long sms messages are always sent as multi-part sms - // messages, with no checked limit on the number of segments. - // If mEnableMultipartSMS is false, then as soon as the user types a message longer - // than a single segment (i.e. 140 chars), then the message will turn into and be sent - // as an mms message. This feature exists for carriers that don't support multi-part sms's. - private static boolean mEnableMultipartSMS = true; - - // If mEnableMultipartSMS is true and mSmsToMmsTextThreshold > 1, then multi-part SMS messages - // will be converted into a single mms message. For example, if the mms_config.xml file - // specifies <int name="smsToMmsTextThreshold">4</int>, then on the 5th sms segment, the - // message will be converted to an mms. - private static int mSmsToMmsTextThreshold = -1; - - private static boolean mEnableSlideDuration = true; - private static boolean mEnableMMSReadReports = true; // key: "enableMMSReadReports" - private static boolean mEnableSMSDeliveryReports = true; // key: "enableSMSDeliveryReports" - private static boolean mEnableMMSDeliveryReports = true; // key: "enableMMSDeliveryReports" - private static int mMaxTextLength = -1; + final static HashMap<Integer, Bundle> mConfigValues = new HashMap<Integer, Bundle>(); // This is the max amount of storage multiplied by mMaxMessageSize that we // allow of unsent messages before blocking the user from sending any more // MMS's. private static int mMaxSizeScaleForPendingMmsAllowed = 4; // default value + private static int mDefaultSMSMessagesPerThread = 200; // default value + private static int mDefaultMMSMessagesPerThread = 20; // default value + private static int mMinMessageCountPerThread = 2; // default value + private static int mMaxMessageCountPerThread = 5000; // default value + private static boolean mEnableSlideDuration = true; + private static int mMinimumSlideElementDuration = 7; // default to 7 sec - // Email gateway alias support, including the master switch and different rules - private static boolean mAliasEnabled = false; - private static int mAliasRuleMinChars = 2; - private static int mAliasRuleMaxChars = 48; - - private static int mMaxSubjectLength = 40; // maximum number of characters allowed for mms - // subject - - // If mEnableGroupMms is true, a message with multiple recipients, regardless of contents, - // will be sent as a single MMS message with multiple "TO" fields set for each recipient. - // If mEnableGroupMms is false, the group MMS setting/preference will be hidden in the settings - // activity. - private static boolean mEnableGroupMms = true; - - public static void init(Context context) { - if (LOCAL_LOGV) { - Log.v(TAG, "MmsConfig.init()"); - } - // Always put the mnc/mcc in the log so we can tell which mms_config.xml was loaded. - Log.v(TAG, "mnc/mcc: " + - android.os.SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC)); - - sMmsAppPackage = context.getApplicationContext().getPackageName(); - - loadMmsSettings(context); - } - - public static boolean isSmsEnabled(Context context) { - String defaultSmsApplication = Telephony.Sms.getDefaultSmsPackage(context); - - if (defaultSmsApplication != null && defaultSmsApplication.equals(sMmsAppPackage)) { - return true; - } - return false; - } - - public static boolean isSmsPromoDismissed(Context context) { - SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); - return preferences.getBoolean(SMS_PROMO_DISMISSED_KEY, false); - } - - public static void setSmsPromoDismissed(Context context) { - SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); - SharedPreferences.Editor editor = preferences.edit(); - editor.putBoolean(SMS_PROMO_DISMISSED_KEY, true); - editor.apply(); - } + private static String sMmsAppPackage; - public static Intent getRequestDefaultSmsAppActivity() { - final Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT); - intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, sMmsAppPackage); - return intent; - } + private static final String SMS_PROMO_DISMISSED_KEY = "sms_promo_dismissed_key"; - public static int getSmsToMmsTextThreshold() { - return mSmsToMmsTextThreshold; - } + /* + * Macro names + */ + // The raw phone number from TelephonyManager.getLine1Number + public static final String MACRO_LINE1 = "LINE1"; + // The phone number without country code + public static final String MACRO_LINE1NOCOUNTRYCODE = "LINE1NOCOUNTRYCODE"; + // NAI (Network Access Identifier), used by Sprint for authentication + public static final String MACRO_NAI = "NAI"; - public static boolean getMmsEnabled() { - return mMmsEnabled == 1 ? true : false; - } - public static int getMaxMessageSize() { - if (LOCAL_LOGV) { - Log.v(TAG, "MmsConfig.getMaxMessageSize(): " + mMaxMessageSize); - } - return mMaxMessageSize; + public static long getLong(int subId, final String valueName) { + Bundle bundle = getBundle(subId); + return bundle != null ? bundle.getLong(valueName) : 0L; } - /** - * This function returns the value of "enabledTransID" present in mms_config file. - * In case of single segment wap push message, this "enabledTransID" indicates whether - * TransactionID should be appended to URI or not. - */ - public static boolean getTransIdEnabled() { - return mTransIdEnabled; + public static long getLong(final String valueName) { + return getLong(SubscriptionManager.getDefaultSmsSubId(), valueName); } - public static String getUserAgent() { - return mUserAgent; + public static int getInt(int subId, final String valueName) { + Bundle bundle = getBundle(subId); + return bundle != null ? bundle.getInt(valueName) : 0; } - public static String getUaProfTagName() { - return mUaProfTagName; + public static int getInt(final String valueName) { + return getInt(SubscriptionManager.getDefaultSmsSubId(), valueName); } - public static String getUaProfUrl() { - return mUaProfUrl; + public static String getString(int subId, final String valueName) { + Bundle bundle = getBundle(subId); + return bundle != null ? bundle.getString(valueName) : null; } - public static String getHttpParams() { - return mHttpParams; + public static String getString(final String valueName) { + return getString(SubscriptionManager.getDefaultSmsSubId(), valueName); } - public static String getHttpParamsLine1Key() { - return mHttpParamsLine1Key; + public static boolean getBoolean(int subId, final String valueName) { + Bundle bundle = getBundle(subId); + return bundle != null ? bundle.getBoolean(valueName) : false; } - public static String getEmailGateway() { - return mEmailGateway; + public static boolean getBoolean(final String valueName) { + return getBoolean(SubscriptionManager.getDefaultSmsSubId(), valueName); } - public static int getMaxImageHeight() { - return mMaxImageHeight; - } + private static Bundle getBundle(int subId) { + final boolean validSubId = SubscriptionManager.isUsableSubIdValue(subId); + if (!validSubId) { + subId = SubscriptionManager.getDefaultSmsSubId(); + } - public static int getMaxImageWidth() { - return mMaxImageWidth; + Bundle bundle = mConfigValues.get(subId); + if (bundle != null) { +// Log.v(TAG, "getBundle CACHED subId: " + subId + " " + bundleToString(bundle)); + return bundle; + } + SmsManager smsManager = SmsManager.getSmsManagerForSubscriber(subId); + bundle = smsManager.getCarrierConfigValues(); + if (bundle != null && validSubId) { + mConfigValues.put(subId, bundle); + } +// Log.v(TAG, "getBundle subId: " + subId + " " + bundleToString(bundle)); + return bundle; + } + + private static String bundleToString(final Bundle bundle) { + StringBuilder sb = new StringBuilder(); + sb.append("Bundle: {"); + if (bundle == null) { + sb.append("null"); + } else { + for (String key : bundle.keySet()) { + sb.append(" " + key + " -> " + bundle.get(key) + ";"); + } + } + sb.append(" }"); + return sb.toString(); } - public static int getRecipientLimit() { - return mRecipientLimit; - } - public static int getMaxTextLimit() { - return mMaxTextLength > -1 ? mMaxTextLength : MAX_TEXT_LENGTH; + public static int getMaxSizeScaleForPendingMmsAllowed() { + return mMaxSizeScaleForPendingMmsAllowed; } public static int getDefaultSMSMessagesPerThread() { @@ -229,230 +150,106 @@ public class MmsConfig { } public static int getMaxMessageCountPerThread() { - // We bumped the defaultSMSMessagesPerThread in various mms_config.xml's without - // bumping the corresponding maxMessageCountPerThread. Return a reasonable value if - // the value appears out of date. - if (mMaxMessageCountPerThread < mDefaultMMSMessagesPerThread || - mDefaultMMSMessagesPerThread < mDefaultSMSMessagesPerThread) { - return 2 * Math.max(mDefaultMMSMessagesPerThread, mDefaultSMSMessagesPerThread); - } return mMaxMessageCountPerThread; } - public static int getHttpSocketTimeout() { - return mHttpSocketTimeout; - } - - public static int getMinimumSlideElementDuration() { - return mMinimumSlideElementDuration; - } - - public static boolean getMultipartSmsEnabled() { - return mEnableMultipartSMS; - } - - public static boolean getSlideDurationEnabled() { - return mEnableSlideDuration; - } + public static boolean isSmsEnabled() { + String defaultSmsApplication = + Telephony.Sms.getDefaultSmsPackage(MmsApp.getApplication().getApplicationContext()); - public static boolean getMMSReadReportsEnabled() { - return mEnableMMSReadReports; - } - - public static boolean getSMSDeliveryReportsEnabled() { - return mEnableSMSDeliveryReports; - } - - public static boolean getMMSDeliveryReportsEnabled() { - return mEnableMMSDeliveryReports; - } - - public static boolean getNotifyWapMMSC() { - return mNotifyWapMMSC; + if (defaultSmsApplication != null && defaultSmsApplication.equals(getMmsAppPackageName())) { + return true; + } + return false; } - public static int getMaxSizeScaleForPendingMmsAllowed() { - return mMaxSizeScaleForPendingMmsAllowed; + private static String getMmsAppPackageName() { + if (sMmsAppPackage == null) { + sMmsAppPackage = MmsApp.getApplication().getApplicationContext().getPackageName(); + } + return sMmsAppPackage; } - public static boolean isAliasEnabled() { - return mAliasEnabled; + public static boolean isSmsPromoDismissed() { + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences( + MmsApp.getApplication().getApplicationContext()); + return preferences.getBoolean(SMS_PROMO_DISMISSED_KEY, false); } - public static int getAliasMinChars() { - return mAliasRuleMinChars; + public static void setSmsPromoDismissed() { + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences( + MmsApp.getApplication().getApplicationContext()); + SharedPreferences.Editor editor = preferences.edit(); + editor.putBoolean(SMS_PROMO_DISMISSED_KEY, true); + editor.apply(); } - public static int getAliasMaxChars() { - return mAliasRuleMaxChars; + public static boolean getSlideDurationEnabled() { + return mEnableSlideDuration; } - public static boolean getAllowAttachAudio() { - return mAllowAttachAudio; + public static int getMinimumSlideElementDuration() { + return mMinimumSlideElementDuration; } - public static int getMaxSubjectLength() { - return mMaxSubjectLength; + public static String getHttpParamMacro(String macro, int subId) { + if (MACRO_LINE1.equals(macro)) { + return getLine1(subId); + } else if (MACRO_LINE1NOCOUNTRYCODE.equals(macro)) { + return getLine1NoCountryCode(subId); + } else if (MACRO_NAI.equals(macro)) { + return getNai(subId); + } + return null; } - public static boolean getGroupMmsEnabled() { - return mEnableGroupMms; + /** + * @return the phone number + */ + private static String getLine1(int subId) { + final TelephonyManager telephonyManager = + (TelephonyManager) MmsApp.getApplication().getApplicationContext().getSystemService( + Context.TELEPHONY_SERVICE); + return telephonyManager.getLine1NumberForSubscriber(subId); } - public static final void beginDocument(XmlPullParser parser, String firstElementName) throws XmlPullParserException, IOException - { - int type; - while ((type=parser.next()) != parser.START_TAG - && type != parser.END_DOCUMENT) { - ; - } - - if (type != parser.START_TAG) { - throw new XmlPullParserException("No start tag found"); - } - - if (!parser.getName().equals(firstElementName)) { - throw new XmlPullParserException("Unexpected start tag: found " + parser.getName() + - ", expected " + firstElementName); - } + private static String getLine1NoCountryCode(int subId) { + final TelephonyManager telephonyManager = + (TelephonyManager) MmsApp.getApplication().getApplicationContext().getSystemService( + Context.TELEPHONY_SERVICE); + // TODO - strip country code + return telephonyManager.getLine1NumberForSubscriber(subId); } - public static final void nextElement(XmlPullParser parser) throws XmlPullParserException, IOException - { - int type; - while ((type=parser.next()) != parser.START_TAG - && type != parser.END_DOCUMENT) { - ; + /** + * @return the NAI (Network Access Identifier) from SystemProperties + */ + private static String getNai(int subId) { + final TelephonyManager telephonyManager = + (TelephonyManager) MmsApp.getApplication().getApplicationContext().getSystemService( + Context.TELEPHONY_SERVICE); + String nai = telephonyManager.getNai(SubscriptionManager.getSlotId(subId)); + if (Log.isLoggable(TAG, Log.VERBOSE)) { + Log.v(TAG, "MmsConfig.getNai: nai=" + nai); } - } - private static void loadMmsSettings(Context context) { - XmlResourceParser parser = context.getResources().getXml(R.xml.mms_config); - - try { - beginDocument(parser, "mms_config"); - - while (true) { - nextElement(parser); - String tag = parser.getName(); - if (tag == null) { - break; - } - String name = parser.getAttributeName(0); - String value = parser.getAttributeValue(0); - String text = null; - if (parser.next() == XmlPullParser.TEXT) { - text = parser.getText(); - } - - if (DEBUG) { - Log.v(TAG, "tag: " + tag + " value: " + value + " - " + - text); - } - if ("name".equalsIgnoreCase(name)) { - if ("bool".equals(tag)) { - // bool config tags go here - if ("enabledMMS".equalsIgnoreCase(value)) { - mMmsEnabled = "true".equalsIgnoreCase(text) ? 1 : 0; - } else if ("enabledTransID".equalsIgnoreCase(value)) { - mTransIdEnabled = "true".equalsIgnoreCase(text); - } else if ("enabledNotifyWapMMSC".equalsIgnoreCase(value)) { - mNotifyWapMMSC = "true".equalsIgnoreCase(text); - } else if ("aliasEnabled".equalsIgnoreCase(value)) { - mAliasEnabled = "true".equalsIgnoreCase(text); - } else if ("allowAttachAudio".equalsIgnoreCase(value)) { - mAllowAttachAudio = "true".equalsIgnoreCase(text); - } else if ("enableMultipartSMS".equalsIgnoreCase(value)) { - mEnableMultipartSMS = "true".equalsIgnoreCase(text); - } else if ("enableSlideDuration".equalsIgnoreCase(value)) { - mEnableSlideDuration = "true".equalsIgnoreCase(text); - } else if ("enableMMSReadReports".equalsIgnoreCase(value)) { - mEnableMMSReadReports = "true".equalsIgnoreCase(text); - } else if ("enableSMSDeliveryReports".equalsIgnoreCase(value)) { - mEnableSMSDeliveryReports = "true".equalsIgnoreCase(text); - } else if ("enableMMSDeliveryReports".equalsIgnoreCase(value)) { - mEnableMMSDeliveryReports = "true".equalsIgnoreCase(text); - } else if ("enableGroupMms".equalsIgnoreCase(value)) { - mEnableGroupMms = "true".equalsIgnoreCase(text); - } - } else if ("int".equals(tag)) { - // int config tags go here - if ("maxMessageSize".equalsIgnoreCase(value)) { - mMaxMessageSize = Integer.parseInt(text); - } else if ("maxImageHeight".equalsIgnoreCase(value)) { - mMaxImageHeight = Integer.parseInt(text); - } else if ("maxImageWidth".equalsIgnoreCase(value)) { - mMaxImageWidth = Integer.parseInt(text); - } else if ("defaultSMSMessagesPerThread".equalsIgnoreCase(value)) { - mDefaultSMSMessagesPerThread = Integer.parseInt(text); - } else if ("defaultMMSMessagesPerThread".equalsIgnoreCase(value)) { - mDefaultMMSMessagesPerThread = Integer.parseInt(text); - } else if ("minMessageCountPerThread".equalsIgnoreCase(value)) { - mMinMessageCountPerThread = Integer.parseInt(text); - } else if ("maxMessageCountPerThread".equalsIgnoreCase(value)) { - mMaxMessageCountPerThread = Integer.parseInt(text); - } else if ("recipientLimit".equalsIgnoreCase(value)) { - mRecipientLimit = Integer.parseInt(text); - if (mRecipientLimit < 0) { - mRecipientLimit = Integer.MAX_VALUE; - } - } else if ("httpSocketTimeout".equalsIgnoreCase(value)) { - mHttpSocketTimeout = Integer.parseInt(text); - } else if ("minimumSlideElementDuration".equalsIgnoreCase(value)) { - mMinimumSlideElementDuration = Integer.parseInt(text); - } else if ("maxSizeScaleForPendingMmsAllowed".equalsIgnoreCase(value)) { - mMaxSizeScaleForPendingMmsAllowed = Integer.parseInt(text); - } else if ("aliasMinChars".equalsIgnoreCase(value)) { - mAliasRuleMinChars = Integer.parseInt(text); - } else if ("aliasMaxChars".equalsIgnoreCase(value)) { - mAliasRuleMaxChars = Integer.parseInt(text); - } else if ("smsToMmsTextThreshold".equalsIgnoreCase(value)) { - mSmsToMmsTextThreshold = Integer.parseInt(text); - } else if ("maxMessageTextSize".equalsIgnoreCase(value)) { - mMaxTextLength = Integer.parseInt(text); - } else if ("maxSubjectLength".equalsIgnoreCase(value)) { - mMaxSubjectLength = Integer.parseInt(text); - } - } else if ("string".equals(tag)) { - // string config tags go here - if ("userAgent".equalsIgnoreCase(value)) { - mUserAgent = text; - } else if ("uaProfTagName".equalsIgnoreCase(value)) { - mUaProfTagName = text; - } else if ("uaProfUrl".equalsIgnoreCase(value)) { - mUaProfUrl = text; - } else if ("httpParams".equalsIgnoreCase(value)) { - mHttpParams = text; - } else if ("httpParamsLine1Key".equalsIgnoreCase(value)) { - mHttpParamsLine1Key = text; - } else if ("emailGatewayNumber".equalsIgnoreCase(value)) { - mEmailGateway = text; - } - } - } + if (!TextUtils.isEmpty(nai)) { + String naiSuffix = getString(subId, SmsManager.MMS_CONFIG_NAI_SUFFIX); + if (!TextUtils.isEmpty(naiSuffix)) { + nai = nai + naiSuffix; + } + byte[] encoded = null; + try { + encoded = Base64.encode(nai.getBytes("UTF-8"), Base64.NO_WRAP); + } catch (UnsupportedEncodingException e) { + encoded = Base64.encode(nai.getBytes(), Base64.NO_WRAP); + } + try { + nai = new String(encoded, "UTF-8"); + } catch (UnsupportedEncodingException e) { + nai = new String(encoded); } - } catch (XmlPullParserException e) { - Log.e(TAG, "loadMmsSettings caught ", e); - } catch (NumberFormatException e) { - Log.e(TAG, "loadMmsSettings caught ", e); - } catch (IOException e) { - Log.e(TAG, "loadMmsSettings caught ", e); - } finally { - parser.close(); - } - - String errorStr = null; - - if (getMmsEnabled() && mUaProfUrl == null) { - errorStr = "uaProfUrl"; - } - - if (errorStr != null) { - String err = - String.format("MmsConfig.loadMmsSettings mms_config.xml missing %s setting", - errorStr); - Log.e(TAG, err); } + return nai; } - } diff --git a/src/com/android/mms/data/Contact.java b/src/com/android/mms/data/Contact.java index f98315a7..02be9c2e 100644 --- a/src/com/android/mms/data/Contact.java +++ b/src/com/android/mms/data/Contact.java @@ -158,16 +158,16 @@ public class Contact { Log.d(tag, sb.toString()); } - public static Contact get(String number, boolean canBlock) { - return sContactCache.get(number, canBlock); + public static Contact get(String number, boolean canBlock, int subId) { + return sContactCache.get(number, canBlock, subId); } - public static Contact getMe(boolean canBlock) { - return sContactCache.getMe(canBlock); + public static Contact getMe(boolean canBlock, int subId) { + return sContactCache.getMe(canBlock, subId); } - public void removeFromCache() { - sContactCache.remove(this); + public void removeFromCache(int subId) { + sContactCache.remove(this, subId); } public static List<Contact> getByPhoneUris(Parcelable[] uris) { @@ -224,9 +224,9 @@ public class Contact { } } - public synchronized void reload() { + public synchronized void reload(int subId) { mIsStale = true; - sContactCache.get(mNumber, false); + sContactCache.get(mNumber, false, subId); } public synchronized String getNumber() { @@ -537,15 +537,15 @@ public class Contact { mTaskQueue.push(r); } - public Contact getMe(boolean canBlock) { - return get(SELF_ITEM_KEY, true, canBlock); + public Contact getMe(boolean canBlock, int subId) { + return get(SELF_ITEM_KEY, true, canBlock, subId); } - public Contact get(String number, boolean canBlock) { - return get(number, false, canBlock); + public Contact get(String number, boolean canBlock, int subId) { + return get(number, false, canBlock, subId); } - private Contact get(String number, boolean isMe, boolean canBlock) { + private Contact get(String number, boolean isMe, boolean canBlock, final int subId) { if (Log.isLoggable(LogTag.CONTACT, Log.DEBUG)) { logWithTrace(TAG, "get(%s, %s, %s)", number, isMe, canBlock); } @@ -559,7 +559,7 @@ public class Contact { // Always return a Contact object, if if we don't have an actual contact // in the contacts db. - Contact contact = internalGet(number, isMe); + Contact contact = internalGet(number, isMe, subId); Runnable r = null; synchronized (contact) { @@ -587,7 +587,7 @@ public class Contact { r = new Runnable() { @Override public void run() { - updateContact(c); + updateContact(c, subId); } }; @@ -723,12 +723,12 @@ public class Contact { return false; } - private void updateContact(final Contact c) { + private void updateContact(final Contact c, int subId) { if (c == null) { return; } - Contact entry = getContactInfo(c); + Contact entry = getContactInfo(c, subId); synchronized (c) { if (contactChanged(c, entry)) { if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) { @@ -783,12 +783,12 @@ public class Contact { /** * Returns the caller info in Contact. */ - private Contact getContactInfo(Contact c) { + private Contact getContactInfo(Contact c, int subId) { if (c.mIsMe) { return getContactInfoForSelf(); } else if (Mms.isEmailAddress(c.mNumber)) { return getContactInfoForEmailAddress(c.mNumber); - } else if (isAlphaNumber(c.mNumber)) { + } else if (isAlphaNumber(c.mNumber, subId)) { // first try to look it up in the email field Contact contact = getContactInfoForEmailAddress(c.mNumber); if (contact.existsInDatabase()) { @@ -817,7 +817,7 @@ public class Contact { // "#4#5#6#" -> true [it is considered to be the address "#4#5#6#"] // "AB12" -> true [2 digits, it is considered to be the address "AB12"] // "12" -> true [2 digits, it is considered to be the address "12"] - private boolean isAlphaNumber(String number) { + private boolean isAlphaNumber(String number, int subId) { // TODO: PhoneNumberUtils.isWellFormedSmsAddress() only check if the number is a valid // GSM SMS address. If the address contains a dialable char, it considers it a well // formed SMS addr. CDMA doesn't work that way and has a different parser for SMS @@ -826,7 +826,7 @@ public class Contact { // The example "T-Mobile" will exit here because there are no numbers. return true; // we're not an sms address, consider it an alpha number } - if (MessageUtils.isAlias(number)) { + if (MessageUtils.isAlias(number, subId)) { return true; } number = PhoneNumberUtils.extractNetworkPortion(number); @@ -1102,12 +1102,12 @@ public class Contact { static final int STATIC_KEY_BUFFER_MAXIMUM_LENGTH = 5; static CharBuffer sStaticKeyBuffer = CharBuffer.allocate(STATIC_KEY_BUFFER_MAXIMUM_LENGTH); - private Contact internalGet(String numberOrEmail, boolean isMe) { + private Contact internalGet(String numberOrEmail, boolean isMe, int subId) { synchronized (ContactsCache.this) { // See if we can find "number" in the hashtable. // If so, just return the result. final boolean isNotRegularPhoneNumber = isMe || Mms.isEmailAddress(numberOrEmail) || - MessageUtils.isAlias(numberOrEmail); + MessageUtils.isAlias(numberOrEmail, subId); final String key = isNotRegularPhoneNumber ? numberOrEmail : key(numberOrEmail, sStaticKeyBuffer); @@ -1154,12 +1154,12 @@ public class Contact { } // Remove a contact from the ContactsCache based on the number or email address - private void remove(Contact contact) { + private void remove(Contact contact, int subId) { synchronized (ContactsCache.this) { String number = contact.getNumber(); final boolean isNotRegularPhoneNumber = contact.isMe() || Mms.isEmailAddress(number) || - MessageUtils.isAlias(number); + MessageUtils.isAlias(number, subId); final String key = isNotRegularPhoneNumber ? number : key(number, sStaticKeyBuffer); ArrayList<Contact> candidates = mContactsHash.get(key); diff --git a/src/com/android/mms/data/ContactList.java b/src/com/android/mms/data/ContactList.java index 01c2598d..964c397b 100644 --- a/src/com/android/mms/data/ContactList.java +++ b/src/com/android/mms/data/ContactList.java @@ -14,11 +14,11 @@ import com.android.mms.ui.MessageUtils; public class ContactList extends ArrayList<Contact> { private static final long serialVersionUID = 1L; - public static ContactList getByNumbers(Iterable<String> numbers, boolean canBlock) { + public static ContactList getByNumbers(Iterable<String> numbers, boolean canBlock, int subId) { ContactList list = new ContactList(); for (String number : numbers) { if (!TextUtils.isEmpty(number)) { - list.add(Contact.get(number, canBlock)); + list.add(Contact.get(number, canBlock, subId)); } } return list; @@ -26,11 +26,12 @@ public class ContactList extends ArrayList<Contact> { public static ContactList getByNumbers(String semiSepNumbers, boolean canBlock, - boolean replaceNumber) { + boolean replaceNumber, + int subId) { ContactList list = new ContactList(); for (String number : semiSepNumbers.split(";")) { if (!TextUtils.isEmpty(number)) { - Contact contact = Contact.get(number, canBlock); + Contact contact = Contact.get(number, canBlock, subId); if (replaceNumber) { contact.setNumber(number); } @@ -46,14 +47,15 @@ public class ContactList extends ArrayList<Contact> { * for the numbers don't belong to any contact. * * @param uris phone URI to create the ContactList + * @param subId subscription for contact */ - public static ContactList blockingGetByUris(Parcelable[] uris) { + public static ContactList blockingGetByUris(Parcelable[] uris, int subId) { ContactList list = new ContactList(); if (uris != null && uris.length > 0) { for (Parcelable p : uris) { Uri uri = (Uri) p; if ("tel".equals(uri.getScheme())) { - Contact contact = Contact.get(uri.getSchemeSpecificPart(), true); + Contact contact = Contact.get(uri.getSchemeSpecificPart(), true, subId); list.add(contact); } } @@ -69,11 +71,11 @@ public class ContactList extends ArrayList<Contact> { * Returns a ContactList for the corresponding recipient ids passed in. This method will * create the contact if it doesn't exist, and would inject the recipient id into the contact. */ - public static ContactList getByIds(String spaceSepIds, boolean canBlock) { + public static ContactList getByIds(String spaceSepIds, boolean canBlock, int subId) { ContactList list = new ContactList(); for (RecipientIdCache.Entry entry : RecipientIdCache.getAddresses(spaceSepIds)) { if (entry != null && !TextUtils.isEmpty(entry.number)) { - Contact contact = Contact.get(entry.number, canBlock); + Contact contact = Contact.get(entry.number, canBlock, subId); contact.setRecipientId(entry.id); list.add(contact); } @@ -107,8 +109,8 @@ public class ContactList extends ArrayList<Contact> { return TextUtils.join(separator, nans); } - public String serialize() { - return TextUtils.join(";", getNumbers()); + public String serialize(int subId) { + return TextUtils.join(";", getNumbers(subId)); } public boolean containsEmail() { @@ -120,11 +122,11 @@ public class ContactList extends ArrayList<Contact> { return false; } - public String[] getNumbers() { - return getNumbers(false /* don't scrub for MMS address */); + public String[] getNumbers(int subId) { + return getNumbers(false /* don't scrub for MMS address */, subId); } - public String[] getNumbers(boolean scrubForMmsAddress) { + public String[] getNumbers(boolean scrubForMmsAddress, int subId) { List<String> numbers = new ArrayList<String>(); String number; for (Contact c : this) { @@ -135,7 +137,7 @@ public class ContactList extends ArrayList<Contact> { // could be null if it's not a valid MMS address. We don't want to send // a message to an invalid number, as the network may do its own stripping, // and end up sending the message to a different number! - number = MessageUtils.parseMmsAddress(number); + number = MessageUtils.parseMmsAddress(number, subId); } // Don't add duplicate numbers. This can happen if a contact name has a comma. diff --git a/src/com/android/mms/data/Conversation.java b/src/com/android/mms/data/Conversation.java index c18d5131..a88f42d0 100755 --- a/src/com/android/mms/data/Conversation.java +++ b/src/com/android/mms/data/Conversation.java @@ -24,6 +24,7 @@ import android.provider.Telephony.Sms.Conversations; import android.provider.Telephony.Threads; import android.provider.Telephony.ThreadsColumns; import android.telephony.PhoneNumberUtils; +import android.telephony.SubscriptionManager; import android.text.TextUtils; import android.util.Log; @@ -163,9 +164,11 @@ public class Conversation { * Find the conversation matching the provided recipient set. * When called with an empty recipient list, equivalent to {@link #createNew}. */ - public static Conversation get(Context context, ContactList recipients, boolean allowQuery) { + public static Conversation get(Context context, ContactList recipients, boolean allowQuery, + int subId) { if (DEBUG) { - Log.v(TAG, "Conversation get by recipients: " + recipients.serialize()); + Log.v(TAG, "Conversation get by recipients: " + + recipients.serialize(SubscriptionManager.getDefaultSmsSubId())); } // If there are no recipients in the list, make a new conversation. if (recipients.size() < 1) { @@ -176,7 +179,7 @@ public class Conversation { if (conv != null) return conv; - long threadId = getOrCreateThreadId(context, recipients); + long threadId = getOrCreateThreadId(context, recipients, subId); conv = new Conversation(context, threadId, allowQuery); Log.d(TAG, "Conversation.get: created new conversation " + /*conv.toString()*/ "xxxxxxx"); @@ -203,7 +206,7 @@ public class Conversation { * {@value sms:+12124797990}. * When called with a null Uri, equivalent to {@link #createNew}. */ - public static Conversation get(Context context, Uri uri, boolean allowQuery) { + public static Conversation get(Context context, Uri uri, boolean allowQuery, int subId) { if (DEBUG) { Log.v(TAG, "Conversation get by uri: " + uri); } @@ -229,14 +232,14 @@ public class Conversation { String recipients = PhoneNumberUtils.replaceUnicodeDigits(getRecipients(uri)) .replace(',', ';'); return get(context, ContactList.getByNumbers(recipients, - allowQuery /* don't block */, true /* replace number */), allowQuery); + allowQuery /* don't block */, true /* replace number */, subId), allowQuery, subId); } /** * Returns true if the recipient in the uri matches the recipient list in this * conversation. */ - public boolean sameRecipient(Uri uri, Context context) { + public boolean sameRecipient(Uri uri, Context context, int subId) { int size = mRecipients.size(); if (size > 1) { return false; @@ -247,7 +250,7 @@ public class Conversation { ContactList incomingRecipient = null; if (uri.getPathSegments().size() >= 2) { // it's a thread id for a conversation - Conversation otherConv = get(context, uri, false); + Conversation otherConv = get(context, uri, false, subId); if (otherConv == null) { return false; } @@ -255,7 +258,7 @@ public class Conversation { } else { String recipient = getRecipients(uri); incomingRecipient = ContactList.getByNumbers(recipient, - false /* don't block */, false /* don't replace number */); + false /* don't block */, false /* don't replace number */, subId); } if (DEBUG) Log.v(TAG, "sameRecipient incomingRecipient: " + incomingRecipient + " mRecipients: " + mRecipients); @@ -463,12 +466,12 @@ public class Conversation { * * @return The thread ID of this conversation in the database */ - public synchronized long ensureThreadId() { + public synchronized long ensureThreadId(int subId) { if (DEBUG || DELETEDEBUG) { LogTag.debug("ensureThreadId before: " + mThreadId); } if (mThreadId <= 0) { - mThreadId = getOrCreateThreadId(mContext, mRecipients); + mThreadId = getOrCreateThreadId(mContext, mRecipients, subId); } if (DEBUG || DELETEDEBUG) { LogTag.debug("ensureThreadId after: " + mThreadId); @@ -604,11 +607,11 @@ public class Conversation { mIsChecked = isChecked; } - private static long getOrCreateThreadId(Context context, ContactList list) { + private static long getOrCreateThreadId(Context context, ContactList list, int subId) { HashSet<String> recipients = new HashSet<String>(); Contact cacheContact = null; for (Contact c : list) { - cacheContact = Contact.get(c.getNumber(), false); + cacheContact = Contact.get(c.getNumber(), false, subId); if (cacheContact != null) { recipients.add(cacheContact.getNumber()); } else { @@ -696,7 +699,8 @@ public class Conversation { @Override public synchronized String toString() { - return String.format("[%s] (tid %d)", mRecipients.serialize(), mThreadId); + return String.format("[%s] (tid %d)", + mRecipients.serialize(SubscriptionManager.getDefaultSmsSubId()), mThreadId); } /** @@ -924,7 +928,8 @@ public class Conversation { // Fill in as much of the conversation as we can before doing the slow stuff of looking // up the contacts associated with this conversation. String recipientIds = c.getString(RECIPIENT_IDS); - ContactList recipients = ContactList.getByIds(recipientIds, allowQuery); + ContactList recipients = ContactList.getByIds(recipientIds, allowQuery, + SubscriptionManager.getDefaultSmsSubId()); synchronized (conv) { conv.mRecipients = recipients; } @@ -1305,7 +1310,7 @@ public class Conversation { Cache.dumpCache(); } - public static void dumpThreadsTable(Context context) { + public static void dumpThreadsTable(Context context, int subId) { LogTag.debug("**** Dump of threads table ****"); Cursor c = context.getContentResolver().query(sAllThreadsUri, ALL_THREADS_PROJECTION, null, null, "date ASC"); @@ -1322,8 +1327,9 @@ public class Conversation { " " + ThreadsColumns.HAS_ATTACHMENT + " : " + c.getInt(HAS_ATTACHMENT) + " " + ThreadsColumns.RECIPIENT_IDS + " : " + c.getString(RECIPIENT_IDS)); - ContactList recipients = ContactList.getByIds(c.getString(RECIPIENT_IDS), false); - Log.d(TAG, "----recipients: " + recipients.serialize()); + ContactList recipients = ContactList.getByIds(c.getString(RECIPIENT_IDS), false, + subId); + Log.d(TAG, "----recipients: " + recipients.serialize(subId)); } } finally { c.close(); @@ -1391,10 +1397,10 @@ public class Conversation { * @return the verified number or email of the recipient */ public static String verifySingleRecipient(final Context context, - final long threadId, final String recipientStr) { + final long threadId, final String recipientStr, int subId) { if (threadId <= 0) { LogTag.error("verifySingleRecipient threadId is ZERO, recipient: " + recipientStr); - LogTag.dumpInternalTables(context); + LogTag.dumpInternalTables(context, subId); return recipientStr; } Cursor c = context.getContentResolver().query(sAllThreadsUri, ALL_THREADS_PROJECTION, @@ -1402,7 +1408,7 @@ public class Conversation { if (c == null) { LogTag.error("verifySingleRecipient threadId: " + threadId + " resulted in NULL cursor , recipient: " + recipientStr); - LogTag.dumpInternalTables(context); + LogTag.dumpInternalTables(context, subId); return recipientStr; } String address = recipientStr; @@ -1411,7 +1417,7 @@ public class Conversation { if (!c.moveToFirst()) { LogTag.error("verifySingleRecipient threadId: " + threadId + " can't moveToFirst , recipient: " + recipientStr); - LogTag.dumpInternalTables(context); + LogTag.dumpInternalTables(context, subId); return recipientStr; } recipientIds = c.getString(RECIPIENT_IDS); @@ -1434,7 +1440,7 @@ public class Conversation { LogTag.error("verifySingleRecipient threadId: " + threadId + " getSingleNumberFromCanonicalAddresses returned empty number for: " + ids[0] + " recipientIds: " + recipientIds); - LogTag.dumpInternalTables(context); + LogTag.dumpInternalTables(context, subId); return recipientStr; } if (PhoneNumberUtils.compareLoosely(recipientStr, address)) { @@ -1450,9 +1456,9 @@ public class Conversation { if (context instanceof Activity) { LogTag.warnPossibleRecipientMismatch("verifySingleRecipient for threadId: " + threadId + " original recipient: " + recipientStr + - " recipient from DB: " + address, (Activity)context); + " recipient from DB: " + address, (Activity)context, subId); } - LogTag.dumpInternalTables(context); + LogTag.dumpInternalTables(context, subId); if (Log.isLoggable(LogTag.THREAD_CACHE, Log.VERBOSE)) { LogTag.debug("verifySingleRecipient for threadId: " + threadId + " original recipient: " + recipientStr + diff --git a/src/com/android/mms/data/WorkingMessage.java b/src/com/android/mms/data/WorkingMessage.java index 62052116..b7581afd 100755 --- a/src/com/android/mms/data/WorkingMessage.java +++ b/src/com/android/mms/data/WorkingMessage.java @@ -40,6 +40,7 @@ import android.provider.Telephony.Mms; import android.provider.Telephony.MmsSms; import android.provider.Telephony.MmsSms.PendingMessages; import android.provider.Telephony.Sms; +import android.telephony.SmsManager; import android.telephony.SmsMessage; import android.text.TextUtils; import android.util.Log; @@ -69,6 +70,7 @@ import com.android.mms.util.DraftCache; import com.android.mms.util.Recycler; import com.android.mms.util.ThumbnailManager; import com.android.mms.widget.MmsWidgetProvider; + import com.google.android.mms.ContentType; import com.google.android.mms.MmsException; import com.google.android.mms.pdu.EncodedStringValue; @@ -145,9 +147,6 @@ public class WorkingMessage { private volatile boolean mHasMmsDraft; private volatile boolean mHasSmsDraft; - // Cached value of mms enabled flag - private static boolean sMmsEnabled = MmsConfig.getMmsEnabled(); - // Our callback interface private final MessageStatusListener mStatusListener; private List<String> mWorkingRecipients; @@ -223,7 +222,7 @@ public class WorkingMessage { * Create a new WorkingMessage from the specified data URI, which typically * contains an MMS message. */ - public static WorkingMessage load(ComposeMessageActivity activity, Uri uri) { + public static WorkingMessage load(ComposeMessageActivity activity, Uri uri, int subId) { // If the message is not already in the draft box, move it there. if (!uri.toString().startsWith(Mms.Draft.CONTENT_URI.toString())) { PduPersister persister = PduPersister.getPduPersister(activity); @@ -239,7 +238,7 @@ public class WorkingMessage { } WorkingMessage msg = new WorkingMessage(activity); - if (msg.loadFromUri(uri)) { + if (msg.loadFromUri(uri, subId)) { msg.mHasMmsDraft = true; return msg; } @@ -247,13 +246,13 @@ public class WorkingMessage { return null; } - private void correctAttachmentState(boolean showToast) { + private void correctAttachmentState(boolean showToast, int subId) { int slideCount = mSlideshow.size(); // If we get an empty slideshow, tear down all MMS // state and discard the unnecessary message Uri. if (slideCount == 0) { - removeAttachment(false); + removeAttachment(false, subId); } else if (slideCount > 1) { mAttachmentType = SLIDESHOW; } else { @@ -267,10 +266,10 @@ public class WorkingMessage { } } - updateState(HAS_ATTACHMENT, hasAttachment(), showToast); + updateState(HAS_ATTACHMENT, hasAttachment(), showToast, subId); } - private boolean loadFromUri(Uri uri) { + private boolean loadFromUri(Uri uri, int subId) { if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) LogTag.debug("loadFromUri %s", uri); try { mSlideshow = SlideshowModel.createFromMessageUri(mActivity, uri); @@ -283,7 +282,7 @@ public class WorkingMessage { // Make sure all our state is as expected. syncTextFromSlideshow(); - correctAttachmentState(false); + correctAttachmentState(false, subId); return true; } @@ -294,7 +293,8 @@ public class WorkingMessage { */ public static WorkingMessage loadDraft(ComposeMessageActivity activity, final Conversation conv, - final Runnable onDraftLoaded) { + final Runnable onDraftLoaded, + final int subId) { if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) LogTag.debug("loadDraft %s", conv); final WorkingMessage msg = createEmpty(activity); @@ -321,7 +321,7 @@ public class WorkingMessage { StringBuilder sb = new StringBuilder(); Uri uri = readDraftMmsMessage(msg.mActivity, conv, sb); if (uri != null) { - if (msg.loadFromUri(uri)) { + if (msg.loadFromUri(uri, subId)) { // If there was an MMS message, readDraftMmsMessage // will put the subject in our supplied StringBuilder. subject = sb.toString(); @@ -341,7 +341,7 @@ public class WorkingMessage { if (result.second != null) { msg.mHasMmsDraft = true; if (!TextUtils.isEmpty(result.second)) { - msg.setSubject(result.second, false); + msg.setSubject(result.second, false, subId); } } if (onDraftLoaded != null) { @@ -375,7 +375,7 @@ public class WorkingMessage { return mText != null && TextUtils.getTrimmedLength(mText) > 0; } - public void removeAttachment(boolean notify) { + public void removeAttachment(boolean notify, int subId) { removeThumbnailsFromCache(mSlideshow); mAttachmentType = TEXT; mSlideshow = null; @@ -384,7 +384,7 @@ public class WorkingMessage { mMessageUri = null; } // mark this message as no longer having an attachment - updateState(HAS_ATTACHMENT, false, notify); + updateState(HAS_ATTACHMENT, false, notify, subId); if (notify) { // Tell ComposeMessageActivity (or other listener) that the attachment has changed. // In the case of ComposeMessageActivity, it will remove its attachment panel because @@ -426,7 +426,7 @@ public class WorkingMessage { * @param append true if we should add the attachment to a new slide * @return An error code such as {@link UNKNOWN_ERROR} or {@link OK} if successful */ - public int setAttachment(int type, Uri dataUri, boolean append) { + public int setAttachment(int type, Uri dataUri, boolean append, int subId) { if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) { LogTag.debug("setAttachment type=%d uri %s", type, dataUri); } @@ -459,7 +459,8 @@ public class WorkingMessage { if (result == OK) { mAttachmentType = type; } - correctAttachmentState(true); // this can remove the slideshow if there are no attachments + // this can remove the slideshow if there are no attachments + correctAttachmentState(true, subId); if (mSlideshow != null && type == IMAGE) { // Prime the image's cache; helps A LOT when the image is coming from the network @@ -487,13 +488,14 @@ public class WorkingMessage { */ int smsSegmentCount = params[0]; - if (!MmsConfig.getMultipartSmsEnabled()) { + if (!MmsConfig.getBoolean(SmsManager.MMS_CONFIG_MULTIPART_SMS_ENABLED)) { // The provider doesn't support multi-part sms's so as soon as the user types // an sms longer than one segment, we have to turn the message into an mms. - setLengthRequiresMms(smsSegmentCount > 1, false); + setLengthRequiresMms(smsSegmentCount > 1, false, subId); } else { - int threshold = MmsConfig.getSmsToMmsTextThreshold(); - setLengthRequiresMms(threshold > 0 && smsSegmentCount > threshold, false); + int threshold = + MmsConfig.getInt(SmsManager.MMS_CONFIG_SMS_TO_MMS_TEXT_LENGTH_THRESHOLD); + setLengthRequiresMms(threshold > 0 && smsSegmentCount > threshold, false, subId); } } return result; @@ -689,9 +691,9 @@ public class WorkingMessage { * MMS when the user adds a subject. An empty subject will be removed * before saving to disk or sending, however. */ - public void setSubject(CharSequence s, boolean notify) { + public void setSubject(CharSequence s, boolean notify, int subId) { mSubject = s; - updateState(HAS_SUBJECT, (s != null), notify); + updateState(HAS_SUBJECT, (s != null), notify, subId); } /** @@ -753,9 +755,9 @@ public class WorkingMessage { /** * Removes the subject if it is empty, possibly converting back to SMS. */ - private void removeSubjectIfEmpty(boolean notify) { + private void removeSubjectIfEmpty(boolean notify, int subId) { if (!hasSubject()) { - setSubject(null, notify); + setSubject(null, notify, subId); } } @@ -763,10 +765,10 @@ public class WorkingMessage { * Gets internal message state ready for storage. Should be called any * time the message is about to be sent or written to disk. */ - private void prepareForSave(boolean notify) { + private void prepareForSave(boolean notify, int subId) { // Make sure our working set of recipients is resolved // to first-class Contact objects before we save. - syncWorkingRecipients(); + syncWorkingRecipients(subId); if (hasMmsContentToSave()) { ensureSlideshow(); @@ -777,36 +779,36 @@ public class WorkingMessage { /** * Resolve the temporary working set of recipients to a ContactList. */ - public void syncWorkingRecipients() { + public void syncWorkingRecipients(int subId) { if (mWorkingRecipients != null) { - ContactList recipients = ContactList.getByNumbers(mWorkingRecipients, false); + ContactList recipients = ContactList.getByNumbers(mWorkingRecipients, false, subId); mConversation.setRecipients(recipients); // resets the threadId to zero - setHasMultipleRecipients(recipients.size() > 1, true); + setHasMultipleRecipients(recipients.size() > 1, true, subId); mWorkingRecipients = null; } } - public String getWorkingRecipients() { + public String getWorkingRecipients(int subId) { // this function is used for DEBUG only if (mWorkingRecipients == null) { return null; } - ContactList recipients = ContactList.getByNumbers(mWorkingRecipients, false); - return recipients.serialize(); + ContactList recipients = ContactList.getByNumbers(mWorkingRecipients, false, subId); + return recipients.serialize(subId); } // Call when we've returned from adding an attachment. We're no longer forcing the message // into a Mms message. At this point we either have the goods to make the message a Mms // or we don't. No longer fake it. - public void removeFakeMmsForDraft() { - updateState(FORCE_MMS, false, false); + public void removeFakeMmsForDraft(int subId) { + updateState(FORCE_MMS, false, false, subId); } /** * Force the message to be saved as MMS and return the Uri of the message. * Typically used when handing a message off to another activity. */ - public Uri saveAsMms(boolean notify) { + public Uri saveAsMms(boolean notify, int subId) { if (DEBUG) LogTag.debug("saveAsMms mConversation=%s", mConversation); // If we have discarded the message, just bail out. @@ -820,27 +822,27 @@ public class WorkingMessage { // the message seem non-empty (and thus not discarded). This bit // is sticky until the last other MMS bit is removed, at which // point the message will fall back to SMS. - updateState(FORCE_MMS, true, notify); + updateState(FORCE_MMS, true, notify, subId); // Collect our state to be written to disk. - prepareForSave(true /* notify */); + prepareForSave(true /* notify */, subId); try { // Make sure we are saving to the correct thread ID. DraftCache.getInstance().setSavingDraft(true); if (!mConversation.getRecipients().isEmpty()) { - mConversation.ensureThreadId(); + mConversation.ensureThreadId(subId); } mConversation.setDraftState(true); PduPersister persister = PduPersister.getPduPersister(mActivity); - SendReq sendReq = makeSendReq(mConversation, mSubject); + SendReq sendReq = makeSendReq(mConversation, mSubject, subId); // If we don't already have a Uri lying around, make a new one. If we do // have one already, make sure it is synced to disk. if (mMessageUri == null) { mMessageUri = createDraftMmsMessage(persister, sendReq, mSlideshow, null, - mActivity, null); + mActivity, null, subId); } else { updateDraftMmsMessage(mMessageUri, persister, mSlideshow, sendReq, null); } @@ -855,7 +857,7 @@ public class WorkingMessage { * Save this message as a draft in the conversation previously specified * to {@link setConversation}. */ - public void saveDraft(final boolean isStopping) { + public void saveDraft(final boolean isStopping, int subId) { // If we have discarded the message, just bail out. if (mDiscarded) { LogTag.warn("saveDraft mDiscarded: true mConversation: " + mConversation + @@ -873,11 +875,11 @@ public class WorkingMessage { } // Get ready to write to disk. But don't notify message status when saving draft - prepareForSave(false /* notify */); + prepareForSave(false /* notify */, subId); if (requiresMms()) { if (hasMmsContentToSave()) { - asyncUpdateDraftMmsMessage(mConversation, isStopping); + asyncUpdateDraftMmsMessage(mConversation, isStopping, subId); mHasMmsDraft = true; } } else { @@ -890,7 +892,7 @@ public class WorkingMessage { // and takes that thread id (because it's the next thread id to be assigned), the // new message will be merged with the draft message thread, causing confusion! if (!TextUtils.isEmpty(content)) { - asyncUpdateDraftSmsMessage(mConversation, content, isStopping); + asyncUpdateDraftSmsMessage(mConversation, content, isStopping, subId); mHasSmsDraft = true; } else { // When there's no associated text message, we have to handle the case where there @@ -963,17 +965,17 @@ public class WorkingMessage { * has given it a Bundle to reinflate * @param bundle The Bundle passed in to onCreate */ - public void readStateFromBundle(Bundle bundle) { + public void readStateFromBundle(Bundle bundle, int subId) { if (bundle == null) { return; } String subject = bundle.getString("subject"); - setSubject(subject, false); + setSubject(subject, false, subId); Uri uri = (Uri)bundle.getParcelable("msg_uri"); if (uri != null) { - loadFromUri(uri); + loadFromUri(uri, subId); return; } else { String body = bundle.getString("sms_body"); @@ -1027,15 +1029,15 @@ public class WorkingMessage { /** * Set the conversation associated with this message. */ - public void setConversation(Conversation conv) { + public void setConversation(Conversation conv, int subId) { if (DEBUG) LogTag.debug("setConversation %s -> %s", mConversation, conv); mConversation = conv; // Convert to MMS if there are any email addresses in the recipient list. ContactList contactList = conv.getRecipients(); - setHasEmail(contactList.containsEmail(), false); - setHasMultipleRecipients(contactList.size() > 1, false); + setHasEmail(contactList.containsEmail(), false, subId); + setHasMultipleRecipients(contactList.size() > 1, false, subId); } public Conversation getConversation() { @@ -1046,11 +1048,11 @@ public class WorkingMessage { * Hint whether or not this message will be delivered to an * an email address. */ - public void setHasEmail(boolean hasEmail, boolean notify) { - if (MmsConfig.getEmailGateway() != null) { - updateState(RECIPIENTS_REQUIRE_MMS, false, notify); + public void setHasEmail(boolean hasEmail, boolean notify, int subId) { + if (MmsConfig.getString(SmsManager.MMS_CONFIG_EMAIL_GATEWAY_NUMBER) != null) { + updateState(RECIPIENTS_REQUIRE_MMS, false, notify, subId); } else { - updateState(RECIPIENTS_REQUIRE_MMS, hasEmail, notify); + updateState(RECIPIENTS_REQUIRE_MMS, hasEmail, notify, subId); } } /** @@ -1060,11 +1062,12 @@ public class WorkingMessage { * whether the message is sent as an mms, but the other factors (such as, "has a picture * attachment") still hold true. */ - public void setHasMultipleRecipients(boolean hasMultipleRecipients, boolean notify) { + public void setHasMultipleRecipients(boolean hasMultipleRecipients, boolean notify, + int subId) { updateState(MULTIPLE_RECIPIENTS, hasMultipleRecipients && - MessagingPreferenceActivity.getIsGroupMmsEnabled(mActivity), - notify); + MessagingPreferenceActivity.getIsGroupMmsEnabled(mActivity, subId), + notify, subId); } /** @@ -1096,8 +1099,8 @@ public class WorkingMessage { * @param: mmsRequired is the value for the LENGTH_REQUIRES_MMS bit. * @param: notify Whether or not to notify the user. */ - public void setLengthRequiresMms(boolean mmsRequired, boolean notify) { - updateState(LENGTH_REQUIRES_MMS, mmsRequired, notify); + public void setLengthRequiresMms(boolean mmsRequired, boolean notify, int subId) { + updateState(LENGTH_REQUIRES_MMS, mmsRequired, notify, subId); } private static String stateString(int state) { @@ -1129,8 +1132,8 @@ public class WorkingMessage { * @param on If true, set it; if false, clear it * @param notify Whether or not to notify the user */ - private void updateState(int state, boolean on, boolean notify) { - if (!sMmsEnabled) { + private void updateState(int state, boolean on, boolean notify, int subId) { + if (!MmsConfig.getBoolean(subId, SmsManager.MMS_CONFIG_MMS_ENABLED)) { // If Mms isn't enabled, the rest of the Messaging UI should not be using any // feature that would cause us to to turn on any Mms flag and show the // "Converting to multimedia..." message. @@ -1181,19 +1184,19 @@ public class WorkingMessage { LogTag.debug("send origThreadId: " + origThreadId); } - removeSubjectIfEmpty(true /* notify */); + removeSubjectIfEmpty(true /* notify */, subId); // Get ready to write to disk. - prepareForSave(true /* notify */); + prepareForSave(true /* notify */, subId); // We need the recipient list for both SMS and MMS. final Conversation conv = mConversation; String msgTxt = mText.toString(); - if (requiresMms() || addressContainsEmailToMms(conv, msgTxt)) { + if (requiresMms() || addressContainsEmailToMms(conv, msgTxt, subId)) { // uaProfUrl setting in mms_config.xml must be present to send an MMS. // However, SMS service will still work in the absence of a uaProfUrl address. - if (MmsConfig.getUaProfUrl() == null) { + if (MmsConfig.getString(subId, SmsManager.MMS_CONFIG_UA_PROF_TAG_NAME) == null) { String err = "WorkingMessage.send MMS sending failure. mms_config.xml is " + "missing uaProfUrl setting. uaProfUrl is required for MMS service, " + "but can be absent for SMS."; @@ -1221,14 +1224,14 @@ public class WorkingMessage { new Thread(new Runnable() { @Override public void run() { - final SendReq sendReq = makeSendReq(conv, subject); + final SendReq sendReq = makeSendReq(conv, subject, subId); // Make sure the text in slide 0 is no longer holding onto a reference to // the text in the message text box. slideshow.prepareForSend(); sendMmsWorker(conv, mmsUri, persister, slideshow, sendReq, textOnly, subId); - updateSendStats(conv); + updateSendStats(conv, subId); } }, "WorkingMessage.send MMS").start(); } else { @@ -1239,7 +1242,7 @@ public class WorkingMessage { public void run() { preSendSmsWorker(conv, msgText, recipientsInUI, subId); - updateSendStats(conv); + updateSendStats(conv, subId); } }, "WorkingMessage.send SMS").start(); } @@ -1252,24 +1255,24 @@ public class WorkingMessage { } // Be sure to only call this on a background thread. - private void updateSendStats(final Conversation conv) { - String[] dests = conv.getRecipients().getNumbers(); + private void updateSendStats(final Conversation conv, int subId) { + String[] dests = conv.getRecipients().getNumbers(subId); final ArrayList<String> phoneNumbers = new ArrayList<String>(Arrays.asList(dests)); DataUsageStatUpdater updater = new DataUsageStatUpdater(mActivity); updater.updateWithPhoneNumber(phoneNumbers); } - private boolean addressContainsEmailToMms(Conversation conv, String text) { - if (MmsConfig.getEmailGateway() != null) { - String[] dests = conv.getRecipients().getNumbers(); + private boolean addressContainsEmailToMms(Conversation conv, String text, int subId) { + if (MmsConfig.getString(SmsManager.MMS_CONFIG_EMAIL_GATEWAY_NUMBER) != null) { + String[] dests = conv.getRecipients().getNumbers(subId); int length = dests.length; for (int i = 0; i < length; i++) { - if (Mms.isEmailAddress(dests[i]) || MessageUtils.isAlias(dests[i])) { + if (Mms.isEmailAddress(dests[i]) || MessageUtils.isAlias(dests[i], subId)) { String mtext = dests[i] + " " + text; int[] params = SmsMessage.calculateLength(mtext, false); if (params[0] > 1) { - updateState(RECIPIENTS_REQUIRE_MMS, true, true); + updateState(RECIPIENTS_REQUIRE_MMS, true, true, subId); ensureSlideshow(); syncTextToSlideshow(); return true; @@ -1282,7 +1285,8 @@ public class WorkingMessage { // Message sending stuff - private void preSendSmsWorker(Conversation conv, String msgText, String recipientsInUI, int subId) { + private void preSendSmsWorker(Conversation conv, String msgText, String recipientsInUI, + int subId) { // If user tries to send the message, it's a signal the inputted text is what they wanted. UserHappinessSignals.userAcceptedImeText(mActivity); @@ -1291,9 +1295,9 @@ public class WorkingMessage { long origThreadId = conv.getThreadId(); // Make sure we are still using the correct thread ID for our recipient set. - long threadId = conv.ensureThreadId(); + long threadId = conv.ensureThreadId(subId); - String semiSepRecipients = conv.getRecipients().serialize(); + String semiSepRecipients = conv.getRecipients().serialize(subId); // recipientsInUI can be empty when the user types in a number and hits send if (LogTag.SEVERE_WARNING && ((origThreadId != 0 && origThreadId != threadId) || @@ -1310,7 +1314,7 @@ public class WorkingMessage { semiSepRecipients + "\""; // Just interrupt the process of sending message if recipient mismatch - LogTag.warnPossibleRecipientMismatch(msg, mActivity); + LogTag.warnPossibleRecipientMismatch(msg, mActivity, subId); }else { // just do a regular send. We're already on a non-ui thread so no need to fire // off another thread to do this work. @@ -1354,7 +1358,7 @@ public class WorkingMessage { // Make sure we are still using the correct thread ID for our // recipient set. - threadId = conv.ensureThreadId(); + threadId = conv.ensureThreadId(subId); if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) { LogTag.debug("sendMmsWorker: update draft MMS message " + mmsUri + @@ -1362,12 +1366,14 @@ public class WorkingMessage { } // One last check to verify the address of the recipient. - String[] dests = conv.getRecipients().getNumbers(true /* scrub for MMS address */); + String[] dests = conv.getRecipients().getNumbers(true /* scrub for MMS address */, + subId); if (dests.length == 1) { // verify the single address matches what's in the database. If we get a different // address back, jam the new value back into the SendReq. String newAddress = - Conversation.verifySingleRecipient(mActivity, conv.getThreadId(), dests[0]); + Conversation.verifySingleRecipient(mActivity, conv.getThreadId(), dests[0], + subId); if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) { LogTag.debug("sendMmsWorker: newAddress " + newAddress + @@ -1410,7 +1416,7 @@ public class WorkingMessage { Mms.Outbox.CONTENT_URI, MMS_OUTBOX_PROJECTION, null, null, null); if (cursor != null) { long maxMessageSize = MmsConfig.getMaxSizeScaleForPendingMmsAllowed() * - MmsConfig.getMaxMessageSize(); + MmsConfig.getInt(subId, SmsManager.MMS_CONFIG_MAX_MESSAGE_SIZE); long totalPendingSize = 0; while (cursor.moveToNext()) { totalPendingSize += cursor.getLong(MMS_MESSAGE_SIZE_INDEX); @@ -1432,7 +1438,7 @@ public class WorkingMessage { if (newMessage) { // Create a new MMS message if one hasn't been made yet. mmsUri = createDraftMmsMessage(persister, sendReq, slideshow, mmsUri, - mActivity, null); + mActivity, null, subId); } else { // Otherwise, sync the MMS message in progress to disk. updateDraftMmsMessage(mmsUri, persister, slideshow, sendReq, null); @@ -1558,8 +1564,9 @@ public class WorkingMessage { * makeSendReq should always return a non-null SendReq, whether the dest addresses are * valid or not. */ - private static SendReq makeSendReq(Conversation conv, CharSequence subject) { - String[] dests = conv.getRecipients().getNumbers(true /* scrub for MMS address */); + private static SendReq makeSendReq(Conversation conv, CharSequence subject, int subId) { + String[] dests = conv.getRecipients().getNumbers(true /* scrub for MMS address */, + subId); SendReq req = new SendReq(); EncodedStringValue[] encodedNumbers = EncodedStringValue.encodeStrings(dests); @@ -1578,7 +1585,7 @@ public class WorkingMessage { private static Uri createDraftMmsMessage(PduPersister persister, SendReq sendReq, SlideshowModel slideshow, Uri preUri, Context context, - HashMap<Uri, InputStream> preOpenedFiles) { + HashMap<Uri, InputStream> preOpenedFiles, int subId) { if (slideshow == null) { return null; } @@ -1586,7 +1593,7 @@ public class WorkingMessage { PduBody pb = slideshow.toPduBody(); sendReq.setBody(pb); Uri res = persister.persist(sendReq, preUri == null ? Mms.Draft.CONTENT_URI : preUri, - true, MessagingPreferenceActivity.getIsGroupMmsEnabled(context), + true, MessagingPreferenceActivity.getIsGroupMmsEnabled(context, subId), preOpenedFiles); slideshow.sync(pb); return res; @@ -1595,7 +1602,8 @@ public class WorkingMessage { } } - private void asyncUpdateDraftMmsMessage(final Conversation conv, final boolean isStopping) { + private void asyncUpdateDraftMmsMessage(final Conversation conv, final boolean isStopping, + final int subId) { if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) { LogTag.debug("asyncUpdateDraftMmsMessage conv=%s mMessageUri=%s", conv, mMessageUri); } @@ -1609,16 +1617,16 @@ public class WorkingMessage { DraftCache.getInstance().setSavingDraft(true); final PduPersister persister = PduPersister.getPduPersister(mActivity); - final SendReq sendReq = makeSendReq(conv, mSubject); + final SendReq sendReq = makeSendReq(conv, mSubject, subId); if (mMessageUri == null) { mMessageUri = createDraftMmsMessage(persister, sendReq, mSlideshow, null, - mActivity, preOpenedFiles); + mActivity, preOpenedFiles, subId); } else { updateDraftMmsMessage(mMessageUri, persister, mSlideshow, sendReq, preOpenedFiles); } - ensureThreadIdIfNeeded(conv, isStopping); + ensureThreadIdIfNeeded(conv, isStopping, subId); conv.setDraftState(true); if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) { LogTag.debug("asyncUpdateDraftMmsMessage conv: " + conv + @@ -1739,7 +1747,7 @@ public class WorkingMessage { } private void asyncUpdateDraftSmsMessage(final Conversation conv, final String contents, - final boolean isStopping) { + final boolean isStopping, final int subId) { new Thread(new Runnable() { @Override public void run() { @@ -1751,7 +1759,7 @@ public class WorkingMessage { } return; } - ensureThreadIdIfNeeded(conv, isStopping); + ensureThreadIdIfNeeded(conv, isStopping, subId); conv.setDraftState(true); updateDraftSmsMessage(conv, contents); } finally { @@ -1824,8 +1832,10 @@ public class WorkingMessage { * one. * @param conv The conversation we are in. * @param isStopping Whether we are saving the draft in CMA'a onStop + * @param subId subscription id */ - private void ensureThreadIdIfNeeded(final Conversation conv, final boolean isStopping) { + private void ensureThreadIdIfNeeded(final Conversation conv, final boolean isStopping, + int subId) { if (isStopping && conv.getMessageCount() == 0) { // We need to save the drafts in an unorphaned thread id. When the user goes // back to ConversationList while we're saving a draft from CMA's.onStop, @@ -1836,7 +1846,7 @@ public class WorkingMessage { conv.clearThreadId(); // force us to get the updated thread id } if (!conv.getRecipients().isEmpty()) { - conv.ensureThreadId(); + conv.ensureThreadId(subId); } } } diff --git a/src/com/android/mms/model/CarrierContentRestriction.java b/src/com/android/mms/model/CarrierContentRestriction.java index 2d167451..b17afef0 100644 --- a/src/com/android/mms/model/CarrierContentRestriction.java +++ b/src/com/android/mms/model/CarrierContentRestriction.java @@ -19,6 +19,7 @@ package com.android.mms.model; import java.util.ArrayList; import android.content.ContentResolver; +import android.telephony.SmsManager; import android.util.Log; import com.android.mms.ContentRestrictionException; @@ -27,6 +28,7 @@ import com.android.mms.LogTag; import com.android.mms.MmsConfig; import com.android.mms.ResolutionException; import com.android.mms.UnsupportContentTypeException; + import com.google.android.mms.ContentType; public class CarrierContentRestriction implements ContentRestriction { @@ -49,7 +51,8 @@ public class CarrierContentRestriction implements ContentRestriction { if (DEBUG) { Log.d(LogTag.APP, "CarrierContentRestriction.checkMessageSize messageSize: " + messageSize + " increaseSize: " + increaseSize + - " MmsConfig.getMaxMessageSize: " + MmsConfig.getMaxMessageSize()); + " MmsConfig.getMaxMessageSize: " + + MmsConfig.getInt(SmsManager.MMS_CONFIG_MAX_MESSAGE_SIZE)); } if ( (messageSize < 0) || (increaseSize < 0) ) { throw new ContentRestrictionException("Negative message size" @@ -57,13 +60,15 @@ public class CarrierContentRestriction implements ContentRestriction { } int newSize = messageSize + increaseSize; - if ( (newSize < 0) || (newSize > MmsConfig.getMaxMessageSize()) ) { + if ( (newSize < 0) || + (newSize > MmsConfig.getInt(SmsManager.MMS_CONFIG_MAX_MESSAGE_SIZE)) ) { throw new ExceedMessageSizeException("Exceed message size limitation"); } } public void checkResolution(int width, int height) throws ContentRestrictionException { - if ( (width > MmsConfig.getMaxImageWidth()) || (height > MmsConfig.getMaxImageHeight()) ) { + if ( (width > MmsConfig.getInt(SmsManager.MMS_CONFIG_MAX_IMAGE_WIDTH) || + (height > MmsConfig.getInt(SmsManager.MMS_CONFIG_MAX_IMAGE_HEIGHT))) ) { throw new ResolutionException("content resolution exceeds restriction."); } } diff --git a/src/com/android/mms/model/ImageModel.java b/src/com/android/mms/model/ImageModel.java index 3dcc649c..ac713adf 100644 --- a/src/com/android/mms/model/ImageModel.java +++ b/src/com/android/mms/model/ImageModel.java @@ -29,6 +29,7 @@ import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; +import android.telephony.SmsManager; import android.text.TextUtils; import android.util.Log; @@ -42,6 +43,7 @@ import com.android.mms.ui.UriImage; import com.android.mms.util.ItemLoadedCallback; import com.android.mms.util.ItemLoadedFuture; import com.android.mms.util.ThumbnailManager; + import com.google.android.mms.MmsException; import com.google.android.mms.pdu.PduPart; import com.google.android.mms.pdu.PduPersister; @@ -186,8 +188,8 @@ public class ImageModel extends RegionMediaModel { protected void resizeMedia(int byteLimit, long messageId) throws MmsException { UriImage image = new UriImage(mContext, getUri()); - int widthLimit = MmsConfig.getMaxImageWidth(); - int heightLimit = MmsConfig.getMaxImageHeight(); + int widthLimit = MmsConfig.getInt(SmsManager.MMS_CONFIG_MAX_IMAGE_WIDTH); + int heightLimit = MmsConfig.getInt(SmsManager.MMS_CONFIG_MAX_IMAGE_HEIGHT); int size = getMediaSize(); // In mms_config.xml, the max width has always been declared larger than the max height. // Swap the width and height limits if necessary so we scale the picture as little as diff --git a/src/com/android/mms/model/MediaModel.java b/src/com/android/mms/model/MediaModel.java index 3993b0ea..b2cb222c 100644 --- a/src/com/android/mms/model/MediaModel.java +++ b/src/com/android/mms/model/MediaModel.java @@ -30,10 +30,12 @@ import android.content.Context; import android.content.Intent; import android.media.MediaMetadataRetriever; import android.net.Uri; +import android.telephony.SmsManager; import android.util.Log; import com.android.mms.LogTag; import com.android.mms.MmsConfig; + import com.google.android.mms.MmsException; // TODO: remove dependency for SDK build @@ -241,9 +243,10 @@ public abstract class MediaModel extends Model implements EventListener { // does below, but that turns out to be very slow. We'll deal with a zero size // when we resize the media. - if (isVideo() && mSize > MmsConfig.getMaxMessageSize()) { + final int maxMessageSize = MmsConfig.getInt(SmsManager.MMS_CONFIG_MAX_MESSAGE_SIZE); + if (isVideo() && mSize > maxMessageSize) { Log.w(TAG, "initMediaSize: Video size: f.getChannel().size(): " + mSize + - " larger than max message size: " + MmsConfig.getMaxMessageSize()); + " larger than max message size: " + maxMessageSize); } } else { while (-1 != input.read()) { diff --git a/src/com/android/mms/model/SlideshowModel.java b/src/com/android/mms/model/SlideshowModel.java index 15259d35..dc512046 100755 --- a/src/com/android/mms/model/SlideshowModel.java +++ b/src/com/android/mms/model/SlideshowModel.java @@ -43,6 +43,7 @@ import android.content.ContentResolver; import android.content.ContentUris; import android.content.Context; import android.net.Uri; +import android.telephony.SmsManager; import android.text.TextUtils; import android.util.Log; @@ -52,6 +53,7 @@ import com.android.mms.LogTag; import com.android.mms.MmsConfig; import com.android.mms.dom.smil.parser.SmilXmlSerializer; import com.android.mms.layout.LayoutManager; + import com.google.android.mms.ContentType; import com.google.android.mms.MmsException; import com.google.android.mms.pdu.GenericPdu; @@ -60,6 +62,7 @@ import com.google.android.mms.pdu.PduBody; import com.google.android.mms.pdu.PduHeaders; import com.google.android.mms.pdu.PduPart; import com.google.android.mms.pdu.PduPersister; + import com.android.mms.UnsupportContentTypeException; public class SlideshowModel extends Model @@ -678,13 +681,14 @@ public class SlideshowModel extends Model } } } + final int maxMessageSize = MmsConfig.getInt(SmsManager.MMS_CONFIG_MAX_MESSAGE_SIZE); if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) { Log.v(TAG, "finalResize: original message size: " + getCurrentMessageSize() + - " getMaxMessageSize: " + MmsConfig.getMaxMessageSize() + + " getMaxMessageSize: " + maxMessageSize + " fixedSizeTotal: " + fixedSizeTotal); } if (resizableCnt > 0) { - int remainingSize = MmsConfig.getMaxMessageSize() - fixedSizeTotal - SLIDESHOW_SLOP; + int remainingSize = maxMessageSize - fixedSizeTotal - SLIDESHOW_SLOP; if (remainingSize <= 0) { throw new ExceedMessageSizeException("No room for pictures"); } @@ -709,7 +713,7 @@ public class SlideshowModel extends Model Log.v(TAG, "finalResize: new message size: " + totalSize); } - if (totalSize > MmsConfig.getMaxMessageSize()) { + if (totalSize > maxMessageSize) { throw new ExceedMessageSizeException("After compressing pictures, message too big"); } setCurrentMessageSize(totalSize); diff --git a/src/com/android/mms/transaction/HttpUtils.java b/src/com/android/mms/transaction/HttpUtils.java index b6c878c7..4f601cd5 100644 --- a/src/com/android/mms/transaction/HttpUtils.java +++ b/src/com/android/mms/transaction/HttpUtils.java @@ -23,6 +23,8 @@ import java.net.SocketException; import java.net.URI; import java.net.URISyntaxException; import java.util.Locale; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.apache.http.HttpEntity; import org.apache.http.HttpHost; @@ -38,9 +40,8 @@ import org.apache.http.params.HttpProtocolParams; import android.content.Context; import android.net.http.AndroidHttpClient; -import android.telephony.TelephonyManager; +import android.telephony.SmsManager; import android.text.TextUtils; -import android.util.Config; import android.util.Log; import com.android.mms.LogTag; @@ -50,7 +51,6 @@ public class HttpUtils { private static final String TAG = LogTag.TRANSACTION; private static final boolean DEBUG = false; - private static final boolean LOCAL_LOGV = DEBUG ? Config.LOGD : Config.LOGV; public static final int HTTP_POST_METHOD = 1; public static final int HTTP_GET_METHOD = 2; @@ -93,7 +93,7 @@ public class HttpUtils { */ protected static byte[] httpConnection(Context context, long token, String url, byte[] pdu, int method, boolean isProxySet, - String proxyHost, int proxyPort) throws IOException { + String proxyHost, int proxyPort, int subId) throws IOException { if (url == null) { throw new IllegalArgumentException("URL must not be null."); } @@ -121,7 +121,7 @@ public class HttpUtils { hostUrl.getHost(), hostUrl.getPort(), HttpHost.DEFAULT_SCHEME_NAME); - client = createHttpClient(context); + client = createHttpClient(context, subId); HttpRequest req = null; switch(method) { case HTTP_POST_METHOD: @@ -155,8 +155,10 @@ public class HttpUtils { // Set necessary HTTP headers for MMS transmission. req.addHeader(HDR_KEY_ACCEPT, HDR_VALUE_ACCEPT); { - String xWapProfileTagName = MmsConfig.getUaProfTagName(); - String xWapProfileUrl = MmsConfig.getUaProfUrl(); + String xWapProfileTagName = + MmsConfig.getString(subId, SmsManager.MMS_CONFIG_UA_PROF_TAG_NAME); + String xWapProfileUrl = + MmsConfig.getString(subId, SmsManager.MMS_CONFIG_UA_PROF_URL); if (xWapProfileUrl != null) { if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) { @@ -171,26 +173,19 @@ public class HttpUtils { // Separate each pair by the first occurrence of ':' to obtain a name and // value. Replace the occurrence of the string returned by // MmsConfig.getHttpParamsLine1Key() with the users telephone number inside - // the value. - String extraHttpParams = MmsConfig.getHttpParams(); + // the value. And replace the occurrence of the string returned by + // MmsConfig.getHttpParamsNaiKey() with the users NAI(Network Access Identifier) + // inside the value. + String extraHttpParams = MmsConfig.getString(subId, SmsManager.MMS_CONFIG_HTTP_PARAMS); if (extraHttpParams != null) { - String line1Number = ((TelephonyManager)context - .getSystemService(Context.TELEPHONY_SERVICE)) - .getLine1Number(); - String line1Key = MmsConfig.getHttpParamsLine1Key(); + // Parse the parameter list String paramList[] = extraHttpParams.split("\\|"); - for (String paramPair : paramList) { String splitPair[] = paramPair.split(":", 2); - if (splitPair.length == 2) { - String name = splitPair[0].trim(); - String value = splitPair[1].trim(); - - if (line1Key != null) { - value = value.replace(line1Key, line1Number); - } + final String name = splitPair[0].trim(); + final String value = resolveMacro(splitPair[1].trim(), subId); if (!TextUtils.isEmpty(name) && !TextUtils.isEmpty(value)) { req.addHeader(name, value); } @@ -224,7 +219,8 @@ public class HttpUtils { } if (entity.isChunked()) { Log.v(TAG, "httpConnection: transfer encoding is chunked"); - int bytesTobeRead = MmsConfig.getMaxMessageSize(); + int bytesTobeRead = + MmsConfig.getInt(subId, SmsManager.MMS_CONFIG_MAX_MESSAGE_SIZE); byte[] tempBody = new byte[bytesTobeRead]; DataInputStream dis = new DataInputStream(entity.getContent()); try { @@ -298,14 +294,14 @@ public class HttpUtils { throw e; } - private static AndroidHttpClient createHttpClient(Context context) { - String userAgent = MmsConfig.getUserAgent(); + private static AndroidHttpClient createHttpClient(Context context, int subId) { + String userAgent = MmsConfig.getString(subId, SmsManager.MMS_CONFIG_USER_AGENT); AndroidHttpClient client = AndroidHttpClient.newInstance(userAgent, context); HttpParams params = client.getParams(); HttpProtocolParams.setContentCharset(params, "UTF-8"); // set the socket timeout - int soTimeout = MmsConfig.getHttpSocketTimeout(); + int soTimeout = MmsConfig.getInt(SmsManager.MMS_CONFIG_HTTP_SOCKET_TIMEOUT); if (Log.isLoggable(LogTag.TRANSACTION, Log.DEBUG)) { Log.d(TAG, "[HttpUtils] createHttpClient w/ socket timeout " + soTimeout + " ms, " @@ -370,4 +366,42 @@ public class HttpUtils { } } } + + private static final Pattern MACRO_P = Pattern.compile("##(\\S+)##"); + /** + * Resolve the macro in HTTP param value text + * For example, "something##LINE1##something" is resolved to "something9139531419something" + * + * @param value The HTTP param value possibly containing macros + * @return The HTTP param with macro resolved to real value + */ + private static String resolveMacro(String value, int subId) { + if (TextUtils.isEmpty(value)) { + return value; + } + final Matcher matcher = MACRO_P.matcher(value); + int nextStart = 0; + StringBuilder replaced = null; + while (matcher.find()) { + if (replaced == null) { + replaced = new StringBuilder(); + } + final int matchedStart = matcher.start(); + if (matchedStart > nextStart) { + replaced.append(value.substring(nextStart, matchedStart)); + } + final String macro = matcher.group(1); + final String macroValue = MmsConfig.getHttpParamMacro(macro, subId); + if (macroValue != null) { + replaced.append(macroValue); + } else { + Log.w(TAG, "HttpUtils: invalid macro " + macro); + } + nextStart = matcher.end(); + } + if (replaced != null && nextStart < value.length()) { + replaced.append(value.substring(nextStart)); + } + return replaced == null ? value : replaced.toString(); + } } diff --git a/src/com/android/mms/transaction/MessagingNotification.java b/src/com/android/mms/transaction/MessagingNotification.java index 8651d0ca..dfa6cc63 100644 --- a/src/com/android/mms/transaction/MessagingNotification.java +++ b/src/com/android/mms/transaction/MessagingNotification.java @@ -104,11 +104,11 @@ public class MessagingNotification { // This must be consistent with the column constants below. private static final String[] MMS_STATUS_PROJECTION = new String[] { - Mms.THREAD_ID, Mms.DATE, Mms._ID, Mms.SUBJECT, Mms.SUBJECT_CHARSET }; + Mms.THREAD_ID, Mms.DATE, Mms._ID, Mms.SUBJECT, Mms.SUBJECT_CHARSET, Mms.SUB_ID }; // This must be consistent with the column constants below. private static final String[] SMS_STATUS_PROJECTION = new String[] { - Sms.THREAD_ID, Sms.DATE, Sms.ADDRESS, Sms.SUBJECT, Sms.BODY }; + Sms.THREAD_ID, Sms.DATE, Sms.ADDRESS, Sms.SUBJECT, Sms.BODY, Sms.SUB_ID }; // These must be consistent with MMS_STATUS_PROJECTION and // SMS_STATUS_PROJECTION. @@ -119,6 +119,7 @@ public class MessagingNotification { private static final int COLUMN_SUBJECT = 3; private static final int COLUMN_SUBJECT_CS = 4; private static final int COLUMN_SMS_BODY = 4; + private static final int COLUMN_SUB_ID = 5; private static final String[] SMS_THREAD_ID_PROJECTION = new String[] { Sms.THREAD_ID }; private static final String[] MMS_THREAD_ID_PROJECTION = new String[] { Mms.THREAD_ID }; @@ -252,7 +253,7 @@ public class MessagingNotification { Contact.logWithTrace(TAG, "blockingUpdateNewMessageIndicator: newMsgThreadId: " + newMsgThreadId); } - final boolean isDefaultSmsApp = MmsConfig.isSmsEnabled(context); + final boolean isDefaultSmsApp = MmsConfig.isSmsEnabled(); if (!isDefaultSmsApp) { cancelNotification(context, NOTIFICATION_ID); if (DEBUG || Log.isLoggable(LogTag.APP, Log.VERBOSE)) { @@ -594,8 +595,9 @@ public class MessagingNotification { Uri msgUri = Mms.CONTENT_URI.buildUpon().appendPath( Long.toString(msgId)).build(); String address = AddressUtils.getFrom(context, msgUri); + int subId = cursor.getInt(COLUMN_SUB_ID); - Contact contact = Contact.get(address, false); + Contact contact = Contact.get(address, false, subId); if (contact.getSendToVoicemail()) { // don't notify, skip this one continue; @@ -647,7 +649,8 @@ public class MessagingNotification { timeMillis, attachedPicture, contact, - attachmentType); + attachmentType, + subId); notificationSet.add(info); @@ -707,8 +710,9 @@ public class MessagingNotification { String address = cursor.getString(COLUMN_SMS_ADDRESS); long timeMillis = 3000; + int subId = cursor.getInt(COLUMN_SUB_ID); - Contact contact = Contact.get(address, false); + Contact contact = Contact.get(address, false, subId); String name = contact.getNameAndNumber(); return new MmsSmsDeliveryInfo(context.getString(R.string.delivery_toast_body, name), @@ -733,8 +737,9 @@ public class MessagingNotification { try { while (cursor.moveToNext()) { String address = cursor.getString(COLUMN_SMS_ADDRESS); + int subId = cursor.getInt(COLUMN_SUB_ID); - Contact contact = Contact.get(address, false); + Contact contact = Contact.get(address, false, subId); if (contact.getSendToVoicemail()) { // don't notify, skip this one continue; @@ -754,7 +759,7 @@ public class MessagingNotification { NotificationInfo info = getNewMessageNotificationInfo(context, true /* isSms */, address, message, null /* subject */, threadId, timeMillis, null /* attachmentBitmap */, - contact, WorkingMessage.TEXT); + contact, WorkingMessage.TEXT, subId); notificationSet.add(info); @@ -776,18 +781,19 @@ public class MessagingNotification { long timeMillis, Bitmap attachmentBitmap, Contact contact, - int attachmentType) { + int attachmentType, + int subId) { Intent clickIntent = ComposeMessageActivity.createIntent(context, threadId); clickIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); String senderInfo = buildTickerMessage( - context, address, null, null).toString(); + context, address, null, null, subId).toString(); String senderInfoName = senderInfo.substring( 0, senderInfo.length() - 2); CharSequence ticker = buildTickerMessage( - context, address, subject, message); + context, address, subject, message, subId); return new NotificationInfo(isSms, clickIntent, message, subject, ticker, timeMillis, @@ -1073,8 +1079,8 @@ public class MessagingNotification { } protected static CharSequence buildTickerMessage( - Context context, String address, String subject, String body) { - String displayAddress = Contact.get(address, true).getName(); + Context context, String address, String subject, String body, int subId) { + String displayAddress = Contact.get(address, true, subId).getName(); StringBuilder buf = new StringBuilder( displayAddress == null diff --git a/src/com/android/mms/transaction/MmsMessageSender.java b/src/com/android/mms/transaction/MmsMessageSender.java index 19dfd440..c2b2c2f6 100755 --- a/src/com/android/mms/transaction/MmsMessageSender.java +++ b/src/com/android/mms/transaction/MmsMessageSender.java @@ -170,7 +170,7 @@ public class MmsMessageSender implements MessageSender { readRec.setDate(System.currentTimeMillis() / 1000); Uri uri = PduPersister.getPduPersister(context).persist(readRec, Mms.Outbox.CONTENT_URI, true, - MessagingPreferenceActivity.getIsGroupMmsEnabled(context), null); + MessagingPreferenceActivity.getIsGroupMmsEnabled(context, subId), null); updateSubIdForSend(context, uri, subId); context.startService(new Intent(context, TransactionService.class)); } catch (InvalidHeaderValueException e) { diff --git a/src/com/android/mms/transaction/NotificationTransaction.java b/src/com/android/mms/transaction/NotificationTransaction.java index bfa9db95..d245a482 100644 --- a/src/com/android/mms/transaction/NotificationTransaction.java +++ b/src/com/android/mms/transaction/NotificationTransaction.java @@ -35,6 +35,7 @@ import android.net.ConnectivityManager; import android.provider.Telephony.Mms; import android.provider.Telephony.Threads; import android.provider.Telephony.Mms.Inbox; +import android.telephony.SmsManager; import android.telephony.TelephonyManager; import android.util.Log; @@ -118,7 +119,7 @@ public class NotificationTransaction extends Transaction implements Runnable { // persist() to create a thread for the notificationInd because it causes UI jank. mUri = PduPersister.getPduPersister(context).persist( ind, Inbox.CONTENT_URI, !allowAutoDownload(context, subId), - MessagingPreferenceActivity.getIsGroupMmsEnabled(context), null); + MessagingPreferenceActivity.getIsGroupMmsEnabled(context, subId), null); } catch (MmsException e) { Log.e(TAG, "Failed to save NotificationInd in constructor.", e); throw new IllegalArgumentException(); @@ -160,12 +161,12 @@ public class NotificationTransaction extends Transaction implements Runnable { int status = STATUS_DEFERRED; // Don't try to download when data is suspended, as it will fail, so defer download if (!autoDownload) { - downloadManager.markState(mUri, DownloadManager.STATE_UNSTARTED); + downloadManager.markState(mUri, DownloadManager.STATE_UNSTARTED, mSubId); sendNotifyRespInd(status); return; } - downloadManager.markState(mUri, DownloadManager.STATE_DOWNLOADING); + downloadManager.markState(mUri, DownloadManager.STATE_DOWNLOADING, mSubId); if (LOCAL_LOGV) { Log.v(TAG, "Content-Location: " + mContentLocation); @@ -191,7 +192,8 @@ public class NotificationTransaction extends Transaction implements Runnable { // Save the received PDU (must be a M-RETRIEVE.CONF). PduPersister p = PduPersister.getPduPersister(mContext); Uri uri = p.persist(pdu, Inbox.CONTENT_URI, true, - MessagingPreferenceActivity.getIsGroupMmsEnabled(mContext), null); + MessagingPreferenceActivity.getIsGroupMmsEnabled(mContext, mSubId), + null); // Use local time instead of PDU time ContentValues values = new ContentValues(2); @@ -262,7 +264,7 @@ public class NotificationTransaction extends Transaction implements Runnable { status); // Pack M-NotifyResp.ind and send it - if(MmsConfig.getNotifyWapMMSC()) { + if(MmsConfig.getBoolean(mSubId, SmsManager.MMS_CONFIG_NOTIFY_WAP_MMSC_ENABLED)) { sendPdu(new PduComposer(mContext, notifyRespInd).make(), mContentLocation); } else { sendPdu(new PduComposer(mContext, notifyRespInd).make()); diff --git a/src/com/android/mms/transaction/PushReceiver.java b/src/com/android/mms/transaction/PushReceiver.java index 434bd35c..2c29d73b 100644 --- a/src/com/android/mms/transaction/PushReceiver.java +++ b/src/com/android/mms/transaction/PushReceiver.java @@ -36,6 +36,7 @@ import android.os.PowerManager; import android.provider.Telephony.Mms; import android.provider.Telephony.Mms.Inbox; import android.provider.Telephony.MmsSms.PendingMessages; +import android.telephony.SmsManager; import android.telephony.SubscriptionManager; import android.util.Log; @@ -88,6 +89,8 @@ public class PushReceiver extends BroadcastReceiver { ContentResolver cr = mContext.getContentResolver(); int type = pdu.getMessageType(); long threadId = -1; + final int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY, + SubscriptionManager.getDefaultSmsSubId()); try { switch (type) { @@ -101,7 +104,8 @@ public class PushReceiver extends BroadcastReceiver { } Uri uri = p.persist(pdu, Inbox.CONTENT_URI, true, - MessagingPreferenceActivity.getIsGroupMmsEnabled(mContext), null); + MessagingPreferenceActivity.getIsGroupMmsEnabled(mContext, subId), + null); // Update thread ID for ReadOrigInd & DeliveryInd. ContentValues values = new ContentValues(1); values.put(Mms.THREAD_ID, threadId); @@ -111,7 +115,8 @@ public class PushReceiver extends BroadcastReceiver { case MESSAGE_TYPE_NOTIFICATION_IND: { NotificationInd nInd = (NotificationInd) pdu; - if (MmsConfig.getTransIdEnabled()) { + if (MmsConfig.getBoolean(subId, + SmsManager.MMS_CONFIG_APPEND_TRANSACTION_ID)) { byte [] contentLocation = nInd.getContentLocation(); if ('=' == contentLocation[contentLocation.length - 1]) { byte [] transactionId = nInd.getTransactionId(); @@ -129,16 +134,14 @@ public class PushReceiver extends BroadcastReceiver { // Save the pdu. If we can start downloading the real pdu immediately, // don't allow persist() to create a thread for the notificationInd // because it causes UI jank. - int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY, - SubscriptionManager.INVALID_SUB_ID); if (!SubscriptionManager.isValidSubId(subId)) { Log.e(TAG, "subId is invalid"); break; } Uri uri = p.persist(pdu, Inbox.CONTENT_URI, !NotificationTransaction.allowAutoDownload(mContext, subId), - MessagingPreferenceActivity.getIsGroupMmsEnabled(mContext), - null); + MessagingPreferenceActivity.getIsGroupMmsEnabled(mContext, + subId), null); // TODO remove updating subId of Mms after refactor ContentValues values = new ContentValues(); values.put(Mms.SUB_ID, subId); @@ -177,7 +180,8 @@ public class PushReceiver extends BroadcastReceiver { pendingCursor.close(); } } - DownloadManager.getInstance().markState(uri, DownloadManager.STATE_DOWNLOADING); + DownloadManager.getInstance().markState(uri, + DownloadManager.STATE_DOWNLOADING, subId); // Start service to finish the notification transaction. Intent svc = new Intent(mContext, TransactionService.class); svc.putExtra(TransactionBundle.URI, uri.toString()); diff --git a/src/com/android/mms/transaction/ReadRecTransaction.java b/src/com/android/mms/transaction/ReadRecTransaction.java index d884e7e4..3b72727a 100755 --- a/src/com/android/mms/transaction/ReadRecTransaction.java +++ b/src/com/android/mms/transaction/ReadRecTransaction.java @@ -83,7 +83,7 @@ public class ReadRecTransaction extends Transaction implements Runnable{ ReadRecInd readRecInd = (ReadRecInd) persister.load(mReadReportURI); // insert the 'from' address per spec - String lineNumber = MessageUtils.getLocalNumber(); + String lineNumber = MessageUtils.getLocalNumber(mSubId); readRecInd.setFrom(new EncodedStringValue(lineNumber)); // Pack M-read-rec.ind and send it diff --git a/src/com/android/mms/transaction/RetrieveTransaction.java b/src/com/android/mms/transaction/RetrieveTransaction.java index 888b7f19..e2753b14 100755 --- a/src/com/android/mms/transaction/RetrieveTransaction.java +++ b/src/com/android/mms/transaction/RetrieveTransaction.java @@ -26,6 +26,7 @@ import android.database.sqlite.SqliteWrapper; import android.net.Uri; import android.provider.Telephony.Mms; import android.provider.Telephony.Mms.Inbox; +import android.telephony.SmsManager; import android.text.TextUtils; import android.util.Log; @@ -132,7 +133,7 @@ public class RetrieveTransaction extends Transaction implements Runnable { try { // Change the downloading state of the M-Notification.ind. DownloadManager.getInstance().markState( - mUri, DownloadManager.STATE_DOWNLOADING); + mUri, DownloadManager.STATE_DOWNLOADING, mSubId); // Send GET request to MMSC and retrieve the response data. byte[] resp = getPdu(mContentLocation); @@ -153,7 +154,7 @@ public class RetrieveTransaction extends Transaction implements Runnable { // Store M-Retrieve.conf into Inbox PduPersister persister = PduPersister.getPduPersister(mContext); msgUri = persister.persist(retrieveConf, Inbox.CONTENT_URI, true, - MessagingPreferenceActivity.getIsGroupMmsEnabled(mContext), null); + MessagingPreferenceActivity.getIsGroupMmsEnabled(mContext, mSubId), null); // Use local time instead of PDU time ContentValues values = new ContentValues(2); @@ -279,11 +280,11 @@ public class RetrieveTransaction extends Transaction implements Runnable { PduHeaders.CURRENT_MMS_VERSION, tranId); // insert the 'from' address per spec - String lineNumber = MessageUtils.getLocalNumber(); + String lineNumber = MessageUtils.getLocalNumber(mSubId); acknowledgeInd.setFrom(new EncodedStringValue(lineNumber)); // Pack M-Acknowledge.ind and send it - if(MmsConfig.getNotifyWapMMSC()) { + if(MmsConfig.getBoolean(mSubId, SmsManager.MMS_CONFIG_NOTIFY_WAP_MMSC_ENABLED)) { sendPdu(new PduComposer(mContext, acknowledgeInd).make(), mContentLocation); } else { sendPdu(new PduComposer(mContext, acknowledgeInd).make()); diff --git a/src/com/android/mms/transaction/RetryScheduler.java b/src/com/android/mms/transaction/RetryScheduler.java index bbe9ed90..edd16cc0 100644 --- a/src/com/android/mms/transaction/RetryScheduler.java +++ b/src/com/android/mms/transaction/RetryScheduler.java @@ -120,6 +120,9 @@ public class RetryScheduler implements Observer { int retryIndex = cursor.getInt(cursor.getColumnIndexOrThrow( PendingMessages.RETRY_INDEX)) + 1; // Count this time. + int subId = cursor.getInt(cursor.getColumnIndexOrThrow( + PendingMessages.SUB_ID)); + // TODO Should exactly understand what was happened. int errorType = MmsSms.ERR_TYPE_GENERIC; @@ -181,7 +184,7 @@ public class RetryScheduler implements Observer { if (isRetryDownloading) { // Downloading process is transiently failed. DownloadManager.getInstance().markState( - uri, DownloadManager.STATE_TRANSIENT_FAILURE); + uri, DownloadManager.STATE_TRANSIENT_FAILURE, subId); } } else { errorType = MmsSms.ERR_TYPE_GENERIC_PERMANENT; @@ -206,7 +209,7 @@ public class RetryScheduler implements Observer { } DownloadManager.getInstance().markState( - uri, DownloadManager.STATE_PERMANENT_FAILURE); + uri, DownloadManager.STATE_PERMANENT_FAILURE, subId); } else { // Mark the failed message as unread. ContentValues readValues = new ContentValues(1); diff --git a/src/com/android/mms/transaction/SendTransaction.java b/src/com/android/mms/transaction/SendTransaction.java index da2fb1ab..d4568529 100755 --- a/src/com/android/mms/transaction/SendTransaction.java +++ b/src/com/android/mms/transaction/SendTransaction.java @@ -103,7 +103,7 @@ public class SendTransaction extends Transaction implements Runnable { mSendReqURI, values, null, null); // fix bug 2100169: insert the 'from' address per spec - String lineNumber = MessageUtils.getLocalNumber(); + String lineNumber = MessageUtils.getLocalNumber(mSubId); if (!TextUtils.isEmpty(lineNumber)) { sendReq.setFrom(new EncodedStringValue(lineNumber)); } diff --git a/src/com/android/mms/transaction/SmsReceiverService.java b/src/com/android/mms/transaction/SmsReceiverService.java index 81519c71..0f6c11b2 100644 --- a/src/com/android/mms/transaction/SmsReceiverService.java +++ b/src/com/android/mms/transaction/SmsReceiverService.java @@ -201,7 +201,7 @@ public class SmsReceiverService extends Service { if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) { Log.v(TAG, "handleMessage serviceId: " + serviceId + " intent: " + intent); } - if (intent != null && MmsConfig.isSmsEnabled(getApplicationContext())) { + if (intent != null && MmsConfig.isSmsEnabled()) { String action = intent.getAction(); int error = intent.getIntExtra("errorCode", 0); @@ -622,8 +622,9 @@ public class SmsReceiverService extends Service { // case 7: address = "#4#5#6#"; break; // } + int subId = sms.getSubId(); if (!TextUtils.isEmpty(address)) { - Contact cacheContact = Contact.get(address,true); + Contact cacheContact = Contact.get(address, true, subId); if (cacheContact != null) { address = cacheContact.getNumber(); } @@ -632,7 +633,6 @@ public class SmsReceiverService extends Service { values.put(Sms.ADDRESS, address); } - int subId = sms.getSubId(); if (!SubscriptionManager.isValidSubId(subId)) { Log.e(TAG, "subId in storeMessage() is invalid!"); return null; diff --git a/src/com/android/mms/transaction/SmsSingleRecipientSender.java b/src/com/android/mms/transaction/SmsSingleRecipientSender.java index 7d9330d6..f2fa4ef3 100755 --- a/src/com/android/mms/transaction/SmsSingleRecipientSender.java +++ b/src/com/android/mms/transaction/SmsSingleRecipientSender.java @@ -51,11 +51,13 @@ public class SmsSingleRecipientSender extends SmsMessageSender { } SmsManager smsManager = SmsManager.getSmsManagerForSubscriber(mSubId); ArrayList<String> messages = null; - if ((MmsConfig.getEmailGateway() != null) && - (Mms.isEmailAddress(mDest) || MessageUtils.isAlias(mDest))) { + final String emailGateway = + MmsConfig.getString(mSubId, SmsManager.MMS_CONFIG_EMAIL_GATEWAY_NUMBER); + if ((emailGateway != null) && + (Mms.isEmailAddress(mDest) || MessageUtils.isAlias(mDest, mSubId))) { String msgText; msgText = mDest + " " + mMessageText; - mDest = MmsConfig.getEmailGateway(); + mDest = emailGateway; messages = smsManager.divideMessage(msgText); } else { messages = smsManager.divideMessage(mMessageText); @@ -63,7 +65,7 @@ public class SmsSingleRecipientSender extends SmsMessageSender { // (e.g. "801 555 1212" -> "8015551212") // (e.g. "+8211-123-4567" -> "+82111234567") mDest = PhoneNumberUtils.stripSeparators(mDest); - mDest = Conversation.verifySingleRecipient(mContext, mThreadId, mDest); + mDest = Conversation.verifySingleRecipient(mContext, mThreadId, mDest, mSubId); } int messageCount = messages.size(); diff --git a/src/com/android/mms/transaction/Transaction.java b/src/com/android/mms/transaction/Transaction.java index c001de61..8588e1e9 100755 --- a/src/com/android/mms/transaction/Transaction.java +++ b/src/com/android/mms/transaction/Transaction.java @@ -183,7 +183,8 @@ public abstract class Transaction extends Observable { pdu, HttpUtils.HTTP_POST_METHOD, mTransactionSettings.isProxySet(), mTransactionSettings.getProxyAddress(), - mTransactionSettings.getProxyPort()); + mTransactionSettings.getProxyPort(), + mSubId); } /** @@ -202,7 +203,8 @@ public abstract class Transaction extends Observable { url, null, HttpUtils.HTTP_GET_METHOD, mTransactionSettings.isProxySet(), mTransactionSettings.getProxyAddress(), - mTransactionSettings.getProxyPort()); + mTransactionSettings.getProxyPort(), + mSubId); } /** diff --git a/src/com/android/mms/transaction/TransactionService.java b/src/com/android/mms/transaction/TransactionService.java index 3d26e7b4..4eac8480 100644 --- a/src/com/android/mms/transaction/TransactionService.java +++ b/src/com/android/mms/transaction/TransactionService.java @@ -207,7 +207,7 @@ public class TransactionService extends Service implements Observer { public void onNewIntent(Intent intent, int serviceId) { mConnMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); if (mConnMgr == null || !SubStatusResolver.isMobileDataEnabledOnAnySub(getApplicationContext()) - || !MmsConfig.isSmsEnabled(getApplicationContext())) { + || !MmsConfig.isSmsEnabled()) { endMmsConnectivity(mMmsDatasubId); stopSelf(serviceId); return; @@ -971,13 +971,16 @@ public class TransactionService extends Service implements Observer { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY, - SubscriptionManager.INVALID_SUB_ID); + SubscriptionManager.getDefaultSmsSubId()); if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) { - Log.w(TAG, "ConnectivityBroadcastReceiver.onReceive() action: " + action); + Log.w(TAG, "ConnectivityBroadcastReceiver.onReceive() action: " + action + + " subId: " + subId); } - if (!action.equals(ConnectivityManager.CONNECTIVITY_ACTION) || !SubscriptionManager.isValidSubId(subId)) { + if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) { + Log.v(TAG, "onReceive: bailing because of non-valid subId: " + subId); + } return; } diff --git a/src/com/android/mms/ui/AttachmentTypeSelectorAdapter.java b/src/com/android/mms/ui/AttachmentTypeSelectorAdapter.java index 5831d6f9..48448754 100644 --- a/src/com/android/mms/ui/AttachmentTypeSelectorAdapter.java +++ b/src/com/android/mms/ui/AttachmentTypeSelectorAdapter.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.List; import android.content.Context; +import android.telephony.SmsManager; import com.android.mms.MmsConfig; import com.android.mms.R; @@ -43,7 +44,7 @@ public class AttachmentTypeSelectorAdapter extends IconListAdapter { public AttachmentTypeSelectorAdapter(Context context, int mode) { super(context, getData(mode, context)); } - + public int buttonToCommand(int whichButton) { AttachmentListItem item = (AttachmentListItem)getItem(whichButton); return item.getCommand(); @@ -63,7 +64,7 @@ public class AttachmentTypeSelectorAdapter extends IconListAdapter { addItem(data, context.getString(R.string.attach_record_video), R.drawable.ic_attach_capture_video_holo_light, RECORD_VIDEO); - if (MmsConfig.getAllowAttachAudio()) { + if (MmsConfig.getBoolean(SmsManager.MMS_CONFIG_ALLOW_ATTACH_AUDIO)) { addItem(data, context.getString(R.string.attach_sound), R.drawable.ic_attach_audio_holo_light, ADD_SOUND); } @@ -84,7 +85,7 @@ public class AttachmentTypeSelectorAdapter extends IconListAdapter { AttachmentListItem temp = new AttachmentListItem(title, resource, command); data.add(temp); } - + public static class AttachmentListItem extends IconListAdapter.IconListItem { private int mCommand; diff --git a/src/com/android/mms/ui/ComposeMessageActivity.java b/src/com/android/mms/ui/ComposeMessageActivity.java index de24b45b..6fe4d5ad 100644 --- a/src/com/android/mms/ui/ComposeMessageActivity.java +++ b/src/com/android/mms/ui/ComposeMessageActivity.java @@ -34,10 +34,8 @@ import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.ArrayList; -import java.util.HashMap; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.regex.Pattern; import android.app.ActionBar; @@ -53,7 +51,6 @@ import android.content.ContentUris; import android.content.ContentValues; import android.content.Context; import android.content.DialogInterface; -import android.content.DialogInterface.OnCancelListener; import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.content.IntentFilter; @@ -63,7 +60,6 @@ import android.database.Cursor; import android.database.sqlite.SQLiteException; import android.database.sqlite.SqliteWrapper; import android.drm.DrmStore; -import android.graphics.drawable.Drawable; import android.media.RingtoneManager; import android.net.Uri; import android.os.AsyncTask; @@ -86,6 +82,7 @@ import android.provider.Settings; import android.provider.Telephony.Mms; import android.provider.Telephony.Sms; import android.telephony.PhoneNumberUtils; +import android.telephony.SmsManager; import android.telephony.SmsMessage; import android.telephony.TelephonyManager; import android.telephony.SubInfoRecord; @@ -116,13 +113,10 @@ import android.webkit.MimeTypeMap; import android.widget.AdapterView; import android.widget.EditText; import android.widget.ImageButton; -import android.widget.ImageView; import android.widget.ListView; -import android.widget.SimpleAdapter; import android.widget.TextView; import android.widget.Toast; -import com.android.internal.telephony.PhoneConstants; import com.android.internal.telephony.TelephonyIntents; import com.android.internal.telephony.TelephonyProperties; import com.android.mms.LogTag; @@ -351,7 +345,7 @@ public class ComposeMessageActivity extends Activity private final static String RECIPIENTS = "recipients"; private AlertDialog mSubSelectDialog; - private int mSelectedSubId; + private int mSelectedSubId = SubscriptionManager.getDefaultSmsSubId(); private List<SubInfoRecord> mSubListInfo = new ArrayList<SubInfoRecord>(); private List<SubInfoRecord> mEmptySubListInfo = new ArrayList<SubInfoRecord>(); private SubChooseAdapter mSubAdapter; @@ -455,7 +449,7 @@ public class ComposeMessageActivity extends Activity @Override public void run() { // This runnable gets run in a background thread. - mTempMmsUri = mWorkingMessage.saveAsMms(false); + mTempMmsUri = mWorkingMessage.saveAsMms(false, mSelectedSubId); } }, new Runnable() { @Override @@ -501,7 +495,7 @@ public class ComposeMessageActivity extends Activity break; case AttachmentEditor.MSG_REMOVE_ATTACHMENT: - mWorkingMessage.removeAttachment(true); + mWorkingMessage.removeAttachment(true, mSelectedSubId); break; default: @@ -528,7 +522,7 @@ public class ComposeMessageActivity extends Activity @Override public void run() { // This runnable gets run in a background thread. - mTempMmsUri = mWorkingMessage.saveAsMms(false); + mTempMmsUri = mWorkingMessage.saveAsMms(false, mSelectedSubId); } }, new Runnable() { @Override @@ -607,7 +601,7 @@ public class ComposeMessageActivity extends Activity // When the subject editor is empty, press "DEL" to hide the input field. if ((keyCode == KeyEvent.KEYCODE_DEL) && (mSubjectTextEditor.length() == 0)) { showSubjectEditor(false); - mWorkingMessage.setSubject(null, true); + mWorkingMessage.setSubject(null, true, mSelectedSubId); return true; } return false; @@ -668,13 +662,15 @@ public class ComposeMessageActivity extends Activity int msgCount = params[0]; int remainingInCurrentMessage = params[2]; - if (!MmsConfig.getMultipartSmsEnabled()) { + if (!MmsConfig.getBoolean(mSelectedSubId, SmsManager.MMS_CONFIG_MULTIPART_SMS_ENABLED)) { // The provider doesn't support multi-part sms's so as soon as the user types // an sms longer than one segment, we have to turn the message into an mms. - mWorkingMessage.setLengthRequiresMms(msgCount > 1, true); + mWorkingMessage.setLengthRequiresMms(msgCount > 1, true, mSelectedSubId); } else { - int threshold = MmsConfig.getSmsToMmsTextThreshold(); - mWorkingMessage.setLengthRequiresMms(threshold > 0 && msgCount > threshold, true); + int threshold = MmsConfig.getInt(mSelectedSubId, + SmsManager.MMS_CONFIG_SMS_TO_MMS_TEXT_LENGTH_THRESHOLD); + mWorkingMessage.setLengthRequiresMms(threshold > 0 && msgCount > threshold, true, + mSelectedSubId); } // Show the counter only if: @@ -792,10 +788,10 @@ public class ComposeMessageActivity extends Activity } boolean isMms = mWorkingMessage.requiresMms(); - if (mRecipientsEditor.hasInvalidRecipient(isMms)) { - if (mRecipientsEditor.hasValidRecipient(isMms)) { + if (mRecipientsEditor.hasInvalidRecipient(isMms, mSelectedSubId)) { + if (mRecipientsEditor.hasValidRecipient(isMms, mSelectedSubId)) { String title = getResourcesString(R.string.has_invalid_recipient, - mRecipientsEditor.formatInvalidNumbers(isMms)); + mRecipientsEditor.formatInvalidNumbers(isMms, mSelectedSubId)); new AlertDialog.Builder(this) .setTitle(title) .setMessage(R.string.invalid_recipient_message) @@ -813,8 +809,9 @@ public class ComposeMessageActivity extends Activity } else { // The recipients editor is still open. Make sure we use what's showing there // as the destination. - ContactList contacts = mRecipientsEditor.constructContactsFromInput(false); - mDebugRecipients = contacts.serialize(); + ContactList contacts = mRecipientsEditor.constructContactsFromInput(false, + mSelectedSubId); + mDebugRecipients = contacts.serialize(mSelectedSubId); sendMessage(true); } } @@ -857,8 +854,8 @@ public class ComposeMessageActivity extends Activity mWorkingMessage.setWorkingRecipients(numbers); boolean multiRecipients = numbers != null && numbers.size() > 1; mMsgListAdapter.setIsGroupConversation(multiRecipients); - mWorkingMessage.setHasMultipleRecipients(multiRecipients, true); - mWorkingMessage.setHasEmail(mRecipientsEditor.containsEmail(), true); + mWorkingMessage.setHasMultipleRecipients(multiRecipients, true, mSelectedSubId); + mWorkingMessage.setHasEmail(mRecipientsEditor.containsEmail(), true, mSelectedSubId); checkForTooManyRecipients(); @@ -870,7 +867,8 @@ public class ComposeMessageActivity extends Activity continue; if (c == ',') { - ContactList contacts = mRecipientsEditor.constructContactsFromInput(false); + ContactList contacts = mRecipientsEditor.constructContactsFromInput(false, + mSelectedSubId); updateTitle(contacts); } @@ -883,7 +881,8 @@ public class ComposeMessageActivity extends Activity }; private void checkForTooManyRecipients() { - final int recipientLimit = MmsConfig.getRecipientLimit(); + final int recipientLimit = + MmsConfig.getInt(mSelectedSubId, SmsManager.MMS_CONFIG_RECIPIENT_LIMIT); if (recipientLimit != Integer.MAX_VALUE) { final int recipientCount = recipientCount(); boolean tooMany = recipientCount > recipientLimit; @@ -1115,7 +1114,7 @@ public class ComposeMessageActivity extends Activity } private Uri getContactUriForPhoneNumber(String phoneNumber) { - Contact contact = Contact.get(phoneNumber, false); + Contact contact = Contact.get(phoneNumber, false, mSelectedSubId); if (contact.existsInDatabase()) { return contact.getUri(); } @@ -1271,7 +1270,8 @@ public class ComposeMessageActivity extends Activity private void editMmsMessageItem(MessageItem msgItem) { // Load the selected message in as the working message. - WorkingMessage newWorkingMessage = WorkingMessage.load(this, msgItem.mMessageUri); + WorkingMessage newWorkingMessage = WorkingMessage.load(this, msgItem.mMessageUri, + mSelectedSubId); if (newWorkingMessage == null) { return; } @@ -1280,14 +1280,14 @@ public class ComposeMessageActivity extends Activity mWorkingMessage.discard(); mWorkingMessage = newWorkingMessage; - mWorkingMessage.setConversation(mConversation); + mWorkingMessage.setConversation(mConversation, mSelectedSubId); drawTopPanel(false); // WorkingMessage.load() above only loads the slideshow. Set the // subject here because we already know what it is and avoid doing // another DB lookup in load() just to get it. - mWorkingMessage.setSubject(msgItem.mSubject, false); + mWorkingMessage.setSubject(msgItem.mSubject, false, mSelectedSubId); if (mWorkingMessage.hasSubject()) { showSubjectEditor(true); @@ -1326,7 +1326,8 @@ public class ComposeMessageActivity extends Activity // Copy the parts of the message here. mTempMmsUri = persister.persist(sendReq, Mms.Draft.CONTENT_URI, true, MessagingPreferenceActivity - .getIsGroupMmsEnabled(ComposeMessageActivity.this), null); + .getIsGroupMmsEnabled(ComposeMessageActivity.this, + mSelectedSubId), null); mTempThreadId = MessagingNotification.getThreadId( ComposeMessageActivity.this, mTempMmsUri); } catch (MmsException e) { @@ -1849,7 +1850,7 @@ public class ComposeMessageActivity extends Activity break; } } - mDebugRecipients = list.serialize(); + mDebugRecipients = list.serialize(mSelectedSubId); ActionBar actionBar = getActionBar(); actionBar.setTitle(title); @@ -1913,7 +1914,7 @@ public class ComposeMessageActivity extends Activity public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { RecipientsEditor editor = (RecipientsEditor) v; - ContactList contacts = editor.constructContactsFromInput(false); + ContactList contacts = editor.constructContactsFromInput(false, mSelectedSubId); updateTitle(contacts); } } @@ -1950,7 +1951,7 @@ public class ComposeMessageActivity extends Activity @Override protected void onCreate(Bundle savedInstanceState) { - mIsSmsEnabled = MmsConfig.isSmsEnabled(this); + mIsSmsEnabled = MmsConfig.isSmsEnabled(); super.onCreate(savedInstanceState); resetConfiguration(getResources().getConfiguration()); @@ -1987,7 +1988,8 @@ public class ComposeMessageActivity extends Activity } mSubjectTextEditor = (EditText)findViewById(R.id.subject); mSubjectTextEditor.setFilters(new InputFilter[] { - new LengthFilter(MmsConfig.getMaxSubjectLength())}); + new LengthFilter(MmsConfig.getInt(mSelectedSubId, + SmsManager.MMS_CONFIG_SUBJECT_MAX_LENGTH))}); } mSubjectTextEditor.setOnKeyListener(show ? mSubjectKeyListener : null); @@ -2019,7 +2021,7 @@ public class ComposeMessageActivity extends Activity if (LogTag.SEVERE_WARNING && originalThreadId != 0 && originalThreadId == mConversation.getThreadId()) { LogTag.warnPossibleRecipientMismatch("ComposeMessageActivity.initialize: " + - " threadId didn't change from: " + originalThreadId, this); + " threadId didn't change from: " + originalThreadId, this, mSelectedSubId); } log("savedInstanceState = " + savedInstanceState + @@ -2049,7 +2051,7 @@ public class ComposeMessageActivity extends Activity } // Let the working message know what conversation it belongs to - mWorkingMessage.setConversation(mConversation); + mWorkingMessage.setConversation(mConversation, mSelectedSubId); // Show the recipients editor if we don't have a valid thread. Hide it otherwise. if (mConversation.getThreadId() <= 0) { @@ -2113,7 +2115,7 @@ public class ComposeMessageActivity extends Activity // We've got a draft. Make sure the working recipients are synched // to the conversation so when we compare conversations later in this function, // the compare will work. - mWorkingMessage.syncWorkingRecipients(); + mWorkingMessage.syncWorkingRecipients(mSelectedSubId); } // Get the "real" conversation based on the intentUri. The intentUri might specify // the conversation by a phone number or by a thread id. We'll typically get a threadId @@ -2124,7 +2126,7 @@ public class ComposeMessageActivity extends Activity // the database and the corresponding entry made in the threads table. The code should // use the real conversation as soon as it can rather than finding out the threadId // when sending with "ensureThreadId". - conversation = Conversation.get(this, intentUri, false); + conversation = Conversation.get(this, intentUri, false, mSelectedSubId); } if (LogTag.VERBOSE || Log.isLoggable(LogTag.APP, Log.VERBOSE)) { @@ -2146,7 +2148,7 @@ public class ComposeMessageActivity extends Activity log("onNewIntent: same conversation"); if (mConversation.getThreadId() == 0) { mConversation = conversation; - mWorkingMessage.setConversation(mConversation); + mWorkingMessage.setConversation(mConversation, mSelectedSubId); updateThreadIdIfRunning(); invalidateOptionsMenu(); } @@ -2166,7 +2168,7 @@ public class ComposeMessageActivity extends Activity LogTag.warnPossibleRecipientMismatch( "ComposeMessageActivity: mWorkingMessage.mConversation=" + mWorkingMessage.getConversation() + ", mConversation=" + - mConversation + ", MISMATCH!", this); + mConversation + ", MISMATCH!", this, mSelectedSubId); } } @@ -2204,7 +2206,7 @@ public class ComposeMessageActivity extends Activity @Override protected void onStart() { super.onStart(); - boolean isSmsEnabled = MmsConfig.isSmsEnabled(this); + boolean isSmsEnabled = MmsConfig.isSmsEnabled(); if (isSmsEnabled != mIsSmsEnabled) { mIsSmsEnabled = isSmsEnabled; invalidateOptionsMenu(); @@ -2261,7 +2263,7 @@ public class ComposeMessageActivity extends Activity // Update the fasttrack info in case any of the recipients' contact info changed // while we were paused. This can happen, for example, if a user changes or adds // an avatar associated with a contact. - mWorkingMessage.syncWorkingRecipients(); + mWorkingMessage.syncWorkingRecipients(mSelectedSubId); if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) { log("update title, mConversation=" + mConversation.toString()); @@ -2326,7 +2328,7 @@ public class ComposeMessageActivity extends Activity public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - outState.putString(RECIPIENTS, getRecipients().serialize()); + outState.putString(RECIPIENTS, getRecipients().serialize(mSelectedSubId)); mWorkingMessage.writeStateToBundle(outState); @@ -2360,7 +2362,8 @@ public class ComposeMessageActivity extends Activity @Override public void run() { ContactList recipients = isRecipientsEditorVisible() ? - mRecipientsEditor.constructContactsFromInput(false) : getRecipients(); + mRecipientsEditor.constructContactsFromInput(false, mSelectedSubId) : + getRecipients(); updateTitle(recipients); } }, 100); @@ -2569,7 +2572,8 @@ public class ComposeMessageActivity extends Activity } if (isRecipientsEditorVisible() && - !mRecipientsEditor.hasValidRecipient(mWorkingMessage.requiresMms())) { + !mRecipientsEditor.hasValidRecipient(mWorkingMessage.requiresMms(), + mSelectedSubId)) { MessageUtils.showDiscardDraftConfirmDialog(this, new DiscardDraftListener()); return; } @@ -2752,7 +2756,8 @@ public class ComposeMessageActivity extends Activity } } - if (MmsConfig.getMmsEnabled() && mIsSmsEnabled) { + if (MmsConfig.getBoolean(mSelectedSubId, SmsManager.MMS_CONFIG_MMS_ENABLED) && + mIsSmsEnabled) { if (!isSubjectEditorVisible()) { menu.add(0, MENU_ADD_SUBJECT, 0, R.string.add_subject).setIcon( R.drawable.ic_menu_edit); @@ -2823,7 +2828,7 @@ public class ComposeMessageActivity extends Activity switch (item.getItemId()) { case MENU_ADD_SUBJECT: showSubjectEditor(true); - mWorkingMessage.setSubject("", true); + mWorkingMessage.setSubject("", true, mSelectedSubId); updateSendButtonState(); mSubjectTextEditor.requestFocus(); break; @@ -2889,7 +2894,7 @@ public class ComposeMessageActivity extends Activity case MENU_DEBUG_DUMP: mWorkingMessage.dump(); Conversation.dump(); - LogTag.dumpInternalTables(this); + LogTag.dumpInternalTables(this, mSelectedSubId); break; } @@ -2963,7 +2968,8 @@ public class ComposeMessageActivity extends Activity public static long computeAttachmentSizeLimit(SlideshowModel slideShow, int currentSlideSize) { // Computer attachment size limit. Subtract 1K for some text. - long sizeLimit = MmsConfig.getMaxMessageSize() - SlideshowModel.SLIDESHOW_SLOP; + long sizeLimit = MmsConfig.getInt(SmsManager.MMS_CONFIG_MAX_MESSAGE_SIZE) - + SlideshowModel.SLIDESHOW_SLOP; if (slideShow != null) { sizeLimit -= slideShow.getCurrentMessageSize(); @@ -3008,7 +3014,7 @@ public class ComposeMessageActivity extends Activity if (mWorkingMessage.isFakeMmsForDraft()) { // We no longer have to fake the fact we're an Mms. At this point we are or we aren't, // based on attachments and other Mms attrs. - mWorkingMessage.removeFakeMmsForDraft(); + mWorkingMessage.removeFakeMmsForDraft(mSelectedSubId); } if (requestCode == REQUEST_CODE_PICK) { @@ -3031,9 +3037,9 @@ public class ComposeMessageActivity extends Activity mAddContactIntent.getStringExtra(ContactsContract.Intents.Insert.PHONE); } if (address != null) { - Contact contact = Contact.get(address, false); + Contact contact = Contact.get(address, false, mSelectedSubId); if (contact != null) { - contact.reload(); + contact.reload(mSelectedSubId); } } } @@ -3047,10 +3053,11 @@ public class ComposeMessageActivity extends Activity switch (requestCode) { case REQUEST_CODE_CREATE_SLIDESHOW: if (data != null) { - WorkingMessage newMessage = WorkingMessage.load(this, data.getData()); + WorkingMessage newMessage = WorkingMessage.load(this, data.getData(), + mSelectedSubId); if (newMessage != null) { mWorkingMessage = newMessage; - mWorkingMessage.setConversation(mConversation); + mWorkingMessage.setConversation(mConversation, mSelectedSubId); updateThreadIdIfRunning(); drawTopPanel(false); updateSendButtonState(); @@ -3084,12 +3091,12 @@ public class ComposeMessageActivity extends Activity // Remove the old captured video's thumbnail from the cache MmsApp.getApplication().getThumbnailManager().removeThumbnail(videoUri); - addVideoAsync(videoUri, false); // can handle null videoUri + addVideoAsync(videoUri, false, mSelectedSubId); // can handle null videoUri break; case REQUEST_CODE_ATTACH_VIDEO: if (data != null) { - addVideoAsync(data.getData(), false); + addVideoAsync(data.getData(), false, mSelectedSubId); } break; @@ -3098,13 +3105,13 @@ public class ComposeMessageActivity extends Activity if (Settings.System.DEFAULT_RINGTONE_URI.equals(uri)) { break; } - addAudio(uri); + addAudio(uri, mSelectedSubId); break; } case REQUEST_CODE_RECORD_SOUND: if (data != null) { - addAudio(data.getData()); + addAudio(data.getData(), mSelectedSubId); } break; @@ -3135,7 +3142,8 @@ public class ComposeMessageActivity extends Activity final int recipientCount = uris != null ? uris.length : 0; - final int recipientLimit = MmsConfig.getRecipientLimit(); + final int recipientLimit = + MmsConfig.getInt(recipientCount, SmsManager.MMS_CONFIG_RECIPIENT_LIMIT); if (recipientLimit != Integer.MAX_VALUE && recipientCount > recipientLimit) { new AlertDialog.Builder(this) .setMessage(getString(R.string.too_many_recipients, recipientCount, recipientLimit)) @@ -3166,7 +3174,7 @@ public class ComposeMessageActivity extends Activity public void run() { final ContactList list; try { - list = ContactList.blockingGetByUris(uris); + list = ContactList.blockingGetByUris(uris, mSelectedSubId); } finally { handler.removeCallbacks(showProgress); progressDialog.dismiss(); @@ -3198,14 +3206,15 @@ public class ComposeMessageActivity extends Activity PduPersister persister = PduPersister.getPduPersister(context); int result; - Uri messageUri = mWorkingMessage.saveAsMms(true); + Uri messageUri = mWorkingMessage.saveAsMms(true, mSelectedSubId); if (messageUri == null) { result = WorkingMessage.UNKNOWN_ERROR; } else { try { Uri dataUri = persister.persistPart(part, ContentUris.parseId(messageUri), null); - result = mWorkingMessage.setAttachment(WorkingMessage.IMAGE, dataUri, append); + result = mWorkingMessage.setAttachment(WorkingMessage.IMAGE, dataUri, append, + mSelectedSubId); if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) { log("ResizeImageResultCallback: dataUri=" + dataUri); } @@ -3271,7 +3280,8 @@ public class ComposeMessageActivity extends Activity log("addImage: append=" + append + ", uri=" + uri); } - int result = mWorkingMessage.setAttachment(WorkingMessage.IMAGE, uri, append); + int result = mWorkingMessage.setAttachment(WorkingMessage.IMAGE, uri, append, + mSelectedSubId); if (result == WorkingMessage.IMAGE_TOO_LARGE || result == WorkingMessage.MESSAGE_SIZE_EXCEEDED) { @@ -3285,24 +3295,24 @@ public class ComposeMessageActivity extends Activity handleAddAttachmentError(result, R.string.type_picture); } - private void addVideoAsync(final Uri uri, final boolean append) { + private void addVideoAsync(final Uri uri, final boolean append, final int subId) { getAsyncDialog().runAsync(new Runnable() { @Override public void run() { - addVideo(uri, append); + addVideo(uri, append, subId); } }, null, R.string.adding_attachments_title); } - private void addVideo(Uri uri, boolean append) { + private void addVideo(Uri uri, boolean append, int subId) { if (uri != null) { - int result = mWorkingMessage.setAttachment(WorkingMessage.VIDEO, uri, append); + int result = mWorkingMessage.setAttachment(WorkingMessage.VIDEO, uri, append, subId); handleAddAttachmentError(result, R.string.type_video); } } - private void addAudio(Uri uri) { - int result = mWorkingMessage.setAttachment(WorkingMessage.AUDIO, uri, false); + private void addAudio(Uri uri, int subId) { + int result = mWorkingMessage.setAttachment(WorkingMessage.AUDIO, uri, false, subId); handleAddAttachmentError(result, R.string.type_audio); } @@ -3329,8 +3339,8 @@ public class ComposeMessageActivity extends Activity } if (uri != null) { - mWorkingMessage = WorkingMessage.load(this, uri); - mWorkingMessage.setSubject(intent.getStringExtra("subject"), false); + mWorkingMessage = WorkingMessage.load(this, uri, mSelectedSubId); + mWorkingMessage.setSubject(intent.getStringExtra("subject"), false, mSelectedSubId); } else { mWorkingMessage.setText(intent.getStringExtra("sms_body")); } @@ -3415,7 +3425,7 @@ public class ComposeMessageActivity extends Activity addImage(uri, append); } else if (type.startsWith("video/") || (wildcard && uri.toString().startsWith(mVideoUri))) { - addVideo(uri, append); + addVideo(uri, append, mSelectedSubId); } } } @@ -3492,7 +3502,7 @@ public class ComposeMessageActivity extends Activity intent.addCategory("android.intent.category.DEFAULT"); intent.setType(Phone.CONTENT_TYPE); // We have to wait for the constructing complete. - ContactList contacts = mRecipientsEditor.constructContactsFromInput(true); + ContactList contacts = mRecipientsEditor.constructContactsFromInput(true, mSelectedSubId); int urisCount = 0; Uri[] uris = new Uri[contacts.size()]; urisCount = 0; @@ -3578,7 +3588,7 @@ public class ComposeMessageActivity extends Activity @Override public void onTextChanged(CharSequence s, int start, int before, int count) { - mWorkingMessage.setSubject(s, true); + mWorkingMessage.setSubject(s, true, mSelectedSubId); updateSendButtonState(); } @@ -3627,8 +3637,11 @@ public class ComposeMessageActivity extends Activity mTextEditor = (EditText) findViewById(R.id.embedded_text_editor); mTextEditor.setOnEditorActionListener(this); mTextEditor.addTextChangedListener(mTextEditorWatcher); - mTextEditor.setFilters(new InputFilter[] { - new LengthFilter(MmsConfig.getMaxTextLimit())}); + final int maxLengthText = MmsConfig.getInt(mSelectedSubId, + SmsManager.MMS_CONFIG_MESSAGE_TEXT_MAX_SIZE); + if (maxLengthText > 0) { + mTextEditor.setFilters(new InputFilter[] {new LengthFilter(maxLengthText)}); + } mTextCounter = (TextView) findViewById(R.id.text_counter); mSendButtonMms = (TextView) findViewById(R.id.send_button_mms); @@ -3774,11 +3787,12 @@ public class ComposeMessageActivity extends Activity drawBottomPanel(); updateSendButtonState(); } - }); + }, + mSelectedSubId); // WorkingMessage.loadDraft() can return a new WorkingMessage object that doesn't // have its conversation set. Make sure it is set. - mWorkingMessage.setConversation(mConversation); + mWorkingMessage.setConversation(mConversation, mSelectedSubId); return true; } @@ -3804,7 +3818,7 @@ public class ComposeMessageActivity extends Activity return; } - mWorkingMessage.saveDraft(isStopping); + mWorkingMessage.saveDraft(isStopping, mSelectedSubId); if (mToastForDraftSave) { Toast.makeText(this, R.string.message_saved_as_draft, @@ -3816,7 +3830,8 @@ public class ComposeMessageActivity extends Activity int recipientCount = recipientCount(); return recipientCount > 0 && - recipientCount <= MmsConfig.getRecipientLimit() && + recipientCount <= + MmsConfig.getInt(mSelectedSubId, SmsManager.MMS_CONFIG_RECIPIENT_LIMIT) && mIsSmsEnabled && (mWorkingMessage.hasAttachment() || mWorkingMessage.hasText() || mWorkingMessage.hasSubject()); @@ -3864,15 +3879,16 @@ public class ComposeMessageActivity extends Activity if (!mSendingMessage) { if (LogTag.SEVERE_WARNING) { - String sendingRecipients = mConversation.getRecipients().serialize(); + String sendingRecipients = mConversation.getRecipients().serialize(mSelectedSubId); if (!sendingRecipients.equals(mDebugRecipients)) { - String workingRecipients = mWorkingMessage.getWorkingRecipients(); + String workingRecipients = mWorkingMessage.getWorkingRecipients(mSelectedSubId); if (!mDebugRecipients.equals(workingRecipients)) { LogTag.warnPossibleRecipientMismatch("ComposeMessageActivity.sendMessage" + " recipients in window: \"" + mDebugRecipients + "\" differ from recipients from conv: \"" + sendingRecipients + "\" and working recipients: " + - workingRecipients, this); + workingRecipients, this, + mSelectedSubId); } } sanityCheckConversation(); @@ -3922,7 +3938,7 @@ public class ComposeMessageActivity extends Activity mWorkingMessage.clearConversation(mConversation, false); mWorkingMessage = WorkingMessage.createEmpty(this); - mWorkingMessage.setConversation(mConversation); + mWorkingMessage.setConversation(mConversation, mSelectedSubId); hideRecipientEditor(); drawBottomPanel(); @@ -3996,7 +4012,8 @@ public class ComposeMessageActivity extends Activity if (LogTag.VERBOSE) log("get mConversation by recipients " + recipients); mConversation = Conversation.get(this, ContactList.getByNumbers(recipients, - false /* don't block */, true /* replace number */), false); + false /* don't block */, true /* replace number */, mSelectedSubId), + false, mSelectedSubId); addRecipientsListeners(); mSendDiscreetMode = bundle.getBoolean(KEY_EXIT_ON_SENT, false); mForwardMessageMode = bundle.getBoolean(KEY_FORWARDED_MESSAGE, false); @@ -4004,7 +4021,7 @@ public class ComposeMessageActivity extends Activity if (mSendDiscreetMode) { mMsgListView.setVisibility(View.INVISIBLE); } - mWorkingMessage.readStateFromBundle(bundle); + mWorkingMessage.readStateFromBundle(bundle, mSelectedSubId); return; } @@ -4019,7 +4036,7 @@ public class ComposeMessageActivity extends Activity if (intentData != null) { // try to get a conversation based on the data URI passed to our intent. if (LogTag.VERBOSE) log("get mConversation by intentData " + intentData); - mConversation = Conversation.get(this, intentData, false); + mConversation = Conversation.get(this, intentData, false, mSelectedSubId); mWorkingMessage.setText(getBody(intentData)); } else { // special intent extra parameter to specify the address @@ -4027,7 +4044,8 @@ public class ComposeMessageActivity extends Activity if (!TextUtils.isEmpty(address)) { if (LogTag.VERBOSE) log("get mConversation by address " + address); mConversation = Conversation.get(this, ContactList.getByNumbers(address, - false /* don't block */, true /* replace number */), false); + false /* don't block */, true /* replace number */, mSelectedSubId), + false, mSelectedSubId); } else { if (LogTag.VERBOSE) log("create new conversation"); mConversation = Conversation.createNew(this); @@ -4045,7 +4063,7 @@ public class ComposeMessageActivity extends Activity if (intent.hasExtra("sms_body")) { mWorkingMessage.setText(intent.getStringExtra("sms_body")); } - mWorkingMessage.setSubject(intent.getStringExtra("subject"), false); + mWorkingMessage.setSubject(intent.getStringExtra("subject"), false, mSelectedSubId); } private void initFocus() { @@ -4376,7 +4394,7 @@ public class ComposeMessageActivity extends Activity // when we init all Conversations below. if (recipients != null) { for (Contact contact : recipients) { - contact.removeFromCache(); + contact.removeFromCache(mSelectedSubId); } } @@ -4399,7 +4417,8 @@ public class ComposeMessageActivity extends Activity @Override public void run() { ContactList recipients = isRecipientsEditorVisible() ? - mRecipientsEditor.constructContactsFromInput(false) : getRecipients(); + mRecipientsEditor.constructContactsFromInput(false, mSelectedSubId) : + getRecipients(); if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) { log("[CMA] onUpdate contact updated: " + updated); log("[CMA] onUpdate recipients: " + recipients); diff --git a/src/com/android/mms/ui/ConversationList.java b/src/com/android/mms/ui/ConversationList.java index 316f42ed..80d337a4 100644 --- a/src/com/android/mms/ui/ConversationList.java +++ b/src/com/android/mms/ui/ConversationList.java @@ -47,6 +47,7 @@ import android.provider.ContactsContract.Contacts; import android.provider.Telephony; import android.provider.Telephony.Mms; import android.provider.Telephony.Threads; +import android.telephony.SubscriptionManager; import android.util.Log; import android.view.ActionMode; import android.view.ContextMenu; @@ -81,6 +82,7 @@ import com.android.mms.transaction.SmsRejectedReceiver; import com.android.mms.util.DraftCache; import com.android.mms.util.Recycler; import com.android.mms.widget.MmsWidgetProvider; + import com.google.android.mms.pdu.PduHeaders; import java.util.ArrayList; @@ -200,7 +202,7 @@ public class ConversationList extends ListActivity implements DraftCache.OnDraft @Override protected void onResume() { super.onResume(); - boolean isSmsEnabled = MmsConfig.isSmsEnabled(this); + boolean isSmsEnabled = MmsConfig.isSmsEnabled(); if (isSmsEnabled != mIsSmsEnabled) { mIsSmsEnabled = isSmsEnabled; invalidateOptionsMenu(); @@ -215,7 +217,7 @@ public class ConversationList extends ListActivity implements DraftCache.OnDraft } // Show or hide the SMS promo banner - if (mIsSmsEnabled || MmsConfig.isSmsPromoDismissed(this)) { + if (mIsSmsEnabled || MmsConfig.isSmsPromoDismissed()) { mSmsPromoBannerView.setVisibility(View.GONE); } else { initSmsPromoBanner(); @@ -561,7 +563,7 @@ public class ConversationList extends ListActivity implements DraftCache.OnDraft startActivityIfNeeded(intent, -1); break; case R.id.action_debug_dump: - LogTag.dumpInternalTables(this); + LogTag.dumpInternalTables(this, SubscriptionManager.getDefaultSmsSubId()); break; case R.id.action_cell_broadcasts: Intent cellBroadcastIntent = new Intent(Intent.ACTION_MAIN); @@ -957,7 +959,7 @@ public class ConversationList extends ListActivity implements DraftCache.OnDraft if (conv != null) { ContactList recipients = conv.getRecipients(); for (Contact contact : recipients) { - contact.removeFromCache(); + contact.removeFromCache(SubscriptionManager.getDefaultSmsSubId()); } } } diff --git a/src/com/android/mms/ui/DeliveryReportActivity.java b/src/com/android/mms/ui/DeliveryReportActivity.java index a08b4c95..18ba1809 100644 --- a/src/com/android/mms/ui/DeliveryReportActivity.java +++ b/src/com/android/mms/ui/DeliveryReportActivity.java @@ -33,6 +33,7 @@ import android.os.Bundle; import android.provider.Telephony.Mms; import android.provider.Telephony.Sms; import android.telephony.PhoneNumberUtils; +import android.telephony.SubscriptionManager; import android.text.TextUtils; import android.util.Log; import android.view.LayoutInflater; @@ -70,14 +71,16 @@ public class DeliveryReportActivity extends ListActivity { static final String[] MMS_REPORT_STATUS_PROJECTION = new String[] { Mms.Addr.ADDRESS, //0 "delivery_status", //1 - "read_status" //2 + "read_status", //2 + Mms.SUB_ID //3 }; static final String[] SMS_REPORT_STATUS_PROJECTION = new String[] { Sms.ADDRESS, //0 Sms.STATUS, //1 Sms.DATE_SENT, //2 - Sms.TYPE //3 + Sms.SUB_ID, //3 + Sms.TYPE //4 }; // These indices must sync up with the projections above. @@ -87,7 +90,8 @@ public class DeliveryReportActivity extends ListActivity { static final int COLUMN_DELIVERY_STATUS = 1; static final int COLUMN_READ_STATUS = 2; static final int COLUMN_DATE_SENT = 2; - static final int COLUMN_MESSAGE_TYPE = 3; + static final int COLUMN_SUB_ID = 3; + static final int COLUMN_MESSAGE_TYPE = 4; private long mMessageId; private String mMessageType; @@ -117,7 +121,8 @@ public class DeliveryReportActivity extends ListActivity { List<DeliveryReportItem> items = getReportItems(); if (items == null) { items = new ArrayList<DeliveryReportItem>(1); - items.add(new DeliveryReportItem("", getString(R.string.status_none), null)); + items.add(new DeliveryReportItem("", getString(R.string.status_none), null, + SubscriptionManager.DEFAULT_SUB_ID)); Log.w(LOG_TAG, "cursor == null"); } setListAdapter(new DeliveryReportAdapter(this, items)); @@ -190,6 +195,7 @@ public class DeliveryReportActivity extends ListActivity { // date_sent column (see MessageStatusReceiver). String deliveryDateString = null; long deliveryDate = c.getLong(COLUMN_DATE_SENT); + int subId = c.getInt(COLUMN_SUB_ID); int messageType = c.getInt(COLUMN_MESSAGE_TYPE); if (messageType == Sms.MESSAGE_TYPE_SENT && deliveryDate > 0) { deliveryDateString = getString(R.string.delivered_label) + @@ -201,7 +207,7 @@ public class DeliveryReportActivity extends ListActivity { getString(R.string.recipient_label) + c.getString(COLUMN_RECIPIENT), getString(R.string.status_label) + getSmsStatusText(c.getInt(COLUMN_DELIVERY_STATUS)), - deliveryDateString)); + deliveryDateString, subId)); } return items; } finally { @@ -284,7 +290,8 @@ public class DeliveryReportActivity extends ListActivity { String statusText = getString(R.string.status_label) + getMmsReportStatusText(reportReq, reportStatus); items.add(new DeliveryReportItem(getString(R.string.recipient_label) + - reportReq.getRecipient(), statusText, null)); + reportReq.getRecipient(), statusText, null, + SubscriptionManager.DEFAULT_SUB_ID)); } return items; } diff --git a/src/com/android/mms/ui/DeliveryReportAdapter.java b/src/com/android/mms/ui/DeliveryReportAdapter.java index ef5fc34a..3ae90dab 100644 --- a/src/com/android/mms/ui/DeliveryReportAdapter.java +++ b/src/com/android/mms/ui/DeliveryReportAdapter.java @@ -54,7 +54,7 @@ public class DeliveryReportAdapter extends ArrayAdapter<DeliveryReportItem> { } } - listItem.bind(item.recipient, item.status, item.deliveryDate); + listItem.bind(item.recipient, item.status, item.deliveryDate, item.subId); return listItem; } diff --git a/src/com/android/mms/ui/DeliveryReportItem.java b/src/com/android/mms/ui/DeliveryReportItem.java index e288b86d..cb04f489 100644 --- a/src/com/android/mms/ui/DeliveryReportItem.java +++ b/src/com/android/mms/ui/DeliveryReportItem.java @@ -25,10 +25,12 @@ public class DeliveryReportItem { String recipient; String status; String deliveryDate; + int subId; - public DeliveryReportItem(String recipient, String status, String deliveryDate) { + public DeliveryReportItem(String recipient, String status, String deliveryDate, int subId) { this.recipient = recipient; this.status = status; this.deliveryDate = deliveryDate; + this.subId = subId; } } diff --git a/src/com/android/mms/ui/DeliveryReportListItem.java b/src/com/android/mms/ui/DeliveryReportListItem.java index 46a9fd97..4eed2306 100644 --- a/src/com/android/mms/ui/DeliveryReportListItem.java +++ b/src/com/android/mms/ui/DeliveryReportListItem.java @@ -56,10 +56,10 @@ public class DeliveryReportListItem extends LinearLayout { super(context, attrs); } - public final void bind(String recipient, String status, String deliveryDate) { + public final void bind(String recipient, String status, String deliveryDate, int subId) { // Recipient if (!TextUtils.isEmpty(recipient)) { - mRecipientView.setText(Contact.get(recipient, false).getName()); + mRecipientView.setText(Contact.get(recipient, false, subId).getName()); } else { mRecipientView.setText(""); } diff --git a/src/com/android/mms/ui/MessageItem.java b/src/com/android/mms/ui/MessageItem.java index 275f975f..88dbf997 100755 --- a/src/com/android/mms/ui/MessageItem.java +++ b/src/com/android/mms/ui/MessageItem.java @@ -141,6 +141,7 @@ public class MessageItem { // Set contact and message body mBoxId = cursor.getInt(columnsMap.mColumnSmsType); mAddress = cursor.getString(columnsMap.mColumnSmsAddress); + mSubId = cursor.getInt(columnsMap.mColumnSmsSubId); if (Sms.isOutgoingFolder(mBoxId)) { String meString = context.getString( R.string.messagelist_sender_self); @@ -148,7 +149,7 @@ public class MessageItem { mContact = meString; } else { // For incoming messages, the ADDRESS field contains the sender. - mContact = Contact.get(mAddress, false).getName(); + mContact = Contact.get(mAddress, false, mSubId).getName(); } mBody = cursor.getString(columnsMap.mColumnSmsBody); @@ -161,7 +162,6 @@ public class MessageItem { mLocked = cursor.getInt(columnsMap.mColumnSmsLocked) != 0; mErrorCode = cursor.getInt(columnsMap.mColumnSmsErrorCode); - mSubId = cursor.getInt(columnsMap.mColumnSmsSubId); } else if ("mms".equals(type)) { mMessageUri = ContentUris.withAppendedId(Mms.CONTENT_URI, mMsgId); @@ -212,7 +212,8 @@ public class MessageItem { // notification system uses. mAddress = AddressUtils.getFrom(mContext, messageUri); } - mContact = TextUtils.isEmpty(mAddress) ? "" : Contact.get(mAddress, false).getName(); + mContact = TextUtils.isEmpty(mAddress) ? "" : + Contact.get(mAddress, false, mSubId).getName(); } public boolean isMms() { diff --git a/src/com/android/mms/ui/MessageListAdapter.java b/src/com/android/mms/ui/MessageListAdapter.java index 4c93f99a..32ca4a90 100755 --- a/src/com/android/mms/ui/MessageListAdapter.java +++ b/src/com/android/mms/ui/MessageListAdapter.java @@ -29,6 +29,7 @@ import android.provider.Telephony.MmsSms.PendingMessages; import android.provider.Telephony.Sms; import android.provider.Telephony.Sms.Conversations; import android.provider.Telephony.TextBasedSmsColumns; +import android.text.TextUtils; import android.util.Log; import android.util.LruCache; import android.view.LayoutInflater; @@ -312,7 +313,8 @@ public class MessageListAdapter extends CursorAdapter { if (cursor.moveToFirst()) { do { long id = cursor.getLong(mRowIDColumn); - if (id == item.mMsgId) { + String type = cursor.getString(mColumnsMap.mColumnMsgType); + if (id == item.mMsgId && TextUtils.equals(type, item.mType)) { return cursor; } } while (cursor.moveToNext()); diff --git a/src/com/android/mms/ui/MessageListItem.java b/src/com/android/mms/ui/MessageListItem.java index b7a10b5e..44c9fc90 100644 --- a/src/com/android/mms/ui/MessageListItem.java +++ b/src/com/android/mms/ui/MessageListItem.java @@ -38,6 +38,7 @@ import android.provider.ContactsContract.Profile; import android.provider.Telephony.Sms; import android.provider.Telephony.Mms; import android.telephony.PhoneNumberUtils; +import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.text.Html; import android.text.Spannable; @@ -272,7 +273,8 @@ public class MessageListItem extends LinearLayout implements intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId); mContext.startService(intent); DownloadManager.getInstance().markState( - mMessageItem.mMessageUri, DownloadManager.STATE_PRE_DOWNLOADING); + mMessageItem.mMessageUri, DownloadManager.STATE_PRE_DOWNLOADING, + subId); } }); break; @@ -304,7 +306,8 @@ public class MessageListItem extends LinearLayout implements private void updateAvatarView(String addr, boolean isSelf) { Drawable avatarDrawable; if (isSelf || !TextUtils.isEmpty(addr)) { - Contact contact = isSelf ? Contact.getMe(false) : Contact.get(addr, false); + Contact contact = isSelf ? Contact.getMe(false, mMessageItem.mSubId) : + Contact.get(addr, false, mMessageItem.mSubId); avatarDrawable = contact.getAvatar(mContext, sDefaultContactImage); if (isSelf) { diff --git a/src/com/android/mms/ui/MessageUtils.java b/src/com/android/mms/ui/MessageUtils.java index cd126ce7..2ea77b95 100644 --- a/src/com/android/mms/ui/MessageUtils.java +++ b/src/com/android/mms/ui/MessageUtils.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -44,6 +45,7 @@ import android.os.Handler; import android.provider.MediaStore; import android.provider.Telephony.Mms; import android.provider.Telephony.Sms; +import android.telephony.SmsManager; import android.telephony.SubInfoRecord; import android.telephony.SubscriptionManager; import android.telephony.PhoneNumberUtils; @@ -68,6 +70,7 @@ import com.android.mms.model.SlideModel; import com.android.mms.model.SlideshowModel; import com.android.mms.transaction.MmsMessageSender; import com.android.mms.util.AddressUtils; + import com.google.android.mms.ContentType; import com.google.android.mms.MmsException; import com.google.android.mms.pdu.CharacterSets; @@ -90,7 +93,6 @@ public class MessageUtils { } private static final String TAG = LogTag.TAG; - private static String sLocalNumber; private static String[] sNoSubjectStrings; // Cache of both groups of space-separated ids to their full @@ -661,8 +663,8 @@ public class MessageUtils { final PduPart part; try { UriImage image = new UriImage(context, imageUri); - int widthLimit = MmsConfig.getMaxImageWidth(); - int heightLimit = MmsConfig.getMaxImageHeight(); + int widthLimit = MmsConfig.getInt(SmsManager.MMS_CONFIG_MAX_IMAGE_WIDTH); + int heightLimit = MmsConfig.getInt(SmsManager.MMS_CONFIG_MAX_IMAGE_HEIGHT); // In mms_config.xml, the max width has always been declared larger than the max // height. Swap the width and height limits if necessary so we scale the picture // as little as possible. @@ -675,7 +677,8 @@ public class MessageUtils { part = image.getResizedImageAsPart( widthLimit, heightLimit, - MmsConfig.getMaxMessageSize() - MESSAGE_OVERHEAD); + MmsConfig.getInt(SmsManager.MMS_CONFIG_MAX_MESSAGE_SIZE) - + MESSAGE_OVERHEAD); } finally { // Cancel pending show of the progress toast if necessary. handler.removeCallbacks(showProgress); @@ -700,14 +703,15 @@ public class MessageUtils { .show(); } - public static String getLocalNumber() { - if (null == sLocalNumber) { - sLocalNumber = MmsApp.getApplication().getTelephonyManager().getLine1Number(); + public static String getLocalNumber(int subId) { + final boolean validSubId = SubscriptionManager.isUsableSubIdValue(subId); + if (!validSubId) { + subId = SubscriptionManager.getDefaultSmsSubId(); } - return sLocalNumber; + return MmsApp.getApplication().getTelephonyManager().getLine1NumberForSubscriber(subId); } - public static boolean isLocalNumber(String number) { + public static boolean isLocalNumber(String number, int subId) { if (number == null) { return false; } @@ -720,7 +724,17 @@ public class MessageUtils { return false; } - return PhoneNumberUtils.compare(number, getLocalNumber()); + return PhoneNumberUtils.compare(number, getLocalNumber(subId)); + } + + public static boolean simHasNumber() { + List<SubInfoRecord> subList = SubscriptionManager.getActiveSubInfoList(); + for (SubInfoRecord sub : subList) { + if (!TextUtils.isEmpty(sub.number)) { + return true; + } + } + return false; } public static void handleReadReport(final Context context, @@ -947,14 +961,15 @@ public class MessageUtils { // An alias (or commonly called "nickname") is: // Nickname must begin with a letter. // Only letters a-z, numbers 0-9, or . are allowed in Nickname field. - public static boolean isAlias(String string) { - if (!MmsConfig.isAliasEnabled()) { + public static boolean isAlias(String string, int subId) { + if (!MmsConfig.getBoolean(subId, SmsManager.MMS_CONFIG_ALIAS_ENABLED)) { return false; } int len = string == null ? 0 : string.length(); - if (len < MmsConfig.getAliasMinChars() || len > MmsConfig.getAliasMaxChars()) { + if (len < MmsConfig.getInt(subId, SmsManager.MMS_CONFIG_ALIAS_MIN_CHARS) || + len > MmsConfig.getInt(subId, SmsManager.MMS_CONFIG_ALIAS_MAX_CHARS)) { return false; } @@ -1004,8 +1019,8 @@ public class MessageUtils { /** * Returns true if the address passed in is a valid MMS address. */ - public static boolean isValidMmsAddress(String address) { - String retVal = parseMmsAddress(address); + public static boolean isValidMmsAddress(String address, int subId) { + String retVal = parseMmsAddress(address, subId); return (retVal != null); } @@ -1015,7 +1030,7 @@ public class MessageUtils { * - if the address can be parsed into a valid MMS phone number, return the parsed number. * - if the address is a compliant alias address, leave it as is. */ - public static String parseMmsAddress(String address) { + public static String parseMmsAddress(String address, int subId) { // if it's a valid Email address, use that. if (Mms.isEmailAddress(address)) { return address; @@ -1028,7 +1043,7 @@ public class MessageUtils { } // if it's an alias compliant address, use that. - if (isAlias(address)) { + if (isAlias(address, subId)) { return address; } diff --git a/src/com/android/mms/ui/MessagingPreferenceActivity.java b/src/com/android/mms/ui/MessagingPreferenceActivity.java index bf2052d4..993c01ef 100644 --- a/src/com/android/mms/ui/MessagingPreferenceActivity.java +++ b/src/com/android/mms/ui/MessagingPreferenceActivity.java @@ -40,6 +40,7 @@ import android.preference.PreferenceScreen; import android.preference.RingtonePreference; import android.provider.SearchRecentSuggestions; import android.provider.Telephony; +import android.telephony.SmsManager; import android.telephony.SubInfoRecord; import android.telephony.SubscriptionManager; import android.text.TextUtils; @@ -127,7 +128,7 @@ public class MessagingPreferenceActivity extends PreferenceActivity @Override protected void onResume() { super.onResume(); - boolean isSmsEnabled = MmsConfig.isSmsEnabled(this); + boolean isSmsEnabled = MmsConfig.isSmsEnabled(); if (isSmsEnabled != mIsSmsEnabled) { mIsSmsEnabled = isSmsEnabled; invalidateOptionsMenu(); @@ -229,6 +230,19 @@ public class MessagingPreferenceActivity extends PreferenceActivity return subInfoRecords != null ? subInfoRecords.size() : 0; } + private static boolean isAnySubscriptionValueSet(String configValue) { + List<SubInfoRecord> subInfoRecords = SubscriptionManager.getActiveSubInfoList(); + if (subInfoRecords == null) { + return false; + } + for (final SubInfoRecord subInfo : subInfoRecords) { + if (MmsConfig.getBoolean(subInfo.subId, configValue)) { + return true; + } + } + return false; + } + private void restoreDefaultPreferences() { PreferenceManager.getDefaultSharedPreferences(this).edit().clear().apply(); setPreferenceScreen(null); @@ -251,28 +265,28 @@ public class MessagingPreferenceActivity extends PreferenceActivity mSmsPrefCategory.removePreference(mManageSimPref); } - if (!MmsConfig.getSMSDeliveryReportsEnabled()) { + if (!isAnySubscriptionValueSet(SmsManager.MMS_CONFIG_SMS_DELIVERY_REPORT_ENABLED)) { mSmsPrefCategory.removePreference(mSmsDeliveryReportPref); if (!isHasActivatedSub) { getPreferenceScreen().removePreference(mSmsPrefCategory); } } - if (!MmsConfig.getMmsEnabled()) { + if (!isAnySubscriptionValueSet(SmsManager.MMS_CONFIG_MMS_ENABLED)) { // No Mms, remove all the mms-related preferences getPreferenceScreen().removePreference(mMmsPrefCategory); mStoragePrefCategory.removePreference(findPreference("pref_key_mms_delete_limit")); } else { - if (!MmsConfig.getMMSDeliveryReportsEnabled()) { + if (!MmsConfig.getBoolean(SmsManager.MMS_CONFIG_MMS_DELIVERY_REPORT_ENABLED)) { mMmsPrefCategory.removePreference(mMmsDeliveryReportPref); } - if (!MmsConfig.getMMSReadReportsEnabled()) { + if (!MmsConfig.getBoolean(SmsManager.MMS_CONFIG_MMS_READ_REPORT_ENABLED)) { mMmsPrefCategory.removePreference(mMmsReadReportPref); } // If the phone's SIM doesn't know it's own number, disable group mms. - if (!MmsConfig.getGroupMmsEnabled() || - TextUtils.isEmpty(MessageUtils.getLocalNumber())) { + if (!MmsConfig.getBoolean(SmsManager.MMS_CONFIG_GROUP_MMS_ENABLED) || + !MessageUtils.simHasNumber()) { mMmsPrefCategory.removePreference(mMmsGroupMmsPref); } } @@ -482,13 +496,13 @@ public class MessagingPreferenceActivity extends PreferenceActivity // 1. the feature is enabled in mms_config.xml (currently on by default) // 2. the feature is enabled in the mms settings page // 3. the SIM knows its own phone number - public static boolean getIsGroupMmsEnabled(Context context) { + public static boolean getIsGroupMmsEnabled(Context context, int subId) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean groupMmsPrefOn = prefs.getBoolean( MessagingPreferenceActivity.GROUP_MMS_MODE, true); - return MmsConfig.getGroupMmsEnabled() && + return MmsConfig.getBoolean(SmsManager.MMS_CONFIG_GROUP_MMS_ENABLED) && groupMmsPrefOn && - !TextUtils.isEmpty(MessageUtils.getLocalNumber()); + !TextUtils.isEmpty(MessageUtils.getLocalNumber(subId)); } private boolean hasActivatedSub() { diff --git a/src/com/android/mms/ui/RecipientsEditor.java b/src/com/android/mms/ui/RecipientsEditor.java index 4de2118a..820d94ba 100644 --- a/src/com/android/mms/ui/RecipientsEditor.java +++ b/src/com/android/mms/ui/RecipientsEditor.java @@ -23,6 +23,8 @@ import java.util.List; import android.content.Context; import android.provider.Telephony.Mms; import android.telephony.PhoneNumberUtils; +import android.telephony.SmsManager; +import android.telephony.SubscriptionManager; import android.text.Annotation; import android.text.Editable; import android.text.Layout; @@ -163,20 +165,20 @@ public class RecipientsEditor extends RecipientEditTextView { return mTokenizer.getNumbers(); } - public ContactList constructContactsFromInput(boolean blocking) { + public ContactList constructContactsFromInput(boolean blocking, int subId) { List<String> numbers = mTokenizer.getNumbers(); ContactList list = new ContactList(); for (String number : numbers) { - Contact contact = Contact.get(number, blocking); + Contact contact = Contact.get(number, blocking, subId); contact.setNumber(number); list.add(contact); } return list; } - private boolean isValidAddress(String number, boolean isMms) { + private boolean isValidAddress(String number, boolean isMms, int subId) { if (isMms) { - return MessageUtils.isValidMmsAddress(number); + return MessageUtils.isValidMmsAddress(number, subId); } else { // TODO: PhoneNumberUtils.isWellFormedSmsAddress() only check if the number is a valid // GSM SMS address. If the address contains a dialable char, it considers it a well @@ -187,20 +189,20 @@ public class RecipientsEditor extends RecipientEditTextView { } } - public boolean hasValidRecipient(boolean isMms) { + public boolean hasValidRecipient(boolean isMms, int subId) { for (String number : mTokenizer.getNumbers()) { - if (isValidAddress(number, isMms)) + if (isValidAddress(number, isMms, subId)) return true; } return false; } - public boolean hasInvalidRecipient(boolean isMms) { + public boolean hasInvalidRecipient(boolean isMms, int subId) { for (String number : mTokenizer.getNumbers()) { - if (!isValidAddress(number, isMms)) { - if (MmsConfig.getEmailGateway() == null) { + if (!isValidAddress(number, isMms, subId)) { + if (MmsConfig.getString(SmsManager.MMS_CONFIG_EMAIL_GATEWAY_NUMBER) == null) { return true; - } else if (!MessageUtils.isAlias(number)) { + } else if (!MessageUtils.isAlias(number, subId)) { return true; } } @@ -208,10 +210,10 @@ public class RecipientsEditor extends RecipientEditTextView { return false; } - public String formatInvalidNumbers(boolean isMms) { + public String formatInvalidNumbers(boolean isMms, int subId) { StringBuilder sb = new StringBuilder(); for (String number : mTokenizer.getNumbers()) { - if (!isValidAddress(number, isMms)) { + if (!isValidAddress(number, isMms, subId)) { if (sb.length() != 0) { sb.append(", "); } @@ -323,7 +325,8 @@ public class RecipientsEditor extends RecipientEditTextView { if (end != start) { String number = getNumberAt(getText(), start, end, getContext()); - Contact c = Contact.get(number, false); + Contact c = Contact.get(number, false, + SubscriptionManager.getDefaultSmsSubId()); return new RecipientContextMenuInfo(c); } } diff --git a/src/com/android/mms/ui/SearchActivity.java b/src/com/android/mms/ui/SearchActivity.java index e7fe0dd6..23e77f6e 100644 --- a/src/com/android/mms/ui/SearchActivity.java +++ b/src/com/android/mms/ui/SearchActivity.java @@ -33,6 +33,7 @@ import android.net.Uri; import android.os.Bundle; import android.provider.SearchRecentSuggestions; import android.provider.Telephony; +import android.telephony.SubscriptionManager; import android.text.SpannableString; import android.text.TextPaint; import android.text.style.StyleSpan; @@ -316,7 +317,8 @@ public class SearchActivity extends ListActivity final TextViewSnippet snippet = (TextViewSnippet)(view.findViewById(R.id.subtitle)); String address = cursor.getString(addressPos); - Contact contact = address != null ? Contact.get(address, false) : null; + Contact contact = address != null ? Contact.get(address, false, + SubscriptionManager.getDefaultSmsSubId()) : null; String titleString = contact != null ? contact.getNameAndNumber() : ""; title.setText(titleString); diff --git a/src/com/android/mms/ui/SlideEditorActivity.java b/src/com/android/mms/ui/SlideEditorActivity.java index b9f71823..5d3e2991 100644 --- a/src/com/android/mms/ui/SlideEditorActivity.java +++ b/src/com/android/mms/ui/SlideEditorActivity.java @@ -29,6 +29,7 @@ import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.provider.Settings; +import android.telephony.SmsManager; import android.text.InputFilter; import android.text.InputFilter.LengthFilter; import android.text.TextUtils; @@ -151,8 +152,10 @@ public class SlideEditorActivity extends Activity { mRemoveSlide.setOnClickListener(mOnRemoveSlide); mTextEditor = (EditText) findViewById(R.id.text_message); - mTextEditor.setFilters(new InputFilter[] { - new LengthFilter(MmsConfig.getMaxTextLimit())}); + final int maxTextLength = MmsConfig.getInt(SmsManager.MMS_CONFIG_MESSAGE_TEXT_MAX_SIZE); + if (maxTextLength > 0) { + mTextEditor.setFilters(new InputFilter[] {new LengthFilter(maxTextLength)}); + } mDone = (Button) findViewById(R.id.done_button); mDone.setOnClickListener(mDoneClickListener); @@ -378,7 +381,7 @@ public class SlideEditorActivity extends Activity { menu.add(0, MENU_DEL_AUDIO, 0, R.string.remove_music).setIcon( R.drawable.ic_menu_remove_sound); } else if (!slide.hasVideo()) { - if (MmsConfig.getAllowAttachAudio()) { + if (MmsConfig.getBoolean(SmsManager.MMS_CONFIG_ALLOW_ATTACH_AUDIO)) { SubMenu subMenu = menu.addSubMenu(0, MENU_SUB_AUDIO, 0, R.string.add_music) .setIcon(R.drawable.ic_menu_add_sound); subMenu.add(0, MENU_ADD_AUDIO, 0, R.string.attach_sound); diff --git a/src/com/android/mms/util/DownloadManager.java b/src/com/android/mms/util/DownloadManager.java index 34c391ea..c1446ccd 100644 --- a/src/com/android/mms/util/DownloadManager.java +++ b/src/com/android/mms/util/DownloadManager.java @@ -186,7 +186,7 @@ public class DownloadManager { return "true".equals(roaming); } - public void markState(final Uri uri, int state) { + public void markState(final Uri uri, int state, final int subId) { // Notify user if the message has expired. try { NotificationInd nInd = (NotificationInd) PduPersister.getPduPersister(mContext) @@ -212,7 +212,7 @@ public class DownloadManager { mHandler.post(new Runnable() { public void run() { try { - Toast.makeText(mContext, getMessage(uri), + Toast.makeText(mContext, getMessage(uri, subId), Toast.LENGTH_LONG).show(); } catch (MmsException e) { Log.e(TAG, e.getMessage(), e); @@ -244,7 +244,7 @@ public class DownloadManager { }); } - private String getMessage(Uri uri) throws MmsException { + private String getMessage(Uri uri, int subId) throws MmsException { NotificationInd ind = (NotificationInd) PduPersister .getPduPersister(mContext).load(uri); @@ -254,7 +254,7 @@ public class DownloadManager { v = ind.getFrom(); String from = (v != null) - ? Contact.get(v.getString(), false).getName() + ? Contact.get(v.getString(), false, subId).getName() : mContext.getString(R.string.unknown_sender); return mContext.getString(R.string.dl_failure_notification, subject, from); diff --git a/tests/src/com/android/mms/RecyclerTest.java b/tests/src/com/android/mms/RecyclerTest.java index 2446a26a..e3d79568 100644 --- a/tests/src/com/android/mms/RecyclerTest.java +++ b/tests/src/com/android/mms/RecyclerTest.java @@ -22,10 +22,10 @@ import java.util.Random; import com.android.mms.data.Contact; import com.android.mms.util.Recycler; + import android.provider.Telephony.Sms; import android.provider.Telephony.Threads; import android.provider.Telephony.Sms.Inbox; - import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; @@ -35,6 +35,7 @@ import android.database.sqlite.SQLiteException; import android.database.sqlite.SqliteWrapper; import android.net.Uri; import android.provider.Telephony.Sms.Conversations; +import android.telephony.SubscriptionManager; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.LargeTest; import android.util.Log; @@ -159,7 +160,7 @@ public class RecyclerTest extends AndroidTestCase { // Make sure we've got a thread id so after the insert we'll be able to delete // excess messages. Long threadId = 0L; - Contact cacheContact = Contact.get(address,true); + Contact cacheContact = Contact.get(address, true, SubscriptionManager.DEFAULT_SUB_ID); if (cacheContact != null) { address = cacheContact.getNumber(); } diff --git a/tests/src/com/android/mms/ui/ComposeMessageActivityTests.java b/tests/src/com/android/mms/ui/ComposeMessageActivityTests.java index ca2fd51a..96c79ba6 100644 --- a/tests/src/com/android/mms/ui/ComposeMessageActivityTests.java +++ b/tests/src/com/android/mms/ui/ComposeMessageActivityTests.java @@ -26,6 +26,7 @@ import com.android.mms.ui.MessageListAdapter.ColumnsMap; import android.content.Context; import android.database.Cursor; +import android.telephony.SubscriptionManager; import android.test.ActivityInstrumentationTestCase2; import android.test.suitebuilder.annotation.MediumTest; import android.test.suitebuilder.annotation.SmallTest; @@ -194,19 +195,23 @@ public class ComposeMessageActivityTests // the threads directly to the mms provider's threads table. @LargeTest public void testCreateManyThreads() { + final int subId = SubscriptionManager.getDefaultSmsSubId(); for (int i = 0; i < 10; i++) { String phoneNum = String.format("424-123-%04d", i); - ContactList contactList = ContactList.getByNumbers(phoneNum, false, false); - Conversation conv = Conversation.get(mActivity, contactList, false); - - WorkingMessage workingMsg = WorkingMessage.loadDraft(mActivity, conv, null); - workingMsg.setConversation(conv); + ContactList contactList = ContactList.getByNumbers(phoneNum, false, false, + SubscriptionManager.DEFAULT_SUB_ID); + Conversation conv = Conversation.get(mActivity, contactList, false, + SubscriptionManager.DEFAULT_SUB_ID); + + WorkingMessage workingMsg = WorkingMessage.loadDraft(mActivity, conv, null, + SubscriptionManager.DEFAULT_SUB_ID); + workingMsg.setConversation(conv, subId); workingMsg.setText("This is test #" + i + " thread id: " + conv.getThreadId()); // Log.i(TAG, "[testCreateManyThreads] workingMsg: "); // workingMsg.dump(); - workingMsg.saveDraft(false); + workingMsg.saveDraft(false, subId); } } } diff --git a/tests/src/com/android/mms/ui/SmsTest.java b/tests/src/com/android/mms/ui/SmsTest.java index 89c04c13..56be37ab 100644 --- a/tests/src/com/android/mms/ui/SmsTest.java +++ b/tests/src/com/android/mms/ui/SmsTest.java @@ -26,6 +26,7 @@ import com.android.mms.SmsTestRunner; import android.database.Cursor; import android.content.Context; +import android.telephony.SubscriptionManager; import android.test.ActivityInstrumentationTestCase2; import android.view.View; import android.view.ViewStub; @@ -93,7 +94,7 @@ public class SmsTest if (mInst.mRecipient != null) { mRecipient = mInst.mRecipient; } else { - mRecipient = getLocalNumber(); + mRecipient = getLocalNumber(SubscriptionManager.getDefaultSmsSubId()); } if (mInst.mReceiveTimer > 0) { mReceiveTimer = mInst.mReceiveTimer; @@ -208,8 +209,8 @@ public class SmsTest /** * @return the local number for this test device */ - protected String getLocalNumber() { - return MessageUtils.getLocalNumber(); + protected String getLocalNumber(int subId) { + return MessageUtils.getLocalNumber(subId); } /** diff --git a/tests/src/com/android/mms/util/VerifyRecipientUnitTests.java b/tests/src/com/android/mms/util/VerifyRecipientUnitTests.java index 53343b39..1c3c1791 100644 --- a/tests/src/com/android/mms/util/VerifyRecipientUnitTests.java +++ b/tests/src/com/android/mms/util/VerifyRecipientUnitTests.java @@ -18,6 +18,7 @@ package com.android.mms.util; import android.content.Context; import android.provider.Telephony.Threads; +import android.telephony.SubscriptionManager; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.SmallTest; @@ -50,11 +51,13 @@ public class VerifyRecipientUnitTests extends AndroidTestCase { */ public void testVerifyRecipients() { assertEquals("Numbers aren't equal", - Conversation.verifySingleRecipient(getContext(), mThreadId1, "(415) 232-4567"), + Conversation.verifySingleRecipient(getContext(), mThreadId1, "(415) 232-4567", + SubscriptionManager.DEFAULT_SUB_ID), "(415) 232-4567"); assertEquals("Numbers aren't equal", - Conversation.verifySingleRecipient(getContext(), mThreadId1, " 232-4567"), + Conversation.verifySingleRecipient(getContext(), mThreadId1, " 232-4567", + SubscriptionManager.DEFAULT_SUB_ID), "232-4567"); } } |