blob: df3fd609d72fcd4e5a5202b397d39cdd6093000c [file] [log] [blame]
Amy Zhangb0f63ab2021-01-06 17:19:27 -08001/*
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 "LnbClient"
18
19#include <android-base/logging.h>
20#include <utils/Log.h>
21
Amy Zhang3ac0a3e2021-01-14 18:55:10 -080022#include "TunerClient.h"
Amy Zhangb0f63ab2021-01-06 17:19:27 -080023#include "LnbClient.h"
24
25using ::android::hardware::tv::tuner::V1_0::Result;
26
27namespace android {
28
29/////////////// LnbClient ///////////////////////
30
Amy Zhang3ac0a3e2021-01-14 18:55:10 -080031LnbClient::LnbClient(shared_ptr<ITunerLnb> tunerLnb) {
32 mTunerLnb = tunerLnb;
Amy Zhangd3d57b42021-01-07 11:14:43 -080033 mId = -1;
Amy Zhangb0f63ab2021-01-06 17:19:27 -080034}
35
36LnbClient::~LnbClient() {
Amy Zhang3ac0a3e2021-01-14 18:55:10 -080037 mTunerLnb = NULL;
Amy Zhangb0f63ab2021-01-06 17:19:27 -080038 mLnb = NULL;
Amy Zhangd3d57b42021-01-07 11:14:43 -080039 mId = -1;
Amy Zhangb0f63ab2021-01-06 17:19:27 -080040}
41
42// TODO: remove after migration to Tuner Service is done.
43void LnbClient::setHidlLnb(sp<ILnb> lnb) {
44 mLnb = lnb;
45}
46
Amy Zhangd3d57b42021-01-07 11:14:43 -080047Result LnbClient::setCallback(sp<LnbClientCallback> cb) {
Amy Zhang3ac0a3e2021-01-14 18:55:10 -080048 if (mTunerLnb != NULL) {
Amy Zhangd3d57b42021-01-07 11:14:43 -080049 mAidlCallback = ::ndk::SharedRefBase::make<TunerLnbCallback>(cb);
Amy Zhang3ac0a3e2021-01-14 18:55:10 -080050 Status s = mTunerLnb->setCallback(mAidlCallback);
51 return TunerClient::getServiceSpecificErrorCode(s);
52 }
Amy Zhangd3d57b42021-01-07 11:14:43 -080053
Amy Zhang9eeba432021-01-21 12:52:05 -080054 if (mLnb != NULL) {
55 mHidlCallback = new HidlLnbCallback(cb);
56 return mLnb->setCallback(mHidlCallback);
57 }
58
59 return Result::INVALID_STATE;
Amy Zhangb0f63ab2021-01-06 17:19:27 -080060}
61
Amy Zhangd3d57b42021-01-07 11:14:43 -080062Result LnbClient::setVoltage(LnbVoltage voltage) {
Amy Zhang3ac0a3e2021-01-14 18:55:10 -080063 if (mTunerLnb != NULL) {
64 Status s = mTunerLnb->setVoltage((int)voltage);
65 return TunerClient::getServiceSpecificErrorCode(s);
66 }
Amy Zhangd3d57b42021-01-07 11:14:43 -080067
68 if (mLnb != NULL) {
69 return mLnb->setVoltage(voltage);
70 }
71
72 return Result::INVALID_STATE;
Amy Zhangb0f63ab2021-01-06 17:19:27 -080073}
74
Amy Zhangd3d57b42021-01-07 11:14:43 -080075Result LnbClient::setTone(LnbTone tone) {
Amy Zhang3ac0a3e2021-01-14 18:55:10 -080076 if (mTunerLnb != NULL) {
77 Status s = mTunerLnb->setTone((int)tone);
78 return TunerClient::getServiceSpecificErrorCode(s);
79 }
Amy Zhangd3d57b42021-01-07 11:14:43 -080080
81 if (mLnb != NULL) {
82 return mLnb->setTone(tone);
83 }
84
85 return Result::INVALID_STATE;
Amy Zhangb0f63ab2021-01-06 17:19:27 -080086}
87
Amy Zhangd3d57b42021-01-07 11:14:43 -080088Result LnbClient::setSatellitePosition(LnbPosition position) {
Amy Zhang3ac0a3e2021-01-14 18:55:10 -080089 if (mTunerLnb != NULL) {
90 Status s = mTunerLnb->setSatellitePosition((int)position);
91 return TunerClient::getServiceSpecificErrorCode(s);
92 }
Amy Zhangd3d57b42021-01-07 11:14:43 -080093
94 if (mLnb != NULL) {
95 return mLnb->setSatellitePosition(position);
96 }
97
98 return Result::INVALID_STATE;
Amy Zhangb0f63ab2021-01-06 17:19:27 -080099}
100
Amy Zhangd3d57b42021-01-07 11:14:43 -0800101Result LnbClient::sendDiseqcMessage(vector<uint8_t> diseqcMessage) {
Amy Zhang3ac0a3e2021-01-14 18:55:10 -0800102 if (mTunerLnb != NULL) {
103 Status s = mTunerLnb->sendDiseqcMessage(diseqcMessage);
104 return TunerClient::getServiceSpecificErrorCode(s);
105 }
Amy Zhangd3d57b42021-01-07 11:14:43 -0800106
107 if (mLnb != NULL) {
108 return mLnb->sendDiseqcMessage(diseqcMessage);
109 }
110
111 return Result::INVALID_STATE;
Amy Zhangb0f63ab2021-01-06 17:19:27 -0800112}
113
114Result LnbClient::close() {
Amy Zhang3ac0a3e2021-01-14 18:55:10 -0800115 if (mTunerLnb != NULL) {
116 Status s = mTunerLnb->close();
117 return TunerClient::getServiceSpecificErrorCode(s);
118 }
Amy Zhangd3d57b42021-01-07 11:14:43 -0800119
120 if (mLnb != NULL) {
121 return mLnb->close();
122 }
123
124 return Result::INVALID_STATE;
Amy Zhangb0f63ab2021-01-06 17:19:27 -0800125}
126
127/////////////// ILnbCallback ///////////////////////
128
129HidlLnbCallback::HidlLnbCallback(sp<LnbClientCallback> lnbClientCallback)
130 : mLnbClientCallback(lnbClientCallback) {}
131
132Return<void> HidlLnbCallback::onEvent(const LnbEventType lnbEventType) {
133 if (mLnbClientCallback != NULL) {
134 mLnbClientCallback->onEvent(lnbEventType);
135 }
136 return Void();
137}
138
139Return<void> HidlLnbCallback::onDiseqcMessage(const hidl_vec<uint8_t>& diseqcMessage) {
140 if (mLnbClientCallback != NULL) {
141 mLnbClientCallback->onDiseqcMessage(diseqcMessage);
142 }
143 return Void();
144}
145
Amy Zhang3ac0a3e2021-01-14 18:55:10 -0800146/////////////// TunerLnbCallback ///////////////////////
Amy Zhangb0f63ab2021-01-06 17:19:27 -0800147
Amy Zhang3ac0a3e2021-01-14 18:55:10 -0800148TunerLnbCallback::TunerLnbCallback(sp<LnbClientCallback> lnbClientCallback)
149 : mLnbClientCallback(lnbClientCallback) {}
150
151Status TunerLnbCallback::onEvent(int lnbEventType) {
152 if (mLnbClientCallback != NULL) {
153 mLnbClientCallback->onEvent(static_cast<LnbEventType>(lnbEventType));
154 return Status::ok();
155 }
156 return Status::fromServiceSpecificError(static_cast<int32_t>(Result::INVALID_STATE));
157}
158
159Status TunerLnbCallback::onDiseqcMessage(const vector<uint8_t>& diseqcMessage) {
160 if (mLnbClientCallback != NULL) {
161 hidl_vec<uint8_t> msg(begin(diseqcMessage), end(diseqcMessage));
162 mLnbClientCallback->onDiseqcMessage(msg);
163 return Status::ok();
164 }
165 return Status::fromServiceSpecificError(static_cast<int32_t>(Result::INVALID_STATE));
166}
Amy Zhangb0f63ab2021-01-06 17:19:27 -0800167} // namespace android