Hongguang | 093c5f3 | 2021-08-09 19:46:34 -0700 | [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 "TunerHidlLnb" |
| 18 | |
| 19 | #include "TunerHidlLnb.h" |
| 20 | |
| 21 | #include <aidl/android/hardware/tv/tuner/Result.h> |
| 22 | |
| 23 | using ::aidl::android::hardware::tv::tuner::Result; |
| 24 | using HidlLnbPosition = ::android::hardware::tv::tuner::V1_0::LnbPosition; |
| 25 | using HidlLnbTone = ::android::hardware::tv::tuner::V1_0::LnbTone; |
| 26 | using HidlLnbVoltage = ::android::hardware::tv::tuner::V1_0::LnbVoltage; |
| 27 | using HidlResult = ::android::hardware::tv::tuner::V1_0::Result; |
| 28 | |
| 29 | using namespace std; |
| 30 | |
| 31 | namespace aidl { |
| 32 | namespace android { |
| 33 | namespace media { |
| 34 | namespace tv { |
| 35 | namespace tuner { |
| 36 | |
| 37 | TunerHidlLnb::TunerHidlLnb(sp<HidlILnb> lnb, int id) { |
| 38 | mLnb = lnb; |
| 39 | mId = id; |
| 40 | } |
| 41 | |
| 42 | TunerHidlLnb::~TunerHidlLnb() { |
| 43 | mLnb = nullptr; |
| 44 | mId = -1; |
| 45 | } |
| 46 | |
| 47 | ::ndk::ScopedAStatus TunerHidlLnb::setCallback( |
| 48 | const shared_ptr<ITunerLnbCallback>& in_tunerLnbCallback) { |
| 49 | if (mLnb == nullptr) { |
| 50 | ALOGE("ILnb is not initialized"); |
| 51 | return ::ndk::ScopedAStatus::fromServiceSpecificError( |
| 52 | static_cast<int32_t>(Result::UNAVAILABLE)); |
| 53 | } |
| 54 | |
| 55 | if (in_tunerLnbCallback == nullptr) { |
| 56 | return ::ndk::ScopedAStatus::fromServiceSpecificError( |
| 57 | static_cast<int32_t>(Result::INVALID_ARGUMENT)); |
| 58 | } |
| 59 | |
| 60 | sp<HidlILnbCallback> lnbCallback = new LnbCallback(in_tunerLnbCallback); |
| 61 | HidlResult status = mLnb->setCallback(lnbCallback); |
| 62 | if (status != HidlResult::SUCCESS) { |
| 63 | return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(status)); |
| 64 | } |
| 65 | return ::ndk::ScopedAStatus::ok(); |
| 66 | } |
| 67 | |
| 68 | ::ndk::ScopedAStatus TunerHidlLnb::setVoltage(LnbVoltage in_voltage) { |
| 69 | if (mLnb == nullptr) { |
| 70 | ALOGE("ILnb is not initialized"); |
| 71 | return ::ndk::ScopedAStatus::fromServiceSpecificError( |
| 72 | static_cast<int32_t>(Result::UNAVAILABLE)); |
| 73 | } |
| 74 | |
| 75 | HidlResult status = mLnb->setVoltage(static_cast<HidlLnbVoltage>(in_voltage)); |
| 76 | if (status != HidlResult::SUCCESS) { |
| 77 | return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(status)); |
| 78 | } |
| 79 | return ::ndk::ScopedAStatus::ok(); |
| 80 | } |
| 81 | |
| 82 | ::ndk::ScopedAStatus TunerHidlLnb::setTone(LnbTone in_tone) { |
| 83 | if (mLnb == nullptr) { |
| 84 | ALOGE("ILnb is not initialized"); |
| 85 | return ::ndk::ScopedAStatus::fromServiceSpecificError( |
| 86 | static_cast<int32_t>(Result::UNAVAILABLE)); |
| 87 | } |
| 88 | |
| 89 | HidlResult status = mLnb->setTone(static_cast<HidlLnbTone>(in_tone)); |
| 90 | if (status != HidlResult::SUCCESS) { |
| 91 | return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(status)); |
| 92 | } |
| 93 | return ::ndk::ScopedAStatus::ok(); |
| 94 | } |
| 95 | |
| 96 | ::ndk::ScopedAStatus TunerHidlLnb::setSatellitePosition(LnbPosition in_position) { |
| 97 | if (mLnb == nullptr) { |
| 98 | ALOGE("ILnb is not initialized"); |
| 99 | return ::ndk::ScopedAStatus::fromServiceSpecificError( |
| 100 | static_cast<int32_t>(Result::UNAVAILABLE)); |
| 101 | } |
| 102 | |
| 103 | HidlResult status = mLnb->setSatellitePosition(static_cast<HidlLnbPosition>(in_position)); |
| 104 | if (status != HidlResult::SUCCESS) { |
| 105 | return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(status)); |
| 106 | } |
| 107 | return ::ndk::ScopedAStatus::ok(); |
| 108 | } |
| 109 | |
| 110 | ::ndk::ScopedAStatus TunerHidlLnb::sendDiseqcMessage(const vector<uint8_t>& in_diseqcMessage) { |
| 111 | if (mLnb == nullptr) { |
| 112 | ALOGE("ILnb is not initialized"); |
| 113 | return ::ndk::ScopedAStatus::fromServiceSpecificError( |
| 114 | static_cast<int32_t>(Result::UNAVAILABLE)); |
| 115 | } |
| 116 | |
| 117 | HidlResult status = mLnb->sendDiseqcMessage(in_diseqcMessage); |
| 118 | if (status != HidlResult::SUCCESS) { |
| 119 | return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(status)); |
| 120 | } |
| 121 | return ::ndk::ScopedAStatus::ok(); |
| 122 | } |
| 123 | |
| 124 | ::ndk::ScopedAStatus TunerHidlLnb::close() { |
| 125 | if (mLnb == nullptr) { |
| 126 | ALOGE("ILnb is not initialized"); |
| 127 | return ::ndk::ScopedAStatus::fromServiceSpecificError( |
| 128 | static_cast<int32_t>(Result::UNAVAILABLE)); |
| 129 | } |
| 130 | |
| 131 | HidlResult res = mLnb->close(); |
| 132 | mLnb = nullptr; |
| 133 | |
| 134 | if (res != HidlResult::SUCCESS) { |
| 135 | return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res)); |
| 136 | } |
| 137 | return ::ndk::ScopedAStatus::ok(); |
| 138 | } |
| 139 | |
| 140 | /////////////// ILnbCallback /////////////////////// |
| 141 | Return<void> TunerHidlLnb::LnbCallback::onEvent(const HidlLnbEventType lnbEventType) { |
| 142 | if (mTunerLnbCallback != nullptr) { |
| 143 | mTunerLnbCallback->onEvent(static_cast<LnbEventType>(lnbEventType)); |
| 144 | } |
| 145 | return Void(); |
| 146 | } |
| 147 | |
| 148 | Return<void> TunerHidlLnb::LnbCallback::onDiseqcMessage(const hidl_vec<uint8_t>& diseqcMessage) { |
| 149 | if (mTunerLnbCallback != nullptr) { |
| 150 | vector<uint8_t> msg(begin(diseqcMessage), end(diseqcMessage)); |
| 151 | mTunerLnbCallback->onDiseqcMessage(msg); |
| 152 | } |
| 153 | return Void(); |
| 154 | } |
| 155 | |
| 156 | } // namespace tuner |
| 157 | } // namespace tv |
| 158 | } // namespace media |
| 159 | } // namespace android |
| 160 | } // namespace aidl |