/** Based on the operator, create a list of cdma data profiles. */
  private void readNaiListFromDatabase() {
    String operator = getOperatorNumeric();
    if (operator == null || operator.length() < 2) {
      loge("operatorNumeric invalid. Won't read database");
      return;
    }

    log("Loading data profiles for operator = " + operator);
    String selection = "numeric = '" + operator + "'";
    // query only enabled nai.
    // carrier_enabled : 1 means enabled nai, 0 disabled nai.
    selection += " and carrier_enabled = 1";
    log("readNaiListFromDatabase: selection=" + selection);

    Cursor cursor =
        mPhone
            .getContext()
            .getContentResolver()
            .query(Telephony.Carriers.CONTENT_URI, null, selection, null, null);

    if (cursor != null) {
      if (cursor.getCount() > 0) {
        populateDataProfilesList(cursor);
      }
      cursor.close();
    }
  }
  CdmaDataProfileTracker(CDMAPhone phone) {
    mPhone = phone;
    mCdmaSsm =
        CdmaSubscriptionSourceManager.getInstance(
            phone.getContext(), phone.mCM, this, EVENT_LOAD_PROFILES, null);

    mOmhServicePriorityMap = new HashMap<String, Integer>();

    sendMessage(obtainMessage(EVENT_LOAD_PROFILES));

    log("SUPPORT_OMH: " + mIsOmhEnabled);
  }
  public DataProfile getDataProfile(String serviceType) {
    DataProfile profile = null;

    // first try to get preferred APN

    String operator = getOperatorNumeric();
    String selection = "numeric = '" + operator + "'";
    // query only enabled nai.
    // carrier_enabled : 1 means enabled nai, 0 disabled nai.
    selection += " and carrier_enabled = 1";
    Cursor cursor =
        mPhone
            .getContext()
            .getContentResolver()
            .query(PREFER_DEFAULT_APN_URI, null, selection, null, null);

    log(
        "getDataProfile operator:"
            + operator
            + " select:"
            + selection
            + " count:"
            + cursor.getCount());
    if (cursor != null && cursor.getCount() > 0) {
      if (cursor.moveToFirst()) {
        do {
          String[] types =
              parseTypes(cursor.getString(cursor.getColumnIndexOrThrow(Telephony.Carriers.TYPE)));
          DataProfile nai =
              new DataProfileCdma(
                  cursor.getInt(cursor.getColumnIndexOrThrow(Telephony.Carriers._ID)),
                  cursor.getString(cursor.getColumnIndexOrThrow(Telephony.Carriers.NUMERIC)),
                  cursor.getString(cursor.getColumnIndexOrThrow(Telephony.Carriers.APN)),
                  cursor.getString(cursor.getColumnIndexOrThrow(Telephony.Carriers.USER)),
                  cursor.getString(cursor.getColumnIndexOrThrow(Telephony.Carriers.PASSWORD)),
                  cursor.getInt(cursor.getColumnIndexOrThrow(Telephony.Carriers.AUTH_TYPE)),
                  types,
                  cursor.getString(cursor.getColumnIndexOrThrow(Telephony.Carriers.PROTOCOL)),
                  cursor.getString(
                      cursor.getColumnIndexOrThrow(Telephony.Carriers.ROAMING_PROTOCOL)),
                  cursor.getInt(cursor.getColumnIndexOrThrow(Telephony.Carriers.BEARER)));
          if (nai.canHandleType(serviceType)) {
            cursor.close();
            return nai;
          }
        } while (cursor.moveToNext());
      }
    }

    if (cursor != null) cursor.close();

    // Go through all the profiles to find one
    for (DataProfile dp : mDataProfilesList) {
      if (dp.canHandleType(serviceType)) {
        profile = dp;
        if (mIsOmhEnabled
            && dp.getDataProfileType() != DataProfile.DataProfileType.PROFILE_TYPE_OMH) {
          // OMH enabled - Keep looking for OMH profile
          continue;
        }
        break;
      }
    }
    return profile;
  }