blob: 6574429a6d8aa366c837f6f3f1cefc3e3155c8b2 [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 */
Shraddha Basantwanif3a43c82021-05-27 19:40:17 +053016#include <hardware/hdmi_cec.h>
Shraddha Basantwanidedd40e2021-09-16 15:56:20 +053017#include <linux/cec.h>
18#include <thread>
Shraddha Basantwani65165d52021-06-23 20:42:08 +053019#include <vector>
20#include "HdmiCecPort.h"
Shraddha Basantwanif3a43c82021-05-27 19:40:17 +053021
22namespace android {
23namespace hardware {
24namespace tv {
25namespace cec {
26namespace V1_0 {
27namespace implementation {
28
Shraddha Basantwani65165d52021-06-23 20:42:08 +053029using std::shared_ptr;
Shraddha Basantwanidedd40e2021-09-16 15:56:20 +053030using std::thread;
Shraddha Basantwani65165d52021-06-23 20:42:08 +053031using std::vector;
Shraddha Basantwanidedd40e2021-09-16 15:56:20 +053032
33class HdmiCecDefault : public IHdmiCec, public hidl_death_recipient {
34 public:
Shraddha Basantwanif3a43c82021-05-27 19:40:17 +053035 HdmiCecDefault();
36 ~HdmiCecDefault();
37 // Methods from ::android::hardware::tv::cec::V1_0::IHdmiCec follow.
38 Return<Result> addLogicalAddress(CecLogicalAddress addr) override;
39 Return<void> clearLogicalAddress() override;
40 Return<void> getPhysicalAddress(getPhysicalAddress_cb _hidl_cb) override;
41 Return<SendMessageResult> sendMessage(const CecMessage& message) override;
42 Return<void> setCallback(const sp<IHdmiCecCallback>& callback) override;
43 Return<int32_t> getCecVersion() override;
44 Return<uint32_t> getVendorId() override;
45 Return<void> getPortInfo(getPortInfo_cb _hidl_cb) override;
46 Return<void> setOption(OptionKey key, bool value) override;
47 Return<void> setLanguage(const hidl_string& language) override;
48 Return<void> enableAudioReturnChannel(int32_t portId, bool enable) override;
49 Return<bool> isConnected(int32_t portId) override;
50
51 virtual void serviceDied(uint64_t, const wp<::android::hidl::base::V1_0::IBase>&) {
52 setCallback(nullptr);
53 }
54
55 Return<Result> init();
56 Return<void> release();
Shraddha Basantwanif3a43c82021-05-27 19:40:17 +053057
Shraddha Basantwanidedd40e2021-09-16 15:56:20 +053058 private:
Shraddha Basantwani65165d52021-06-23 20:42:08 +053059 void event_thread(HdmiCecPort* hdmiCecPort);
Shraddha Basantwanidedd40e2021-09-16 15:56:20 +053060 static int getOpcode(cec_msg message);
Shraddha Basantwani9fb5e822021-06-23 20:42:08 +053061 static int getFirstParam(cec_msg message);
Shraddha Basantwanidedd40e2021-09-16 15:56:20 +053062 static bool isWakeupMessage(cec_msg message);
Shraddha Basantwani9fb5e822021-06-23 20:42:08 +053063 static bool isTransferableInSleep(cec_msg message);
64 static bool isPowerUICommand(cec_msg message);
Shraddha Basantwani65165d52021-06-23 20:42:08 +053065 static Return<SendMessageResult> getSendMessageResult(int tx_status);
Shraddha Basantwanidedd40e2021-09-16 15:56:20 +053066
Shraddha Basantwani65165d52021-06-23 20:42:08 +053067 vector<thread> mEventThreads;
68 vector<shared_ptr<HdmiCecPort>> mHdmiCecPorts;
Shraddha Basantwanidedd40e2021-09-16 15:56:20 +053069
70 // When set to false, all the CEC commands are discarded. True by default after initialization.
71 bool mCecEnabled;
72 /*
73 * When set to false, HAL does not wake up the system upon receiving <Image View On> or
74 * <Text View On>. True by default after initialization.
75 */
76 bool mWakeupEnabled;
Shraddha Basantwani9fb5e822021-06-23 20:42:08 +053077 /*
78 * Updated when system goes into or comes out of standby mode.
79 * When set to true, Android system is handling CEC commands.
80 * When set to false, microprocessor is handling CEC commands.
81 * True by default after initialization.
82 */
83 bool mCecControlEnabled;
Shraddha Basantwanidedd40e2021-09-16 15:56:20 +053084 sp<IHdmiCecCallback> mCallback;
Shraddha Basantwanidedd40e2021-09-16 15:56:20 +053085};
Shraddha Basantwanif3a43c82021-05-27 19:40:17 +053086} // namespace implementation
87} // namespace V1_0
88} // namespace cec
89} // namespace tv
90} // namespace hardware
91} // namespace android