Ejemplo n.º 1
0
  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);
        }
        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 ("int".equals(tag)) {
            // int config tags go here
            if ("maxMessageSize".equalsIgnoreCase(value)) {
              mMaxMessageSize = Integer.parseInt(text);
            } else if ("max2GDownloadLimit".equalsIgnoreCase(value)) {
              max2GDownloadLimit = Integer.parseInt(text);
            } else if ("maxTDDownloadLimit".equalsIgnoreCase(value)) {
              maxTDDownloadLimit = Integer.parseInt(text);
            } else if ("maxPduHeadLimit".equalsIgnoreCase(value)) {
              maxPduHeadLimit = Integer.parseInt(text);
            } else if ("maxSingleSlideSize".equalsIgnoreCase(value)) {
              maxSingleSlideSize = 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 ("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;
            }
          }
        }
      }
    } 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);
      throw new ContentRestrictionException(err);
    }
  }