1 /* 2 * Copyright (C) 2017 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 #ifndef ANDROID_HARDWARE_BROADCASTRADIO_V1_1_TUNER_H 17 #define ANDROID_HARDWARE_BROADCASTRADIO_V1_1_TUNER_H 18 19 #include "VirtualRadio.h" 20 21 #include <android/hardware/broadcastradio/1.1/ITuner.h> 22 #include <android/hardware/broadcastradio/1.1/ITunerCallback.h> 23 #include <broadcastradio-utils/WorkerThread.h> 24 25 namespace android { 26 namespace hardware { 27 namespace broadcastradio { 28 namespace V1_1 { 29 namespace implementation { 30 31 struct BroadcastRadio; 32 33 struct Tuner : public ITuner { 34 Tuner(const sp<BroadcastRadio> module, V1_0::Class classId, 35 const sp<V1_0::ITunerCallback>& callback); 36 37 void forceClose(); 38 39 // V1_1::ITuner methods 40 virtual Return<Result> setConfiguration(const V1_0::BandConfig& config) override; 41 virtual Return<void> getConfiguration(getConfiguration_cb _hidl_cb) override; 42 virtual Return<Result> scan(V1_0::Direction direction, bool skipSubChannel) override; 43 virtual Return<Result> step(V1_0::Direction direction, bool skipSubChannel) override; 44 virtual Return<Result> tune(uint32_t channel, uint32_t subChannel) override; 45 virtual Return<Result> tuneByProgramSelector(const V1_1::ProgramSelector& program) override; 46 virtual Return<Result> cancel() override; 47 virtual Return<Result> cancelAnnouncement() override; 48 virtual Return<void> getProgramInformation(getProgramInformation_cb _hidl_cb) override; 49 virtual Return<void> getProgramInformation_1_1(getProgramInformation_1_1_cb _hidl_cb) override; 50 virtual Return<V1_1::ProgramListResult> startBackgroundScan() override; 51 virtual Return<void> getProgramList(const hidl_vec<V1_1::VendorKeyValue>& filter, 52 getProgramList_cb _hidl_cb) override; 53 virtual Return<Result> setAnalogForced(bool isForced) override; 54 virtual Return<void> isAnalogForced(isAnalogForced_cb _hidl_cb) override; 55 56 private: 57 std::mutex mMut; 58 WorkerThread mThread; 59 bool mIsClosed = false; 60 61 const sp<BroadcastRadio> mModule; 62 V1_0::Class mClassId; 63 const sp<V1_0::ITunerCallback> mCallback; 64 const sp<V1_1::ITunerCallback> mCallback1_1; 65 66 std::reference_wrapper<VirtualRadio> mVirtualRadio; 67 bool mIsAmfmConfigSet = false; 68 V1_0::BandConfig mAmfmConfig; 69 bool mIsTuneCompleted = false; 70 V1_1::ProgramSelector mCurrentProgram = {}; 71 V1_1::ProgramInfo mCurrentProgramInfo = {}; 72 std::atomic<bool> mIsAnalogForced; 73 74 utils::HalRevision getHalRev() const; 75 void setConfigurationInternalLocked(const V1_0::BandConfig& config); 76 void tuneInternalLocked(const V1_1::ProgramSelector& sel); 77 bool autoConfigureLocked(uint64_t frequency); 78 }; 79 80 } // namespace implementation 81 } // namespace V1_1 82 } // namespace broadcastradio 83 } // namespace hardware 84 } // namespace android 85 86 #endif // ANDROID_HARDWARE_BROADCASTRADIO_V1_1_TUNER_H 87