blob: 8c66f08c0c43cf19ed8147c896260047a3abc855 [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();
Sham Rathodd0a67fa2023-12-08 16:25:31 +053044 ~HdmiConnectionMock();
Venkatarama Avadhani820b5482022-05-18 15:19:04 +053045 ::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 Clair3944d072023-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);
Sham Rathodd0a67fa2023-12-08 16:25:31 +053059 void stopThread();
Venkatarama Avadhani820b5482022-05-18 15:19:04 +053060
61 private:
62 static void serviceDied(void* cookie);
Venkatarama Avadhani601d2992022-12-12 22:29:30 +053063 std::shared_ptr<IHdmiConnectionCallback> mCallback;
Venkatarama Avadhani820b5482022-05-18 15:19:04 +053064
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
Venkatarama Avadhani04ee1a42022-11-09 16:21:55 +053073 // HPD Signal being used
Nathalie Le Clair3944d072023-01-24 17:26:42 +010074 std::vector<HpdSignal> mHpdSignal;
Venkatarama Avadhani04ee1a42022-11-09 16:21:55 +053075
Venkatarama Avadhani820b5482022-05-18 15:19:04 +053076 // 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
Venkatarama Avadhani601d2992022-12-12 22:29:30 +053085} // namespace connection
Venkatarama Avadhani820b5482022-05-18 15:19:04 +053086} // namespace hdmi
87} // Namespace tv
88} // namespace hardware
89} // namespace android