blob: 51abaff0311910f20a21c52de7ed04f78584e2af [file] [log] [blame]
Venkatarama Avadhani820b5482022-05-18 15:19:04 +05301/*
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/BnHdmi.h>
Venkatarama Avadhani04ee1a42022-11-09 16:21:55 +053018#include <aidl/android/hardware/tv/hdmi/Result.h>
Venkatarama Avadhani820b5482022-05-18 15:19:04 +053019#include <algorithm>
20#include <vector>
21
22using namespace std;
23
24namespace android {
25namespace hardware {
26namespace tv {
27namespace hdmi {
28namespace implementation {
29
30using ::aidl::android::hardware::tv::hdmi::BnHdmi;
31using ::aidl::android::hardware::tv::hdmi::HdmiPortInfo;
32using ::aidl::android::hardware::tv::hdmi::HdmiPortType;
Venkatarama Avadhani04ee1a42022-11-09 16:21:55 +053033using ::aidl::android::hardware::tv::hdmi::HpdSignal;
Venkatarama Avadhani820b5482022-05-18 15:19:04 +053034using ::aidl::android::hardware::tv::hdmi::IHdmi;
35using ::aidl::android::hardware::tv::hdmi::IHdmiCallback;
Venkatarama Avadhani04ee1a42022-11-09 16:21:55 +053036using ::aidl::android::hardware::tv::hdmi::Result;
Venkatarama Avadhani820b5482022-05-18 15:19:04 +053037
38#define HDMI_MSG_IN_FIFO "/dev/hdmi_in_pipe"
39#define MESSAGE_BODY_MAX_LENGTH 4
40
41struct HdmiMock : public BnHdmi {
42 HdmiMock();
43
44 ::ndk::ScopedAStatus getPortInfo(std::vector<HdmiPortInfo>* _aidl_return) override;
45 ::ndk::ScopedAStatus isConnected(int32_t portId, bool* _aidl_return) override;
46 ::ndk::ScopedAStatus setCallback(const std::shared_ptr<IHdmiCallback>& callback) override;
Venkatarama Avadhani04ee1a42022-11-09 16:21:55 +053047 ::ndk::ScopedAStatus setHpdSignal(HpdSignal signal) override;
48 ::ndk::ScopedAStatus getHpdSignal(HpdSignal* _aidl_return) override;
Venkatarama Avadhani820b5482022-05-18 15:19:04 +053049
50 void printEventBuf(const char* msg_buf, int len);
51
52 private:
53 static void* __threadLoop(void* data);
54 void threadLoop();
55 int readMessageFromFifo(unsigned char* buf, int msgCount);
56 void handleHotplugMessage(unsigned char* msgBuf);
57
58 private:
59 static void serviceDied(void* cookie);
60 std::shared_ptr<IHdmiCallback> mCallback;
61
62 // Variables for the virtual HDMI hal impl
63 std::vector<HdmiPortInfo> mPortInfos;
64 std::vector<bool> mPortConnectionStatus;
65
66 // Port configuration
67 uint16_t mPhysicalAddress = 0xFFFF;
68 int mTotalPorts = 1;
69
Venkatarama Avadhani04ee1a42022-11-09 16:21:55 +053070 // HPD Signal being used
71 HpdSignal mHpdSignal = HpdSignal::HDMI_HPD_PHYSICAL;
72
Venkatarama Avadhani820b5482022-05-18 15:19:04 +053073 // Testing variables
74 // Input file descriptor
75 int mInputFile;
76 bool mHdmiThreadRun = true;
77 pthread_t mThreadId = 0;
78
79 ::ndk::ScopedAIBinder_DeathRecipient mDeathRecipient;
80};
81} // namespace implementation
82} // namespace hdmi
83} // Namespace tv
84} // namespace hardware
85} // namespace android