/* For all the OMH service types not present in the card, add them to the
   * UNSPECIFIED/DEFAULT data profile.
   */
  private void addServiceTypeToUnSpecified() {
    for (String apntype : mSupportedApnTypes) {
      if (!mOmhServicePriorityMap.containsKey(apntype)) {

        // ServiceType :apntype is not provisioned in the card,
        // Look through the profiles read from the card to locate
        // the UNSPECIFIED profile and add the service type to it.
        for (DataProfile dp : mTempOmhDataProfilesList) {
          if (((DataProfileOmh) dp).getDataProfileTypeModem()
              == DataProfileTypeModem.PROFILE_TYPE_UNSPECIFIED) {
            ((DataProfileOmh) dp)
                .addServiceType(DataProfileTypeModem.getDataProfileTypeModem(apntype));
            log(
                "OMH: Service Type added to UNSPECIFIED is : "
                    + DataProfileTypeModem.getDataProfileTypeModem(apntype));
            break;
          }
        }
      }
    }
  }
  /*
   * Reads all the data profiles from the modem
   */
  private void onReadDataProfilesFromModem() {
    log("OMH: onReadDataProfilesFromModem()");
    mOmhReadProfileContext++;

    mOmhReadProfileCount = 0; // Reset the count and list(s)
    /* Clear out the modem profiles lists (main and temp) which were read/saved */
    mOmhDataProfilesList.clear();
    mTempOmhDataProfilesList.clear();
    mOmhServicePriorityMap.clear();

    // For all the service types known in modem, read the data profies
    for (DataProfileTypeModem p : DataProfileTypeModem.values()) {
      log("OMH: Reading profiles for:" + p.getid());
      mOmhReadProfileCount++;
      mPhone.mCM.getDataCallProfile(
          p.getid(),
          obtainMessage(
              EVENT_GET_DATA_CALL_PROFILE_DONE, // what
              mOmhReadProfileContext, // arg1
              0, // arg2  -- ignore
              p)); // userObj
    }
  }
  /*
   * Process the response for the RIL request GET_DATA_CALL_PROFILE.
   * Save the profile details received.
   */
  private void onGetDataCallProfileDone(AsyncResult ar, int context) {
    if (ar.exception != null) {
      log("OMH: Exception in onGetDataCallProfileDone:" + ar.exception);
      return;
    }

    if (context != mOmhReadProfileContext) {
      // we have other onReadOmhDataprofiles() on the way.
      return;
    }

    // DataProfile list from the modem for a given SERVICE_TYPE. These may
    // be from RUIM in case of OMH
    ArrayList<DataProfile> dataProfileListModem = new ArrayList<DataProfile>();
    dataProfileListModem = (ArrayList<DataProfile>) ar.result;

    DataProfileTypeModem modemProfile = (DataProfileTypeModem) ar.userObj;

    mOmhReadProfileCount--;

    if (dataProfileListModem != null && dataProfileListModem.size() > 0) {
      String serviceType;

      /* For the modem service type, get the android DataServiceType */
      serviceType = modemProfile.getDataServiceType();

      log(
          "OMH: # profiles returned from modem:"
              + dataProfileListModem.size()
              + " for "
              + serviceType);

      mOmhServicePriorityMap.put(
          serviceType, omhListGetArbitratedPriority(dataProfileListModem, serviceType));

      for (DataProfile dp : dataProfileListModem) {

        /* Store the modem profile type in the data profile */
        ((DataProfileOmh) dp).setDataProfileTypeModem(modemProfile);

        /* Look through mTempOmhDataProfilesList for existing profile id's
         * before adding it. This implies that the (similar) profile with same
         * priority already exists.
         */
        DataProfileOmh omhDuplicatedp = getDuplicateProfile(dp);
        if (null == omhDuplicatedp) {
          mTempOmhDataProfilesList.add(dp);
          ((DataProfileOmh) dp)
              .addServiceType(DataProfileTypeModem.getDataProfileTypeModem(serviceType));
        } else {
          /*  To share the already established data connection
           * (say between SUPL and DUN) in cases such as below:
           *  Ex:- SUPL+DUN [profile id 201, priority 1]
           *  'dp' instance is found at this point. Add the non-provisioned
           *   service type to this 'dp' instance
           */
          log("OMH: Duplicate Profile " + omhDuplicatedp);
          ((DataProfileOmh) omhDuplicatedp)
              .addServiceType(DataProfileTypeModem.getDataProfileTypeModem(serviceType));
        }
      }
    }

    // (Re)Load APN List
    if (mOmhReadProfileCount == 0) {
      log("OMH: Modem omh profile read complete.");
      addServiceTypeToUnSpecified();
      mDataProfilesList.addAll(mTempOmhDataProfilesList);
      mModemDataProfileRegistrants.notifyRegistrants();
    }

    return;
  }