shubang | 23aa3ac | 2020-09-07 18:56:28 -0700 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (c) 2020, 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 "TunerService" |
| 18 | |
| 19 | #include <android/binder_manager.h> |
| 20 | #include <utils/Log.h> |
| 21 | #include "TunerService.h" |
| 22 | |
| 23 | using ::android::hardware::hidl_vec; |
| 24 | using ::android::hardware::tv::tuner::V1_0::FrontendId; |
| 25 | using ::android::hardware::tv::tuner::V1_0::Result; |
| 26 | |
| 27 | namespace android { |
| 28 | |
| 29 | sp<ITuner> TunerService::mTuner; |
| 30 | |
| 31 | TunerService::TunerService() {} |
| 32 | TunerService::~TunerService() {} |
| 33 | |
| 34 | void TunerService::instantiate() { |
| 35 | std::shared_ptr<TunerService> service = |
| 36 | ::ndk::SharedRefBase::make<TunerService>(); |
| 37 | AServiceManager_addService(service->asBinder().get(), getServiceName()); |
| 38 | } |
| 39 | |
| 40 | Status TunerService::getFrontendIds(std::vector<int32_t>* ids, int32_t* /* _aidl_return */) { |
| 41 | if (mTuner == nullptr) { |
| 42 | // TODO: create a method for init. |
| 43 | mTuner = ITuner::getService(); |
| 44 | if (mTuner == nullptr) { |
| 45 | ALOGE("Failed to get ITuner service."); |
| 46 | return ::ndk::ScopedAStatus::fromServiceSpecificError( |
| 47 | static_cast<int32_t>(Result::UNAVAILABLE)); |
| 48 | } |
| 49 | } |
| 50 | hidl_vec<FrontendId> feIds; |
| 51 | Result res; |
| 52 | mTuner->getFrontendIds([&](Result r, const hidl_vec<FrontendId>& frontendIds) { |
| 53 | feIds = frontendIds; |
| 54 | res = r; |
| 55 | }); |
| 56 | if (res != Result::SUCCESS) { |
| 57 | return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res)); |
| 58 | } |
| 59 | ids->resize(feIds.size()); |
| 60 | std::copy(feIds.begin(), feIds.end(), ids->begin()); |
| 61 | |
| 62 | return ::ndk::ScopedAStatus::ok(); |
| 63 | } |
| 64 | |
| 65 | } // namespace android |