blob: 81229d32ce1171b9eb93a08ca3cb8000dc8b840f [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);
Shraddha Basantwani9fb5e822021-06-23 20:42:08 +053059 static int getFirstParam(cec_msg message);
Shraddha Basantwanidedd40e2021-09-16 15:56:20 +053060 static bool isWakeupMessage(cec_msg message);
Shraddha Basantwani9fb5e822021-06-23 20:42:08 +053061 static bool isTransferableInSleep(cec_msg message);
62 static bool isPowerUICommand(cec_msg message);
Shraddha Basantwanidedd40e2021-09-16 15:56:20 +053063
64 thread mEventThread;
65
66 // When set to false, all the CEC commands are discarded. True by default after initialization.
67 bool mCecEnabled;
68 /*
69 * When set to false, HAL does not wake up the system upon receiving <Image View On> or
70 * <Text View On>. True by default after initialization.
71 */
72 bool mWakeupEnabled;
Shraddha Basantwani9fb5e822021-06-23 20:42:08 +053073 /*
74 * Updated when system goes into or comes out of standby mode.
75 * When set to true, Android system is handling CEC commands.
76 * When set to false, microprocessor is handling CEC commands.
77 * True by default after initialization.
78 */
79 bool mCecControlEnabled;
Shraddha Basantwanidedd40e2021-09-16 15:56:20 +053080 sp<IHdmiCecCallback> mCallback;
81
82 int mCecFd;
83 int mExitFd;
84};
Shraddha Basantwanif3a43c82021-05-27 19:40:17 +053085} // namespace implementation
86} // namespace V1_0
87} // namespace cec
88} // namespace tv
89} // namespace hardware
90} // namespace android