blob: e78b1cfae41f3fd21244e9818c4383a20e75723e [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();
Venkatarama Avadhanie0178782023-09-11 09:03:18 +053043 ~HdmiCecMock();
Venkatarama Avadhani820b5482022-05-18 15:19:04 +053044 ::ndk::ScopedAStatus addLogicalAddress(CecLogicalAddress addr, Result* _aidl_return) override;
45 ::ndk::ScopedAStatus clearLogicalAddress() override;
46 ::ndk::ScopedAStatus enableAudioReturnChannel(int32_t portId, bool enable) override;
47 ::ndk::ScopedAStatus getCecVersion(int32_t* _aidl_return) override;
48 ::ndk::ScopedAStatus getPhysicalAddress(int32_t* _aidl_return) override;
49 ::ndk::ScopedAStatus getVendorId(int32_t* _aidl_return) override;
50 ::ndk::ScopedAStatus sendMessage(const CecMessage& message,
51 SendMessageResult* _aidl_return) override;
52 ::ndk::ScopedAStatus setCallback(const std::shared_ptr<IHdmiCecCallback>& callback) override;
53 ::ndk::ScopedAStatus setLanguage(const std::string& language) override;
54 ::ndk::ScopedAStatus enableWakeupByOtp(bool value) override;
55 ::ndk::ScopedAStatus enableCec(bool value) override;
56 ::ndk::ScopedAStatus enableSystemCecControl(bool value) override;
57 void printCecMsgBuf(const char* msg_buf, int len);
58
59 private:
60 static void* __threadLoop(void* data);
61 void threadLoop();
62 int readMessageFromFifo(unsigned char* buf, int msgCount);
63 int sendMessageToFifo(const CecMessage& message);
64 void handleCecMessage(unsigned char* msgBuf, int length);
65
66 private:
67 static void serviceDied(void* cookie);
68 std::shared_ptr<IHdmiCecCallback> mCallback;
69
70 // Variables for the virtual cec hal impl
71 uint16_t mPhysicalAddress = 0xFFFF;
72 vector<CecLogicalAddress> mLogicalAddresses;
73 int32_t mCecVersion = 0x06;
74 uint32_t mCecVendorId = 0x01;
75
76 // CEC Option value
77 bool mOptionWakeUp = 0;
78 bool mOptionEnableCec = 0;
79 bool mOptionSystemCecControl = 0;
80 int mOptionLanguage;
81
82 // Testing variables
83 // Input file descriptor
84 int mInputFile;
85 // Output file descriptor
86 int mOutputFile;
87 bool mCecThreadRun = true;
88 pthread_t mThreadId = 0;
89
90 ::ndk::ScopedAIBinder_DeathRecipient mDeathRecipient;
91};
92} // namespace implementation
93} // namespace cec
Venkatarama Avadhani601d2992022-12-12 22:29:30 +053094} // namespace hdmi
Venkatarama Avadhani820b5482022-05-18 15:19:04 +053095} // namespace tv
96} // namespace hardware
97} // namespace android