@huchengtw-moz, I've re-written the updateAPNSettings() because it doesn't work correctly. I've followed the same -more or less- algorithm than yours. Please, take a look at it,  test it and consider to replace it or make it yours much easier to follow please, thanks.

    function buildNewApnSettingsValue(type, apnsForIccCards) {
      var apnToBeMerged = {};

      // Load the fields from the form into the apn to be merged.
      var keys = ['user', 'passwd', 'httpProxyHost', 'httpProxyPort'];
      keys.forEach(function(key) {
        apnToBeMerged[(keyMappings[key] || key)] = rilData(usage, key).value;
      });

      var newApnsForIccCards = [];
      for (var iccCardIndex = 0; iccCardIndex < apnsForIccCards.length; iccCardIndex++) {

        var newApnsForIccCard = [];
        var apnsForIccCard = apnsForIccCards[iccCardIndex];
        for (var apnIndex = 0; apnIndex < apnsForIccCard.length; apnIndex++) {

          var apn = apnsForIccCard[apnIndex];
          if (apn.type.indexOf(type) != -1) {
            // Compare the existing apn to the apn to be merge.
            var sameApn = true;
            keys.forEach(function(key) {
              if (apn[key] !== apnToBeMerged[key]) {
                sameApn= false;
              }
            });
            if (sameApn) {
              newApnsForIccCard.push(apn);
            } else {
              // Add the apn to be merged.
              var newType = [];
              newType.push(type);
              apnToBeMerged.type = newType;
              newApnsForIccCard.push(apnToBeMerged);             

              // Delete the type from the existing apn and add that apn if the
              // APN had other types.
              apn.types.splice(apn.type.indexOf(type), 1);
              if (apn.types.length !== 0) {
                newApnsForIccCard.push(newApn);
              }
            }
          } else {          
            newApnsForIccCard.push(apn);
          }
        }
        newApnsForIccCards.push(newApnsForIccCard);
      }
      settings.createLock().set({'ril.data.apnSettings': newApnsForIccCards});
    }