private void updateChannelsWithSingleConfig(SmsBroadcastConfigInfo info) {
    int channelBeginIndex = info.getFromServiceId();
    int channelEndIndex = info.getToServiceId();
    boolean state = info.isSelected();
    MmsLog.d(LOG_TAG, "updateChannelsWithSingleConfig STATE = " + state);

    if (channelBeginIndex != -1) {
      for (int j = channelBeginIndex; j <= channelEndIndex; j++) {
        if (mCellBroadcastAsyncTask.isCancelled()) {
          break;
        }
        String jStr = String.valueOf(j);
        CellBroadcastChannel channel = getChannelObjectFromKey(jStr);
        if (channel != null) {
          channel.setChannelState(state);
        } else {
          // add a new channel to dataBase while the channel doesn't exists
          String tName = getString(R.string.cb_default_new_channel_name) + jStr;
          CellBroadcastChannel newChannel = new CellBroadcastChannel(j, tName, state);
          if (!insertChannelToDatabase(newChannel)) {
            showUpdateDBErrorInfoDialog();
          }
          mChannelArray.add(newChannel);
          mChannelMap.put(jStr, newChannel);
        }
      }
    }
  }
 private boolean queryChannelFromDatabase() {
   MmsLog.d(LOG_TAG, "queryChannelFromDatabase start");
   clearChannel();
   String[] projection = new String[] {KEYID, NAME, NUMBER, ENABLE};
   Cursor cursor = null;
   try {
     cursor = this.getContentResolver().query(mUri, projection, null, null, null);
     if (cursor != null) {
       while (cursor.moveToNext()) {
         CellBroadcastChannel channel = new CellBroadcastChannel();
         channel.setChannelId(cursor.getInt(2));
         channel.setKeyId(cursor.getInt(0));
         channel.setChannelName(cursor.getString(1));
         channel.setChannelState(cursor.getInt(3) == 1);
         mChannelArray.add(channel);
       }
     }
   } catch (IllegalArgumentException e) {
     return false;
   } finally {
     cursor.close();
   }
   MmsLog.d(LOG_TAG, "queryChannelFromDatabase end");
   return true;
 }
 @Override
 public boolean onContextItemSelected(MenuItem item) {
   AdapterView.AdapterContextMenuInfo info =
       (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
   int index = info.position - 3;
   CellBroadcastChannel oldChannel = mChannelArray.get(index);
   switch (item.getItemId()) {
     case MENU_CHANNEL_ENABLE_DISABLE:
       CellBroadcastChannel newChannel = new CellBroadcastChannel();
       newChannel = oldChannel;
       newChannel.setChannelState(!oldChannel.getChannelState());
       int tempOldChannelId = oldChannel.getChannelId();
       SmsBroadcastConfigInfo[] objectList = new SmsBroadcastConfigInfo[1];
       objectList[0] =
           new SmsBroadcastConfigInfo(
               tempOldChannelId, tempOldChannelId, -1, -1, newChannel.getChannelState());
       if (updateChannelToDatabase(oldChannel, newChannel)) {
         setCellBroadcastConfig(objectList);
       } else {
         showUpdateDBErrorInfoDialog();
       }
       break;
     case MENU_CHANNEL_EDIT:
       showEditChannelDialog(oldChannel);
       break;
     case MENU_CHANNEL_DELETE:
       oldChannel.setChannelState(false);
       SmsBroadcastConfigInfo[] objectList1 = makeChannelConfigArray(oldChannel);
       if (deleteChannelFromDatabase(oldChannel)) {
         setCellBroadcastConfig(objectList1);
       } else {
         showUpdateDBErrorInfoDialog();
       }
       break;
     default:
       break;
   }
   return super.onContextItemSelected(item);
 }