blob: 05795dd3aa0d4b44ec31bb715c8e54cf90b6b79f [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>
18#include <algorithm>
19#include <vector>
20
21using namespace std;
22
23namespace android {
24namespace hardware {
25namespace tv {
26namespace hdmi {
27namespace implementation {
28
29using ::aidl::android::hardware::tv::hdmi::BnHdmi;
30using ::aidl::android::hardware::tv::hdmi::HdmiPortInfo;
31using ::aidl::android::hardware::tv::hdmi::HdmiPortType;
32using ::aidl::android::hardware::tv::hdmi::IHdmi;
33using ::aidl::android::hardware::tv::hdmi::IHdmiCallback;
34
35#define HDMI_MSG_IN_FIFO "/dev/hdmi_in_pipe"
36#define MESSAGE_BODY_MAX_LENGTH 4
37
38struct HdmiMock : public BnHdmi {
39 HdmiMock();
40
41 ::ndk::ScopedAStatus getPortInfo(std::vector<HdmiPortInfo>* _aidl_return) override;
42 ::ndk::ScopedAStatus isConnected(int32_t portId, bool* _aidl_return) override;
43 ::ndk::ScopedAStatus setCallback(const std::shared_ptr<IHdmiCallback>& callback) override;
44
45 void printEventBuf(const char* msg_buf, int len);
46
47 private:
48 static void* __threadLoop(void* data);
49 void threadLoop();
50 int readMessageFromFifo(unsigned char* buf, int msgCount);
51 void handleHotplugMessage(unsigned char* msgBuf);
52
53 private:
54 static void serviceDied(void* cookie);
55 std::shared_ptr<IHdmiCallback> mCallback;
56
57 // Variables for the virtual HDMI hal impl
58 std::vector<HdmiPortInfo> mPortInfos;
59 std::vector<bool> mPortConnectionStatus;
60
61 // Port configuration
62 uint16_t mPhysicalAddress = 0xFFFF;
63 int mTotalPorts = 1;
64
65 // Testing variables
66 // Input file descriptor
67 int mInputFile;
68 bool mHdmiThreadRun = true;
69 pthread_t mThreadId = 0;
70
71 ::ndk::ScopedAIBinder_DeathRecipient mDeathRecipient;
72};
73} // namespace implementation
74} // namespace hdmi
75} // Namespace tv
76} // namespace hardware
77} // namespace android