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