• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <android-base/logging.h>
20 #include <android_media_tuner_testing_configuration_V1_0.h>
21 #include <android_media_tuner_testing_configuration_V1_0_enums.h>
22 
23 #include <aidl/android/hardware/tv/tuner/DataFormat.h>
24 #include <aidl/android/hardware/tv/tuner/DemuxAlpFilterType.h>
25 #include <aidl/android/hardware/tv/tuner/DemuxFilterAvSettings.h>
26 #include <aidl/android/hardware/tv/tuner/DemuxFilterEvent.h>
27 #include <aidl/android/hardware/tv/tuner/DemuxFilterMainType.h>
28 #include <aidl/android/hardware/tv/tuner/DemuxFilterRecordSettings.h>
29 #include <aidl/android/hardware/tv/tuner/DemuxFilterSectionSettings.h>
30 #include <aidl/android/hardware/tv/tuner/DemuxFilterSettings.h>
31 #include <aidl/android/hardware/tv/tuner/DemuxFilterType.h>
32 #include <aidl/android/hardware/tv/tuner/DemuxIpAddress.h>
33 #include <aidl/android/hardware/tv/tuner/DemuxIpFilterSettings.h>
34 #include <aidl/android/hardware/tv/tuner/DemuxIpFilterType.h>
35 #include <aidl/android/hardware/tv/tuner/DemuxMmtpFilterType.h>
36 #include <aidl/android/hardware/tv/tuner/DemuxRecordScIndexType.h>
37 #include <aidl/android/hardware/tv/tuner/DemuxTlvFilterType.h>
38 #include <aidl/android/hardware/tv/tuner/DemuxTsFilterType.h>
39 #include <aidl/android/hardware/tv/tuner/DvrSettings.h>
40 #include <aidl/android/hardware/tv/tuner/DvrType.h>
41 #include <aidl/android/hardware/tv/tuner/FrontendDvbsSettings.h>
42 #include <aidl/android/hardware/tv/tuner/FrontendDvbtBandwidth.h>
43 #include <aidl/android/hardware/tv/tuner/FrontendDvbtCoderate.h>
44 #include <aidl/android/hardware/tv/tuner/FrontendDvbtConstellation.h>
45 #include <aidl/android/hardware/tv/tuner/FrontendDvbtGuardInterval.h>
46 #include <aidl/android/hardware/tv/tuner/FrontendDvbtHierarchy.h>
47 #include <aidl/android/hardware/tv/tuner/FrontendDvbtPlpMode.h>
48 #include <aidl/android/hardware/tv/tuner/FrontendDvbtSettings.h>
49 #include <aidl/android/hardware/tv/tuner/FrontendDvbtStandard.h>
50 #include <aidl/android/hardware/tv/tuner/FrontendDvbtTransmissionMode.h>
51 #include <aidl/android/hardware/tv/tuner/FrontendSettings.h>
52 #include <aidl/android/hardware/tv/tuner/FrontendStatus.h>
53 #include <aidl/android/hardware/tv/tuner/FrontendStatusType.h>
54 #include <aidl/android/hardware/tv/tuner/FrontendType.h>
55 #include <aidl/android/hardware/tv/tuner/LnbPosition.h>
56 #include <aidl/android/hardware/tv/tuner/LnbTone.h>
57 #include <aidl/android/hardware/tv/tuner/LnbVoltage.h>
58 #include <aidl/android/hardware/tv/tuner/PlaybackSettings.h>
59 #include <aidl/android/hardware/tv/tuner/RecordSettings.h>
60 
61 using namespace std;
62 using namespace aidl::android::hardware::tv::tuner;
63 using namespace android::media::tuner::testing::configuration::V1_0;
64 
65 static bool hasHwFe = false;
66 static bool hasSwFe = false;
67 static bool configFileRead = false;
68 static bool configuredLive = false;
69 static bool configuredScan = false;
70 static bool configuredRecord = false;
71 static bool configuredLnbLive = false;
72 static bool configuredPlayback = false;
73 static bool configuredLnbRecord = false;
74 static bool configuredTimeFilter = false;
75 static bool configuredDescrambling = false;
76 static bool configuredLnbDescrambling = false;
77 
78 const string emptyHardwareId = "";
79 
80 static string mConfigFilePath;
81 
82 static vector<string> playbackDvrIds;
83 static vector<string> ipFilterIds;
84 static vector<string> recordDvrIds;
85 static vector<string> pcrFilterIds;
86 static vector<string> timeFilterIds;
87 static vector<string> audioFilterIds;
88 static vector<string> videoFilterIds;
89 static vector<string> recordFilterIds;
90 static vector<string> sectionFilterIds;
91 static vector<string> frontendIds;
92 static vector<string> lnbIds;
93 static vector<string> diseqcMsgs;
94 static vector<string> descramblerIds;
95 
96 #define PROVISION_STR                                      \
97     "{                                                   " \
98     "  \"id\": 21140844,                                 " \
99     "  \"name\": \"Test Title\",                         " \
100     "  \"lowercase_organization_name\": \"Android\",     " \
101     "  \"asset_key\": {                                  " \
102     "  \"encryption_key\": \"nezAr3CHFrmBR9R8Tedotw==\"  " \
103     "  },                                                " \
104     "  \"cas_type\": 1,                                  " \
105     "  \"track_types\": [ ]                              " \
106     "}                                                   "
107 
108 struct FrontendConfig {
109     bool isSoftwareFe;
110     FrontendType type;
111     bool canConnectToCiCam;
112     int32_t ciCamId;
113     int32_t removePid;
114     FrontendSettings settings;
115     vector<FrontendStatusType> tuneStatusTypes;
116     vector<FrontendStatus> expectTuneStatuses;
117     bool supportBlindScan;
118 };
119 
120 struct FilterConfig {
121     int32_t bufferSize;
122     DemuxFilterType type;
123     DemuxFilterSettings settings;
124     bool getMqDesc;
125     AvStreamType streamType;
126     int32_t ipCid;
127     int32_t monitorEventTypes;
128     int timeDelayInMs = 0;
129     int dataDelayInBytes = 0;
130 
131     bool operator<(const FilterConfig& /*c*/) const { return false; }
132 };
133 
134 struct DvrConfig {
135     DvrType type;
136     int32_t bufferSize;
137     DvrSettings settings;
138     string playbackInputFile;
139 };
140 
141 struct LnbConfig {
142     string name;
143     LnbVoltage voltage;
144     LnbTone tone;
145     LnbPosition position;
146 };
147 
148 struct TimeFilterConfig {
149     int64_t timeStamp;
150 };
151 
152 struct DescramblerConfig {
153     int32_t casSystemId;
154     string provisionStr;
155     vector<uint8_t> hidlPvtData;
156 };
157 
158 struct LiveBroadcastHardwareConnections {
159     bool hasFrontendConnection;
160     string frontendId;
161     string dvrSoftwareFeId;
162     string audioFilterId;
163     string videoFilterId;
164     string sectionFilterId;
165     string ipFilterId;
166     string pcrFilterId;
167     /* list string of extra filters; */
168     vector<string> extraFilters;
169 };
170 
171 struct ScanHardwareConnections {
172     bool hasFrontendConnection;
173     string frontendId;
174 };
175 
176 struct DvrPlaybackHardwareConnections {
177     bool support;
178     bool hasExtraFilters = false;
179     string frontendId;
180     string dvrId;
181     string audioFilterId;
182     string videoFilterId;
183     string sectionFilterId;
184     vector<string> extraFilters;
185 };
186 
187 struct DvrRecordHardwareConnections {
188     bool support;
189     bool hasFrontendConnection;
190     string frontendId;
191     string dvrRecordId;
192     string dvrSoftwareFeId;
193     string recordFilterId;
194     string dvrSourceId;
195 };
196 
197 struct DescramblingHardwareConnections {
198     bool support;
199     bool hasFrontendConnection;
200     string frontendId;
201     string dvrSoftwareFeId;
202     string audioFilterId;
203     string videoFilterId;
204     string descramblerId;
205     string dvrSourceId;
206     vector<string> extraFilters;
207 };
208 
209 struct LnbLiveHardwareConnections {
210     bool support;
211     string frontendId;
212     string audioFilterId;
213     string videoFilterId;
214     string lnbId;
215     vector<string> diseqcMsgs;
216     vector<string> extraFilters;
217 };
218 
219 struct LnbRecordHardwareConnections {
220     bool support;
221     string frontendId;
222     string dvrRecordId;
223     string recordFilterId;
224     string lnbId;
225     vector<string> diseqcMsgs;
226     vector<string> extraFilters;
227 };
228 
229 struct TimeFilterHardwareConnections {
230     bool support;
231     string timeFilterId;
232 };
233 
234 struct LnbDescramblingHardwareConnections {
235     bool support;
236     string frontendId;
237     string audioFilterId;
238     string videoFilterId;
239     string lnbId;
240     string descramblerId;
241     vector<string> diseqcMsgs;
242 };
243 
244 struct TunerTestingConfigAidlReader1_0 {
245   public:
setConfigFilePathTunerTestingConfigAidlReader1_0246     static void setConfigFilePath(string path) { mConfigFilePath = path; }
247 
checkConfigFileExistsTunerTestingConfigAidlReader1_0248     static bool checkConfigFileExists() {
249         auto res = read(mConfigFilePath.c_str());
250         if (res == nullopt) {
251             ALOGW("[ConfigReader] Couldn't read %s."
252                   "Please check tuner_testing_dynamic_configuration.xsd"
253                   "and sample_tuner_vts_config.xml for more details on how to config Tune VTS.",
254                   mConfigFilePath.c_str());
255         }
256         return (res != nullopt);
257     }
258 
getTunerConfigTunerTestingConfigAidlReader1_0259     static TunerConfiguration getTunerConfig() { return *read(mConfigFilePath.c_str()); }
260 
getDataFlowConfigurationTunerTestingConfigAidlReader1_0261     static DataFlowConfiguration getDataFlowConfiguration() {
262         return *getTunerConfig().getFirstDataFlowConfiguration();
263     }
264 
getHardwareConfigTunerTestingConfigAidlReader1_0265     static HardwareConfiguration getHardwareConfig() {
266         return *getTunerConfig().getFirstHardwareConfiguration();
267     }
268 
readFrontendConfig1_0TunerTestingConfigAidlReader1_0269     static void readFrontendConfig1_0(map<string, FrontendConfig>& frontendMap) {
270         auto hardwareConfig = getHardwareConfig();
271         if (hardwareConfig.hasFrontends()) {
272             // TODO: b/182519645 complete the tune status config
273             vector<FrontendStatusType> types;
274             vector<FrontendStatus> statuses;
275 
276             types.push_back(FrontendStatusType::UEC);
277 
278             FrontendStatus status;
279             status.set<FrontendStatus::Tag::uec>(0);
280             statuses.push_back(status);
281 
282             auto frontends = *hardwareConfig.getFirstFrontends();
283             for (auto feConfig : frontends.getFrontend()) {
284                 string id = feConfig.getId();
285                 frontendIds.push_back(id);
286                 if (id.compare(string("FE_DEFAULT")) == 0) {
287                     // overrid default
288                     frontendMap.erase(string("FE_DEFAULT"));
289                 }
290                 FrontendType type;
291                 switch (feConfig.getType()) {
292                     case FrontendTypeEnum::UNDEFINED:
293                         type = FrontendType::UNDEFINED;
294                         break;
295                     // TODO: b/182519645 finish all other frontend settings
296                     case FrontendTypeEnum::ANALOG:
297                         type = FrontendType::ANALOG;
298                         break;
299                     case FrontendTypeEnum::ATSC:
300                         type = FrontendType::ATSC;
301                         frontendMap[id].settings.set<
302                             FrontendSettings::Tag::atsc>(
303                                 readAtscFrontendSettings(feConfig));
304                         break;
305                     case FrontendTypeEnum::ATSC3:
306                         type = FrontendType::ATSC3;
307                         break;
308                     case FrontendTypeEnum::DVBC:
309                         type = FrontendType::DVBC;
310                         break;
311                     case FrontendTypeEnum::DVBS:
312                         type = FrontendType::DVBS;
313                         frontendMap[id].settings.set<FrontendSettings::Tag::dvbs>(
314                                 readDvbsFrontendSettings(feConfig));
315                         break;
316                     case FrontendTypeEnum::DVBT: {
317                         type = FrontendType::DVBT;
318                         frontendMap[id].settings.set<FrontendSettings::Tag::dvbt>(
319                                 readDvbtFrontendSettings(feConfig));
320                         break;
321                     }
322                     case FrontendTypeEnum::ISDBS:
323                         type = FrontendType::ISDBS;
324                         frontendMap[id].settings.set<FrontendSettings::Tag::isdbs>(
325                                 readIsdbsFrontendSettings(feConfig));
326                         break;
327                     case FrontendTypeEnum::ISDBS3:
328                         type = FrontendType::ISDBS3;
329                         break;
330                     case FrontendTypeEnum::ISDBT:
331                         type = FrontendType::ISDBT;
332                         frontendMap[id].settings.set<FrontendSettings::Tag::isdbt>(
333                                 readIsdbtFrontendSettings(feConfig));
334                         break;
335                     case FrontendTypeEnum::DTMB:
336                         type = FrontendType::DTMB;
337                         break;
338                     case FrontendTypeEnum::UNKNOWN:
339                         ALOGW("[ConfigReader] invalid frontend type");
340                         return;
341                     default:
342                         ALOGW("[ConfigReader] fe already handled in 1_0 reader.");
343                         break;
344                 }
345                 frontendMap[id].type = type;
346                 frontendMap[id].isSoftwareFe = feConfig.getIsSoftwareFrontend();
347                 if (frontendMap[id].isSoftwareFe) {
348                     hasSwFe = true;
349                 } else {
350                     hasHwFe = true;
351                 }
352                 if (feConfig.hasSupportBlindScan()) {
353                     frontendMap[id].supportBlindScan = feConfig.getSupportBlindScan();
354                 } else {
355                     frontendMap[id].supportBlindScan = true;
356                 }
357                 // TODO: b/182519645 complete the tune status config
358                 frontendMap[id].tuneStatusTypes = types;
359                 frontendMap[id].expectTuneStatuses = statuses;
360                 getCiCamInfo(feConfig, frontendMap[id].canConnectToCiCam, frontendMap[id].ciCamId,
361                              frontendMap[id].removePid);
362             }
363         }
364     }
365 
readFilterConfig1_0TunerTestingConfigAidlReader1_0366     static void readFilterConfig1_0(map<string, FilterConfig>& filterMap) {
367         auto hardwareConfig = getHardwareConfig();
368         if (hardwareConfig.hasFilters()) {
369             auto filters = *hardwareConfig.getFirstFilters();
370             for (auto filterConfig : filters.getFilter()) {
371                 string id = filterConfig.getId();
372                 if (id.compare(string("FILTER_AUDIO_DEFAULT")) == 0) {
373                     // overrid default
374                     filterMap.erase(string("FILTER_AUDIO_DEFAULT"));
375                 }
376                 if (id.compare(string("FILTER_VIDEO_DEFAULT")) == 0) {
377                     // overrid default
378                     filterMap.erase(string("FILTER_VIDEO_DEFAULT"));
379                 }
380 
381                 DemuxFilterType type;
382                 DemuxFilterSettings settings;
383                 if (!readFilterTypeAndSettings(filterConfig, type, settings)) {
384                     ALOGW("[ConfigReader] invalid filter type");
385                     return;
386                 }
387                 filterMap[id].type = type;
388                 filterMap[id].bufferSize = filterConfig.getBufferSize();
389                 filterMap[id].getMqDesc = filterConfig.getUseFMQ();
390                 filterMap[id].settings = settings;
391 
392                 if (filterConfig.hasMonitorEventTypes()) {
393                     filterMap[id].monitorEventTypes = (int32_t)filterConfig.getMonitorEventTypes();
394                 }
395                 if (filterConfig.hasTimeDelayInMs()) {
396                     filterMap[id].timeDelayInMs = filterConfig.getTimeDelayInMs();
397                 }
398                 if (filterConfig.hasDataDelayInBytes()) {
399                     filterMap[id].dataDelayInBytes = filterConfig.getDataDelayInBytes();
400                 }
401                 if (filterConfig.hasAvFilterSettings_optional()) {
402                     auto av = filterConfig.getFirstAvFilterSettings_optional();
403                     if (av->hasAudioStreamType_optional()) {
404                         filterMap[id].streamType.set<AvStreamType::Tag::audio>(
405                                 static_cast<AudioStreamType>(av->getAudioStreamType_optional()));
406                     }
407                     if (av->hasVideoStreamType_optional()) {
408                         filterMap[id].streamType.set<AvStreamType::Tag::video>(
409                                 static_cast<VideoStreamType>(av->getVideoStreamType_optional()));
410                     }
411                 }
412                 if (filterConfig.hasIpFilterConfig_optional()) {
413                     auto ip = filterConfig.getFirstIpFilterConfig_optional();
414                     if (ip->hasIpCid()) {
415                         filterMap[id].ipCid = ip->getIpCid();
416                     }
417                 }
418             }
419         }
420     }
421 
readDvrConfig1_0TunerTestingConfigAidlReader1_0422     static void readDvrConfig1_0(map<string, DvrConfig>& dvrMap) {
423         auto hardwareConfig = getHardwareConfig();
424         if (hardwareConfig.hasDvrs()) {
425             auto dvrs = *hardwareConfig.getFirstDvrs();
426             for (auto dvrConfig : dvrs.getDvr()) {
427                 string id = dvrConfig.getId();
428                 DvrType type;
429                 switch (dvrConfig.getType()) {
430                     case DvrTypeEnum::PLAYBACK:
431                         playbackDvrIds.push_back(id);
432                         type = DvrType::PLAYBACK;
433                         dvrMap[id].settings.set<DvrSettings::Tag::playback>(
434                                 readPlaybackSettings(dvrConfig));
435                         break;
436                     case DvrTypeEnum::RECORD:
437                         recordDvrIds.push_back(id);
438                         type = DvrType::RECORD;
439                         dvrMap[id].settings.set<DvrSettings::Tag::record>(
440                                 readRecordSettings(dvrConfig));
441                         break;
442                     case DvrTypeEnum::UNKNOWN:
443                         ALOGW("[ConfigReader] invalid DVR type");
444                         return;
445                 }
446                 dvrMap[id].type = type;
447                 dvrMap[id].bufferSize = static_cast<int32_t>(dvrConfig.getBufferSize());
448                 if (dvrConfig.hasInputFilePath()) {
449                     dvrMap[id].playbackInputFile = dvrConfig.getInputFilePath();
450                 }
451             }
452         }
453     }
454 
readLnbConfig1_0TunerTestingConfigAidlReader1_0455     static void readLnbConfig1_0(map<string, LnbConfig>& lnbMap) {
456         auto hardwareConfig = getHardwareConfig();
457         if (hardwareConfig.hasLnbs()) {
458             auto lnbs = *hardwareConfig.getFirstLnbs();
459             for (auto lnbConfig : lnbs.getLnb()) {
460                 string id = lnbConfig.getId();
461                 lnbIds.push_back(id);
462                 if (lnbConfig.hasName()) {
463                     lnbMap[id].name = lnbConfig.getName();
464                 } else {
465                     lnbMap[id].name = emptyHardwareId;
466                 }
467                 lnbMap[id].voltage = static_cast<LnbVoltage>(lnbConfig.getVoltage());
468                 lnbMap[id].tone = static_cast<LnbTone>(lnbConfig.getTone());
469                 lnbMap[id].position = static_cast<LnbPosition>(lnbConfig.getPosition());
470             }
471         }
472     }
473 
readDescramblerConfig1_0TunerTestingConfigAidlReader1_0474     static void readDescramblerConfig1_0(map<string, DescramblerConfig>& descramblerMap) {
475         auto hardwareConfig = getHardwareConfig();
476         if (hardwareConfig.hasDescramblers()) {
477             auto descramblers = *hardwareConfig.getFirstDescramblers();
478             for (auto descramblerConfig : descramblers.getDescrambler()) {
479                 string id = descramblerConfig.getId();
480                 descramblerIds.push_back(id);
481                 descramblerMap[id].casSystemId =
482                         static_cast<int32_t>(descramblerConfig.getCasSystemId());
483                 if (descramblerConfig.hasProvisionStr()) {
484                     descramblerMap[id].provisionStr = descramblerConfig.getProvisionStr();
485                 } else {
486                     descramblerMap[id].provisionStr = PROVISION_STR;
487                 }
488                 if (descramblerConfig.hasSesstionPrivatData()) {
489                     auto privateData = descramblerConfig.getSesstionPrivatData();
490                     int size = privateData.size();
491                     descramblerMap[id].hidlPvtData.resize(size);
492                     memcpy(descramblerMap[id].hidlPvtData.data(), privateData.data(), size);
493                 } else {
494                     descramblerMap[id].hidlPvtData.resize(256);
495                 }
496             }
497         }
498     }
499 
readDiseqcMessagesTunerTestingConfigAidlReader1_0500     static void readDiseqcMessages(map<string, vector<uint8_t>>& diseqcMsgMap) {
501         auto hardwareConfig = getHardwareConfig();
502         if (hardwareConfig.hasDiseqcMessages()) {
503             auto msgs = *hardwareConfig.getFirstDiseqcMessages();
504             for (auto msgConfig : msgs.getDiseqcMessage()) {
505                 string name = msgConfig.getMsgName();
506                 diseqcMsgs.push_back(name);
507                 for (uint8_t atom : msgConfig.getMsgBody()) {
508                     diseqcMsgMap[name].push_back(atom);
509                 }
510             }
511         }
512     }
513 
readTimeFilterConfig1_0TunerTestingConfigAidlReader1_0514     static void readTimeFilterConfig1_0(map<string, TimeFilterConfig>& timeFilterMap) {
515         auto hardwareConfig = getHardwareConfig();
516         if (hardwareConfig.hasTimeFilters()) {
517             auto timeFilters = *hardwareConfig.getFirstTimeFilters();
518             for (auto timeFilterConfig : timeFilters.getTimeFilter()) {
519                 string id = timeFilterConfig.getId();
520                 timeFilterIds.push_back(id);
521                 timeFilterMap[id].timeStamp = static_cast<int64_t>(timeFilterConfig.getTimeStamp());
522             }
523         }
524     }
525 
connectLiveBroadcastTunerTestingConfigAidlReader1_0526     static void connectLiveBroadcast(LiveBroadcastHardwareConnections& live) {
527         auto dataFlow = getDataFlowConfiguration();
528         if (dataFlow.hasClearLiveBroadcast()) {
529             live.hasFrontendConnection = true;
530             configuredLive = true;
531         } else {
532             live.hasFrontendConnection = false;
533             return;
534         }
535         auto liveConfig = *dataFlow.getFirstClearLiveBroadcast();
536         live.frontendId = liveConfig.getFrontendConnection();
537 
538         live.audioFilterId = liveConfig.getAudioFilterConnection();
539         live.videoFilterId = liveConfig.getVideoFilterConnection();
540         if (liveConfig.hasPcrFilterConnection()) {
541             live.pcrFilterId = liveConfig.getPcrFilterConnection();
542         } else {
543             live.pcrFilterId = emptyHardwareId;
544         }
545         if (liveConfig.hasSectionFilterConnection()) {
546             live.sectionFilterId = liveConfig.getSectionFilterConnection();
547         } else {
548             live.sectionFilterId = emptyHardwareId;
549         }
550         if (liveConfig.hasDvrSoftwareFeConnection()) {
551             live.dvrSoftwareFeId = liveConfig.getDvrSoftwareFeConnection();
552         }
553         if (liveConfig.hasIpFilterConnection()) {
554             live.ipFilterId = liveConfig.getIpFilterConnection();
555         } else {
556             live.ipFilterId = emptyHardwareId;
557         }
558         if (liveConfig.hasOptionalFilters()) {
559             auto optionalFilters = liveConfig.getOptionalFilters();
560             live.extraFilters = optionalFilters;
561         }
562     }
563 
connectScanTunerTestingConfigAidlReader1_0564     static void connectScan(ScanHardwareConnections& scan) {
565         auto dataFlow = getDataFlowConfiguration();
566         if (dataFlow.hasScan()) {
567             scan.hasFrontendConnection = true;
568             configuredScan = true;
569         } else {
570             scan.hasFrontendConnection = false;
571             return;
572         }
573         auto scanConfig = *dataFlow.getFirstScan();
574         scan.frontendId = scanConfig.getFrontendConnection();
575     }
576 
connectDvrPlaybackTunerTestingConfigAidlReader1_0577     static void connectDvrPlayback(DvrPlaybackHardwareConnections& playback) {
578         auto dataFlow = getDataFlowConfiguration();
579         if (dataFlow.hasDvrPlayback()) {
580             playback.support = true;
581             configuredPlayback = true;
582         } else {
583             playback.support = false;
584             return;
585         }
586         auto playbackConfig = *dataFlow.getFirstDvrPlayback();
587         playback.dvrId = playbackConfig.getDvrConnection();
588         playback.audioFilterId = playbackConfig.getAudioFilterConnection();
589         playback.videoFilterId = playbackConfig.getVideoFilterConnection();
590         if (playbackConfig.hasSectionFilterConnection()) {
591             playback.sectionFilterId = playbackConfig.getSectionFilterConnection();
592         } else {
593             playback.sectionFilterId = emptyHardwareId;
594         }
595         if (playbackConfig.hasOptionalFilters()) {
596             auto optionalFilters = playbackConfig.getOptionalFilters();
597             playback.extraFilters = optionalFilters;
598         }
599     }
600 
connectDvrRecordTunerTestingConfigAidlReader1_0601     static void connectDvrRecord(DvrRecordHardwareConnections& record) {
602         auto dataFlow = getDataFlowConfiguration();
603         if (dataFlow.hasDvrRecord()) {
604             record.support = true;
605             configuredRecord = true;
606         } else {
607             record.support = false;
608             return;
609         }
610         auto recordConfig = *dataFlow.getFirstDvrRecord();
611         record.recordFilterId = recordConfig.getRecordFilterConnection();
612         record.dvrRecordId = recordConfig.getDvrRecordConnection();
613         if (recordConfig.hasDvrSoftwareFeConnection()) {
614             record.dvrSoftwareFeId = recordConfig.getDvrSoftwareFeConnection();
615         }
616         if (recordConfig.getHasFrontendConnection()) {
617             record.hasFrontendConnection = true;
618             record.dvrSourceId = emptyHardwareId;
619             record.frontendId = recordConfig.getFrontendConnection();
620         } else {
621             record.hasFrontendConnection = false;
622             record.dvrSourceId = recordConfig.getDvrSourceConnection();
623         }
624     }
625 
connectDescramblingTunerTestingConfigAidlReader1_0626     static void connectDescrambling(DescramblingHardwareConnections& descrambling) {
627         auto dataFlow = getDataFlowConfiguration();
628         if (dataFlow.hasDescrambling()) {
629             descrambling.support = true;
630             configuredDescrambling = true;
631         } else {
632             descrambling.support = false;
633             return;
634         }
635         auto descConfig = *dataFlow.getFirstDescrambling();
636         descrambling.descramblerId = descConfig.getDescramblerConnection();
637         descrambling.audioFilterId = descConfig.getAudioFilterConnection();
638         descrambling.videoFilterId = descConfig.getVideoFilterConnection();
639         if (descConfig.hasDvrSoftwareFeConnection()) {
640             descrambling.dvrSoftwareFeId = descConfig.getDvrSoftwareFeConnection();
641         }
642         if (descConfig.getHasFrontendConnection()) {
643             descrambling.hasFrontendConnection = true;
644             descrambling.dvrSourceId = emptyHardwareId;
645             descrambling.frontendId = descConfig.getFrontendConnection();
646         } else {
647             descrambling.hasFrontendConnection = false;
648             descrambling.dvrSourceId = descConfig.getDvrSourceConnection();
649         }
650         if (descConfig.hasOptionalFilters()) {
651             auto optionalFilters = descConfig.getOptionalFilters();
652             descrambling.extraFilters = optionalFilters;
653         }
654     }
655 
connectLnbLiveTunerTestingConfigAidlReader1_0656     static void connectLnbLive(LnbLiveHardwareConnections& lnbLive) {
657         auto dataFlow = getDataFlowConfiguration();
658         if (dataFlow.hasLnbLive()) {
659             lnbLive.support = true;
660             configuredLnbLive = true;
661         } else {
662             lnbLive.support = false;
663             return;
664         }
665         auto lnbLiveConfig = *dataFlow.getFirstLnbLive();
666         lnbLive.frontendId = lnbLiveConfig.getFrontendConnection();
667         lnbLive.audioFilterId = lnbLiveConfig.getAudioFilterConnection();
668         lnbLive.videoFilterId = lnbLiveConfig.getVideoFilterConnection();
669         lnbLive.lnbId = lnbLiveConfig.getLnbConnection();
670         if (lnbLiveConfig.hasDiseqcMsgSender()) {
671             for (auto msgName : lnbLiveConfig.getDiseqcMsgSender()) {
672                 lnbLive.diseqcMsgs.push_back(msgName);
673             }
674         }
675         if (lnbLiveConfig.hasOptionalFilters()) {
676             auto optionalFilters = lnbLiveConfig.getOptionalFilters();
677             lnbLive.extraFilters = optionalFilters;
678         }
679     }
680 
connectLnbRecordTunerTestingConfigAidlReader1_0681     static void connectLnbRecord(LnbRecordHardwareConnections& lnbRecord) {
682         auto dataFlow = getDataFlowConfiguration();
683         if (dataFlow.hasLnbRecord()) {
684             lnbRecord.support = true;
685             configuredLnbRecord = true;
686         } else {
687             lnbRecord.support = false;
688             return;
689         }
690         auto lnbRecordConfig = *dataFlow.getFirstLnbRecord();
691         lnbRecord.frontendId = lnbRecordConfig.getFrontendConnection();
692         lnbRecord.recordFilterId = lnbRecordConfig.getRecordFilterConnection();
693         lnbRecord.dvrRecordId = lnbRecordConfig.getDvrRecordConnection();
694         lnbRecord.lnbId = lnbRecordConfig.getLnbConnection();
695         if (lnbRecordConfig.hasDiseqcMsgSender()) {
696             for (auto msgName : lnbRecordConfig.getDiseqcMsgSender()) {
697                 lnbRecord.diseqcMsgs.push_back(msgName);
698             }
699         }
700         if (lnbRecordConfig.hasOptionalFilters()) {
701             auto optionalFilters = lnbRecordConfig.getOptionalFilters();
702             lnbRecord.extraFilters = optionalFilters;
703         }
704     }
705 
connectTimeFilterTunerTestingConfigAidlReader1_0706     static void connectTimeFilter(TimeFilterHardwareConnections& timeFilter) {
707         auto dataFlow = getDataFlowConfiguration();
708         if (dataFlow.hasTimeFilter()) {
709             timeFilter.support = true;
710             configuredTimeFilter = true;
711         } else {
712             timeFilter.support = false;
713             return;
714         }
715         auto timeFilterConfig = *dataFlow.getFirstTimeFilter();
716         timeFilter.timeFilterId = timeFilterConfig.getTimeFilterConnection();
717     }
718 
connectLnbDescramblingTunerTestingConfigAidlReader1_0719     static void connectLnbDescrambling(LnbDescramblingHardwareConnections& lnbDescrambling) {
720         auto dataFlow = getDataFlowConfiguration();
721         if (dataFlow.hasLnbDescrambling()) {
722             lnbDescrambling.support = true;
723             configuredLnbDescrambling = true;
724         } else {
725             lnbDescrambling.support = false;
726             return;
727         }
728         auto lnbDescramblingConfig = *dataFlow.getFirstLnbDescrambling();
729         lnbDescrambling.frontendId = lnbDescramblingConfig.getFrontendConnection();
730         lnbDescrambling.audioFilterId = lnbDescramblingConfig.getAudioFilterConnection();
731         lnbDescrambling.videoFilterId = lnbDescramblingConfig.getVideoFilterConnection();
732         lnbDescrambling.lnbId = lnbDescramblingConfig.getLnbConnection();
733         lnbDescrambling.descramblerId = lnbDescramblingConfig.getDescramblerConnection();
734         if (lnbDescramblingConfig.hasDiseqcMsgSender()) {
735             for (auto& msgName : lnbDescramblingConfig.getDiseqcMsgSender()) {
736                 lnbDescrambling.diseqcMsgs.push_back(msgName);
737             }
738         }
739     }
740 
741   private:
readDvbtFrontendSettingsTunerTestingConfigAidlReader1_0742     static FrontendDvbtSettings readDvbtFrontendSettings(Frontend feConfig) {
743         ALOGW("[ConfigReader] fe type is dvbt");
744         FrontendDvbtSettings dvbtSettings{
745                 .frequency = (int64_t)feConfig.getFrequency(),
746         };
747         if (feConfig.hasEndFrequency()) {
748             dvbtSettings.endFrequency = (int64_t)feConfig.getEndFrequency();
749         }
750         if (!feConfig.hasDvbtFrontendSettings_optional()) {
751             ALOGW("[ConfigReader] no more dvbt settings");
752             return dvbtSettings;
753         }
754         auto dvbt = feConfig.getFirstDvbtFrontendSettings_optional();
755         int32_t trans = static_cast<int32_t>(dvbt->getTransmissionMode());
756         dvbtSettings.transmissionMode = static_cast<FrontendDvbtTransmissionMode>(trans);
757         dvbtSettings.bandwidth = static_cast<FrontendDvbtBandwidth>(dvbt->getBandwidth());
758         dvbtSettings.isHighPriority = dvbt->getIsHighPriority();
759         dvbtSettings.hierarchy = static_cast<FrontendDvbtHierarchy>(dvbt->getHierarchy());
760         dvbtSettings.hpCoderate = static_cast<FrontendDvbtCoderate>(dvbt->getHpCoderate());
761         dvbtSettings.lpCoderate = static_cast<FrontendDvbtCoderate>(dvbt->getLpCoderate());
762         dvbtSettings.guardInterval =
763                 static_cast<FrontendDvbtGuardInterval>(dvbt->getGuardInterval());
764         dvbtSettings.standard = static_cast<FrontendDvbtStandard>(dvbt->getStandard());
765         dvbtSettings.isMiso = dvbt->getIsMiso();
766         dvbtSettings.plpMode = static_cast<FrontendDvbtPlpMode>(dvbt->getPlpMode());
767         dvbtSettings.plpId = dvbt->getPlpId();
768         dvbtSettings.plpGroupId = dvbt->getPlpGroupId();
769         if (dvbt->hasConstellation()) {
770             dvbtSettings.constellation =
771                     static_cast<FrontendDvbtConstellation>(dvbt->getConstellation());
772         }
773         return dvbtSettings;
774     }
775 
readDvbsFrontendSettingsTunerTestingConfigAidlReader1_0776     static FrontendDvbsSettings readDvbsFrontendSettings(Frontend feConfig) {
777         ALOGW("[ConfigReader] fe type is dvbs");
778         FrontendDvbsSettings dvbsSettings{
779                 .frequency = (int64_t)feConfig.getFrequency(),
780         };
781         if (feConfig.hasEndFrequency()) {
782             dvbsSettings.endFrequency = (int64_t)feConfig.getEndFrequency();
783         }
784         if (!feConfig.hasDvbsFrontendSettings_optional()) {
785             ALOGW("[ConfigReader] no more dvbs settings");
786             return dvbsSettings;
787         }
788         auto dvbs = feConfig.getFirstDvbsFrontendSettings_optional();
789         dvbsSettings.symbolRate = static_cast<int32_t>(dvbs->getSymbolRate());
790         dvbsSettings.inputStreamId = static_cast<int32_t>(dvbs->getInputStreamId());
791         dvbsSettings.scanType = static_cast<FrontendDvbsScanType>(dvbs->getScanType());
792         dvbsSettings.isDiseqcRxMessage = dvbs->getIsDiseqcRxMessage();
793         dvbsSettings.inversion = static_cast<FrontendSpectralInversion>(dvbs->getInversion());
794         dvbsSettings.modulation = static_cast<FrontendDvbsModulation>(dvbs->getModulation());
795         dvbsSettings.rolloff = static_cast<FrontendDvbsRolloff>(dvbs->getRolloff());
796         dvbsSettings.pilot = static_cast<FrontendDvbsPilot>(dvbs->getPilot());
797         dvbsSettings.standard = static_cast<FrontendDvbsStandard>(dvbs->getStandard());
798         dvbsSettings.vcmMode = static_cast<FrontendDvbsVcmMode>(dvbs->getVcmMode());
799         return dvbsSettings;
800     }
801 
readAtscFrontendSettingsTunerTestingConfigAidlReader1_0802     static FrontendAtscSettings readAtscFrontendSettings(Frontend& feConfig) {
803         ALOGW("[ConfigReader] fe type is atsc");
804         FrontendAtscSettings atscSettings{
805                 .frequency = (int64_t)feConfig.getFrequency(),
806         };
807         if (feConfig.hasEndFrequency()) {
808             atscSettings.endFrequency = (int64_t)feConfig.getEndFrequency();
809         }
810         if (!feConfig.hasAtscFrontendSettings_optional()) {
811             ALOGW("[ConfigReader] no more atsc settings");
812             return atscSettings;
813         }
814         auto atsc = feConfig.getFirstAtscFrontendSettings_optional();
815         atscSettings.inversion = static_cast<FrontendSpectralInversion>(atsc->getInversion());
816         atscSettings.modulation = static_cast<FrontendAtscModulation>(atsc->getModulation());
817         return atscSettings;
818     }
819 
readIsdbsFrontendSettingsTunerTestingConfigAidlReader1_0820     static FrontendIsdbsSettings readIsdbsFrontendSettings(Frontend& feConfig) {
821         ALOGW("[ConfigReader] fe type is isdbs");
822         FrontendIsdbsSettings isdbsSettings{.frequency = (int64_t)feConfig.getFrequency()};
823         if (feConfig.hasEndFrequency()) {
824             isdbsSettings.endFrequency = (int64_t)feConfig.getEndFrequency();
825         }
826         if (!feConfig.hasIsdbsFrontendSettings_optional()) {
827             ALOGW("[ConfigReader] no more isdbs settings");
828             return isdbsSettings;
829         }
830         auto isdbs = feConfig.getFirstIsdbsFrontendSettings_optional();
831         isdbsSettings.streamId = (int32_t)isdbs->getStreamId();
832         isdbsSettings.symbolRate = (int32_t)isdbs->getSymbolRate();
833         isdbsSettings.modulation = static_cast<FrontendIsdbsModulation>(isdbs->getModulation());
834         isdbsSettings.coderate = static_cast<FrontendIsdbsCoderate>(isdbs->getCoderate());
835         isdbsSettings.rolloff = static_cast<FrontendIsdbsRolloff>(isdbs->getRolloff());
836         isdbsSettings.streamIdType =
837                 static_cast<FrontendIsdbsStreamIdType>(isdbs->getStreamIdType());
838         return isdbsSettings;
839     }
840 
readIsdbtFrontendSettingsTunerTestingConfigAidlReader1_0841     static FrontendIsdbtSettings readIsdbtFrontendSettings(Frontend& feConfig) {
842         ALOGW("[ConfigReader] fe type is isdbt");
843         FrontendIsdbtSettings isdbtSettings{
844                 .frequency = (int64_t)feConfig.getFrequency(),
845         };
846         if (feConfig.hasEndFrequency()) {
847             isdbtSettings.endFrequency = (int64_t)feConfig.getEndFrequency();
848         }
849         if (!feConfig.hasIsdbtFrontendSettings_optional()) {
850             ALOGW("[ConfigReader] no more isdbt settings");
851             return isdbtSettings;
852         }
853         auto isdbt = feConfig.getFirstIsdbtFrontendSettings_optional();
854         isdbtSettings.inversion = static_cast<FrontendSpectralInversion>(isdbt->getInversion());
855         isdbtSettings.bandwidth = static_cast<FrontendIsdbtBandwidth>(isdbt->getBandwidth());
856         isdbtSettings.mode = static_cast<FrontendIsdbtMode>(isdbt->getMode());
857         isdbtSettings.guardInterval =
858                 static_cast<FrontendIsdbtGuardInterval>(isdbt->getGuardInterval());
859         isdbtSettings.serviceAreaId = (int32_t)isdbt->getServiceAreaId();
860         isdbtSettings.partialReceptionFlag =
861                 static_cast<FrontendIsdbtPartialReceptionFlag>(isdbt->getPartialReceptionFlag());
862         if (!isdbt->hasFrontendIsdbtLayerSettings()) {
863             ALOGW("[ConfigReader] no isdbt layer settings");
864             return isdbtSettings;
865         }
866         auto layerSettings = isdbt->getFirstFrontendIsdbtLayerSettings();
867         ::aidl::android::hardware::tv::tuner::FrontendIsdbtLayerSettings mLayerSettings;
868         mLayerSettings.modulation =
869                 static_cast<FrontendIsdbtModulation>(layerSettings->getModulation());
870         mLayerSettings.coderate = static_cast<FrontendIsdbtCoderate>(layerSettings->getCoderate());
871         mLayerSettings.timeInterleave =
872                 static_cast<FrontendIsdbtTimeInterleaveMode>(layerSettings->getTimeInterleave());
873         mLayerSettings.numOfSegment = (int32_t)layerSettings->getNumOfSegment();
874         isdbtSettings.layerSettings.push_back(mLayerSettings);
875         return isdbtSettings;
876     }
877 
readFilterTypeAndSettingsTunerTestingConfigAidlReader1_0878     static bool readFilterTypeAndSettings(Filter filterConfig, DemuxFilterType& type,
879                                           DemuxFilterSettings& settings) {
880         auto mainType = filterConfig.getMainType();
881         auto subType = filterConfig.getSubType();
882 
883         if (subType == FilterSubTypeEnum::AUDIO) {
884             audioFilterIds.push_back(filterConfig.getId());
885         } else if (subType == FilterSubTypeEnum::VIDEO) {
886             videoFilterIds.push_back(filterConfig.getId());
887         } else if (subType == FilterSubTypeEnum::RECORD) {
888             recordFilterIds.push_back(filterConfig.getId());
889         } else if (subType == FilterSubTypeEnum::SECTION) {
890             sectionFilterIds.push_back(filterConfig.getId());
891         } else if (subType == FilterSubTypeEnum::PCR) {
892             pcrFilterIds.push_back(filterConfig.getId());
893         } else if (subType == FilterSubTypeEnum::IP) {
894             ipFilterIds.push_back(filterConfig.getId());
895         }
896 
897         switch (mainType) {
898             case FilterMainTypeEnum::TS: {
899                 ALOGW("[ConfigReader] filter main type is ts");
900                 type.mainType = DemuxFilterMainType::TS;
901                 DemuxTsFilterSettings ts;
902                 bool isTsSet = false;
903                 switch (subType) {
904                     case FilterSubTypeEnum::UNDEFINED:
905                         type.subType.set<DemuxFilterSubType::Tag::tsFilterType>(
906                                 DemuxTsFilterType::UNDEFINED);
907                         break;
908                     case FilterSubTypeEnum::SECTION:
909                         type.subType.set<DemuxFilterSubType::Tag::tsFilterType>(
910                                 DemuxTsFilterType::SECTION);
911                         ts.filterSettings.set<DemuxTsFilterSettingsFilterSettings::Tag::section>(
912                                 readSectionFilterSettings(filterConfig));
913                         isTsSet = true;
914                         break;
915                     case FilterSubTypeEnum::PES:
916                         // TODO: b/182519645 support all the filter settings
917                         type.subType.set<DemuxFilterSubType::Tag::tsFilterType>(
918                                 DemuxTsFilterType::PES);
919                         break;
920                     case FilterSubTypeEnum::TS:
921                         type.subType.set<DemuxFilterSubType::Tag::tsFilterType>(
922                                 DemuxTsFilterType::TS);
923                         ts.filterSettings.set<DemuxTsFilterSettingsFilterSettings::Tag::noinit>(
924                                 true);
925                         isTsSet = true;
926                         break;
927                     case FilterSubTypeEnum::PCR:
928                         type.subType.set<DemuxFilterSubType::Tag::tsFilterType>(
929                                 DemuxTsFilterType::PCR);
930                         ts.filterSettings.set<DemuxTsFilterSettingsFilterSettings::Tag::noinit>(
931                                 true);
932                         isTsSet = true;
933                         break;
934                     case FilterSubTypeEnum::TEMI:
935                         type.subType.set<DemuxFilterSubType::Tag::tsFilterType>(
936                                 DemuxTsFilterType::TEMI);
937                         ts.filterSettings.set<DemuxTsFilterSettingsFilterSettings::Tag::noinit>(
938                                 true);
939                         isTsSet = true;
940                         break;
941                     case FilterSubTypeEnum::AUDIO:
942                         type.subType.set<DemuxFilterSubType::Tag::tsFilterType>(
943                                 DemuxTsFilterType::AUDIO);
944                         ts.filterSettings.set<DemuxTsFilterSettingsFilterSettings::Tag::av>(
945                                 readAvFilterSettings(filterConfig));
946                         isTsSet = true;
947                         break;
948                     case FilterSubTypeEnum::VIDEO:
949                         type.subType.set<DemuxFilterSubType::Tag::tsFilterType>(
950                                 DemuxTsFilterType::VIDEO);
951                         ts.filterSettings.set<DemuxTsFilterSettingsFilterSettings::Tag::av>(
952                                 readAvFilterSettings(filterConfig));
953                         isTsSet = true;
954                         break;
955                     case FilterSubTypeEnum::RECORD:
956                         type.subType.set<DemuxFilterSubType::Tag::tsFilterType>(
957                                 DemuxTsFilterType::RECORD);
958                         ts.filterSettings.set<DemuxTsFilterSettingsFilterSettings::Tag::record>(
959                                 readRecordFilterSettings(filterConfig));
960                         isTsSet = true;
961                         break;
962                     default:
963                         ALOGW("[ConfigReader] ts subtype is not supported");
964                         return false;
965                 }
966                 if (filterConfig.hasPid()) {
967                     ts.tpid = static_cast<int32_t>(filterConfig.getPid());
968                     isTsSet = true;
969                 }
970                 if (isTsSet) {
971                     settings.set<DemuxFilterSettings::Tag::ts>(ts);
972                 }
973                 break;
974             }
975             case FilterMainTypeEnum::MMTP: {
976                 ALOGW("[ConfigReader] filter main type is mmtp");
977                 type.mainType = DemuxFilterMainType::MMTP;
978                 DemuxMmtpFilterSettings mmtp;
979                 bool isMmtpSet = false;
980                 switch (subType) {
981                     case FilterSubTypeEnum::UNDEFINED:
982                         type.subType.set<DemuxFilterSubType::Tag::mmtpFilterType>(
983                                 DemuxMmtpFilterType::UNDEFINED);
984                         break;
985                     case FilterSubTypeEnum::SECTION:
986                         type.subType.set<DemuxFilterSubType::Tag::mmtpFilterType>(
987                                 DemuxMmtpFilterType::SECTION);
988                         mmtp.filterSettings
989                                 .set<DemuxMmtpFilterSettingsFilterSettings::Tag::section>(
990                                         readSectionFilterSettings(filterConfig));
991                         isMmtpSet = true;
992                         break;
993                     case FilterSubTypeEnum::PES:
994                         type.subType.set<DemuxFilterSubType::Tag::mmtpFilterType>(
995                                 DemuxMmtpFilterType::PES);
996                         // TODO: b/182519645 support all the filter settings
997                         break;
998                     case FilterSubTypeEnum::MMTP:
999                         type.subType.set<DemuxFilterSubType::Tag::mmtpFilterType>(
1000                                 DemuxMmtpFilterType::MMTP);
1001                         mmtp.filterSettings.set<DemuxMmtpFilterSettingsFilterSettings::Tag::noinit>(
1002                                 true);
1003                         isMmtpSet = true;
1004                         break;
1005                     case FilterSubTypeEnum::AUDIO:
1006                         type.subType.set<DemuxFilterSubType::Tag::mmtpFilterType>(
1007                                 DemuxMmtpFilterType::AUDIO);
1008                         mmtp.filterSettings.set<DemuxMmtpFilterSettingsFilterSettings::Tag::av>(
1009                                 readAvFilterSettings(filterConfig));
1010                         isMmtpSet = true;
1011                         break;
1012                     case FilterSubTypeEnum::VIDEO:
1013                         type.subType.set<DemuxFilterSubType::Tag::mmtpFilterType>(
1014                                 DemuxMmtpFilterType::VIDEO);
1015                         mmtp.filterSettings.set<DemuxMmtpFilterSettingsFilterSettings::Tag::av>(
1016                                 readAvFilterSettings(filterConfig));
1017                         isMmtpSet = true;
1018                         break;
1019                     case FilterSubTypeEnum::RECORD:
1020                         type.subType.set<DemuxFilterSubType::Tag::mmtpFilterType>(
1021                                 DemuxMmtpFilterType::RECORD);
1022                         mmtp.filterSettings.set<DemuxMmtpFilterSettingsFilterSettings::Tag::record>(
1023                                 readRecordFilterSettings(filterConfig));
1024                         isMmtpSet = true;
1025                         break;
1026                     case FilterSubTypeEnum::DOWNLOAD:
1027                         type.subType.set<DemuxFilterSubType::Tag::mmtpFilterType>(
1028                                 DemuxMmtpFilterType::DOWNLOAD);
1029                         // TODO: b/182519645 support all the filter settings
1030                         break;
1031                     default:
1032                         ALOGW("[ConfigReader] mmtp subtype is not supported");
1033                         return false;
1034                 }
1035                 if (filterConfig.hasPid()) {
1036                     mmtp.mmtpPid = static_cast<int32_t>(filterConfig.getPid());
1037                     isMmtpSet = true;
1038                 }
1039                 if (isMmtpSet) {
1040                     settings.set<DemuxFilterSettings::Tag::mmtp>(mmtp);
1041                 }
1042                 break;
1043             }
1044             case FilterMainTypeEnum::IP: {
1045                 ALOGW("[ConfigReader] filter main type is ip");
1046                 type.mainType = DemuxFilterMainType::IP;
1047                 DemuxIpFilterSettings ip;
1048                 switch (subType) {
1049                     case FilterSubTypeEnum::UNDEFINED:
1050                         type.subType.set<DemuxFilterSubType::Tag::ipFilterType>(
1051                                 DemuxIpFilterType::UNDEFINED);
1052                         break;
1053                     case FilterSubTypeEnum::SECTION:
1054                         type.subType.set<DemuxFilterSubType::Tag::ipFilterType>(
1055                                 DemuxIpFilterType::SECTION);
1056                         ip.filterSettings.set<DemuxIpFilterSettingsFilterSettings::Tag::section>(
1057                                 readSectionFilterSettings(filterConfig));
1058                         settings.set<DemuxFilterSettings::Tag::ip>(ip);
1059                         break;
1060                     case FilterSubTypeEnum::NTP:
1061                         type.subType.set<DemuxFilterSubType::Tag::ipFilterType>(
1062                                 DemuxIpFilterType::NTP);
1063                         ip.filterSettings.set<DemuxIpFilterSettingsFilterSettings::Tag::noinit>(
1064                                 true);
1065                         settings.set<DemuxFilterSettings::Tag::ip>(ip);
1066                         break;
1067                     case FilterSubTypeEnum::IP: {
1068                         type.subType.set<DemuxFilterSubType::Tag::ipFilterType>(
1069                                 DemuxIpFilterType::IP);
1070                         ip.ipAddr = readIpAddress(filterConfig),
1071                         ip.filterSettings
1072                                 .set<DemuxIpFilterSettingsFilterSettings::Tag::bPassthrough>(
1073                                         readPassthroughSettings(filterConfig));
1074                         settings.set<DemuxFilterSettings::Tag::ip>(ip);
1075                         break;
1076                     }
1077                     case FilterSubTypeEnum::IP_PAYLOAD:
1078                         type.subType.set<DemuxFilterSubType::Tag::ipFilterType>(
1079                                 DemuxIpFilterType::IP_PAYLOAD);
1080                         ip.filterSettings.set<DemuxIpFilterSettingsFilterSettings::Tag::noinit>(
1081                                 true);
1082                         settings.set<DemuxFilterSettings::Tag::ip>(ip);
1083                         break;
1084                     case FilterSubTypeEnum::PAYLOAD_THROUGH:
1085                         type.subType.set<DemuxFilterSubType::Tag::ipFilterType>(
1086                                 DemuxIpFilterType::PAYLOAD_THROUGH);
1087                         ip.filterSettings.set<DemuxIpFilterSettingsFilterSettings::Tag::noinit>(
1088                                 true);
1089                         settings.set<DemuxFilterSettings::Tag::ip>(ip);
1090                         break;
1091                     default:
1092                         ALOGW("[ConfigReader] mmtp subtype is not supported");
1093                         return false;
1094                 }
1095                 break;
1096             }
1097             default:
1098                 // TODO: b/182519645 support all the filter configs
1099                 ALOGW("[ConfigReader] filter main type is not supported in dynamic config");
1100                 return false;
1101         }
1102         return true;
1103     }
1104 
readIpAddressTunerTestingConfigAidlReader1_01105     static DemuxIpAddress readIpAddress(Filter filterConfig) {
1106         DemuxIpAddress ipAddress;
1107         vector<uint8_t> data;
1108         if (!filterConfig.hasIpFilterConfig_optional()) {
1109             return ipAddress;
1110         }
1111         auto ipFilterConfig = filterConfig.getFirstIpFilterConfig_optional();
1112         if (ipFilterConfig->hasSrcPort()) {
1113             ipAddress.srcPort = ipFilterConfig->getSrcPort();
1114         }
1115         if (ipFilterConfig->hasDestPort()) {
1116             ipAddress.dstPort = ipFilterConfig->getDestPort();
1117         }
1118         if (ipFilterConfig->getFirstSrcIpAddress()->getIsIpV4()) {
1119             data.resize(4);
1120             memcpy(data.data(), ipFilterConfig->getFirstSrcIpAddress()->getIp().data(), 4);
1121             ipAddress.srcIpAddress.set<DemuxIpAddressIpAddress::Tag::v4>(data);
1122         } else {
1123             data.resize(6);
1124             memcpy(data.data(), ipFilterConfig->getFirstSrcIpAddress()->getIp().data(), 6);
1125             ipAddress.srcIpAddress.set<DemuxIpAddressIpAddress::Tag::v6>(data);
1126         }
1127         if (ipFilterConfig->getFirstDestIpAddress()->getIsIpV4()) {
1128             data.resize(4);
1129             memcpy(data.data(), ipFilterConfig->getFirstDestIpAddress()->getIp().data(), 4);
1130             ipAddress.dstIpAddress.set<DemuxIpAddressIpAddress::Tag::v4>(data);
1131         } else {
1132             data.resize(6);
1133             memcpy(data.data(), ipFilterConfig->getFirstDestIpAddress()->getIp().data(), 6);
1134             ipAddress.dstIpAddress.set<DemuxIpAddressIpAddress::Tag::v6>(data);
1135         }
1136         return ipAddress;
1137     }
1138 
readPassthroughSettingsTunerTestingConfigAidlReader1_01139     static bool readPassthroughSettings(Filter filterConfig) {
1140         if (!filterConfig.hasIpFilterConfig_optional()) {
1141             return false;
1142         }
1143         auto ipFilterConfig = filterConfig.getFirstIpFilterConfig_optional();
1144         if (ipFilterConfig->hasDataPassthrough()) {
1145             return ipFilterConfig->getDataPassthrough();
1146         }
1147         return false;
1148     }
1149 
readSectionFilterSettingsTunerTestingConfigAidlReader1_01150     static DemuxFilterSectionSettings readSectionFilterSettings(Filter filterConfig) {
1151         DemuxFilterSectionSettings settings;
1152         if (!filterConfig.hasSectionFilterSettings_optional()) {
1153             return settings;
1154         }
1155         auto section = filterConfig.getFirstSectionFilterSettings_optional();
1156         settings.isCheckCrc = section->getIsCheckCrc();
1157         settings.isRepeat = section->getIsRepeat();
1158         settings.isRaw = section->getIsRaw();
1159         settings.bitWidthOfLengthField = section->getBitWidthOfLengthField();
1160         return settings;
1161     }
1162 
readAvFilterSettingsTunerTestingConfigAidlReader1_01163     static DemuxFilterAvSettings readAvFilterSettings(Filter filterConfig) {
1164         DemuxFilterAvSettings settings;
1165         if (!filterConfig.hasAvFilterSettings_optional()) {
1166             return settings;
1167         }
1168         auto av = filterConfig.getFirstAvFilterSettings_optional();
1169         settings.isPassthrough = av->getIsPassthrough();
1170         settings.isSecureMemory = av->getIsSecureMemory();
1171         return settings;
1172     }
1173 
readRecordFilterSettingsTunerTestingConfigAidlReader1_01174     static DemuxFilterRecordSettings readRecordFilterSettings(Filter filterConfig) {
1175         DemuxFilterRecordSettings settings;
1176         if (!filterConfig.hasRecordFilterSettings_optional()) {
1177             return settings;
1178         }
1179         auto record = filterConfig.getFirstRecordFilterSettings_optional();
1180         settings.tsIndexMask = record->getTsIndexMask();
1181         settings.scIndexType = static_cast<DemuxRecordScIndexType>(record->getScIndexType());
1182         return settings;
1183     }
1184 
readPlaybackSettingsTunerTestingConfigAidlReader1_01185     static PlaybackSettings readPlaybackSettings(Dvr dvrConfig) {
1186         ALOGW("[ConfigReader] dvr type is playback");
1187         PlaybackSettings playbackSettings{
1188                 .statusMask = static_cast<int8_t>(dvrConfig.getStatusMask()),
1189                 .lowThreshold = static_cast<int64_t>(dvrConfig.getLowThreshold()),
1190                 .highThreshold = static_cast<int64_t>(dvrConfig.getHighThreshold()),
1191                 .dataFormat = static_cast<DataFormat>(dvrConfig.getDataFormat()),
1192                 .packetSize = static_cast<int64_t>(dvrConfig.getPacketSize()),
1193         };
1194         return playbackSettings;
1195     }
1196 
readRecordSettingsTunerTestingConfigAidlReader1_01197     static RecordSettings readRecordSettings(Dvr dvrConfig) {
1198         ALOGW("[ConfigReader] dvr type is record");
1199         RecordSettings recordSettings{
1200                 .statusMask = static_cast<int8_t>(dvrConfig.getStatusMask()),
1201                 .lowThreshold = static_cast<int64_t>(dvrConfig.getLowThreshold()),
1202                 .highThreshold = static_cast<int64_t>(dvrConfig.getHighThreshold()),
1203                 .dataFormat = static_cast<DataFormat>(dvrConfig.getDataFormat()),
1204                 .packetSize = static_cast<int64_t>(dvrConfig.getPacketSize()),
1205         };
1206         return recordSettings;
1207     }
1208 
getCiCamInfoTunerTestingConfigAidlReader1_01209     static void getCiCamInfo(Frontend feConfig, bool& canConnectToCiCam, int32_t& ciCamId,
1210                              int32_t& removePid) {
1211         if (!feConfig.hasConnectToCicamId()) {
1212             canConnectToCiCam = false;
1213             ciCamId = -1;
1214             removePid = -1;
1215             return;
1216         }
1217         canConnectToCiCam = true;
1218         ciCamId = static_cast<int32_t>(feConfig.getConnectToCicamId());
1219         removePid = static_cast<int32_t>(feConfig.getRemoveOutputPid());
1220     }
1221 };
1222