blob: c013fddd5617cbba4c30ae8432d9bfaac9c56446 [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
Venkatarama Avadhani601d2992022-12-12 22:29:30 +053017#include <aidl/android/hardware/tv/hdmi/connection/BnHdmiConnection.h>
18#include <aidl/android/hardware/tv/hdmi/connection/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 {
Venkatarama Avadhani601d2992022-12-12 22:29:30 +053028namespace connection {
Venkatarama Avadhani820b5482022-05-18 15:19:04 +053029namespace implementation {
30
Venkatarama Avadhani601d2992022-12-12 22:29:30 +053031using ::aidl::android::hardware::tv::hdmi::connection::BnHdmiConnection;
32using ::aidl::android::hardware::tv::hdmi::connection::HdmiPortInfo;
33using ::aidl::android::hardware::tv::hdmi::connection::HdmiPortType;
34using ::aidl::android::hardware::tv::hdmi::connection::HpdSignal;
35using ::aidl::android::hardware::tv::hdmi::connection::IHdmiConnection;
36using ::aidl::android::hardware::tv::hdmi::connection::IHdmiConnectionCallback;
37using ::aidl::android::hardware::tv::hdmi::connection::Result;
Venkatarama Avadhani820b5482022-05-18 15:19:04 +053038
39#define HDMI_MSG_IN_FIFO "/dev/hdmi_in_pipe"
40#define MESSAGE_BODY_MAX_LENGTH 4
41
Venkatarama Avadhani601d2992022-12-12 22:29:30 +053042struct HdmiConnectionMock : public BnHdmiConnection {
43 HdmiConnectionMock();
Venkatarama Avadhani820b5482022-05-18 15:19:04 +053044
45 ::ndk::ScopedAStatus getPortInfo(std::vector<HdmiPortInfo>* _aidl_return) override;
46 ::ndk::ScopedAStatus isConnected(int32_t portId, bool* _aidl_return) override;
Venkatarama Avadhani601d2992022-12-12 22:29:30 +053047 ::ndk::ScopedAStatus setCallback(
48 const std::shared_ptr<IHdmiConnectionCallback>& callback) override;
Nathalie Le Clair4eaa1782023-01-24 17:26:42 +010049 ::ndk::ScopedAStatus setHpdSignal(HpdSignal signal, int32_t portId) override;
50 ::ndk::ScopedAStatus getHpdSignal(int32_t portId, HpdSignal* _aidl_return) override;
Venkatarama Avadhani820b5482022-05-18 15:19:04 +053051
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
60 private:
61 static void serviceDied(void* cookie);
Venkatarama Avadhani601d2992022-12-12 22:29:30 +053062 std::shared_ptr<IHdmiConnectionCallback> mCallback;
Venkatarama Avadhani820b5482022-05-18 15:19:04 +053063
64 // Variables for the virtual HDMI hal impl
65 std::vector<HdmiPortInfo> mPortInfos;
66 std::vector<bool> mPortConnectionStatus;
67
68 // Port configuration
69 uint16_t mPhysicalAddress = 0xFFFF;
70 int mTotalPorts = 1;
71
Venkatarama Avadhani04ee1a42022-11-09 16:21:55 +053072 // HPD Signal being used
Nathalie Le Clair4eaa1782023-01-24 17:26:42 +010073 std::vector<HpdSignal> mHpdSignal;
Venkatarama Avadhani04ee1a42022-11-09 16:21:55 +053074
Venkatarama Avadhani820b5482022-05-18 15:19:04 +053075 // Testing variables
76 // Input file descriptor
77 int mInputFile;
78 bool mHdmiThreadRun = true;
79 pthread_t mThreadId = 0;
80
81 ::ndk::ScopedAIBinder_DeathRecipient mDeathRecipient;
82};
83} // namespace implementation
Venkatarama Avadhani601d2992022-12-12 22:29:30 +053084} // namespace connection
Venkatarama Avadhani820b5482022-05-18 15:19:04 +053085} // namespace hdmi
86} // Namespace tv
87} // namespace hardware
88} // namespace android