1 /* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.mms; 18 19 import java.io.IOException; 20 21 import org.xmlpull.v1.XmlPullParser; 22 import org.xmlpull.v1.XmlPullParserException; 23 24 import com.android.internal.telephony.TelephonyProperties; 25 26 import android.content.Context; 27 import android.content.res.XmlResourceParser; 28 import android.util.Log; 29 30 public class MmsConfig { 31 private static final String TAG = "MmsConfig"; 32 private static final boolean DEBUG = true; 33 private static final boolean LOCAL_LOGV = false; 34 35 private static final String DEFAULT_HTTP_KEY_X_WAP_PROFILE = "x-wap-profile"; 36 private static final String DEFAULT_USER_AGENT = "Android-Mms/2.0"; 37 38 private static final int MAX_IMAGE_HEIGHT = 480; 39 private static final int MAX_IMAGE_WIDTH = 640; 40 private static final int MAX_TEXT_LENGTH = 2000; 41 42 /** 43 * Whether to hide MMS functionality from the user (i.e. SMS only). 44 */ 45 private static boolean mTransIdEnabled = false; 46 private static int mMmsEnabled = 1; // default to true 47 private static int mMaxMessageSize = 300 * 1024; // default to 300k max size 48 private static String mUserAgent = DEFAULT_USER_AGENT; 49 private static String mUaProfTagName = DEFAULT_HTTP_KEY_X_WAP_PROFILE; 50 private static String mUaProfUrl = null; 51 private static String mHttpParams = null; 52 private static String mHttpParamsLine1Key = null; 53 private static String mEmailGateway = null; 54 private static int mMaxImageHeight = MAX_IMAGE_HEIGHT; // default value 55 private static int mMaxImageWidth = MAX_IMAGE_WIDTH; // default value 56 private static int mRecipientLimit = Integer.MAX_VALUE; // default value 57 private static int mDefaultSMSMessagesPerThread = 500; // default value 58 private static int mDefaultMMSMessagesPerThread = 50; // default value 59 private static int mMinMessageCountPerThread = 2; // default value 60 private static int mMaxMessageCountPerThread = 5000; // default value 61 private static int mHttpSocketTimeout = 60*1000; // default to 1 min 62 private static int mMinimumSlideElementDuration = 7; // default to 7 sec 63 private static boolean mNotifyWapMMSC = false; 64 private static boolean mAllowAttachAudio = true; 65 66 // If mEnableMultipartSMS is true, long sms messages are always sent as multi-part sms 67 // messages, with no checked limit on the number of segments. 68 // If mEnableMultipartSMS is false, then as soon as the user types a message longer 69 // than a single segment (i.e. 140 chars), then the message will turn into and be sent 70 // as an mms message. This feature exists for carriers that don't support multi-part sms's. 71 private static boolean mEnableMultipartSMS = true; 72 73 private static boolean mEnableSlideDuration = true; 74 private static boolean mEnableMMSReadReports = true; // key: "enableMMSReadReports" 75 private static boolean mEnableSMSDeliveryReports = true; // key: "enableSMSDeliveryReports" 76 private static boolean mEnableMMSDeliveryReports = true; // key: "enableMMSDeliveryReports" 77 private static int mMaxTextLength = -1; 78 79 // This is the max amount of storage multiplied by mMaxMessageSize that we 80 // allow of unsent messages before blocking the user from sending any more 81 // MMS's. 82 private static int mMaxSizeScaleForPendingMmsAllowed = 4; // default value 83 84 // Email gateway alias support, including the master switch and different rules 85 private static boolean mAliasEnabled = false; 86 private static int mAliasRuleMinChars = 2; 87 private static int mAliasRuleMaxChars = 48; 88 89 private static int mMaxSubjectLength = 40; // maximum number of characters allowed for mms 90 // subject 91 init(Context context)92 public static void init(Context context) { 93 if (LOCAL_LOGV) { 94 Log.v(TAG, "MmsConfig.init()"); 95 } 96 // Always put the mnc/mcc in the log so we can tell which mms_config.xml was loaded. 97 Log.v(TAG, "mnc/mcc: " + 98 android.os.SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC)); 99 100 loadMmsSettings(context); 101 } 102 getMmsEnabled()103 public static boolean getMmsEnabled() { 104 return mMmsEnabled == 1 ? true : false; 105 } 106 getMaxMessageSize()107 public static int getMaxMessageSize() { 108 if (LOCAL_LOGV) { 109 Log.v(TAG, "MmsConfig.getMaxMessageSize(): " + mMaxMessageSize); 110 } 111 return mMaxMessageSize; 112 } 113 114 /** 115 * This function returns the value of "enabledTransID" present in mms_config file. 116 * In case of single segment wap push message, this "enabledTransID" indicates whether 117 * TransactionID should be appended to URI or not. 118 */ getTransIdEnabled()119 public static boolean getTransIdEnabled() { 120 return mTransIdEnabled; 121 } 122 getUserAgent()123 public static String getUserAgent() { 124 return mUserAgent; 125 } 126 getUaProfTagName()127 public static String getUaProfTagName() { 128 return mUaProfTagName; 129 } 130 getUaProfUrl()131 public static String getUaProfUrl() { 132 return mUaProfUrl; 133 } 134 getHttpParams()135 public static String getHttpParams() { 136 return mHttpParams; 137 } 138 getHttpParamsLine1Key()139 public static String getHttpParamsLine1Key() { 140 return mHttpParamsLine1Key; 141 } 142 getEmailGateway()143 public static String getEmailGateway() { 144 return mEmailGateway; 145 } 146 getMaxImageHeight()147 public static int getMaxImageHeight() { 148 return mMaxImageHeight; 149 } 150 getMaxImageWidth()151 public static int getMaxImageWidth() { 152 return mMaxImageWidth; 153 } 154 getRecipientLimit()155 public static int getRecipientLimit() { 156 return mRecipientLimit; 157 } 158 getMaxTextLimit()159 public static int getMaxTextLimit() { 160 return mMaxTextLength > -1 ? mMaxTextLength : MAX_TEXT_LENGTH; 161 } 162 getDefaultSMSMessagesPerThread()163 public static int getDefaultSMSMessagesPerThread() { 164 return mDefaultSMSMessagesPerThread; 165 } 166 getDefaultMMSMessagesPerThread()167 public static int getDefaultMMSMessagesPerThread() { 168 return mDefaultMMSMessagesPerThread; 169 } 170 getMinMessageCountPerThread()171 public static int getMinMessageCountPerThread() { 172 return mMinMessageCountPerThread; 173 } 174 getMaxMessageCountPerThread()175 public static int getMaxMessageCountPerThread() { 176 return mMaxMessageCountPerThread; 177 } 178 getHttpSocketTimeout()179 public static int getHttpSocketTimeout() { 180 return mHttpSocketTimeout; 181 } 182 getMinimumSlideElementDuration()183 public static int getMinimumSlideElementDuration() { 184 return mMinimumSlideElementDuration; 185 } 186 getMultipartSmsEnabled()187 public static boolean getMultipartSmsEnabled() { 188 return mEnableMultipartSMS; 189 } 190 getSlideDurationEnabled()191 public static boolean getSlideDurationEnabled() { 192 return mEnableSlideDuration; 193 } 194 getMMSReadReportsEnabled()195 public static boolean getMMSReadReportsEnabled() { 196 return mEnableMMSReadReports; 197 } 198 getSMSDeliveryReportsEnabled()199 public static boolean getSMSDeliveryReportsEnabled() { 200 return mEnableSMSDeliveryReports; 201 } 202 getMMSDeliveryReportsEnabled()203 public static boolean getMMSDeliveryReportsEnabled() { 204 return mEnableMMSDeliveryReports; 205 } 206 getNotifyWapMMSC()207 public static boolean getNotifyWapMMSC() { 208 return mNotifyWapMMSC; 209 } 210 getMaxSizeScaleForPendingMmsAllowed()211 public static int getMaxSizeScaleForPendingMmsAllowed() { 212 return mMaxSizeScaleForPendingMmsAllowed; 213 } 214 isAliasEnabled()215 public static boolean isAliasEnabled() { 216 return mAliasEnabled; 217 } 218 getAliasMinChars()219 public static int getAliasMinChars() { 220 return mAliasRuleMinChars; 221 } 222 getAliasMaxChars()223 public static int getAliasMaxChars() { 224 return mAliasRuleMaxChars; 225 } 226 getAllowAttachAudio()227 public static boolean getAllowAttachAudio() { 228 return mAllowAttachAudio; 229 } 230 getMaxSubjectLength()231 public static int getMaxSubjectLength() { 232 return mMaxSubjectLength; 233 } 234 beginDocument(XmlPullParser parser, String firstElementName)235 public static final void beginDocument(XmlPullParser parser, String firstElementName) throws XmlPullParserException, IOException 236 { 237 int type; 238 while ((type=parser.next()) != parser.START_TAG 239 && type != parser.END_DOCUMENT) { 240 ; 241 } 242 243 if (type != parser.START_TAG) { 244 throw new XmlPullParserException("No start tag found"); 245 } 246 247 if (!parser.getName().equals(firstElementName)) { 248 throw new XmlPullParserException("Unexpected start tag: found " + parser.getName() + 249 ", expected " + firstElementName); 250 } 251 } 252 nextElement(XmlPullParser parser)253 public static final void nextElement(XmlPullParser parser) throws XmlPullParserException, IOException 254 { 255 int type; 256 while ((type=parser.next()) != parser.START_TAG 257 && type != parser.END_DOCUMENT) { 258 ; 259 } 260 } 261 loadMmsSettings(Context context)262 private static void loadMmsSettings(Context context) { 263 XmlResourceParser parser = context.getResources().getXml(R.xml.mms_config); 264 265 try { 266 beginDocument(parser, "mms_config"); 267 268 while (true) { 269 nextElement(parser); 270 String tag = parser.getName(); 271 if (tag == null) { 272 break; 273 } 274 String name = parser.getAttributeName(0); 275 String value = parser.getAttributeValue(0); 276 String text = null; 277 if (parser.next() == XmlPullParser.TEXT) { 278 text = parser.getText(); 279 } 280 281 if (DEBUG) { 282 Log.v(TAG, "tag: " + tag + " value: " + value + " - " + 283 text); 284 } 285 if ("name".equalsIgnoreCase(name)) { 286 if ("bool".equals(tag)) { 287 // bool config tags go here 288 if ("enabledMMS".equalsIgnoreCase(value)) { 289 mMmsEnabled = "true".equalsIgnoreCase(text) ? 1 : 0; 290 } else if ("enabledTransID".equalsIgnoreCase(value)) { 291 mTransIdEnabled = "true".equalsIgnoreCase(text); 292 } else if ("enabledNotifyWapMMSC".equalsIgnoreCase(value)) { 293 mNotifyWapMMSC = "true".equalsIgnoreCase(text); 294 } else if ("aliasEnabled".equalsIgnoreCase(value)) { 295 mAliasEnabled = "true".equalsIgnoreCase(text); 296 } else if ("allowAttachAudio".equalsIgnoreCase(value)) { 297 mAllowAttachAudio = "true".equalsIgnoreCase(text); 298 } else if ("enableMultipartSMS".equalsIgnoreCase(value)) { 299 mEnableMultipartSMS = "true".equalsIgnoreCase(text); 300 } else if ("enableSlideDuration".equalsIgnoreCase(value)) { 301 mEnableSlideDuration = "true".equalsIgnoreCase(text); 302 } else if ("enableMMSReadReports".equalsIgnoreCase(value)) { 303 mEnableMMSReadReports = "true".equalsIgnoreCase(text); 304 } else if ("enableSMSDeliveryReports".equalsIgnoreCase(value)) { 305 mEnableSMSDeliveryReports = "true".equalsIgnoreCase(text); 306 } else if ("enableMMSDeliveryReports".equalsIgnoreCase(value)) { 307 mEnableMMSDeliveryReports = "true".equalsIgnoreCase(text); 308 } 309 } else if ("int".equals(tag)) { 310 // int config tags go here 311 if ("maxMessageSize".equalsIgnoreCase(value)) { 312 mMaxMessageSize = Integer.parseInt(text); 313 } else if ("maxImageHeight".equalsIgnoreCase(value)) { 314 mMaxImageHeight = Integer.parseInt(text); 315 } else if ("maxImageWidth".equalsIgnoreCase(value)) { 316 mMaxImageWidth = Integer.parseInt(text); 317 } else if ("defaultSMSMessagesPerThread".equalsIgnoreCase(value)) { 318 mDefaultSMSMessagesPerThread = Integer.parseInt(text); 319 } else if ("defaultMMSMessagesPerThread".equalsIgnoreCase(value)) { 320 mDefaultMMSMessagesPerThread = Integer.parseInt(text); 321 } else if ("minMessageCountPerThread".equalsIgnoreCase(value)) { 322 mMinMessageCountPerThread = Integer.parseInt(text); 323 } else if ("maxMessageCountPerThread".equalsIgnoreCase(value)) { 324 mMaxMessageCountPerThread = Integer.parseInt(text); 325 } else if ("recipientLimit".equalsIgnoreCase(value)) { 326 mRecipientLimit = Integer.parseInt(text); 327 if (mRecipientLimit < 0) { 328 mRecipientLimit = Integer.MAX_VALUE; 329 } 330 } else if ("httpSocketTimeout".equalsIgnoreCase(value)) { 331 mHttpSocketTimeout = Integer.parseInt(text); 332 } else if ("minimumSlideElementDuration".equalsIgnoreCase(value)) { 333 mMinimumSlideElementDuration = Integer.parseInt(text); 334 } else if ("maxSizeScaleForPendingMmsAllowed".equalsIgnoreCase(value)) { 335 mMaxSizeScaleForPendingMmsAllowed = Integer.parseInt(text); 336 } else if ("aliasMinChars".equalsIgnoreCase(value)) { 337 mAliasRuleMinChars = Integer.parseInt(text); 338 } else if ("aliasMaxChars".equalsIgnoreCase(value)) { 339 mAliasRuleMaxChars = Integer.parseInt(text); 340 } else if ("maxMessageTextSize".equalsIgnoreCase(value)) { 341 mMaxTextLength = Integer.parseInt(text); 342 } else if ("maxSubjectLength".equalsIgnoreCase(value)) { 343 mMaxSubjectLength = Integer.parseInt(text); 344 } 345 } else if ("string".equals(tag)) { 346 // string config tags go here 347 if ("userAgent".equalsIgnoreCase(value)) { 348 mUserAgent = text; 349 } else if ("uaProfTagName".equalsIgnoreCase(value)) { 350 mUaProfTagName = text; 351 } else if ("uaProfUrl".equalsIgnoreCase(value)) { 352 mUaProfUrl = text; 353 } else if ("httpParams".equalsIgnoreCase(value)) { 354 mHttpParams = text; 355 } else if ("httpParamsLine1Key".equalsIgnoreCase(value)) { 356 mHttpParamsLine1Key = text; 357 } else if ("emailGatewayNumber".equalsIgnoreCase(value)) { 358 mEmailGateway = text; 359 } 360 } 361 } 362 } 363 } catch (XmlPullParserException e) { 364 Log.e(TAG, "loadMmsSettings caught ", e); 365 } catch (NumberFormatException e) { 366 Log.e(TAG, "loadMmsSettings caught ", e); 367 } catch (IOException e) { 368 Log.e(TAG, "loadMmsSettings caught ", e); 369 } finally { 370 parser.close(); 371 } 372 373 String errorStr = null; 374 375 if (getMmsEnabled() && mUaProfUrl == null) { 376 errorStr = "uaProfUrl"; 377 } 378 379 if (errorStr != null) { 380 String err = 381 String.format("MmsConfig.loadMmsSettings mms_config.xml missing %s setting", 382 errorStr); 383 Log.e(TAG, err); 384 } 385 } 386 387 } 388