blob: 08f4d6f886b7e66b66a138019cd7736850e0e859 [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/cec/BnHdmiCec.h>
18#include <algorithm>
19#include <vector>
20
21using namespace std;
22
23namespace android {
24namespace hardware {
25namespace tv {
26namespace cec {
27namespace implementation {
28
29using ::aidl::android::hardware::tv::cec::BnHdmiCec;
30using ::aidl::android::hardware::tv::cec::CecLogicalAddress;
31using ::aidl::android::hardware::tv::cec::CecMessage;
32using ::aidl::android::hardware::tv::cec::IHdmiCec;
33using ::aidl::android::hardware::tv::cec::IHdmiCecCallback;
34using ::aidl::android::hardware::tv::cec::Result;
35using ::aidl::android::hardware::tv::cec::SendMessageResult;
36
37#define CEC_MSG_IN_FIFO "/dev/cec_aidl_in_pipe"
38#define CEC_MSG_OUT_FIFO "/dev/cec_aidl_out_pipe"
39
40struct HdmiCecMock : public BnHdmiCec {
41 HdmiCecMock();
42 ::ndk::ScopedAStatus addLogicalAddress(CecLogicalAddress addr, Result* _aidl_return) override;
43 ::ndk::ScopedAStatus clearLogicalAddress() override;
44 ::ndk::ScopedAStatus enableAudioReturnChannel(int32_t portId, bool enable) override;
45 ::ndk::ScopedAStatus getCecVersion(int32_t* _aidl_return) override;
46 ::ndk::ScopedAStatus getPhysicalAddress(int32_t* _aidl_return) override;
47 ::ndk::ScopedAStatus getVendorId(int32_t* _aidl_return) override;
48 ::ndk::ScopedAStatus sendMessage(const CecMessage& message,
49 SendMessageResult* _aidl_return) override;
50 ::ndk::ScopedAStatus setCallback(const std::shared_ptr<IHdmiCecCallback>& callback) override;
51 ::ndk::ScopedAStatus setLanguage(const std::string& language) override;
52 ::ndk::ScopedAStatus enableWakeupByOtp(bool value) override;
53 ::ndk::ScopedAStatus enableCec(bool value) override;
54 ::ndk::ScopedAStatus enableSystemCecControl(bool value) override;
55 void printCecMsgBuf(const char* msg_buf, int len);
56
57 private:
58 static void* __threadLoop(void* data);
59 void threadLoop();
60 int readMessageFromFifo(unsigned char* buf, int msgCount);
61 int sendMessageToFifo(const CecMessage& message);
62 void handleCecMessage(unsigned char* msgBuf, int length);
63
64 private:
65 static void serviceDied(void* cookie);
66 std::shared_ptr<IHdmiCecCallback> mCallback;
67
68 // Variables for the virtual cec hal impl
69 uint16_t mPhysicalAddress = 0xFFFF;
70 vector<CecLogicalAddress> mLogicalAddresses;
71 int32_t mCecVersion = 0x06;
72 uint32_t mCecVendorId = 0x01;
73
74 // CEC Option value
75 bool mOptionWakeUp = 0;
76 bool mOptionEnableCec = 0;
77 bool mOptionSystemCecControl = 0;
78 int mOptionLanguage;
79
80 // Testing variables
81 // Input file descriptor
82 int mInputFile;
83 // Output file descriptor
84 int mOutputFile;
85 bool mCecThreadRun = true;
86 pthread_t mThreadId = 0;
87
88 ::ndk::ScopedAIBinder_DeathRecipient mDeathRecipient;
89};
90} // namespace implementation
91} // namespace cec
92} // namespace tv
93} // namespace hardware
94} // namespace android