Amy Zhang | b0f63ab | 2021-01-06 17:19:27 -0800 | [diff] [blame] | 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 "LnbClient" |
| 18 | |
| 19 | #include <android-base/logging.h> |
| 20 | #include <utils/Log.h> |
| 21 | |
Amy Zhang | 3ac0a3e | 2021-01-14 18:55:10 -0800 | [diff] [blame] | 22 | #include "TunerClient.h" |
Amy Zhang | b0f63ab | 2021-01-06 17:19:27 -0800 | [diff] [blame] | 23 | #include "LnbClient.h" |
| 24 | |
| 25 | using ::android::hardware::tv::tuner::V1_0::Result; |
| 26 | |
| 27 | namespace android { |
| 28 | |
| 29 | /////////////// LnbClient /////////////////////// |
| 30 | |
Amy Zhang | 3ac0a3e | 2021-01-14 18:55:10 -0800 | [diff] [blame] | 31 | LnbClient::LnbClient(shared_ptr<ITunerLnb> tunerLnb) { |
| 32 | mTunerLnb = tunerLnb; |
Amy Zhang | d3d57b4 | 2021-01-07 11:14:43 -0800 | [diff] [blame] | 33 | mId = -1; |
Amy Zhang | b0f63ab | 2021-01-06 17:19:27 -0800 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | LnbClient::~LnbClient() { |
Amy Zhang | 3ac0a3e | 2021-01-14 18:55:10 -0800 | [diff] [blame] | 37 | mTunerLnb = NULL; |
Amy Zhang | b0f63ab | 2021-01-06 17:19:27 -0800 | [diff] [blame] | 38 | mLnb = NULL; |
Amy Zhang | d3d57b4 | 2021-01-07 11:14:43 -0800 | [diff] [blame] | 39 | mId = -1; |
Amy Zhang | b0f63ab | 2021-01-06 17:19:27 -0800 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | // TODO: remove after migration to Tuner Service is done. |
| 43 | void LnbClient::setHidlLnb(sp<ILnb> lnb) { |
| 44 | mLnb = lnb; |
| 45 | } |
| 46 | |
Amy Zhang | d3d57b4 | 2021-01-07 11:14:43 -0800 | [diff] [blame] | 47 | Result LnbClient::setCallback(sp<LnbClientCallback> cb) { |
Amy Zhang | 3ac0a3e | 2021-01-14 18:55:10 -0800 | [diff] [blame] | 48 | if (mTunerLnb != NULL) { |
Amy Zhang | d3d57b4 | 2021-01-07 11:14:43 -0800 | [diff] [blame] | 49 | mAidlCallback = ::ndk::SharedRefBase::make<TunerLnbCallback>(cb); |
Amy Zhang | 3ac0a3e | 2021-01-14 18:55:10 -0800 | [diff] [blame] | 50 | Status s = mTunerLnb->setCallback(mAidlCallback); |
| 51 | return TunerClient::getServiceSpecificErrorCode(s); |
| 52 | } |
Amy Zhang | d3d57b4 | 2021-01-07 11:14:43 -0800 | [diff] [blame] | 53 | |
Amy Zhang | 9eeba43 | 2021-01-21 12:52:05 -0800 | [diff] [blame^] | 54 | if (mLnb != NULL) { |
| 55 | mHidlCallback = new HidlLnbCallback(cb); |
| 56 | return mLnb->setCallback(mHidlCallback); |
| 57 | } |
| 58 | |
| 59 | return Result::INVALID_STATE; |
Amy Zhang | b0f63ab | 2021-01-06 17:19:27 -0800 | [diff] [blame] | 60 | } |
| 61 | |
Amy Zhang | d3d57b4 | 2021-01-07 11:14:43 -0800 | [diff] [blame] | 62 | Result LnbClient::setVoltage(LnbVoltage voltage) { |
Amy Zhang | 3ac0a3e | 2021-01-14 18:55:10 -0800 | [diff] [blame] | 63 | if (mTunerLnb != NULL) { |
| 64 | Status s = mTunerLnb->setVoltage((int)voltage); |
| 65 | return TunerClient::getServiceSpecificErrorCode(s); |
| 66 | } |
Amy Zhang | d3d57b4 | 2021-01-07 11:14:43 -0800 | [diff] [blame] | 67 | |
| 68 | if (mLnb != NULL) { |
| 69 | return mLnb->setVoltage(voltage); |
| 70 | } |
| 71 | |
| 72 | return Result::INVALID_STATE; |
Amy Zhang | b0f63ab | 2021-01-06 17:19:27 -0800 | [diff] [blame] | 73 | } |
| 74 | |
Amy Zhang | d3d57b4 | 2021-01-07 11:14:43 -0800 | [diff] [blame] | 75 | Result LnbClient::setTone(LnbTone tone) { |
Amy Zhang | 3ac0a3e | 2021-01-14 18:55:10 -0800 | [diff] [blame] | 76 | if (mTunerLnb != NULL) { |
| 77 | Status s = mTunerLnb->setTone((int)tone); |
| 78 | return TunerClient::getServiceSpecificErrorCode(s); |
| 79 | } |
Amy Zhang | d3d57b4 | 2021-01-07 11:14:43 -0800 | [diff] [blame] | 80 | |
| 81 | if (mLnb != NULL) { |
| 82 | return mLnb->setTone(tone); |
| 83 | } |
| 84 | |
| 85 | return Result::INVALID_STATE; |
Amy Zhang | b0f63ab | 2021-01-06 17:19:27 -0800 | [diff] [blame] | 86 | } |
| 87 | |
Amy Zhang | d3d57b4 | 2021-01-07 11:14:43 -0800 | [diff] [blame] | 88 | Result LnbClient::setSatellitePosition(LnbPosition position) { |
Amy Zhang | 3ac0a3e | 2021-01-14 18:55:10 -0800 | [diff] [blame] | 89 | if (mTunerLnb != NULL) { |
| 90 | Status s = mTunerLnb->setSatellitePosition((int)position); |
| 91 | return TunerClient::getServiceSpecificErrorCode(s); |
| 92 | } |
Amy Zhang | d3d57b4 | 2021-01-07 11:14:43 -0800 | [diff] [blame] | 93 | |
| 94 | if (mLnb != NULL) { |
| 95 | return mLnb->setSatellitePosition(position); |
| 96 | } |
| 97 | |
| 98 | return Result::INVALID_STATE; |
Amy Zhang | b0f63ab | 2021-01-06 17:19:27 -0800 | [diff] [blame] | 99 | } |
| 100 | |
Amy Zhang | d3d57b4 | 2021-01-07 11:14:43 -0800 | [diff] [blame] | 101 | Result LnbClient::sendDiseqcMessage(vector<uint8_t> diseqcMessage) { |
Amy Zhang | 3ac0a3e | 2021-01-14 18:55:10 -0800 | [diff] [blame] | 102 | if (mTunerLnb != NULL) { |
| 103 | Status s = mTunerLnb->sendDiseqcMessage(diseqcMessage); |
| 104 | return TunerClient::getServiceSpecificErrorCode(s); |
| 105 | } |
Amy Zhang | d3d57b4 | 2021-01-07 11:14:43 -0800 | [diff] [blame] | 106 | |
| 107 | if (mLnb != NULL) { |
| 108 | return mLnb->sendDiseqcMessage(diseqcMessage); |
| 109 | } |
| 110 | |
| 111 | return Result::INVALID_STATE; |
Amy Zhang | b0f63ab | 2021-01-06 17:19:27 -0800 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | Result LnbClient::close() { |
Amy Zhang | 3ac0a3e | 2021-01-14 18:55:10 -0800 | [diff] [blame] | 115 | if (mTunerLnb != NULL) { |
| 116 | Status s = mTunerLnb->close(); |
| 117 | return TunerClient::getServiceSpecificErrorCode(s); |
| 118 | } |
Amy Zhang | d3d57b4 | 2021-01-07 11:14:43 -0800 | [diff] [blame] | 119 | |
| 120 | if (mLnb != NULL) { |
| 121 | return mLnb->close(); |
| 122 | } |
| 123 | |
| 124 | return Result::INVALID_STATE; |
Amy Zhang | b0f63ab | 2021-01-06 17:19:27 -0800 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | /////////////// ILnbCallback /////////////////////// |
| 128 | |
| 129 | HidlLnbCallback::HidlLnbCallback(sp<LnbClientCallback> lnbClientCallback) |
| 130 | : mLnbClientCallback(lnbClientCallback) {} |
| 131 | |
| 132 | Return<void> HidlLnbCallback::onEvent(const LnbEventType lnbEventType) { |
| 133 | if (mLnbClientCallback != NULL) { |
| 134 | mLnbClientCallback->onEvent(lnbEventType); |
| 135 | } |
| 136 | return Void(); |
| 137 | } |
| 138 | |
| 139 | Return<void> HidlLnbCallback::onDiseqcMessage(const hidl_vec<uint8_t>& diseqcMessage) { |
| 140 | if (mLnbClientCallback != NULL) { |
| 141 | mLnbClientCallback->onDiseqcMessage(diseqcMessage); |
| 142 | } |
| 143 | return Void(); |
| 144 | } |
| 145 | |
Amy Zhang | 3ac0a3e | 2021-01-14 18:55:10 -0800 | [diff] [blame] | 146 | /////////////// TunerLnbCallback /////////////////////// |
Amy Zhang | b0f63ab | 2021-01-06 17:19:27 -0800 | [diff] [blame] | 147 | |
Amy Zhang | 3ac0a3e | 2021-01-14 18:55:10 -0800 | [diff] [blame] | 148 | TunerLnbCallback::TunerLnbCallback(sp<LnbClientCallback> lnbClientCallback) |
| 149 | : mLnbClientCallback(lnbClientCallback) {} |
| 150 | |
| 151 | Status 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 | |
| 159 | Status 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 Zhang | b0f63ab | 2021-01-06 17:19:27 -0800 | [diff] [blame] | 167 | } // namespace android |