1 /*
2  * Copyright (C) 2019 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 "android.hardware.tv.tuner@1.0-Frontend"
18 
19 #include "Frontend.h"
20 #include <android/hardware/tv/tuner/1.0/IFrontendCallback.h>
21 #include <utils/Log.h>
22 
23 namespace android {
24 namespace hardware {
25 namespace tv {
26 namespace tuner {
27 namespace V1_0 {
28 namespace implementation {
29 
Frontend(FrontendType type,FrontendId id,sp<Tuner> tuner)30 Frontend::Frontend(FrontendType type, FrontendId id, sp<Tuner> tuner) {
31     mType = type;
32     mId = id;
33     mTunerService = tuner;
34     // Init callback to nullptr
35     mCallback = nullptr;
36 }
37 
~Frontend()38 Frontend::~Frontend() {}
39 
close()40 Return<Result> Frontend::close() {
41     ALOGV("%s", __FUNCTION__);
42     // Reset callback
43     mCallback = nullptr;
44 
45     return Result::SUCCESS;
46 }
47 
setCallback(const sp<IFrontendCallback> & callback)48 Return<Result> Frontend::setCallback(const sp<IFrontendCallback>& callback) {
49     ALOGV("%s", __FUNCTION__);
50     if (callback == nullptr) {
51         ALOGW("[   WARN   ] Set Frontend callback with nullptr");
52         return Result::INVALID_ARGUMENT;
53     }
54 
55     mCallback = callback;
56     return Result::SUCCESS;
57 }
58 
tune(const FrontendSettings &)59 Return<Result> Frontend::tune(const FrontendSettings& /* settings */) {
60     ALOGV("%s", __FUNCTION__);
61     if (mCallback == nullptr) {
62         ALOGW("[   WARN   ] Frontend callback is not set when tune");
63         return Result::INVALID_STATE;
64     }
65 
66     // TODO dynamically allocate file to the source file
67     mSourceStreamFile = FRONTEND_STREAM_FILE;
68 
69     mCallback->onEvent(FrontendEventType::LOCKED);
70     return Result::SUCCESS;
71 }
72 
stopTune()73 Return<Result> Frontend::stopTune() {
74     ALOGV("%s", __FUNCTION__);
75 
76     mTunerService->frontendStopTune(mId);
77 
78     return Result::SUCCESS;
79 }
80 
scan(const FrontendSettings &,FrontendScanType)81 Return<Result> Frontend::scan(const FrontendSettings& /* settings */, FrontendScanType /* type */) {
82     ALOGV("%s", __FUNCTION__);
83 
84     return Result::SUCCESS;
85 }
86 
stopScan()87 Return<Result> Frontend::stopScan() {
88     ALOGV("%s", __FUNCTION__);
89 
90     return Result::SUCCESS;
91 }
92 
getStatus(const hidl_vec<FrontendStatusType> &,getStatus_cb _hidl_cb)93 Return<void> Frontend::getStatus(const hidl_vec<FrontendStatusType>& /* statusTypes */,
94                                  getStatus_cb _hidl_cb) {
95     ALOGV("%s", __FUNCTION__);
96 
97     vector<FrontendStatus> statuses;
98     _hidl_cb(Result::SUCCESS, statuses);
99 
100     return Void();
101 }
102 
setLna(bool)103 Return<Result> Frontend::setLna(bool /* bEnable */) {
104     ALOGV("%s", __FUNCTION__);
105 
106     return Result::SUCCESS;
107 }
108 
setLnb(uint32_t)109 Return<Result> Frontend::setLnb(uint32_t /* lnb */) {
110     ALOGV("%s", __FUNCTION__);
111 
112     return Result::SUCCESS;
113 }
114 
getFrontendType()115 FrontendType Frontend::getFrontendType() {
116     return mType;
117 }
118 
getFrontendId()119 FrontendId Frontend::getFrontendId() {
120     return mId;
121 }
122 
getSourceFile()123 string Frontend::getSourceFile() {
124     return mSourceStreamFile;
125 }
126 
127 }  // namespace implementation
128 }  // namespace V1_0
129 }  // namespace tuner
130 }  // namespace tv
131 }  // namespace hardware
132 }  // namespace android
133