blob: 6b850ac40ec81894a93db45e7f6e2b25e6b174a6 [file] [log] [blame]
Shraddha Basantwanif3a43c82021-05-27 19:40:17 +05301/*
2 * Copyright (C) 2021 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 <android/hardware/tv/cec/1.0/IHdmiCec.h>
18#include <hardware/hdmi_cec.h>
Shraddha Basantwanidedd40e2021-09-16 15:56:20 +053019#include <linux/cec.h>
20#include <thread>
Shraddha Basantwanif3a43c82021-05-27 19:40:17 +053021
22namespace android {
23namespace hardware {
24namespace tv {
25namespace cec {
26namespace V1_0 {
27namespace implementation {
28
Shraddha Basantwanidedd40e2021-09-16 15:56:20 +053029using std::thread;
30
31class HdmiCecDefault : public IHdmiCec, public hidl_death_recipient {
32 public:
Shraddha Basantwanif3a43c82021-05-27 19:40:17 +053033 HdmiCecDefault();
34 ~HdmiCecDefault();
35 // Methods from ::android::hardware::tv::cec::V1_0::IHdmiCec follow.
36 Return<Result> addLogicalAddress(CecLogicalAddress addr) override;
37 Return<void> clearLogicalAddress() override;
38 Return<void> getPhysicalAddress(getPhysicalAddress_cb _hidl_cb) override;
39 Return<SendMessageResult> sendMessage(const CecMessage& message) override;
40 Return<void> setCallback(const sp<IHdmiCecCallback>& callback) override;
41 Return<int32_t> getCecVersion() override;
42 Return<uint32_t> getVendorId() override;
43 Return<void> getPortInfo(getPortInfo_cb _hidl_cb) override;
44 Return<void> setOption(OptionKey key, bool value) override;
45 Return<void> setLanguage(const hidl_string& language) override;
46 Return<void> enableAudioReturnChannel(int32_t portId, bool enable) override;
47 Return<bool> isConnected(int32_t portId) override;
48
49 virtual void serviceDied(uint64_t, const wp<::android::hidl::base::V1_0::IBase>&) {
50 setCallback(nullptr);
51 }
52
53 Return<Result> init();
54 Return<void> release();
Shraddha Basantwanif3a43c82021-05-27 19:40:17 +053055
Shraddha Basantwanidedd40e2021-09-16 15:56:20 +053056 private:
57 void event_thread();
58 static int getOpcode(cec_msg message);
59 static bool isWakeupMessage(cec_msg message);
60
61 thread mEventThread;
62
63 // When set to false, all the CEC commands are discarded. True by default after initialization.
64 bool mCecEnabled;
65 /*
66 * When set to false, HAL does not wake up the system upon receiving <Image View On> or
67 * <Text View On>. True by default after initialization.
68 */
69 bool mWakeupEnabled;
70 sp<IHdmiCecCallback> mCallback;
71
72 int mCecFd;
73 int mExitFd;
74};
Shraddha Basantwanif3a43c82021-05-27 19:40:17 +053075} // namespace implementation
76} // namespace V1_0
77} // namespace cec
78} // namespace tv
79} // namespace hardware
80} // namespace android