• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 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 #define LOG_TAG "FrontendClient"
18 
19 #include <android-base/logging.h>
20 #include <utils/Log.h>
21 
22 #include "FrontendClient.h"
23 
24 using ::aidl::android::media::tv::tuner::TunerFrontendScanAtsc3PlpInfo;
25 using ::aidl::android::media::tv::tuner::TunerFrontendUnionSettings;
26 
27 using ::android::hardware::tv::tuner::V1_0::FrontendAnalogSifStandard;
28 using ::android::hardware::tv::tuner::V1_0::FrontendAnalogType;
29 using ::android::hardware::tv::tuner::V1_0::FrontendAtscModulation;
30 using ::android::hardware::tv::tuner::V1_0::FrontendAtsc3Bandwidth;
31 using ::android::hardware::tv::tuner::V1_0::FrontendAtsc3Modulation;
32 using ::android::hardware::tv::tuner::V1_0::FrontendAtsc3TimeInterleaveMode;
33 using ::android::hardware::tv::tuner::V1_0::FrontendDvbcAnnex;
34 using ::android::hardware::tv::tuner::V1_0::FrontendDvbcModulation;
35 using ::android::hardware::tv::tuner::V1_0::FrontendDvbcSpectralInversion;
36 using ::android::hardware::tv::tuner::V1_0::FrontendDvbsModulation;
37 using ::android::hardware::tv::tuner::V1_0::FrontendDvbsStandard;
38 using ::android::hardware::tv::tuner::V1_0::FrontendDvbsRolloff;
39 using ::android::hardware::tv::tuner::V1_0::FrontendDvbtBandwidth;
40 using ::android::hardware::tv::tuner::V1_0::FrontendDvbtGuardInterval;
41 using ::android::hardware::tv::tuner::V1_0::FrontendDvbtHierarchy;
42 using ::android::hardware::tv::tuner::V1_0::FrontendDvbtStandard;
43 using ::android::hardware::tv::tuner::V1_0::FrontendInnerFec;
44 using ::android::hardware::tv::tuner::V1_0::FrontendIsdbsModulation;
45 using ::android::hardware::tv::tuner::V1_0::FrontendIsdbsRolloff;
46 using ::android::hardware::tv::tuner::V1_0::FrontendIsdbs3Modulation;
47 using ::android::hardware::tv::tuner::V1_0::FrontendIsdbs3Rolloff;
48 using ::android::hardware::tv::tuner::V1_0::FrontendIsdbtBandwidth;
49 using ::android::hardware::tv::tuner::V1_0::FrontendIsdbtGuardInterval;
50 using ::android::hardware::tv::tuner::V1_0::FrontendIsdbtMode;
51 using ::android::hardware::tv::tuner::V1_0::FrontendIsdbtModulation;
52 using ::android::hardware::tv::tuner::V1_0::FrontendModulationStatus;
53 using ::android::hardware::tv::tuner::V1_0::FrontendScanAtsc3PlpInfo;
54 using ::android::hardware::tv::tuner::V1_0::FrontendStatusAtsc3PlpInfo;
55 using ::android::hardware::tv::tuner::V1_0::LnbVoltage;
56 using ::android::hardware::tv::tuner::V1_1::Constant;
57 using ::android::hardware::tv::tuner::V1_1::FrontendBandwidth;
58 using ::android::hardware::tv::tuner::V1_1::FrontendCableTimeInterleaveMode;
59 using ::android::hardware::tv::tuner::V1_1::FrontendDtmbBandwidth;
60 using ::android::hardware::tv::tuner::V1_1::FrontendDtmbGuardInterval;
61 using ::android::hardware::tv::tuner::V1_1::FrontendDtmbModulation;
62 using ::android::hardware::tv::tuner::V1_1::FrontendDtmbTimeInterleaveMode;
63 using ::android::hardware::tv::tuner::V1_1::FrontendDtmbTransmissionMode;
64 using ::android::hardware::tv::tuner::V1_1::FrontendDvbcBandwidth;
65 using ::android::hardware::tv::tuner::V1_1::FrontendDvbtConstellation;
66 using ::android::hardware::tv::tuner::V1_1::FrontendDvbtTransmissionMode;
67 using ::android::hardware::tv::tuner::V1_1::FrontendGuardInterval;
68 using ::android::hardware::tv::tuner::V1_1::FrontendInterleaveMode;
69 using ::android::hardware::tv::tuner::V1_1::FrontendModulation;
70 using ::android::hardware::tv::tuner::V1_1::FrontendRollOff;
71 using ::android::hardware::tv::tuner::V1_1::FrontendSpectralInversion;
72 using ::android::hardware::tv::tuner::V1_1::FrontendTransmissionMode;
73 using ::android::hardware::tv::tuner::V1_1::FrontendType;
74 
75 namespace android {
76 
77 /////////////// FrontendClient ///////////////////////
78 
FrontendClient(shared_ptr<ITunerFrontend> tunerFrontend,int type)79 FrontendClient::FrontendClient(shared_ptr<ITunerFrontend> tunerFrontend, int type) {
80     mTunerFrontend = tunerFrontend;
81     mType = type;
82 }
83 
~FrontendClient()84 FrontendClient::~FrontendClient() {
85     mTunerFrontend = NULL;
86     mFrontend = NULL;
87     mFrontend_1_1 = NULL;
88     mId = -1;
89     mType = -1;
90 }
91 
setCallback(sp<FrontendClientCallback> frontendClientCallback)92 Result FrontendClient::setCallback(sp<FrontendClientCallback> frontendClientCallback) {
93     if (mTunerFrontend != NULL) {
94         shared_ptr<TunerFrontendCallback> aidlCallback =
95                 ::ndk::SharedRefBase::make<TunerFrontendCallback>(frontendClientCallback);
96         aidlCallback->setFrontendType(mType);
97         Status s = mTunerFrontend->setCallback(aidlCallback);
98         return ClientHelper::getServiceSpecificErrorCode(s);
99     }
100 
101     sp<HidlFrontendCallback> hidlCallback = new HidlFrontendCallback(frontendClientCallback);
102     return mFrontend->setCallback(hidlCallback);
103 }
104 
setHidlFrontend(sp<IFrontend> frontend)105 void FrontendClient::setHidlFrontend(sp<IFrontend> frontend) {
106     mFrontend = frontend;
107     mFrontend_1_1 = ::android::hardware::tv::tuner::V1_1::IFrontend::castFrom(mFrontend);
108 }
109 
110 // TODO: move after migration is done
setId(int id)111 void FrontendClient::setId(int id) {
112     mId = id;
113 }
114 
tune(const FrontendSettings & settings,const FrontendSettingsExt1_1 & settingsExt1_1)115 Result FrontendClient::tune(const FrontendSettings& settings,
116         const FrontendSettingsExt1_1& settingsExt1_1) {
117     if (mTunerFrontend != NULL) {
118         TunerFrontendSettings tunerFeSettings = getAidlFrontendSettings(settings, settingsExt1_1);
119         Status s = mTunerFrontend->tune(tunerFeSettings);
120         return ClientHelper::getServiceSpecificErrorCode(s);
121     }
122 
123     Result result;
124     if (mFrontend_1_1 != NULL && validateExtendedSettings(settingsExt1_1)) {
125         result = mFrontend_1_1->tune_1_1(settings, settingsExt1_1);
126         return result;
127     }
128 
129     if (mFrontend != NULL) {
130         result = mFrontend->tune(settings);
131         return result;
132     }
133 
134     return Result::INVALID_STATE;
135 }
136 
stopTune()137 Result FrontendClient::stopTune() {
138     if (mTunerFrontend != NULL) {
139         Status s = mTunerFrontend->stopTune();
140         return ClientHelper::getServiceSpecificErrorCode(s);
141     }
142 
143     if (mFrontend != NULL) {
144         Result result = mFrontend->stopTune();
145         return result;
146     }
147 
148     return Result::INVALID_STATE;
149 }
150 
scan(const FrontendSettings & settings,FrontendScanType type,const FrontendSettingsExt1_1 & settingsExt1_1)151 Result FrontendClient::scan(const FrontendSettings& settings, FrontendScanType type,
152         const FrontendSettingsExt1_1& settingsExt1_1) {
153     if (mTunerFrontend != NULL) {
154         TunerFrontendSettings tunerFeSettings = getAidlFrontendSettings(settings, settingsExt1_1);
155         Status s = mTunerFrontend->scan(tunerFeSettings, (int)type);
156         return ClientHelper::getServiceSpecificErrorCode(s);
157     }
158 
159     Result result;
160     if (mFrontend_1_1 != NULL && validateExtendedSettings(settingsExt1_1)) {
161         result = mFrontend_1_1->scan_1_1(settings, type, settingsExt1_1);
162         return result;
163     }
164 
165     if (mFrontend != NULL) {
166         result = mFrontend->scan(settings, type);
167         return result;
168     }
169 
170     return Result::INVALID_STATE;
171 }
172 
stopScan()173 Result FrontendClient::stopScan() {
174     if (mTunerFrontend != NULL) {
175         Status s = mTunerFrontend->stopScan();
176         return ClientHelper::getServiceSpecificErrorCode(s);
177     }
178 
179     if (mFrontend != NULL) {
180         Result result = mFrontend->stopScan();
181         return result;
182     }
183 
184     return Result::INVALID_STATE;
185 }
186 
getStatus(vector<FrontendStatusType> statusTypes)187 vector<FrontendStatus> FrontendClient::getStatus(vector<FrontendStatusType> statusTypes) {
188     vector<FrontendStatus> status;
189 
190     if (mTunerFrontend != NULL) {
191         vector<TunerFrontendStatus> aidlStatus;
192         vector<int> types;
193         for (auto t : statusTypes) {
194             types.push_back((int)t);
195         }
196         Status s = mTunerFrontend->getStatus(types, &aidlStatus);
197         if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS) {
198             return status;
199         }
200         return getHidlStatus(aidlStatus);
201     }
202 
203     if (mFrontend != NULL && statusTypes.size() > 0) {
204         Result res;
205         mFrontend->getStatus(statusTypes,
206                 [&](Result r, const hidl_vec<FrontendStatus>& s) {
207                     res = r;
208                     status = s;
209                 });
210         if (res != Result::SUCCESS) {
211             status.clear();
212             return status;
213         }
214     }
215 
216     return status;
217 }
218 
getStatusExtended_1_1(vector<FrontendStatusTypeExt1_1> statusTypes)219 vector<FrontendStatusExt1_1> FrontendClient::getStatusExtended_1_1(
220         vector<FrontendStatusTypeExt1_1> statusTypes) {
221     vector<FrontendStatusExt1_1> status;
222 
223     if (mTunerFrontend != NULL) {
224         vector<TunerFrontendStatus> aidlStatus;
225         vector<int> types;
226         for (auto t : statusTypes) {
227             types.push_back((int)t);
228         }
229         Status s = mTunerFrontend->getStatusExtended_1_1(types, &aidlStatus);
230         if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS) {
231             return status;
232         }
233         return getHidlStatusExt(aidlStatus);
234     }
235 
236     if (mFrontend_1_1 != NULL && statusTypes.size() > 0) {
237         Result res;
238         mFrontend_1_1->getStatusExt1_1(statusTypes,
239             [&](Result r, const hidl_vec<FrontendStatusExt1_1>& s) {
240                 res = r;
241                 status = s;
242             });
243         if (res != Result::SUCCESS) {
244             status.clear();
245             return status;
246         }
247     }
248 
249     return status;
250 }
251 
setLnb(sp<LnbClient> lnbClient)252 Result FrontendClient::setLnb(sp<LnbClient> lnbClient) {
253     if (mTunerFrontend != NULL) {
254         Status s = mTunerFrontend->setLnb(lnbClient->getAidlLnb());
255         return ClientHelper::getServiceSpecificErrorCode(s);
256     }
257 
258     if (mFrontend != NULL) {
259         Result result = mFrontend->setLnb(lnbClient->getId());
260         return result;
261     }
262 
263     return Result::INVALID_STATE;
264 }
265 
setLna(bool bEnable)266 Result FrontendClient::setLna(bool bEnable) {
267     if (mTunerFrontend != NULL) {
268         Status s = mTunerFrontend->setLna(bEnable);
269         return ClientHelper::getServiceSpecificErrorCode(s);
270     }
271 
272     if (mFrontend != NULL) {
273         Result result = mFrontend->setLna(bEnable);
274         return result;
275     }
276 
277     return Result::INVALID_STATE;
278 }
279 
linkCiCamToFrontend(int ciCamId)280 int FrontendClient::linkCiCamToFrontend(int ciCamId) {
281     int ltsId = (int)Constant::INVALID_LTS_ID;
282 
283     if (mTunerFrontend != NULL) {
284         Status s = mTunerFrontend->linkCiCamToFrontend(ciCamId, &ltsId);
285         if (ClientHelper::getServiceSpecificErrorCode(s) == Result::SUCCESS) {
286             return ltsId;
287         }
288         return (int)Constant::INVALID_LTS_ID;
289     }
290 
291     if (mFrontend_1_1 != NULL) {
292         Result res;
293         mFrontend_1_1->linkCiCam(static_cast<uint32_t>(ciCamId),
294             [&](Result r, uint32_t id) {
295                 res = r;
296                 ltsId = id;
297             });
298         if (res != Result::SUCCESS) {
299             return (int)Constant::INVALID_LTS_ID;
300         }
301     }
302 
303     return ltsId;
304 }
305 
unlinkCiCamToFrontend(int ciCamId)306 Result FrontendClient::unlinkCiCamToFrontend(int ciCamId) {
307     if (mTunerFrontend != NULL) {
308         Status s = mTunerFrontend->unlinkCiCamToFrontend(ciCamId);
309         return ClientHelper::getServiceSpecificErrorCode(s);
310     }
311 
312     if (mFrontend_1_1 != NULL) {
313         return mFrontend_1_1->unlinkCiCam(static_cast<uint32_t>(ciCamId));
314     }
315 
316     return Result::INVALID_STATE;
317 }
318 
close()319 Result FrontendClient::close() {
320     if (mTunerFrontend != NULL) {
321         Status s = mTunerFrontend->close();
322         mTunerFrontend = NULL;
323         return ClientHelper::getServiceSpecificErrorCode(s);
324     }
325 
326     if (mFrontend != NULL) {
327         Result result = mFrontend->close();
328         mFrontend = NULL;
329         mFrontend_1_1 = NULL;
330         return result;
331     }
332 
333     return Result::INVALID_STATE;
334 }
335 
336 /////////////// TunerFrontend Helper Methods ///////////////////////
337 
getAidlFrontend()338 shared_ptr<ITunerFrontend> FrontendClient::getAidlFrontend() {
339     return mTunerFrontend;
340 }
341 
getId()342 int FrontendClient::getId() {
343     if (mTunerFrontend != NULL) {
344         Status s = mTunerFrontend->getFrontendId(&mId);
345         if (ClientHelper::getServiceSpecificErrorCode(s) == Result::SUCCESS) {
346             return mId;
347         }
348         ALOGE("Failed to getFrontendId from Tuner Frontend");
349         return -1;
350     }
351 
352     if (mFrontend != NULL) {
353         return mId;
354     }
355 
356     return -1;
357 }
358 
getHidlStatus(vector<TunerFrontendStatus> & aidlStatus)359 vector<FrontendStatus> FrontendClient::getHidlStatus(vector<TunerFrontendStatus>& aidlStatus) {
360     vector<FrontendStatus> hidlStatus;
361     for (TunerFrontendStatus s : aidlStatus) {
362         FrontendStatus status = FrontendStatus();
363         switch (s.getTag()) {
364             case TunerFrontendStatus::isDemodLocked: {
365                 status.isDemodLocked(s.get<TunerFrontendStatus::isDemodLocked>());
366                 hidlStatus.push_back(status);
367                 break;
368             }
369             case TunerFrontendStatus::snr: {
370                 status.snr(s.get<TunerFrontendStatus::snr>());
371                 hidlStatus.push_back(status);
372                 break;
373             }
374             case TunerFrontendStatus::ber: {
375                 status.ber((uint32_t)s.get<TunerFrontendStatus::ber>());
376                 hidlStatus.push_back(status);
377                 break;
378             }
379             case TunerFrontendStatus::per: {
380                 status.per((uint32_t)s.get<TunerFrontendStatus::per>());
381                 hidlStatus.push_back(status);
382                 break;
383             }
384             case TunerFrontendStatus::preBer: {
385                 status.preBer((uint32_t)s.get<TunerFrontendStatus::preBer>());
386                 hidlStatus.push_back(status);
387                 break;
388             }
389             case TunerFrontendStatus::signalQuality: {
390                 status.signalQuality((uint32_t)s.get<TunerFrontendStatus::signalQuality>());
391                 hidlStatus.push_back(status);
392                 break;
393             }
394             case TunerFrontendStatus::signalStrength: {
395                 status.signalStrength(s.get<TunerFrontendStatus::signalStrength>());
396                 hidlStatus.push_back(status);
397                 break;
398             }
399             case TunerFrontendStatus::symbolRate: {
400                 status.symbolRate((uint32_t)s.get<TunerFrontendStatus::symbolRate>());
401                 hidlStatus.push_back(status);
402                 break;
403             }
404             case TunerFrontendStatus::innerFec: {
405                 status.innerFec(static_cast<FrontendInnerFec>(
406                         s.get<TunerFrontendStatus::innerFec>()));
407                 hidlStatus.push_back(status);
408                 break;
409             }
410             case TunerFrontendStatus::modulation: {
411                 auto aidlMod = s.get<TunerFrontendStatus::modulation>();
412                 FrontendModulationStatus modulation;
413                 switch (mType) {
414                     case (int)FrontendType::DVBC:
415                         modulation.dvbc(static_cast<FrontendDvbcModulation>(aidlMod));
416                         status.modulation(modulation);
417                         hidlStatus.push_back(status);
418                         break;
419                     case (int)FrontendType::DVBS:
420                         modulation.dvbs(static_cast<FrontendDvbsModulation>(aidlMod));
421                         status.modulation(modulation);
422                         hidlStatus.push_back(status);
423                         break;
424                     case (int)FrontendType::ISDBS:
425                         modulation.isdbs(static_cast<FrontendIsdbsModulation>(aidlMod));
426                         status.modulation(modulation);
427                         hidlStatus.push_back(status);
428                         break;
429                     case (int)FrontendType::ISDBS3:
430                         modulation.isdbs3(static_cast<FrontendIsdbs3Modulation>(aidlMod));
431                         status.modulation(modulation);
432                         hidlStatus.push_back(status);
433                         break;
434                     case (int)FrontendType::ISDBT:
435                         modulation.isdbt(static_cast<FrontendIsdbtModulation>(aidlMod));
436                         status.modulation(modulation);
437                         hidlStatus.push_back(status);
438                         break;
439                     default:
440                         break;
441                 }
442                 break;
443             }
444             case TunerFrontendStatus::inversion: {
445                 status.inversion(static_cast<FrontendDvbcSpectralInversion>(
446                         s.get<TunerFrontendStatus::inversion>()));
447                 hidlStatus.push_back(status);
448                 break;
449             }
450             case TunerFrontendStatus::lnbVoltage: {
451                 status.lnbVoltage(static_cast<LnbVoltage>(
452                         s.get<TunerFrontendStatus::lnbVoltage>()));
453                 hidlStatus.push_back(status);
454                 break;
455             }
456             case TunerFrontendStatus::plpId: {
457                 status.plpId((uint8_t)s.get<TunerFrontendStatus::plpId>());
458                 hidlStatus.push_back(status);
459                 break;
460             }
461             case TunerFrontendStatus::isEWBS: {
462                 status.isEWBS(s.get<TunerFrontendStatus::isEWBS>());
463                 hidlStatus.push_back(status);
464                 break;
465             }
466             case TunerFrontendStatus::agc: {
467                 status.agc((uint8_t)s.get<TunerFrontendStatus::agc>());
468                 hidlStatus.push_back(status);
469                 break;
470             }
471             case TunerFrontendStatus::isLnaOn: {
472                 status.isLnaOn(s.get<TunerFrontendStatus::isLnaOn>());
473                 hidlStatus.push_back(status);
474                 break;
475             }
476             case TunerFrontendStatus::isLayerError: {
477                 auto aidlE = s.get<TunerFrontendStatus::isLayerError>();
478                 hidl_vec<bool> e(aidlE.begin(), aidlE.end());
479                 status.isLayerError(e);
480                 hidlStatus.push_back(status);
481                 break;
482             }
483             case TunerFrontendStatus::mer: {
484                 status.mer(s.get<TunerFrontendStatus::mer>());
485                 hidlStatus.push_back(status);
486                 break;
487             }
488             case TunerFrontendStatus::freqOffset: {
489                 status.freqOffset(s.get<TunerFrontendStatus::freqOffset>());
490                 hidlStatus.push_back(status);
491                 break;
492             }
493             case TunerFrontendStatus::hierarchy: {
494                 status.hierarchy(static_cast<FrontendDvbtHierarchy>(
495                         s.get<TunerFrontendStatus::hierarchy>()));
496                 hidlStatus.push_back(status);
497                 break;
498             }
499             case TunerFrontendStatus::isRfLocked: {
500                 status.isRfLocked(s.get<TunerFrontendStatus::isRfLocked>());
501                 hidlStatus.push_back(status);
502                 break;
503             }
504             case TunerFrontendStatus::plpInfo: {
505                 int size = s.get<TunerFrontendStatus::plpInfo>().size();
506                 hidl_vec<FrontendStatusAtsc3PlpInfo> info(size);
507                 for (int i = 0; i < size; i++) {
508                     auto aidlInfo = s.get<TunerFrontendStatus::plpInfo>()[i];
509                     info[i] = {
510                         .plpId = (uint8_t)aidlInfo.plpId,
511                         .isLocked = aidlInfo.isLocked,
512                         .uec = (uint32_t)aidlInfo.uec,
513                     };
514                 }
515                 status.plpInfo(info);
516                 hidlStatus.push_back(status);
517                 break;
518             }
519             default:
520                 break;
521         }
522     }
523     return hidlStatus;
524 }
525 
getHidlStatusExt(vector<TunerFrontendStatus> & aidlStatus)526 vector<FrontendStatusExt1_1> FrontendClient::getHidlStatusExt(
527         vector<TunerFrontendStatus>& aidlStatus) {
528     vector<FrontendStatusExt1_1> hidlStatus;
529     for (TunerFrontendStatus s : aidlStatus) {
530         FrontendStatusExt1_1 status;
531         switch (s.getTag()) {
532             case TunerFrontendStatus::modulations: {
533                 vector<FrontendModulation> ms;
534                 for (auto aidlMod : s.get<TunerFrontendStatus::modulations>()) {
535                     FrontendModulation m;
536                     switch (mType) {
537                         case (int)FrontendType::DVBC:
538                             m.dvbc(static_cast<FrontendDvbcModulation>(aidlMod));
539                             ms.push_back(m);
540                             break;
541                         case (int)FrontendType::DVBS:
542                             m.dvbs(static_cast<FrontendDvbsModulation>(aidlMod));
543                             ms.push_back(m);
544                             break;
545                         case (int)FrontendType::DVBT:
546                             m.dvbt(static_cast<FrontendDvbtConstellation>(aidlMod));
547                             ms.push_back(m);
548                             break;
549                         case (int)FrontendType::ISDBS:
550                             m.isdbs(static_cast<FrontendIsdbsModulation>(aidlMod));
551                             ms.push_back(m);
552                             break;
553                         case (int)FrontendType::ISDBS3:
554                             m.isdbs3(static_cast<FrontendIsdbs3Modulation>(aidlMod));
555                             ms.push_back(m);
556                             break;
557                         case (int)FrontendType::ISDBT:
558                             m.isdbt(static_cast<FrontendIsdbtModulation>(aidlMod));
559                             ms.push_back(m);
560                             break;
561                         case (int)FrontendType::ATSC:
562                             m.atsc(static_cast<FrontendAtscModulation>(aidlMod));
563                             ms.push_back(m);
564                             break;
565                         case (int)FrontendType::ATSC3:
566                             m.atsc3(static_cast<FrontendAtsc3Modulation>(aidlMod));
567                             ms.push_back(m);
568                             break;
569                         case (int)FrontendType::DTMB:
570                             m.dtmb(static_cast<FrontendDtmbModulation>(aidlMod));
571                             ms.push_back(m);
572                             break;
573                         default:
574                             break;
575                     }
576                 }
577                 if (ms.size() > 0) {
578                     status.modulations(ms);
579                     hidlStatus.push_back(status);
580                 }
581                 break;
582             }
583             case TunerFrontendStatus::bers: {
584                 auto aidlB = s.get<TunerFrontendStatus::bers>();
585                 hidl_vec<uint32_t> b(aidlB.begin(), aidlB.end());
586                 status.bers(b);
587                 hidlStatus.push_back(status);
588                 break;
589             }
590             case TunerFrontendStatus::codeRates: {
591                 vector<hardware::tv::tuner::V1_1::FrontendInnerFec> codeRates;
592                 for (auto aidlCodeRate : s.get<TunerFrontendStatus::codeRates>()) {
593                     codeRates.push_back(
594                             static_cast<hardware::tv::tuner::V1_1::FrontendInnerFec>(aidlCodeRate));
595                 }
596                 if (codeRates.size() > 0) {
597                     status.codeRates(codeRates);
598                     hidlStatus.push_back(status);
599                 }
600                 break;
601             }
602             case TunerFrontendStatus::bandwidth: {
603                 auto aidlBand = s.get<TunerFrontendStatus::bandwidth>();
604                 FrontendBandwidth band;
605                 switch (mType) {
606                     case (int)FrontendType::ATSC3:
607                         band.atsc3(static_cast<FrontendAtsc3Bandwidth>(aidlBand));
608                         status.bandwidth(band);
609                         hidlStatus.push_back(status);
610                         break;
611                     case (int)FrontendType::DVBC:
612                         band.dvbc(static_cast<FrontendDvbcBandwidth>(aidlBand));
613                         status.bandwidth(band);
614                         hidlStatus.push_back(status);
615                         break;
616                     case (int)FrontendType::DVBT:
617                         band.dvbt(static_cast<FrontendDvbtBandwidth>(aidlBand));
618                         status.bandwidth(band);
619                         hidlStatus.push_back(status);
620                         break;
621                     case (int)FrontendType::ISDBT:
622                         band.isdbt(static_cast<FrontendIsdbtBandwidth>(aidlBand));
623                         status.bandwidth(band);
624                         hidlStatus.push_back(status);
625                         break;
626                     case (int)FrontendType::DTMB:
627                         band.dtmb(static_cast<FrontendDtmbBandwidth>(aidlBand));
628                         status.bandwidth(band);
629                         hidlStatus.push_back(status);
630                         break;
631                     default:
632                         break;
633                 }
634                 break;
635             }
636             case TunerFrontendStatus::interval: {
637                 auto aidlInter = s.get<TunerFrontendStatus::interval>();
638                 FrontendGuardInterval inter;
639                 switch (mType) {
640                     case (int)FrontendType::DVBT:
641                         inter.dvbt(static_cast<FrontendDvbtGuardInterval>(aidlInter));
642                         status.interval(inter);
643                         hidlStatus.push_back(status);
644                         break;
645                     case (int)FrontendType::ISDBT:
646                         inter.isdbt(static_cast<FrontendIsdbtGuardInterval>(aidlInter));
647                         status.interval(inter);
648                         hidlStatus.push_back(status);
649                         break;
650                     case (int)FrontendType::DTMB:
651                         inter.dtmb(static_cast<FrontendDtmbGuardInterval>(aidlInter));
652                         status.interval(inter);
653                         hidlStatus.push_back(status);
654                         break;
655                     default:
656                         break;
657                 }
658                 break;
659             }
660             case TunerFrontendStatus::transmissionMode: {
661                 auto aidlTran = s.get<TunerFrontendStatus::transmissionMode>();
662                 FrontendTransmissionMode trans;
663                 switch (mType) {
664                     case (int)FrontendType::DVBT:
665                         trans.dvbt(static_cast<FrontendDvbtTransmissionMode>(aidlTran));
666                         status.transmissionMode(trans);
667                         hidlStatus.push_back(status);
668                         break;
669                     case (int)FrontendType::ISDBT:
670                         trans.isdbt(static_cast<FrontendIsdbtMode>(aidlTran));
671                         status.transmissionMode(trans);
672                         hidlStatus.push_back(status);
673                         break;
674                     case (int)FrontendType::DTMB:
675                         trans.dtmb(static_cast<FrontendDtmbTransmissionMode>(aidlTran));
676                         status.transmissionMode(trans);
677                         hidlStatus.push_back(status);
678                         break;
679                     default:
680                         break;
681                 }
682                 break;
683             }
684             case TunerFrontendStatus::uec: {
685                 status.uec((uint32_t)s.get<TunerFrontendStatus::uec>());
686                 hidlStatus.push_back(status);
687                 break;
688             }
689             case TunerFrontendStatus::systemId: {
690                 status.systemId((uint16_t)s.get<TunerFrontendStatus::systemId>());
691                 hidlStatus.push_back(status);
692                 break;
693             }
694             case TunerFrontendStatus::interleaving: {
695                 vector<FrontendInterleaveMode> modes;
696                 for (auto aidlInter : s.get<TunerFrontendStatus::interleaving>()) {
697                     FrontendInterleaveMode mode;
698                     switch (mType) {
699                         case (int)FrontendType::DVBC:
700                             mode.dvbc(static_cast<FrontendCableTimeInterleaveMode>(aidlInter));
701                             modes.push_back(mode);
702                             break;
703                         case (int)FrontendType::ATSC3:
704                             mode.atsc3(static_cast<FrontendAtsc3TimeInterleaveMode>(aidlInter));
705                             modes.push_back(mode);
706                             break;
707                         case (int)FrontendType::DTMB:
708                             mode.dtmb(static_cast<FrontendDtmbTimeInterleaveMode>(aidlInter));
709                             modes.push_back(mode);
710                             break;
711                         default:
712                             break;
713                     }
714                 }
715                 if (modes.size() > 0) {
716                     status.interleaving(modes);
717                     hidlStatus.push_back(status);
718                 }
719                 break;
720             }
721             case TunerFrontendStatus::isdbtSegment: {
722                 auto aidlSeg = s.get<TunerFrontendStatus::isdbtSegment>();
723                 hidl_vec<uint8_t> s(aidlSeg.begin(), aidlSeg.end());
724                 status.isdbtSegment(s);
725                 hidlStatus.push_back(status);
726                 break;
727             }
728             case TunerFrontendStatus::tsDataRate: {
729                 auto aidlTs = s.get<TunerFrontendStatus::tsDataRate>();
730                 hidl_vec<uint32_t> ts(aidlTs.begin(), aidlTs.end());
731                 status.tsDataRate(ts);
732                 hidlStatus.push_back(status);
733                 break;
734             }
735             case TunerFrontendStatus::rollOff: {
736                 auto aidlRoll = s.get<TunerFrontendStatus::rollOff>();
737                 FrontendRollOff roll;
738                 switch (mType) {
739                     case (int)FrontendType::DVBS:
740                         roll.dvbs(static_cast<FrontendDvbsRolloff>(aidlRoll));
741                         status.rollOff(roll);
742                         hidlStatus.push_back(status);
743                         break;
744                     case (int)FrontendType::ISDBS:
745                         roll.isdbs(static_cast<FrontendIsdbsRolloff>(aidlRoll));
746                         status.rollOff(roll);
747                         hidlStatus.push_back(status);
748                         break;
749                     case (int)FrontendType::ISDBS3:
750                         roll.isdbs3(static_cast<FrontendIsdbs3Rolloff>(aidlRoll));
751                         status.rollOff(roll);
752                         hidlStatus.push_back(status);
753                         break;
754                     default:
755                         break;
756                 }
757                 break;
758             }
759             case TunerFrontendStatus::isMiso: {
760                 status.isMiso(s.get<TunerFrontendStatus::isMiso>());
761                 hidlStatus.push_back(status);
762                 break;
763             }
764             case TunerFrontendStatus::isLinear: {
765                 status.isLinear(s.get<TunerFrontendStatus::isLinear>());
766                 hidlStatus.push_back(status);
767                 break;
768             }
769             case TunerFrontendStatus::isShortFrames: {
770                 status.isShortFrames(s.get<TunerFrontendStatus::isShortFrames>());
771                 hidlStatus.push_back(status);
772                 break;
773             }
774             default:
775                 break;
776         }
777     }
778     return hidlStatus;
779 }
780 
getAidlFrontendSettings(const FrontendSettings & settings,const FrontendSettingsExt1_1 & settingsExt1_1)781 TunerFrontendSettings FrontendClient::getAidlFrontendSettings(const FrontendSettings& settings,
782         const FrontendSettingsExt1_1& settingsExt1_1) {
783     bool isExtended = validateExtendedSettings(settingsExt1_1);
784     TunerFrontendSettings s{
785         .isExtended = isExtended,
786         .endFrequency = (int) settingsExt1_1.endFrequency,
787         .inversion = (int) settingsExt1_1.inversion,
788     };
789 
790     if (settingsExt1_1.settingExt.getDiscriminator()
791             == FrontendSettingsExt1_1::SettingsExt::hidl_discriminator::dtmb) {
792         s.settings.set<TunerFrontendUnionSettings::dtmb>(getAidlDtmbSettings(settingsExt1_1));
793         return s;
794     }
795 
796     switch (settings.getDiscriminator()) {
797         case FrontendSettings::hidl_discriminator::analog: {
798             s.settings.set<TunerFrontendUnionSettings::analog>(
799                     getAidlAnalogSettings(settings, settingsExt1_1));
800             break;
801         }
802         case FrontendSettings::hidl_discriminator::atsc: {
803             s.settings.set<TunerFrontendUnionSettings::atsc>(getAidlAtscSettings(settings));
804             break;
805         }
806         case FrontendSettings::hidl_discriminator::atsc3: {
807             s.settings.set<TunerFrontendUnionSettings::atsc3>(getAidlAtsc3Settings(settings));
808             break;
809         }
810         case FrontendSettings::hidl_discriminator::dvbs: {
811             s.settings.set<TunerFrontendUnionSettings::dvbs>(
812                     getAidlDvbsSettings(settings, settingsExt1_1));
813             break;
814         }
815         case FrontendSettings::hidl_discriminator::dvbc: {
816             s.settings.set<TunerFrontendUnionSettings::cable>(
817                     getAidlCableSettings(settings, settingsExt1_1));
818             break;
819         }
820         case FrontendSettings::hidl_discriminator::dvbt: {
821             s.settings.set<TunerFrontendUnionSettings::dvbt>(
822                     getAidlDvbtSettings(settings, settingsExt1_1));
823             break;
824         }
825         case FrontendSettings::hidl_discriminator::isdbs: {
826             s.settings.set<TunerFrontendUnionSettings::isdbs>(getAidlIsdbsSettings(settings));
827             break;
828         }
829         case FrontendSettings::hidl_discriminator::isdbs3: {
830             s.settings.set<TunerFrontendUnionSettings::isdbs3>(getAidlIsdbs3Settings(settings));
831             break;
832         }
833         case FrontendSettings::hidl_discriminator::isdbt: {
834             s.settings.set<TunerFrontendUnionSettings::isdbt>(getAidlIsdbtSettings(settings));
835             break;
836         }
837         default:
838             break;
839     }
840     return s;
841 }
842 
getAidlAnalogSettings(const FrontendSettings & settings,const FrontendSettingsExt1_1 & settingsExt1_1)843 TunerFrontendAnalogSettings FrontendClient::getAidlAnalogSettings(const FrontendSettings& settings,
844         const FrontendSettingsExt1_1& settingsExt1_1) {
845     TunerFrontendAnalogSettings analogSettings{
846         .frequency = (int)settings.analog().frequency,
847         .signalType = (int)settings.analog().type,
848         .sifStandard = (int)settings.analog().sifStandard,
849     };
850     if (settingsExt1_1.settingExt.getDiscriminator()
851             == FrontendSettingsExt1_1::SettingsExt::hidl_discriminator::analog) {
852         analogSettings.isExtended = true;
853         analogSettings.aftFlag = (int)settingsExt1_1.settingExt.analog().aftFlag;
854     } else {
855         analogSettings.isExtended = false;
856     }
857     return analogSettings;
858 }
859 
getAidlDvbsSettings(const FrontendSettings & settings,const FrontendSettingsExt1_1 & settingsExt1_1)860 TunerFrontendDvbsSettings FrontendClient::getAidlDvbsSettings(const FrontendSettings& settings,
861         const FrontendSettingsExt1_1& settingsExt1_1) {
862     TunerFrontendDvbsSettings dvbsSettings{
863         .frequency = (int)settings.dvbs().frequency,
864         .modulation = (int)settings.dvbs().modulation,
865         .codeRate = {
866             .fec = (long)settings.dvbs().coderate.fec,
867             .isLinear = settings.dvbs().coderate.isLinear,
868             .isShortFrames = settings.dvbs().coderate.isShortFrames,
869             .bitsPer1000Symbol = (int)settings.dvbs().coderate.bitsPer1000Symbol,
870         },
871         .symbolRate = (int)settings.dvbs().symbolRate,
872         .rolloff = (int)settings.dvbs().rolloff,
873         .pilot = (int)settings.dvbs().pilot,
874         .inputStreamId = (int)settings.dvbs().inputStreamId,
875         .standard = (int)settings.dvbs().standard,
876         .vcm = (int)settings.dvbs().vcmMode,
877     };
878     if (settingsExt1_1.settingExt.getDiscriminator()
879             == FrontendSettingsExt1_1::SettingsExt::hidl_discriminator::dvbs) {
880         dvbsSettings.isExtended = true;
881         dvbsSettings.scanType = (int)settingsExt1_1.settingExt.dvbs().scanType;
882         dvbsSettings.isDiseqcRxMessage = settingsExt1_1.settingExt.dvbs().isDiseqcRxMessage;
883     } else {
884         dvbsSettings.isExtended = false;
885     }
886     return dvbsSettings;
887 }
888 
getAidlCableSettings(const FrontendSettings & settings,const FrontendSettingsExt1_1 & settingsExt1_1)889 TunerFrontendCableSettings FrontendClient::getAidlCableSettings(const FrontendSettings& settings,
890         const FrontendSettingsExt1_1& settingsExt1_1) {
891     TunerFrontendCableSettings cableSettings{
892         .frequency = (int)settings.dvbc().frequency,
893         .modulation = (int)settings.dvbc().modulation,
894         .innerFec = (long)settings.dvbc().fec,
895         .symbolRate = (int)settings.dvbc().symbolRate,
896         .outerFec = (int)settings.dvbc().outerFec,
897         .annex = (int)settings.dvbc().annex,
898         .spectralInversion = (int)settings.dvbc().spectralInversion,
899     };
900     if (settingsExt1_1.settingExt.getDiscriminator()
901             == FrontendSettingsExt1_1::SettingsExt::hidl_discriminator::dvbc) {
902         cableSettings.isExtended = true;
903         cableSettings.interleaveMode = (int)settingsExt1_1.settingExt.dvbc().interleaveMode;
904         cableSettings.bandwidth = (int)settingsExt1_1.settingExt.dvbc().bandwidth;
905     } else {
906         cableSettings.isExtended = false;
907     }
908     return cableSettings;
909 }
910 
getAidlDvbtSettings(const FrontendSettings & settings,const FrontendSettingsExt1_1 & settingsExt1_1)911 TunerFrontendDvbtSettings FrontendClient::getAidlDvbtSettings(const FrontendSettings& settings,
912         const FrontendSettingsExt1_1& settingsExt1_1) {
913     TunerFrontendDvbtSettings dvbtSettings{
914         .frequency = (int)settings.dvbt().frequency,
915         .transmissionMode = (int)settings.dvbt().transmissionMode,
916         .bandwidth = (int)settings.dvbt().bandwidth,
917         .constellation = (int)settings.dvbt().constellation,
918         .hierarchy = (int)settings.dvbt().hierarchy,
919         .hpCodeRate = (int)settings.dvbt().hpCoderate,
920         .lpCodeRate = (int)settings.dvbt().lpCoderate,
921         .guardInterval = (int)settings.dvbt().guardInterval,
922         .isHighPriority = settings.dvbt().isHighPriority,
923         .standard = (int)settings.dvbt().standard,
924         .isMiso = settings.dvbt().isMiso,
925         .plpMode = (int)settings.dvbt().plpMode,
926         .plpId = (int)settings.dvbt().plpId,
927         .plpGroupId = (int)settings.dvbt().plpGroupId,
928     };
929     if (settingsExt1_1.settingExt.getDiscriminator()
930             == FrontendSettingsExt1_1::SettingsExt::hidl_discriminator::dvbt) {
931         dvbtSettings.isExtended = true;
932         dvbtSettings.constellation = (int)settingsExt1_1.settingExt.dvbt().constellation;
933         dvbtSettings.transmissionMode =
934                 (int)settingsExt1_1.settingExt.dvbt().transmissionMode;
935     } else {
936         dvbtSettings.isExtended = false;
937     }
938     return dvbtSettings;
939 }
940 
getAidlDtmbSettings(const FrontendSettingsExt1_1 & settingsExt1_1)941 TunerFrontendDtmbSettings FrontendClient::getAidlDtmbSettings(
942         const FrontendSettingsExt1_1& settingsExt1_1) {
943     TunerFrontendDtmbSettings dtmbSettings{
944         .frequency = (int)settingsExt1_1.settingExt.dtmb().frequency,
945         .transmissionMode = (int)settingsExt1_1.settingExt.dtmb().transmissionMode,
946         .bandwidth = (int)settingsExt1_1.settingExt.dtmb().bandwidth,
947         .modulation = (int)settingsExt1_1.settingExt.dtmb().modulation,
948         .codeRate = (int)settingsExt1_1.settingExt.dtmb().codeRate,
949         .guardInterval = (int)settingsExt1_1.settingExt.dtmb().guardInterval,
950         .interleaveMode = (int)settingsExt1_1.settingExt.dtmb().interleaveMode,
951     };
952     return dtmbSettings;
953 }
954 
getAidlAtscSettings(const FrontendSettings & settings)955 TunerFrontendAtscSettings FrontendClient::getAidlAtscSettings(const FrontendSettings& settings) {
956     TunerFrontendAtscSettings atscSettings{
957         .frequency = (int)settings.atsc().frequency,
958         .modulation = (int)settings.atsc().modulation,
959     };
960     return atscSettings;
961 }
962 
getAidlAtsc3Settings(const FrontendSettings & settings)963 TunerFrontendAtsc3Settings FrontendClient::getAidlAtsc3Settings(const FrontendSettings& settings) {
964     TunerFrontendAtsc3Settings atsc3Settings{
965         .frequency = (int)settings.atsc3().frequency,
966         .bandwidth = (int)settings.atsc3().bandwidth,
967         .demodOutputFormat = (int)settings.atsc3().demodOutputFormat,
968     };
969     atsc3Settings.plpSettings.resize(settings.atsc3().plpSettings.size());
970     for (auto plpSetting : settings.atsc3().plpSettings) {
971         atsc3Settings.plpSettings.push_back({
972             .plpId = (int)plpSetting.plpId,
973             .modulation = (int)plpSetting.modulation,
974             .interleaveMode = (int)plpSetting.interleaveMode,
975             .codeRate = (int)plpSetting.codeRate,
976             .fec = (int)plpSetting.fec,
977         });
978     }
979     return atsc3Settings;
980 }
981 
getAidlIsdbsSettings(const FrontendSettings & settings)982 TunerFrontendIsdbsSettings FrontendClient::getAidlIsdbsSettings(const FrontendSettings& settings) {
983     TunerFrontendIsdbsSettings isdbsSettings{
984         .frequency = (int)settings.isdbs().frequency,
985         .streamId = (char16_t)settings.isdbs().streamId,
986         .streamIdType = (int)settings.isdbs().streamIdType,
987         .modulation = (int)settings.isdbs().modulation,
988         .codeRate = (int)settings.isdbs().coderate,
989         .symbolRate = (int)settings.isdbs().symbolRate,
990         .rolloff = (int)settings.isdbs().rolloff,
991     };
992     return isdbsSettings;
993 }
994 
getAidlIsdbs3Settings(const FrontendSettings & settings)995 TunerFrontendIsdbs3Settings FrontendClient::getAidlIsdbs3Settings(
996         const FrontendSettings& settings) {
997     TunerFrontendIsdbs3Settings isdbs3Settings{
998         .frequency = (int)settings.isdbs3().frequency,
999         .streamId = (char16_t)settings.isdbs3().streamId,
1000         .streamIdType = (int)settings.isdbs3().streamIdType,
1001         .modulation = (int)settings.isdbs3().modulation,
1002         .codeRate = (int)settings.isdbs3().coderate,
1003         .symbolRate = (int)settings.isdbs3().symbolRate,
1004         .rolloff = (int)settings.isdbs3().rolloff,
1005     };
1006     return isdbs3Settings;
1007 }
1008 
getAidlIsdbtSettings(const FrontendSettings & settings)1009 TunerFrontendIsdbtSettings FrontendClient::getAidlIsdbtSettings(const FrontendSettings& settings) {
1010     TunerFrontendIsdbtSettings isdbtSettings{
1011         .frequency = (int)settings.isdbt().frequency,
1012         .modulation = (int)settings.isdbt().modulation,
1013         .bandwidth = (int)settings.isdbt().bandwidth,
1014         .mode = (int)settings.isdbt().mode,
1015         .codeRate = (int)settings.isdbt().coderate,
1016         .guardInterval = (int)settings.isdbt().guardInterval,
1017         .serviceAreaId = (int)settings.isdbt().serviceAreaId,
1018     };
1019     return isdbtSettings;
1020 }
1021 
validateExtendedSettings(const FrontendSettingsExt1_1 & settingsExt1_1)1022 bool FrontendClient::validateExtendedSettings(const FrontendSettingsExt1_1& settingsExt1_1) {
1023     return settingsExt1_1.endFrequency != (uint32_t)Constant::INVALID_FRONTEND_SETTING_FREQUENCY
1024             || settingsExt1_1.inversion != FrontendSpectralInversion::UNDEFINED
1025             || settingsExt1_1.settingExt.getDiscriminator()
1026                     != FrontendSettingsExt1_1::SettingsExt::hidl_discriminator::noinit;
1027 }
1028 
1029 /////////////// TunerFrontendCallback ///////////////////////
1030 
TunerFrontendCallback(sp<FrontendClientCallback> frontendClientCallback)1031 TunerFrontendCallback::TunerFrontendCallback(sp<FrontendClientCallback> frontendClientCallback)
1032         : mFrontendClientCallback(frontendClientCallback) {}
1033 
onEvent(int frontendEventType)1034 Status TunerFrontendCallback::onEvent(int frontendEventType) {
1035     if (mFrontendClientCallback != NULL) {
1036         mFrontendClientCallback->onEvent(static_cast<FrontendEventType>(frontendEventType));
1037         return Status::ok();
1038     }
1039     return Status::fromServiceSpecificError(static_cast<int32_t>(Result::INVALID_STATE));
1040 }
1041 
onScanMessage(int messageType,const TunerFrontendScanMessage & message)1042 Status TunerFrontendCallback::onScanMessage(int messageType,
1043         const TunerFrontendScanMessage& message) {
1044     if (mFrontendClientCallback != NULL) {
1045         if (!is1_1ExtendedScanMessage(messageType)) {
1046             mFrontendClientCallback->onScanMessage(
1047                     static_cast<FrontendScanMessageType>(messageType),
1048                     getHalScanMessage(messageType, message));
1049         } else {
1050             mFrontendClientCallback->onScanMessageExt1_1(
1051                     static_cast<FrontendScanMessageTypeExt1_1>(messageType),
1052                     getHalScanMessageExt1_1(messageType, message));
1053         }
1054         return Status::ok();
1055     }
1056     return Status::fromServiceSpecificError(static_cast<int32_t>(Result::INVALID_STATE));
1057 }
1058 
1059 /////////////// IFrontendCallback ///////////////////////
1060 
HidlFrontendCallback(sp<FrontendClientCallback> frontendClientCallback)1061 HidlFrontendCallback::HidlFrontendCallback(sp<FrontendClientCallback> frontendClientCallback)
1062         : mFrontendClientCallback(frontendClientCallback) {}
1063 
onEvent(FrontendEventType frontendEventType)1064 Return<void> HidlFrontendCallback::onEvent(FrontendEventType frontendEventType) {
1065     if (mFrontendClientCallback != NULL) {
1066         mFrontendClientCallback->onEvent(frontendEventType);
1067     }
1068     return Void();
1069 }
1070 
onScanMessage(FrontendScanMessageType type,const FrontendScanMessage & message)1071 Return<void> HidlFrontendCallback::onScanMessage(FrontendScanMessageType type,
1072         const FrontendScanMessage& message) {
1073     if (mFrontendClientCallback != NULL) {
1074         mFrontendClientCallback->onScanMessage(type, message);
1075     }
1076     return Void();
1077 }
1078 
onScanMessageExt1_1(FrontendScanMessageTypeExt1_1 type,const FrontendScanMessageExt1_1 & message)1079 Return<void> HidlFrontendCallback::onScanMessageExt1_1(FrontendScanMessageTypeExt1_1 type,
1080         const FrontendScanMessageExt1_1& message) {
1081     if (mFrontendClientCallback != NULL) {
1082         mFrontendClientCallback->onScanMessageExt1_1(type, message);
1083     }
1084     return Void();
1085 }
1086 
1087 /////////////// FrontendClientCallback Helper Methods ///////////////////////
1088 
getHalScanMessage(int messageType,const TunerFrontendScanMessage & message)1089 FrontendScanMessage TunerFrontendCallback::getHalScanMessage(
1090         int messageType, const TunerFrontendScanMessage& message) {
1091     FrontendScanMessage scanMessage;
1092     switch (messageType) {
1093         case (int) FrontendScanMessageType::LOCKED:
1094             scanMessage.isLocked(message.get<TunerFrontendScanMessage::isLocked>());
1095             break;
1096         case (int) FrontendScanMessageType::END:
1097             scanMessage.isEnd(message.get<TunerFrontendScanMessage::isEnd>());
1098             break;
1099         case (int) FrontendScanMessageType::PROGRESS_PERCENT:
1100             scanMessage.progressPercent(message.get<TunerFrontendScanMessage::progressPercent>());
1101             break;
1102         case (int) FrontendScanMessageType::FREQUENCY: {
1103             vector<int> f = message.get<TunerFrontendScanMessage::frequencies>();
1104             hidl_vec<uint32_t> frequencies(begin(f), end(f));
1105             scanMessage.frequencies(frequencies);
1106             break;
1107         }
1108         case (int) FrontendScanMessageType::SYMBOL_RATE: {
1109             vector<int> s = message.get<TunerFrontendScanMessage::symbolRates>();
1110             hidl_vec<uint32_t> symbolRates(begin(s), end(s));
1111             scanMessage.symbolRates(symbolRates);
1112             break;
1113         }
1114         case (int) FrontendScanMessageType::HIERARCHY:
1115             scanMessage.hierarchy(static_cast<FrontendDvbtHierarchy>(
1116                     message.get<TunerFrontendScanMessage::hierarchy>()));
1117             break;
1118         case (int) FrontendScanMessageType::ANALOG_TYPE:
1119             scanMessage.analogType(static_cast<FrontendAnalogType>(
1120                     message.get<TunerFrontendScanMessage::analogType>()));
1121             break;
1122         case (int) FrontendScanMessageType::PLP_IDS: {
1123             vector<uint8_t> p = message.get<TunerFrontendScanMessage::plpIds>();
1124             hidl_vec<uint8_t> plpIds(begin(p), end(p));
1125             scanMessage.plpIds(plpIds);
1126             break;
1127         }
1128         case (int) FrontendScanMessageType::GROUP_IDS: {
1129             vector<uint8_t> g = message.get<TunerFrontendScanMessage::groupIds>();
1130             hidl_vec<uint8_t> groupIds(begin(g), end(g));
1131             scanMessage.groupIds(groupIds);
1132             break;
1133         }
1134         case (int) FrontendScanMessageType::INPUT_STREAM_IDS: {
1135             vector<char16_t> i = message.get<TunerFrontendScanMessage::inputStreamIds>();
1136             hidl_vec<uint16_t> inputStreamIds(begin(i), end(i));
1137             scanMessage.inputStreamIds(inputStreamIds);
1138             break;
1139         }
1140         case (int) FrontendScanMessageType::STANDARD: {
1141             FrontendScanMessage::Standard std;
1142             int standard = message.get<TunerFrontendScanMessage::std>();
1143             switch (mType) {
1144                 case (int) FrontendType::DVBS:
1145                     std.sStd(static_cast<FrontendDvbsStandard>(standard));
1146                     scanMessage.std(std);
1147                     break;
1148                 case (int) FrontendType::DVBT:
1149                     std.tStd(static_cast<FrontendDvbtStandard>(standard));
1150                     scanMessage.std(std);
1151                     break;
1152                 case (int) FrontendType::ANALOG:
1153                     std.sifStd(static_cast<FrontendAnalogSifStandard>(standard));
1154                     scanMessage.std(std);
1155                     break;
1156                 default:
1157                     break;
1158             }
1159             break;
1160         }
1161         case (int) FrontendScanMessageType::ATSC3_PLP_INFO: {
1162             vector<TunerFrontendScanAtsc3PlpInfo> plp =
1163                     message.get<TunerFrontendScanMessage::atsc3PlpInfos>();
1164             hidl_vec<FrontendScanAtsc3PlpInfo> plpInfo;
1165             int size = plp.size();
1166             plpInfo.resize(size);
1167             for (int i = 0; i < size; i++) {
1168                 auto info = message.get<TunerFrontendScanMessage::atsc3PlpInfos>()[i];
1169                 FrontendScanAtsc3PlpInfo p{
1170                     .plpId = static_cast<uint8_t>(info.plpId),
1171                     .bLlsFlag = info.llsFlag,
1172                 };
1173                 plpInfo[i] = p;
1174             }
1175             scanMessage.atsc3PlpInfos(plpInfo);
1176             break;
1177         }
1178         default:
1179             break;
1180     }
1181     return scanMessage;
1182 }
1183 
getHalScanMessageExt1_1(int messageType,const TunerFrontendScanMessage & message)1184 FrontendScanMessageExt1_1 TunerFrontendCallback::getHalScanMessageExt1_1(
1185         int messageType, const TunerFrontendScanMessage& message) {
1186     FrontendScanMessageExt1_1 scanMessage;
1187     switch (messageType) {
1188         case (int) FrontendScanMessageTypeExt1_1::HIGH_PRIORITY:
1189             scanMessage.isHighPriority(message.get<TunerFrontendScanMessage::isHighPriority>());
1190             break;
1191         case (int) FrontendScanMessageTypeExt1_1::DVBC_ANNEX:
1192             scanMessage.annex(static_cast<FrontendDvbcAnnex>(
1193                     message.get<TunerFrontendScanMessage::annex>()));
1194             break;
1195         case (int) FrontendScanMessageTypeExt1_1::MODULATION: {
1196             FrontendModulation m;
1197             int modulation = message.get<TunerFrontendScanMessage::modulation>();
1198             switch (mType) {
1199                 case (int) FrontendType::DVBC:
1200                     m.dvbc(static_cast<FrontendDvbcModulation>(modulation));
1201                     scanMessage.modulation(m);
1202                     break;
1203                 case (int) FrontendType::DVBS:
1204                     m.dvbs(static_cast<FrontendDvbsModulation>(modulation));
1205                     scanMessage.modulation(m);
1206                     break;
1207                 case (int) FrontendType::DVBT:
1208                     m.dvbt(static_cast<FrontendDvbtConstellation>(modulation));
1209                     scanMessage.modulation(m);
1210                     break;
1211                 case (int) FrontendType::ISDBS:
1212                     m.isdbs(static_cast<FrontendIsdbsModulation>(modulation));
1213                     scanMessage.modulation(m);
1214                     break;
1215                 case (int) FrontendType::ISDBS3:
1216                     m.isdbs3(static_cast<FrontendIsdbs3Modulation>(modulation));
1217                     scanMessage.modulation(m);
1218                     break;
1219                 case (int) FrontendType::ISDBT:
1220                     m.isdbt(static_cast<FrontendIsdbtModulation>(modulation));
1221                     scanMessage.modulation(m);
1222                     break;
1223                 case (int) FrontendType::ATSC:
1224                     m.atsc(static_cast<FrontendAtscModulation>(modulation));
1225                     scanMessage.modulation(m);
1226                     break;
1227                 case (int) FrontendType::ATSC3:
1228                     m.atsc3(static_cast<FrontendAtsc3Modulation>(modulation));
1229                     scanMessage.modulation(m);
1230                     break;
1231                 case (int) hardware::tv::tuner::V1_1::FrontendType::DTMB:
1232                     m.dtmb(static_cast<FrontendDtmbModulation>(modulation));
1233                     scanMessage.modulation(m);
1234                     break;
1235                 default:
1236                     break;
1237             }
1238             break;
1239         }
1240         default:
1241             break;
1242     }
1243     return scanMessage;
1244 }
1245 
is1_1ExtendedScanMessage(int messageType)1246 bool TunerFrontendCallback::is1_1ExtendedScanMessage(int messageType) {
1247     return messageType >= (int)FrontendScanMessageTypeExt1_1::MODULATION
1248             && messageType <= (int)FrontendScanMessageTypeExt1_1::HIGH_PRIORITY;
1249 }
1250 }  // namespace android
1251