1 /* 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 #include <hardware/hdmi_cec.h> 17 #include <linux/cec.h> 18 #include <thread> 19 #include <vector> 20 #include "HdmiCecPort.h" 21 22 namespace android { 23 namespace hardware { 24 namespace tv { 25 namespace cec { 26 namespace V1_0 { 27 namespace implementation { 28 29 using std::shared_ptr; 30 using std::thread; 31 using std::vector; 32 33 class HdmiCecDefault : public IHdmiCec, public hidl_death_recipient { 34 public: 35 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 serviceDied(uint64_t,const wp<::android::hidl::base::V1_0::IBase> &)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(); 57 58 private: 59 void event_thread(HdmiCecPort* hdmiCecPort); 60 static int getOpcode(cec_msg message); 61 static int getFirstParam(cec_msg message); 62 static bool isWakeupMessage(cec_msg message); 63 static bool isTransferableInSleep(cec_msg message); 64 static bool isPowerUICommand(cec_msg message); 65 static Return<SendMessageResult> getSendMessageResult(int tx_status); 66 67 vector<thread> mEventThreads; 68 vector<shared_ptr<HdmiCecPort>> mHdmiCecPorts; 69 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; 77 /* 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; 84 sp<IHdmiCecCallback> mCallback; 85 }; 86 } // namespace implementation 87 } // namespace V1_0 88 } // namespace cec 89 } // namespace tv 90 } // namespace hardware 91 } // namespace android 92