1 /* 2 * Copyright 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 #include <android-base/logging.h> 18 #include <android/hardware/tv/tuner/1.0/ILnb.h> 19 #include <android/hardware/tv/tuner/1.0/ITuner.h> 20 #include <android/hardware/tv/tuner/1.0/types.h> 21 #include <gtest/gtest.h> 22 #include <hidl/HidlSupport.h> 23 #include <hidl/HidlTransportSupport.h> 24 #include <hidl/ServiceManagement.h> 25 #include <hidl/Status.h> 26 #include <hidlmemory/FrameworkUtils.h> 27 #include <utils/Condition.h> 28 #include <utils/Mutex.h> 29 #include <map> 30 31 using android::Condition; 32 using android::Mutex; 33 using android::sp; 34 using android::hardware::hidl_vec; 35 using android::hardware::Return; 36 using android::hardware::Void; 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::ITuner; 40 using android::hardware::tv::tuner::V1_0::LnbEventType; 41 using android::hardware::tv::tuner::V1_0::LnbPosition; 42 using android::hardware::tv::tuner::V1_0::LnbTone; 43 using android::hardware::tv::tuner::V1_0::LnbVoltage; 44 using android::hardware::tv::tuner::V1_0::Result; 45 46 using ::testing::AssertionResult; 47 48 using namespace std; 49 50 class LnbCallback : public ILnbCallback { 51 public: 52 virtual Return<void> onEvent(LnbEventType lnbEventType) override; 53 virtual Return<void> onDiseqcMessage(const hidl_vec<uint8_t>& diseqcMessage) override; 54 55 private: 56 bool mEventReceived = false; 57 android::Mutex mMsgLock; 58 android::Condition mMsgCondition; 59 }; 60 61 class LnbTests { 62 public: setService(sp<ITuner> tuner)63 void setService(sp<ITuner> tuner) { mService = tuner; } 64 65 AssertionResult getLnbIds(vector<uint32_t>& ids); 66 AssertionResult openLnbById(uint32_t lnbId); 67 AssertionResult openLnbByName(string lnbName, uint32_t& lnbId); 68 AssertionResult setLnbCallback(); 69 AssertionResult setVoltage(LnbVoltage voltage); 70 AssertionResult setTone(LnbTone tone); 71 AssertionResult setSatellitePosition(LnbPosition position); 72 AssertionResult sendDiseqcMessage(vector<uint8_t> diseqcMsg); 73 AssertionResult closeLnb(); 74 75 protected: failure()76 static AssertionResult failure() { return ::testing::AssertionFailure(); } 77 success()78 static AssertionResult success() { return ::testing::AssertionSuccess(); } 79 80 sp<ITuner> mService; 81 sp<ILnb> mLnb; 82 sp<LnbCallback> mLnbCallback; 83 hidl_vec<uint32_t> mLnbIds; 84 }; 85