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 android.content.Context; 25 import android.content.res.XmlResourceParser; 26 import android.util.Config; 27 import android.util.Log; 28 29 import com.android.internal.util.XmlUtils; 30 31 public class MmsConfig { 32 private static final String TAG = "MmsConfig"; 33 private static final boolean DEBUG = false; 34 private static final boolean LOCAL_LOGV = DEBUG ? Config.LOGD : Config.LOGV; 35 36 private static final String DEFAULT_HTTP_KEY_X_WAP_PROFILE = "x-wap-profile"; 37 private static final String DEFAULT_USER_AGENT = "Android-Mms/0.1"; 38 39 /** 40 * Whether to hide MMS functionality from the user (i.e. SMS only). 41 */ 42 private static boolean mTransIdEnabled = false; 43 private static int mMmsEnabled = -1; // an int so we can tell whether it's been inited 44 private static int mMaxMessageSize = 0; 45 private static String mUserAgent = null; 46 private static String mUaProfTagName = null; 47 private static String mUaProfUrl = null; 48 private static String mHttpParams = null; 49 private static String mHttpParamsLine1Key = null; 50 private static String mEmailGateway = null; 51 private static int mMaxImageHeight = 0; 52 private static int mMaxImageWidth = 0; 53 private static int mRecipientLimit = Integer.MAX_VALUE; // default value 54 private static int mDefaultSMSMessagesPerThread = 200; // default value 55 private static int mDefaultMMSMessagesPerThread = 20; // default value 56 private static int mMinMessageCountPerThread = 2; // default value 57 private static int mMaxMessageCountPerThread = 5000; // default value 58 private static int mSmsToMmsTextThreshold = 4; // default value 59 private static int mHttpSocketTimeout = 60*1000; // default to 1 min 60 private static int mMinimumSlideElementDuration = 7; // default to 7 sec 61 private static boolean mNotifyWapMMSC = false; 62 private static boolean mAllowAttachAudio = true; 63 64 // This is the max amount of storage multiplied by mMaxMessageSize that we 65 // allow of unsent messages before blocking the user from sending any more 66 // MMS's. 67 private static int mMaxSizeScaleForPendingMmsAllowed = 4; // default value 68 69 // Email gateway alias support, including the master switch and different rules 70 private static boolean mAliasEnabled = false; 71 private static int mAliasRuleMinChars = 2; 72 private static int mAliasRuleMaxChars = 48; 73 init(Context context)74 public static void init(Context context) { 75 if (LOCAL_LOGV) { 76 Log.v(TAG, "MmsConfig.init()"); 77 } 78 79 loadMmsSettings(context); 80 } 81 getMmsEnabled()82 public static boolean getMmsEnabled() { 83 return mMmsEnabled == 1 ? true : false; 84 } 85 getMaxMessageSize()86 public static int getMaxMessageSize() { 87 return mMaxMessageSize; 88 } 89 90 /** 91 * This function returns the value of "enabledTransID" present in mms_config file. 92 * In case of single segment wap push message, this "enabledTransID" indicates whether 93 * TransactionID should be appended to URI or not. 94 */ getTransIdEnabled()95 public static boolean getTransIdEnabled() { 96 return mTransIdEnabled; 97 } 98 getUserAgent()99 public static String getUserAgent() { 100 return mUserAgent; 101 } 102 getUaProfTagName()103 public static String getUaProfTagName() { 104 return mUaProfTagName; 105 } 106 getUaProfUrl()107 public static String getUaProfUrl() { 108 return mUaProfUrl; 109 } 110 getHttpParams()111 public static String getHttpParams() { 112 return mHttpParams; 113 } 114 getHttpParamsLine1Key()115 public static String getHttpParamsLine1Key() { 116 return mHttpParamsLine1Key; 117 } 118 getEmailGateway()119 public static String getEmailGateway() { 120 return mEmailGateway; 121 } 122 getMaxImageHeight()123 public static int getMaxImageHeight() { 124 return mMaxImageHeight; 125 } 126 getMaxImageWidth()127 public static int getMaxImageWidth() { 128 return mMaxImageWidth; 129 } 130 getRecipientLimit()131 public static int getRecipientLimit() { 132 return mRecipientLimit; 133 } 134 getDefaultSMSMessagesPerThread()135 public static int getDefaultSMSMessagesPerThread() { 136 return mDefaultSMSMessagesPerThread; 137 } 138 getDefaultMMSMessagesPerThread()139 public static int getDefaultMMSMessagesPerThread() { 140 return mDefaultMMSMessagesPerThread; 141 } 142 getMinMessageCountPerThread()143 public static int getMinMessageCountPerThread() { 144 return mMinMessageCountPerThread; 145 } 146 getMaxMessageCountPerThread()147 public static int getMaxMessageCountPerThread() { 148 return mMaxMessageCountPerThread; 149 } 150 getSmsToMmsTextThreshold()151 public static int getSmsToMmsTextThreshold() { 152 return mSmsToMmsTextThreshold; 153 } 154 getHttpSocketTimeout()155 public static int getHttpSocketTimeout() { 156 return mHttpSocketTimeout; 157 } 158 getMinimumSlideElementDuration()159 public static int getMinimumSlideElementDuration() { 160 return mMinimumSlideElementDuration; 161 } 162 getNotifyWapMMSC()163 public static boolean getNotifyWapMMSC() { 164 return mNotifyWapMMSC; 165 } 166 getMaxSizeScaleForPendingMmsAllowed()167 public static int getMaxSizeScaleForPendingMmsAllowed() { 168 return mMaxSizeScaleForPendingMmsAllowed; 169 } 170 isAliasEnabled()171 public static boolean isAliasEnabled() { 172 return mAliasEnabled; 173 } 174 getAliasMinChars()175 public static int getAliasMinChars() { 176 return mAliasRuleMinChars; 177 } 178 getAliasMaxChars()179 public static int getAliasMaxChars() { 180 return mAliasRuleMaxChars; 181 } 182 getAllowAttachAudio()183 public static boolean getAllowAttachAudio() { 184 return mAllowAttachAudio; 185 } 186 loadMmsSettings(Context context)187 private static void loadMmsSettings(Context context) { 188 XmlResourceParser parser = context.getResources() 189 .getXml(R.xml.mms_config); 190 191 try { 192 XmlUtils.beginDocument(parser, "mms_config"); 193 194 while (true) { 195 XmlUtils.nextElement(parser); 196 String tag = parser.getName(); 197 if (tag == null) { 198 break; 199 } 200 String name = parser.getAttributeName(0); 201 String value = parser.getAttributeValue(0); 202 String text = null; 203 if (parser.next() == XmlPullParser.TEXT) { 204 text = parser.getText(); 205 } 206 207 if (DEBUG) { 208 Log.v(TAG, "tag: " + tag + " value: " + value); 209 } 210 if ("name".equalsIgnoreCase(name)) { 211 if ("bool".equals(tag)) { 212 // bool config tags go here 213 if ("enabledMMS".equalsIgnoreCase(value)) { 214 mMmsEnabled = "true".equalsIgnoreCase(text) ? 1 : 0; 215 } else if ("enabledTransID".equalsIgnoreCase(value)) { 216 mTransIdEnabled = "true".equalsIgnoreCase(text); 217 } else if ("enabledNotifyWapMMSC".equalsIgnoreCase(value)) { 218 mNotifyWapMMSC = "true".equalsIgnoreCase(text); 219 } else if ("aliasEnabled".equalsIgnoreCase(value)) { 220 mAliasEnabled = "true".equalsIgnoreCase(text); 221 } else if ("allowAttachAudio".equalsIgnoreCase(value)) { 222 mAllowAttachAudio = "true".equalsIgnoreCase(text); 223 } 224 } else if ("int".equals(tag)) { 225 // int config tags go here 226 if ("maxMessageSize".equalsIgnoreCase(value)) { 227 mMaxMessageSize = Integer.parseInt(text); 228 } else if ("maxImageHeight".equalsIgnoreCase(value)) { 229 mMaxImageHeight = Integer.parseInt(text); 230 } else if ("maxImageWidth".equalsIgnoreCase(value)) { 231 mMaxImageWidth = Integer.parseInt(text); 232 } else if ("defaultSMSMessagesPerThread".equalsIgnoreCase(value)) { 233 mDefaultSMSMessagesPerThread = Integer.parseInt(text); 234 } else if ("defaultMMSMessagesPerThread".equalsIgnoreCase(value)) { 235 mDefaultMMSMessagesPerThread = Integer.parseInt(text); 236 } else if ("minMessageCountPerThread".equalsIgnoreCase(value)) { 237 mMinMessageCountPerThread = Integer.parseInt(text); 238 } else if ("maxMessageCountPerThread".equalsIgnoreCase(value)) { 239 mMaxMessageCountPerThread = Integer.parseInt(text); 240 } else if ("smsToMmsTextThreshold".equalsIgnoreCase(value)) { 241 mSmsToMmsTextThreshold = Integer.parseInt(text); 242 } else if ("recipientLimit".equalsIgnoreCase(value)) { 243 mRecipientLimit = Integer.parseInt(text); 244 if (mRecipientLimit < 0) { 245 mRecipientLimit = Integer.MAX_VALUE; 246 } 247 } else if ("httpSocketTimeout".equalsIgnoreCase(value)) { 248 mHttpSocketTimeout = Integer.parseInt(text); 249 } else if ("minimumSlideElementDuration".equalsIgnoreCase(value)) { 250 mMinimumSlideElementDuration = Integer.parseInt(text); 251 } else if ("maxSizeScaleForPendingMmsAllowed".equalsIgnoreCase(value)) { 252 mMaxSizeScaleForPendingMmsAllowed = Integer.parseInt(text); 253 } else if ("aliasMinChars".equalsIgnoreCase(value)) { 254 mAliasRuleMinChars = Integer.parseInt(text); 255 } else if ("aliasMaxChars".equalsIgnoreCase(value)) { 256 mAliasRuleMaxChars = Integer.parseInt(text); 257 } 258 } else if ("string".equals(tag)) { 259 // string config tags go here 260 if ("userAgent".equalsIgnoreCase(value)) { 261 mUserAgent = text; 262 } else if ("uaProfTagName".equalsIgnoreCase(value)) { 263 mUaProfTagName = text; 264 } else if ("uaProfUrl".equalsIgnoreCase(value)) { 265 mUaProfUrl = text; 266 } else if ("httpParams".equalsIgnoreCase(value)) { 267 mHttpParams = text; 268 } else if ("httpParamsLine1Key".equalsIgnoreCase(value)) { 269 mHttpParamsLine1Key = text; 270 } else if ("emailGatewayNumber".equalsIgnoreCase(value)) { 271 mEmailGateway = text; 272 } 273 } 274 } 275 } 276 } catch (XmlPullParserException e) { 277 Log.e(TAG, "loadMmsSettings caught ", e); 278 } catch (NumberFormatException e) { 279 Log.e(TAG, "loadMmsSettings caught ", e); 280 } catch (IOException e) { 281 Log.e(TAG, "loadMmsSettings caught ", e); 282 } finally { 283 parser.close(); 284 } 285 286 String errorStr = null; 287 288 if (mMmsEnabled == -1) { 289 errorStr = "enableMMS"; 290 } 291 if (mMaxMessageSize == 0) { 292 errorStr = "maxMessageSize"; 293 } 294 if (mMaxImageHeight == 0) { 295 errorStr = "maxImageHeight"; 296 } 297 if (mMaxImageWidth == 0) { 298 errorStr = "maxImageWidth"; 299 } 300 if (getMmsEnabled() && mUaProfUrl == null) { 301 errorStr = "uaProfUrl"; 302 } 303 if (mUaProfTagName == null) { 304 mUaProfTagName = DEFAULT_HTTP_KEY_X_WAP_PROFILE; 305 } 306 if (mUserAgent == null) { 307 mUserAgent = DEFAULT_USER_AGENT; 308 } 309 310 if (errorStr != null) { 311 String err = 312 String.format("MmsConfig.loadMmsSettings mms_config.xml missing %s setting", 313 errorStr); 314 Log.e(TAG, err); 315 throw new ContentRestrictionException(err); 316 } 317 } 318 319 } 320