public List<ServiceInfoBean> getServiceInfoInSearchResult( NativeInstallation.Install_Search_Result_t searchResult) { ServiceInfoBean serviceInfoBean = null; TPInfoBean tpInfoBean = null; List<ServiceInfoBean> serviceInfoBeans = new ArrayList<ServiceInfoBean>(); Install_Serv_t[] servList = searchResult.ptServList; if (servList.length != 0) { for (int i = 0; i < servList.length; i++) { serviceInfoBean = new ServiceInfoBean(); String servName = servList[i].sServName; if (null == servName || "".equals(servName)) { servName = "SDT:" + servList[i].u16ServId; } Install_Tp_t tpDesc = servList[i].ptTpDesc; DVBCore_Cab_Desc_t tunerDesc = tpDesc.uTunerDesc; char tunerId = tunerDesc.getU8TunerId(); int freq = tunerDesc.getU32Freq(); int symbRate = tunerDesc.getU32SymbRate(); int mod = tunerDesc.geteMod(); int fec_Inner = tunerDesc.geteFEC_Inner(); int fec_Outer = tunerDesc.geteFEC_Outer(); serviceInfoBean.setTunerType(tpDesc.eSignalSource); serviceInfoBean.setServiceId(servList[i].u16ServId); serviceInfoBean.setServiceType(servList[i].u8ServType); serviceInfoBean.setPmtPid(servList[i].u16PMTPid); serviceInfoBean.setCaMode(servList[i].u8FreeCA_Mode); serviceInfoBean.setChannelName(servName); serviceInfoBean.setLogicalNumber(servList[i].u16LogicalNum); serviceInfoBean.setAudioPid(servList[i].u16AudioPid); serviceInfoBean.setAudioType((int) servList[i].u8AudioFmt); serviceInfoBean.setVideoPid(servList[i].u16VideoPid); serviceInfoBean.setVideoType((int) servList[i].u8VideoFmt); // serviceInfoBean.setEcmId(ecmId); // serviceInfoBean.setEmmId(emmId); tpInfoBean = new TPInfoBean(); tpInfoBean.setTunerType(tpDesc.eSignalSource); tpInfoBean.setTunerId(tunerId); tpInfoBean.setNetId(tpDesc.u16NetId); tpInfoBean.setOriginalNetId(tpDesc.u16ON_Id); tpInfoBean.setTranStreamId(tpDesc.u16TS_Id); tpInfoBean.setTunerFreq(freq); tpInfoBean.setTunerSymbRate(symbRate); tpInfoBean.setTunerEmod(mod); tpInfoBean.setEfecInner(fec_Inner); tpInfoBean.setEfecOuter(fec_Outer); tpInfoBean.setPatVersion(tpDesc.u8Pat_Ver); serviceInfoBean.setTpInfoBean(tpInfoBean); serviceInfoBeans.add(serviceInfoBean); } } return serviceInfoBeans; }
/** * <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; }