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 #ifndef _ANDROID_MEDIA_TV_LNB_CLIENT_H_ 18 #define _ANDROID_MEDIA_TV_LNB_CLIENT_H_ 19 20 #include <aidl/android/media/tv/tuner/BnTunerLnbCallback.h> 21 #include <aidl/android/media/tv/tuner/ITunerLnb.h> 22 #include <android/hardware/tv/tuner/1.0/ILnb.h> 23 #include <android/hardware/tv/tuner/1.0/ILnbCallback.h> 24 #include <android/hardware/tv/tuner/1.1/types.h> 25 26 #include "ClientHelper.h" 27 #include "LnbClientCallback.h" 28 29 using Status = ::ndk::ScopedAStatus; 30 31 using ::aidl::android::media::tv::tuner::BnTunerLnbCallback; 32 using ::aidl::android::media::tv::tuner::ITunerLnb; 33 34 using ::android::hardware::Return; 35 using ::android::hardware::Void; 36 using ::android::hardware::hidl_vec; 37 using ::android::hardware::tv::tuner::V1_0::ILnb; 38 using ::android::hardware::tv::tuner::V1_0::ILnbCallback; 39 using ::android::hardware::tv::tuner::V1_0::LnbId; 40 using ::android::hardware::tv::tuner::V1_0::LnbPosition; 41 using ::android::hardware::tv::tuner::V1_0::LnbTone; 42 using ::android::hardware::tv::tuner::V1_0::LnbVoltage; 43 using ::android::hardware::tv::tuner::V1_0::Result; 44 45 using namespace std; 46 47 namespace android { 48 49 class TunerLnbCallback : public BnTunerLnbCallback { 50 51 public: 52 TunerLnbCallback(sp<LnbClientCallback> lnbClientCallback); 53 54 Status onEvent(int lnbEventType); 55 Status onDiseqcMessage(const vector<uint8_t>& diseqcMessage); 56 57 private: 58 sp<LnbClientCallback> mLnbClientCallback; 59 }; 60 61 struct HidlLnbCallback : public ILnbCallback { 62 63 public: 64 HidlLnbCallback(sp<LnbClientCallback> lnbClientCallback); 65 virtual Return<void> onEvent(const LnbEventType lnbEventType); 66 virtual Return<void> onDiseqcMessage(const hidl_vec<uint8_t>& diseqcMessage); 67 68 private: 69 sp<LnbClientCallback> mLnbClientCallback; 70 }; 71 72 struct LnbClient : public RefBase { 73 74 public: 75 LnbClient(shared_ptr<ITunerLnb> tunerLnb); 76 ~LnbClient(); 77 78 // TODO: remove after migration to Tuner Service is done. 79 void setHidlLnb(sp<ILnb> lnb); 80 81 /** 82 * Set the lnb callback. 83 */ 84 Result setCallback(sp<LnbClientCallback> cb); 85 86 /** 87 * Set the lnb's power voltage. 88 */ 89 Result setVoltage(LnbVoltage voltage); 90 91 /** 92 * Set the lnb's tone mode. 93 */ 94 Result setTone(LnbTone tone); 95 96 /** 97 * Select the lnb's position. 98 */ 99 Result setSatellitePosition(LnbPosition position); 100 101 /** 102 * Sends DiSEqC (Digital Satellite Equipment Control) message. 103 */ 104 Result sendDiseqcMessage(vector<uint8_t> diseqcMessage); 105 106 /** 107 * Releases the LNB instance. 108 */ 109 Result close(); 110 getAidlLnbLnbClient111 shared_ptr<ITunerLnb> getAidlLnb() { return mTunerLnb; } setIdLnbClient112 void setId(LnbId id) { mId = id; } getIdLnbClient113 LnbId getId() { return mId; } 114 115 private: 116 /** 117 * An AIDL Tuner Lnb Singleton assigned at the first time the Tuner Client 118 * opens an Lnb. Default null when lnb is not opened. 119 */ 120 shared_ptr<ITunerLnb> mTunerLnb; 121 122 /** 123 * A Lnb HAL interface that is ready before migrating to the TunerLnb. 124 * This is a temprary interface before Tuner Framework migrates to use TunerService. 125 * Default null when the HAL service does not exist. 126 */ 127 sp<ILnb> mLnb; 128 129 LnbId mId; 130 }; 131 } // namespace android 132 133 #endif // _ANDROID_MEDIA_TV_LNB_CLIENT_H_ 134