• 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 #define LOG_TAG "FrontendClient"
18 
19 #include "FrontendClient.h"
20 
21 #include <aidl/android/hardware/tv/tuner/Constant.h>
22 #include <android-base/logging.h>
23 #include <utils/Log.h>
24 
25 using ::aidl::android::hardware::tv::tuner::Constant;
26 
27 namespace android {
28 /////////////// FrontendClient ///////////////////////
FrontendClient(shared_ptr<ITunerFrontend> tunerFrontend,FrontendType type)29 FrontendClient::FrontendClient(shared_ptr<ITunerFrontend> tunerFrontend, FrontendType type) {
30     mTunerFrontend = tunerFrontend;
31     mType = type;
32 }
33 
~FrontendClient()34 FrontendClient::~FrontendClient() {
35     mTunerFrontend = nullptr;
36     mType = FrontendType::UNDEFINED;
37 }
38 
setCallback(sp<FrontendClientCallback> frontendClientCallback)39 Result FrontendClient::setCallback(sp<FrontendClientCallback> frontendClientCallback) {
40     if (mTunerFrontend != nullptr) {
41         shared_ptr<TunerFrontendCallback> aidlCallback =
42                 ::ndk::SharedRefBase::make<TunerFrontendCallback>(frontendClientCallback);
43         Status s = mTunerFrontend->setCallback(aidlCallback);
44         return ClientHelper::getServiceSpecificErrorCode(s);
45     }
46 
47     return Result::INVALID_STATE;
48 }
49 
tune(const FrontendSettings & settings)50 Result FrontendClient::tune(const FrontendSettings& settings) {
51     if (mTunerFrontend != nullptr) {
52         Status s = mTunerFrontend->tune(settings);
53         return ClientHelper::getServiceSpecificErrorCode(s);
54     }
55 
56     return Result::INVALID_STATE;
57 }
58 
stopTune()59 Result FrontendClient::stopTune() {
60     if (mTunerFrontend != nullptr) {
61         Status s = mTunerFrontend->stopTune();
62         return ClientHelper::getServiceSpecificErrorCode(s);
63     }
64 
65     return Result::INVALID_STATE;
66 }
67 
scan(const FrontendSettings & settings,FrontendScanType type)68 Result FrontendClient::scan(const FrontendSettings& settings, FrontendScanType type) {
69     if (mTunerFrontend != nullptr) {
70         Status s = mTunerFrontend->scan(settings, type);
71         return ClientHelper::getServiceSpecificErrorCode(s);
72     }
73 
74     return Result::INVALID_STATE;
75 }
76 
stopScan()77 Result FrontendClient::stopScan() {
78     if (mTunerFrontend != nullptr) {
79         Status s = mTunerFrontend->stopScan();
80         return ClientHelper::getServiceSpecificErrorCode(s);
81     }
82 
83     return Result::INVALID_STATE;
84 }
85 
getStatus(vector<FrontendStatusType> statusTypes)86 vector<FrontendStatus> FrontendClient::getStatus(vector<FrontendStatusType> statusTypes) {
87     vector<FrontendStatus> status;
88 
89     if (mTunerFrontend != nullptr) {
90         mTunerFrontend->getStatus(statusTypes, &status);
91     }
92 
93     return status;
94 }
95 
setLnb(sp<LnbClient> lnbClient)96 Result FrontendClient::setLnb(sp<LnbClient> lnbClient) {
97     if (mTunerFrontend != nullptr) {
98         Status s = mTunerFrontend->setLnb(lnbClient->getAidlLnb());
99         return ClientHelper::getServiceSpecificErrorCode(s);
100     }
101 
102     return Result::INVALID_STATE;
103 }
104 
linkCiCamToFrontend(int32_t ciCamId)105 int32_t FrontendClient::linkCiCamToFrontend(int32_t ciCamId) {
106     int32_t ltsId = static_cast<int32_t>(Constant::INVALID_LTS_ID);
107 
108     if (mTunerFrontend != nullptr) {
109         Status s = mTunerFrontend->linkCiCamToFrontend(ciCamId, &ltsId);
110         if (!s.isOk()) {
111             return static_cast<int32_t>(Constant::INVALID_LTS_ID);
112         }
113     }
114 
115     return ltsId;
116 }
117 
unlinkCiCamToFrontend(int32_t ciCamId)118 Result FrontendClient::unlinkCiCamToFrontend(int32_t ciCamId) {
119     if (mTunerFrontend != nullptr) {
120         Status s = mTunerFrontend->unlinkCiCamToFrontend(ciCamId);
121         return ClientHelper::getServiceSpecificErrorCode(s);
122     }
123 
124     return Result::INVALID_STATE;
125 }
126 
close()127 Result FrontendClient::close() {
128     if (mTunerFrontend != nullptr) {
129         Status s = mTunerFrontend->close();
130         mTunerFrontend = nullptr;
131         return ClientHelper::getServiceSpecificErrorCode(s);
132     }
133 
134     return Result::INVALID_STATE;
135 }
136 
getHardwareInfo(string & info)137 Result FrontendClient::getHardwareInfo(string& info) {
138     if (mTunerFrontend != nullptr) {
139         Status s = mTunerFrontend->getHardwareInfo(&info);
140         return ClientHelper::getServiceSpecificErrorCode(s);
141     }
142 
143     return Result::INVALID_STATE;
144 }
145 
removeOutputPid(int32_t pid)146 Result FrontendClient::removeOutputPid(int32_t pid) {
147     if (mTunerFrontend != nullptr) {
148         Status s = mTunerFrontend->removeOutputPid(pid);
149         return ClientHelper::getServiceSpecificErrorCode(s);
150     }
151 
152     return Result::INVALID_STATE;
153 }
154 
getStatusReadiness(const std::vector<FrontendStatusType> & statusTypes)155 vector<FrontendStatusReadiness> FrontendClient::getStatusReadiness(
156         const std::vector<FrontendStatusType>& statusTypes) {
157     vector<FrontendStatusReadiness> readiness;
158     if (mTunerFrontend != nullptr) {
159         mTunerFrontend->getFrontendStatusReadiness(statusTypes, &readiness);
160     }
161 
162     return readiness;
163 }
164 
getAidlFrontend()165 shared_ptr<ITunerFrontend> FrontendClient::getAidlFrontend() {
166     return mTunerFrontend;
167 }
168 
getId()169 int32_t FrontendClient::getId() {
170     if (mTunerFrontend != nullptr) {
171         int32_t id;
172         Status s = mTunerFrontend->getFrontendId(&id);
173         if (s.isOk()) {
174             return id;
175         }
176     }
177 
178     return static_cast<int32_t>(Constant::INVALID_FRONTEND_ID);
179 }
180 
181 /////////////// IFrontendCallback ///////////////////////
TunerFrontendCallback(sp<FrontendClientCallback> frontendClientCallback)182 TunerFrontendCallback::TunerFrontendCallback(sp<FrontendClientCallback> frontendClientCallback)
183         : mFrontendClientCallback(frontendClientCallback) {}
184 
onEvent(FrontendEventType frontendEventType)185 Status TunerFrontendCallback::onEvent(FrontendEventType frontendEventType) {
186     if (mFrontendClientCallback != nullptr) {
187         mFrontendClientCallback->onEvent(frontendEventType);
188         return Status::ok();
189     }
190     return Status::fromServiceSpecificError(static_cast<int32_t>(Result::INVALID_STATE));
191 }
192 
onScanMessage(FrontendScanMessageType messageType,const FrontendScanMessage & message)193 Status TunerFrontendCallback::onScanMessage(FrontendScanMessageType messageType,
194                                             const FrontendScanMessage& message) {
195     if (mFrontendClientCallback != nullptr) {
196         mFrontendClientCallback->onScanMessage(messageType, message);
197         return Status::ok();
198     }
199     return Status::fromServiceSpecificError(static_cast<int32_t>(Result::INVALID_STATE));
200 }
201 
202 }  // namespace android
203