1 /* 2 * Copyright (C) 2022 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 <aidl/android/hardware/tv/hdmi/connection/BnHdmiConnection.h> 18 #include <aidl/android/hardware/tv/hdmi/connection/Result.h> 19 #include <algorithm> 20 #include <vector> 21 22 using namespace std; 23 24 namespace android { 25 namespace hardware { 26 namespace tv { 27 namespace hdmi { 28 namespace connection { 29 namespace implementation { 30 31 using ::aidl::android::hardware::tv::hdmi::connection::BnHdmiConnection; 32 using ::aidl::android::hardware::tv::hdmi::connection::HdmiPortInfo; 33 using ::aidl::android::hardware::tv::hdmi::connection::HdmiPortType; 34 using ::aidl::android::hardware::tv::hdmi::connection::HpdSignal; 35 using ::aidl::android::hardware::tv::hdmi::connection::IHdmiConnection; 36 using ::aidl::android::hardware::tv::hdmi::connection::IHdmiConnectionCallback; 37 using ::aidl::android::hardware::tv::hdmi::connection::Result; 38 39 #define HDMI_MSG_IN_FIFO "/dev/hdmi_in_pipe" 40 #define MESSAGE_BODY_MAX_LENGTH 4 41 42 struct HdmiConnectionMock : public BnHdmiConnection { 43 HdmiConnectionMock(); 44 ~HdmiConnectionMock(); 45 ::ndk::ScopedAStatus getPortInfo(std::vector<HdmiPortInfo>* _aidl_return) override; 46 ::ndk::ScopedAStatus isConnected(int32_t portId, bool* _aidl_return) override; 47 ::ndk::ScopedAStatus setCallback( 48 const std::shared_ptr<IHdmiConnectionCallback>& callback) override; 49 ::ndk::ScopedAStatus setHpdSignal(HpdSignal signal, int32_t portId) override; 50 ::ndk::ScopedAStatus getHpdSignal(int32_t portId, HpdSignal* _aidl_return) override; 51 52 void printEventBuf(const char* msg_buf, int len); 53 54 private: 55 static void* __threadLoop(void* data); 56 void threadLoop(); 57 int readMessageFromFifo(unsigned char* buf, int msgCount); 58 void handleHotplugMessage(unsigned char* msgBuf); 59 void stopThread(); 60 61 private: 62 static void serviceDied(void* cookie); 63 std::shared_ptr<IHdmiConnectionCallback> mCallback; 64 65 // Variables for the virtual HDMI hal impl 66 std::vector<HdmiPortInfo> mPortInfos; 67 std::vector<bool> mPortConnectionStatus; 68 69 // Port configuration 70 uint16_t mPhysicalAddress = 0xFFFF; 71 int mTotalPorts = 1; 72 73 // HPD Signal being used 74 std::vector<HpdSignal> mHpdSignal; 75 76 // Testing variables 77 // Input file descriptor 78 int mInputFile; 79 bool mHdmiThreadRun = true; 80 pthread_t mThreadId = 0; 81 82 ::ndk::ScopedAIBinder_DeathRecipient mDeathRecipient; 83 }; 84 } // namespace implementation 85 } // namespace connection 86 } // namespace hdmi 87 } // Namespace tv 88 } // namespace hardware 89 } // namespace android 90