/**
   * <save tp information>
   *
   * @see [类、类#方法、类#成员]
   */
  public void saveTpInfoData() {
    List<TPInfoBean> tpInfoInSearchResult = getTpInfoInSearchResult(searchResult);

    if (searchMode == Config.Install_Search_Type_eAUTO_SEARCH
        || searchMode == Config.Install_Search_Type_eALL_SEARCH) {
      // clear db.
      TpInfoDao tpInfoDao = new TpInfoDaoImpl(this);
      ServiceInfoDao serviceInfoDao = new ServiceInfoDaoImpl(this);
      serviceInfoDao.clearService();
      tpInfoDao.clearTpData();
    }
    if (null != tpInfoInSearchResult) {
      TpInfoDao tpInfoDao = new TpInfoDaoImpl(this);

      for (TPInfoBean tpInfoBean : tpInfoInSearchResult) {
        int freq = tpInfoBean.getTunerFreq();
        int symbRate = tpInfoBean.getTunerSymbRate();

        // check this tp whether exist or not.
        int tpId = tpInfoDao.getTpId(freq, symbRate);
        if (tpId == 0) {
          tpInfoDao.addTpInfo(tpInfoBean);
        } else {
          tpInfoDao.updateServiceInfo(tpInfoBean, tpId);
        }
      }
    } else {
      Message message = new Message();
      message.what = Config.AUTO_SEARCH_FAILED;
      handler.sendMessage(message);
    }
  }
  /**
   * <save service information>
   *
   * @see [类、类#方法、类#成员]
   */
  public void saveServiceInfoData() {
    TpInfoDao tpInfoDao = new TpInfoDaoImpl(this);
    ServiceInfoDao serviceInfoDao = new ServiceInfoDaoImpl(this);

    List<ServiceInfoBean> serviceInfoInSearchResult = getServiceInfoInSearchResult(searchResult);
    List<ServiceInfoBean> curServiceList = new ArrayList<ServiceInfoBean>();
    List<ServiceInfoBean> oriServiceList = serviceInfoDao.getAllChannelInfo(false);

    // tmp list for java.util.ConcurrentModificationException
    List<ServiceInfoBean> tmpServiceList = new ArrayList<ServiceInfoBean>();

    // auto search,save nit version.
    if (searchMode == Config.Install_Search_Type_eAUTO_SEARCH) {
      // update nit version.
      MessageNit messageNit = new MessageNit();
      Nativenit nativenit = new Nativenit();
      nativenit.NitMessageInit(messageNit);
      Editor edit = getSharedPreferences("dvb_nit", 8).edit();
      int nitVersion = messageNit.nitSearchVer();
      Log.i(TAG, "--->>>the nit version is: " + nitVersion);
      edit.putInt("version_code", nitVersion);
      edit.commit();
      nativenit.NitMessageUnint();
    }

    if (null == serviceInfoInSearchResult) {
      LogUtils.printLog(1, 4, TAG, "--->>>search result is null,save service info data failed.");
      handler.sendEmptyMessage(Config.AUTO_SEARCH_FAILED);
      return;
    }

    //        // test start 2014-04-24 10:36:56
    //        for (ServiceInfoBean serviceInfoBean1 : oriServiceList)
    //        {
    //            LogUtils.printLog(1, 3, TAG, "--->>>oriServiceList size is: " +
    // serviceInfoBean1.getServiceId());
    //        }
    //        // test end 2014-04-24 10:37:05
    //        // test start 2014-04-24 10:36:56
    //        for (ServiceInfoBean serviceInfoBean : serviceInfoInSearchResult)
    //        {
    //            LogUtils.printLog(1, 3, TAG, "--->>>serviceInfoInSearchResult size is: " +
    // serviceInfoBean.getServiceId());
    //        }
    //        // test end 2014-04-24 10:37:05

    for (ServiceInfoBean serviceInfoBean : serviceInfoInSearchResult) {
      // check service's tp is avaliable.
      int tpId =
          tpInfoDao.getTpId(
              serviceInfoBean.getTpInfoBean().getTunerFreq(),
              serviceInfoBean.getTpInfoBean().getTunerSymbRate());
      if (tpId == 0) {
        break;
      }
      serviceInfoBean.setTpId(tpId);

      // manual search,no type service looks as tv type.
      if (searchMode == Config.Install_Search_Type_eTP_SEARCH) {
        if (serviceInfoBean.getServiceType() == Config.SERVICE_TYPE_NOTYPE) {
          serviceInfoBean.setServiceType((char) Config.SERVICE_TYPE_TV);
        }
      }

      if (!oriServiceList.contains(serviceInfoBean)) {
        LogUtils.printLog(
            1, 3, TAG, "--->>>step1,add service in search result and not in oriservicelist.");
        // step1,add service in search result and not in oriservicelist.
        curServiceList.add(serviceInfoBean);
      }
    }

    for (ServiceInfoBean oriBean : oriServiceList) {
      for (ServiceInfoBean curBean : serviceInfoInSearchResult) {
        /*
         * step2,sync service settings,the service in both oriservicelist and searchresult. save these service
         * in tmpservicelist.
         */
        if (curBean.equals(oriBean)) {
          curBean.setFavFlag(oriBean.getFavFlag());
          curBean.setLockFlag(oriBean.getLockFlag());

          LogUtils.printLog(1, 3, TAG, "--->>>step2,sync service settings");
          tmpServiceList.add(curBean);
        }
        // step3
        else {
          // step3.1, delete the same tp service not disappear in searchresult.
          if (curBean.getTpId() == oriBean.getTpId()) {
            // pat update,delete some service.
          }
          // step3.2,add the different tp service.
          else {
            LogUtils.printLog(1, 3, TAG, "--->>>step3.2,add the different tp service");
            if (!curServiceList.contains(oriBean)) {
              curServiceList.add(oriBean);
            }
          }
        }
      }
    }

    // step4,add add service from tmpserviclist to curservicelist
    for (ServiceInfoBean tmpBean : tmpServiceList) {
      LogUtils.printLog(
          1, 3, TAG, "--->>>step4,add add service from tmpserviclist to curservicelist");
      curServiceList.add(tmpBean);
    }

    // test start 2014-04-24 10:36:56
    //        for (ServiceInfoBean serviceInfoBean1 : curServiceList)
    //        {
    //            LogUtils.printLog(1, 3, TAG, "--->>>curServiceList size is: " +
    // serviceInfoBean1.getServiceId());
    //        }
    // test end 2014-04-24 10:37:05

    // sort the services.
    Collections.sort(curServiceList, new ServiceSort());

    // save the services.
    ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
    ops.add(serviceInfoDao.clearServiceData());

    for (int i = 0; i < curServiceList.size(); i++) {
      ops.add(serviceInfoDao.addServiceInfo(curServiceList.get(i), i + 1));
      LogUtils.printLog(
          1, 3, TAG, "--->>>curServiceList size is: " + curServiceList.get(i).getServiceId());
    }
    try {
      getContentResolver().applyBatch(DBService.SERVICE_AUTHORITY, ops);
    } catch (Exception e) {
      e.printStackTrace();
    }

    // clear data.
    serviceInfoInSearchResult = null;
    oriServiceList = null;
    curServiceList = null;
  }