blob: 77248d4e81d8d35674d34448d736664df904cf3f [file] [log] [blame]
Amy Zhanga046eee2021-01-12 14:44:58 -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 "TunerLnb"
18
19#include "TunerLnb.h"
20
Amy Zhang077cc1f2021-01-14 18:54:07 -080021using ::android::hardware::tv::tuner::V1_0::LnbPosition;
22using ::android::hardware::tv::tuner::V1_0::LnbTone;
23using ::android::hardware::tv::tuner::V1_0::LnbVoltage;
Amy Zhanga046eee2021-01-12 14:44:58 -080024using ::android::hardware::tv::tuner::V1_0::Result;
25
26namespace android {
27
28TunerLnb::TunerLnb(sp<ILnb> lnb, int id) {
29 mLnb = lnb;
30 mId = id;
31}
32
33TunerLnb::~TunerLnb() {
34 mLnb = NULL;
35 mId = -1;
36}
37
38Status TunerLnb::setCallback(
39 const shared_ptr<ITunerLnbCallback>& tunerLnbCallback) {
40 if (mLnb == NULL) {
41 ALOGE("ILnb is not initialized");
42 return Status::fromServiceSpecificError(static_cast<int32_t>(Result::UNAVAILABLE));
43 }
44
45 if (tunerLnbCallback == NULL) {
46 return Status::fromServiceSpecificError(static_cast<int32_t>(Result::INVALID_ARGUMENT));
47 }
48
49 sp<ILnbCallback> lnbCallback = new LnbCallback(tunerLnbCallback);
50 Result status = mLnb->setCallback(lnbCallback);
Amy Zhangd48a2a62021-04-12 21:39:19 -070051 if (status != Result::SUCCESS) {
52 return Status::fromServiceSpecificError(static_cast<int32_t>(status));
53 }
54 return Status::ok();
Amy Zhanga046eee2021-01-12 14:44:58 -080055}
56
Amy Zhang077cc1f2021-01-14 18:54:07 -080057Status TunerLnb::setVoltage(int voltage) {
58 if (mLnb == NULL) {
59 ALOGE("ILnb is not initialized");
60 return Status::fromServiceSpecificError(static_cast<int32_t>(Result::UNAVAILABLE));
61 }
62
63 Result status = mLnb->setVoltage(static_cast<LnbVoltage>(voltage));
Amy Zhangd48a2a62021-04-12 21:39:19 -070064 if (status != Result::SUCCESS) {
65 return Status::fromServiceSpecificError(static_cast<int32_t>(status));
66 }
67 return Status::ok();
Amy Zhanga046eee2021-01-12 14:44:58 -080068}
69
Amy Zhang077cc1f2021-01-14 18:54:07 -080070Status TunerLnb::setTone(int tone) {
71 if (mLnb == NULL) {
72 ALOGE("ILnb is not initialized");
73 return Status::fromServiceSpecificError(static_cast<int32_t>(Result::UNAVAILABLE));
74 }
75
76 Result status = mLnb->setTone(static_cast<LnbTone>(tone));
Amy Zhangd48a2a62021-04-12 21:39:19 -070077 if (status != Result::SUCCESS) {
78 return Status::fromServiceSpecificError(static_cast<int32_t>(status));
79 }
80 return Status::ok();
Amy Zhanga046eee2021-01-12 14:44:58 -080081}
82
Amy Zhang077cc1f2021-01-14 18:54:07 -080083Status TunerLnb::setSatellitePosition(int position) {
84 if (mLnb == NULL) {
85 ALOGE("ILnb is not initialized");
86 return Status::fromServiceSpecificError(static_cast<int32_t>(Result::UNAVAILABLE));
87 }
88
89 Result status = mLnb->setSatellitePosition(static_cast<LnbPosition>(position));
Amy Zhangd48a2a62021-04-12 21:39:19 -070090 if (status != Result::SUCCESS) {
91 return Status::fromServiceSpecificError(static_cast<int32_t>(status));
92 }
93 return Status::ok();
Amy Zhanga046eee2021-01-12 14:44:58 -080094}
95
Amy Zhang077cc1f2021-01-14 18:54:07 -080096Status TunerLnb::sendDiseqcMessage(const vector<uint8_t>& diseqcMessage) {
97 if (mLnb == NULL) {
98 ALOGE("ILnb is not initialized");
99 return Status::fromServiceSpecificError(static_cast<int32_t>(Result::UNAVAILABLE));
100 }
101
102 Result status = mLnb->sendDiseqcMessage(diseqcMessage);
Amy Zhangd48a2a62021-04-12 21:39:19 -0700103 if (status != Result::SUCCESS) {
104 return Status::fromServiceSpecificError(static_cast<int32_t>(status));
105 }
106 return Status::ok();
Amy Zhanga046eee2021-01-12 14:44:58 -0800107}
108
109Status TunerLnb::close() {
Amy Zhang077cc1f2021-01-14 18:54:07 -0800110 if (mLnb == NULL) {
111 ALOGE("ILnb is not initialized");
112 return Status::fromServiceSpecificError(static_cast<int32_t>(Result::UNAVAILABLE));
113 }
114
Amy Zhang14a60e82021-02-11 15:22:52 -0800115 Result res = mLnb->close();
116 mLnb = NULL;
117
118 if (res != Result::SUCCESS) {
119 return Status::fromServiceSpecificError(static_cast<int32_t>(res));
120 }
121 return Status::ok();
Amy Zhanga046eee2021-01-12 14:44:58 -0800122}
123
124/////////////// ILnbCallback ///////////////////////
125
126Return<void> TunerLnb::LnbCallback::onEvent(const LnbEventType lnbEventType) {
127 if (mTunerLnbCallback != NULL) {
128 mTunerLnbCallback->onEvent((int)lnbEventType);
129 }
130 return Void();
131}
132
133Return<void> TunerLnb::LnbCallback::onDiseqcMessage(const hidl_vec<uint8_t>& diseqcMessage) {
134 if (mTunerLnbCallback != NULL && diseqcMessage != NULL) {
135 vector<uint8_t> msg(begin(diseqcMessage), end(diseqcMessage));
136 mTunerLnbCallback->onDiseqcMessage(msg);
137 }
138 return Void();
139}
140} // namespace android