Exemplo n.º 1
0
  private void fillList(int simId) {
    String where = getFillListQuery();
    Xlog.e(TAG, "fillList where: " + where);

    if (mUri == null) {
      Xlog.e(TAG, "fillList, mUri null !");
      finish();
      return;
    }
    Cursor cursor =
        getContentResolver()
            .query(
                mUri, new String[] {"_id", "name", "apn", "type", "sourcetype"}, where, null, null);

    PreferenceGroup apnList = (PreferenceGroup) findPreference("apn_list");
    apnList.removeAll();

    ArrayList<Preference> mmsApnList = new ArrayList<Preference>();

    boolean keySetChecked = false;

    mSelectedKey = getSelectedApnKey();
    Xlog.d(TAG, "fillList : mSelectedKey = " + mSelectedKey);

    cursor.moveToFirst();

    while (!cursor.isAfterLast()) {
      String type = cursor.getString(TYPES_INDEX);

      if (mIsTetherApn && !TETHER_TYPE.equals(type)) {
        cursor.moveToNext();
        continue;
      }

      String name = cursor.getString(NAME_INDEX);
      String apn = cursor.getString(APN_INDEX);
      String key = cursor.getString(ID_INDEX);

      int sourcetype = cursor.getInt(SOURCE_TYPE_INDEX);

      if ("cmmail".equals(apn) && sourcetype == 0) {
        cursor.moveToNext();
        continue;
      }
      if (RCSE_TYPE.equals(type) && mRcseExt != null) {
        if (!mRcseExt.isRcseOnlyApnEnabled()) {
          cursor.moveToNext();
          Xlog.d(TAG, "Vodafone not matched");
          continue;
        } else {
          Xlog.d(TAG, "Vodafone matched");
        }
      }

      ApnPreference pref = new ApnPreference(this);

      pref.setSimId(simId); // set pre sim id info to the ApnEditor
      pref.setKey(key);
      pref.setTitle(name);
      pref.setSummary(apn);
      pref.setPersistent(false);
      pref.setSourceType(sourcetype);
      pref.setOnPreferenceChangeListener(this);

      boolean isEditable = mExt.isAllowEditPresetApn(type, apn, mNumeric);
      pref.setApnEditable((sourcetype != 0) || isEditable);

      // All tether apn will be selectable for otthers , mms will not be selectable.
      boolean selectable = true;
      if (TETHER_TYPE.equals(type)) {
        selectable = mIsTetherApn;
      } else {
        selectable = !"mms".equals(type);
      }
      pref.setSelectable(selectable);

      if (selectable) {
        if ((mSelectedKey != null) && mSelectedKey.equals(key)) {
          pref.setChecked();
          keySetChecked = true;
          Xlog.d(TAG, "apn key: " + key + " set.");
        }
        apnList.addPreference(pref);
        Xlog.i(TAG, "key:  " + key + " added!");
      } else {
        mmsApnList.add(pref);
      }
      cursor.moveToNext();
    }
    cursor.close();

    mSelectableApnCount = apnList.getPreferenceCount();
    // if no key selected, choose the 1st one.
    if (!keySetChecked && mSelectableApnCount > 0) {
      int[] sourceTypeArray = new int[mSelectableApnCount];
      for (int i = 0; i < mSelectableApnCount; i++) {
        sourceTypeArray[i] = ((ApnPreference) apnList.getPreference(i)).getSourceType();
      }
      ApnPreference apnPref =
          (ApnPreference) mExt.getApnPref(apnList, mSelectableApnCount, sourceTypeArray);
      if (apnPref != null) {
        setSelectedApnKey(apnPref.getKey());
        apnPref.setChecked();
        Xlog.i(TAG, "Key does not match.Set key: " + apnPref.getKey() + ".");
      }
    }

    if (!mIsTetherApn) {
      for (Preference preference : mmsApnList) {
        apnList.addPreference(preference);
      }
    }
    getPreferenceScreen().setEnabled(getScreenEnableState());
  }