cec: add rpi hal implementation

* TODO: Convert to AIDL.
This commit is contained in:
Konsta
2025-02-04 20:18:32 +02:00
parent 625166b4d3
commit 701855aaac
17 changed files with 213 additions and 171 deletions

View File

@@ -1,43 +1,26 @@
cc_library_shared { // Copyright (C) 2021 The Android Open Source Project
name: "android.hardware.tv.cec@1.0-impl", // Copyright (C) 2025 KonstaKANG
defaults: ["hidl_defaults"], //
vendor: true, // SPDX-License-Identifier: Apache-2.0
relative_install_path: "hw",
srcs: [
"HdmiCecDefault.cpp",
"HdmiCecPort.cpp",
],
shared_libs: [
"libhidlbase",
"liblog",
"libbase",
"libcutils",
"libutils",
"libhardware",
"android.hardware.tv.cec@1.0",
],
}
cc_binary { cc_binary {
name: "android.hardware.tv.cec@1.0-service", name: "android.hardware.tv.cec@1.0-service.rpi",
defaults: ["hidl_defaults"],
relative_install_path: "hw", relative_install_path: "hw",
init_rc: ["android.hardware.tv.cec@1.0-service.rpi.rc"],
vintf_fragments: ["android.hardware.tv.cec@1.0-service.rpi.xml"],
vendor: true, vendor: true,
init_rc: ["android.hardware.tv.cec@1.0-service.rc"], srcs: [
srcs: ["service.cpp"], "HdmiCec.cpp",
"HdmiCecPort.cpp",
"service.cpp",
],
shared_libs: [ shared_libs: [
"liblog", "android.hardware.tv.cec@1.0",
"libcutils",
"libdl",
"libbase", "libbase",
"libutils", "libcutils",
"libhardware_legacy",
"libhardware", "libhardware",
"libhidlbase", "libhidlbase",
"android.hardware.tv.cec@1.0", "liblog",
"libutils",
], ],
} }

View File

@@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2021 The Android Open Source Project * Copyright (C) 2021 The Android Open Source Project
* Copyright (C) 2025 KonstaKANG
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -14,7 +15,8 @@
* limitations under the License. * limitations under the License.
*/ */
#define LOG_TAG "android.hardware.tv.cec@1.0-impl" #define LOG_TAG "android.hardware.tv.cec@1.0-service.rpi"
#include <android-base/logging.h> #include <android-base/logging.h>
#include <android-base/properties.h> #include <android-base/properties.h>
@@ -25,12 +27,11 @@
#include <linux/ioctl.h> #include <linux/ioctl.h>
#include <poll.h> #include <poll.h>
#include "HdmiCecDefault.h" #include "HdmiCec.h"
#define PROPERTY_DEVICE_TYPE "ro.hdmi.device_type" #define PROPERTY_CEC_DEVICE "persist.hdmi.cec_device"
#define MIN_PORT_ID 0 #define PROPERTY_CEC_VERSION "ro.hdmi.cec_version"
#define MAX_PORT_ID 15 #define PROPERTY_VENDOR_ID "ro.hdmi.vendor_id"
#define INVALID_PHYSICAL_ADDRESS 0xFFFF
namespace android { namespace android {
namespace hardware { namespace hardware {
@@ -39,30 +40,34 @@ namespace cec {
namespace V1_0 { namespace V1_0 {
namespace implementation { namespace implementation {
using android::base::GetUintProperty; using android::base::GetProperty;
using std::stoi;
using std::string; using std::string;
HdmiCecDefault::HdmiCecDefault() { HdmiCec::HdmiCec() {
mCecEnabled = false; mCecEnabled = false;
mWakeupEnabled = false; mWakeupEnabled = false;
mCecControlEnabled = false; mCecControlEnabled = false;
mCallback = nullptr; mCallback = nullptr;
Result result = init();
if (result != Result::SUCCESS) {
LOG(ERROR) << "Failed to init HDMI-CEC HAL";
}
} }
HdmiCecDefault::~HdmiCecDefault() { HdmiCec::~HdmiCec() {
release(); release();
} }
// Methods from ::android::hardware::tv::cec::V1_0::IHdmiCec follow. // Methods from ::android::hardware::tv::cec::V1_0::IHdmiCec follow.
Return<Result> HdmiCecDefault::addLogicalAddress(CecLogicalAddress addr) { Return<Result> HdmiCec::addLogicalAddress(CecLogicalAddress addr) {
if (addr < CecLogicalAddress::TV || addr >= CecLogicalAddress::BROADCAST) { if (addr < CecLogicalAddress::TV || addr >= CecLogicalAddress::BROADCAST) {
LOG(ERROR) << "Add logical address failed, Invalid address"; LOG(ERROR) << "Add logical address failed, Invalid address";
return Result::FAILURE_INVALID_ARGS; return Result::FAILURE_INVALID_ARGS;
} }
cec_log_addrs cecLogAddrs; cec_log_addrs cecLogAddrs;
int ret = ioctl(mHdmiCecPorts[MIN_PORT_ID]->mCecFd, CEC_ADAP_G_LOG_ADDRS, &cecLogAddrs); int ret = ioctl(mHdmiCecPorts[0]->mCecFd, CEC_ADAP_G_LOG_ADDRS, &cecLogAddrs);
if (ret) { if (ret) {
LOG(ERROR) << "Add logical address failed, Error = " << strerror(errno); LOG(ERROR) << "Add logical address failed, Error = " << strerror(errno);
return Result::FAILURE_BUSY; return Result::FAILURE_BUSY;
@@ -119,7 +124,6 @@ Return<Result> HdmiCecDefault::addLogicalAddress(CecLogicalAddress addr) {
} }
int logAddrIndex = cecLogAddrs.num_log_addrs; int logAddrIndex = cecLogAddrs.num_log_addrs;
cecLogAddrs.num_log_addrs += 1; cecLogAddrs.num_log_addrs += 1;
cecLogAddrs.log_addr[logAddrIndex] = static_cast<cec_logical_address_t>(addr); cecLogAddrs.log_addr[logAddrIndex] = static_cast<cec_logical_address_t>(addr);
cecLogAddrs.log_addr_type[logAddrIndex] = logAddrType; cecLogAddrs.log_addr_type[logAddrIndex] = logAddrType;
@@ -128,46 +132,45 @@ Return<Result> HdmiCecDefault::addLogicalAddress(CecLogicalAddress addr) {
cecLogAddrs.features[logAddrIndex][0] = 0; cecLogAddrs.features[logAddrIndex][0] = 0;
cecLogAddrs.features[logAddrIndex][1] = 0; cecLogAddrs.features[logAddrIndex][1] = 0;
// Return failure only if add logical address fails for all the ports ret = ioctl(mHdmiCecPorts[0]->mCecFd, CEC_ADAP_S_LOG_ADDRS, &cecLogAddrs);
Return<Result> result = Result::FAILURE_BUSY;
for (int i = 0; i < mHdmiCecPorts.size(); i++) {
ret = ioctl(mHdmiCecPorts[i]->mCecFd, CEC_ADAP_S_LOG_ADDRS, &cecLogAddrs);
if (ret) { if (ret) {
LOG(ERROR) << "Add logical address failed for port " << mHdmiCecPorts[i]->mPortId LOG(ERROR) << "Add logical address failed for port " << mHdmiCecPorts[0]->mPortId
<< ", Error = " << strerror(errno); << ", Error = " << strerror(errno);
} else { return Result::FAILURE_BUSY;
result = Result::SUCCESS;
}
}
return result;
} }
Return<void> HdmiCecDefault::clearLogicalAddress() { return Result::SUCCESS;
}
Return<void> HdmiCec::clearLogicalAddress() {
cec_log_addrs cecLogAddrs; cec_log_addrs cecLogAddrs;
memset(&cecLogAddrs, 0, sizeof(cecLogAddrs)); memset(&cecLogAddrs, 0, sizeof(cecLogAddrs));
for (int i = 0; i < mHdmiCecPorts.size(); i++) {
int ret = ioctl(mHdmiCecPorts[i]->mCecFd, CEC_ADAP_S_LOG_ADDRS, &cecLogAddrs); int ret = ioctl(mHdmiCecPorts[0]->mCecFd, CEC_ADAP_S_LOG_ADDRS, &cecLogAddrs);
if (ret) { if (ret) {
LOG(ERROR) << "Clear logical Address failed for port " << mHdmiCecPorts[i]->mPortId LOG(ERROR) << "Clear logical Address failed for port " << mHdmiCecPorts[0]->mPortId
<< ", Error = " << strerror(errno); << ", Error = " << strerror(errno);
} }
}
return Void(); return Void();
} }
Return<void> HdmiCecDefault::getPhysicalAddress(getPhysicalAddress_cb callback) { Return<void> HdmiCec::getPhysicalAddress(getPhysicalAddress_cb callback) {
uint16_t addr; uint16_t addr;
int ret = ioctl(mHdmiCecPorts[MIN_PORT_ID]->mCecFd, CEC_ADAP_G_PHYS_ADDR, &addr);
int ret = ioctl(mHdmiCecPorts[0]->mCecFd, CEC_ADAP_G_PHYS_ADDR, &addr);
if (ret) { if (ret) {
LOG(ERROR) << "Get physical address failed, Error = " << strerror(errno); LOG(ERROR) << "Get physical address failed, Error = " << strerror(errno);
callback(Result::FAILURE_INVALID_STATE, addr); callback(Result::FAILURE_INVALID_STATE, addr);
return Void(); return Void();
} }
callback(Result::SUCCESS, addr); callback(Result::SUCCESS, addr);
return Void(); return Void();
} }
Return<SendMessageResult> HdmiCecDefault::sendMessage(const CecMessage& message) { Return<SendMessageResult> HdmiCec::sendMessage(const CecMessage& message) {
if (!mCecEnabled) { if (!mCecEnabled) {
return SendMessageResult::FAIL; return SendMessageResult::FAIL;
} }
@@ -184,28 +187,20 @@ Return<SendMessageResult> HdmiCecDefault::sendMessage(const CecMessage& message)
} }
cecMsg.len = message.body.size() + 1; cecMsg.len = message.body.size() + 1;
// Return failure only if send message fails for all the ports int ret = ioctl(mHdmiCecPorts[0]->mCecFd, CEC_TRANSMIT, &cecMsg);
Return<SendMessageResult> result = SendMessageResult::FAIL;
for (int i = 0; i < mHdmiCecPorts.size(); i++) {
int ret = ioctl(mHdmiCecPorts[i]->mCecFd, CEC_TRANSMIT, &cecMsg);
if (ret) { if (ret) {
LOG(ERROR) << "Send message failed, Error = " << strerror(errno); LOG(ERROR) << "Send message failed, Error = " << strerror(errno);
continue; return SendMessageResult::FAIL;
} }
if (cecMsg.tx_status != CEC_TX_STATUS_OK) { if (cecMsg.tx_status != CEC_TX_STATUS_OK) {
LOG(ERROR) << "Send message tx_status = " << cecMsg.tx_status; LOG(ERROR) << "Send message tx_status = " << cecMsg.tx_status;
} }
if (result != SendMessageResult::SUCCESS) { return getSendMessageResult(cecMsg.tx_status);
result = getSendMessageResult(cecMsg.tx_status);
}
}
return result;
} }
Return<void> HdmiCecDefault::setCallback(const sp<IHdmiCecCallback>& callback) { Return<void> HdmiCec::setCallback(const sp<IHdmiCecCallback>& callback) {
if (mCallback != nullptr) { if (mCallback != nullptr) {
mCallback->unlinkToDeath(this); mCallback->unlinkToDeath(this);
mCallback = nullptr; mCallback = nullptr;
@@ -215,42 +210,40 @@ Return<void> HdmiCecDefault::setCallback(const sp<IHdmiCecCallback>& callback) {
mCallback = callback; mCallback = callback;
mCallback->linkToDeath(this, 0 /*cookie*/); mCallback->linkToDeath(this, 0 /*cookie*/);
} }
return Void(); return Void();
} }
Return<int32_t> HdmiCecDefault::getCecVersion() { Return<int32_t> HdmiCec::getCecVersion() {
return property_get_int32("ro.hdmi.cec_version", CEC_OP_CEC_VERSION_1_4); return property_get_int32(PROPERTY_CEC_VERSION, CEC_OP_CEC_VERSION_1_4);
} }
Return<uint32_t> HdmiCecDefault::getVendorId() { Return<uint32_t> HdmiCec::getVendorId() {
return property_get_int32("ro.hdmi.vendor_id", 0x000c03 /* HDMI LLC vendor ID */); return property_get_int32(PROPERTY_VENDOR_ID, 0x000c03 /* HDMI LLC vendor ID */);
} }
Return<void> HdmiCecDefault::getPortInfo(getPortInfo_cb callback) { Return<void> HdmiCec::getPortInfo(getPortInfo_cb callback) {
hidl_vec<HdmiPortInfo> portInfos(mHdmiCecPorts.size()); uint16_t addr = CEC_PHYS_ADDR_INVALID;
for (int i = 0; i < mHdmiCecPorts.size(); i++) {
uint16_t addr = INVALID_PHYSICAL_ADDRESS; int ret = ioctl(mHdmiCecPorts[0]->mCecFd, CEC_ADAP_G_PHYS_ADDR, &addr);
int ret = ioctl(mHdmiCecPorts[i]->mCecFd, CEC_ADAP_G_PHYS_ADDR, &addr);
if (ret) { if (ret) {
LOG(ERROR) << "Get port info failed for port : " << mHdmiCecPorts[i]->mPortId LOG(ERROR) << "Get port info failed for port : " << mHdmiCecPorts[0]->mPortId
<< ", Error = " << strerror(errno); << ", Error = " << strerror(errno);
} }
HdmiPortType type = HdmiPortType::INPUT;
uint32_t deviceType = GetUintProperty<uint32_t>(PROPERTY_DEVICE_TYPE, CEC_DEVICE_PLAYBACK); hidl_vec<HdmiPortInfo> portInfos {
if (deviceType != CEC_DEVICE_TV && i == MIN_PORT_ID) { {.type = HdmiPortType::OUTPUT,
type = HdmiPortType::OUTPUT; .portId = mHdmiCecPorts[0]->mPortId,
}
portInfos[i] = {.type = type,
.portId = mHdmiCecPorts[i]->mPortId,
.cecSupported = true, .cecSupported = true,
.arcSupported = false, .arcSupported = false,
.physicalAddress = addr}; .physicalAddress = addr}
} };
callback(portInfos); callback(portInfos);
return Void(); return Void();
} }
Return<void> HdmiCecDefault::setOption(OptionKey key, bool value) { Return<void> HdmiCec::setOption(OptionKey key, bool value) {
switch (key) { switch (key) {
case OptionKey::ENABLE_CEC: case OptionKey::ENABLE_CEC:
LOG(DEBUG) << "setOption: Enable CEC: " << value; LOG(DEBUG) << "setOption: Enable CEC: " << value;
@@ -265,82 +258,68 @@ Return<void> HdmiCecDefault::setOption(OptionKey key, bool value) {
mCecControlEnabled = value; mCecControlEnabled = value;
break; break;
} }
return Void(); return Void();
} }
Return<void> HdmiCecDefault::setLanguage(const hidl_string& /*language*/) { Return<void> HdmiCec::setLanguage(const hidl_string& language __unused) {
return Void(); return Void();
} }
Return<void> HdmiCecDefault::enableAudioReturnChannel(int32_t /*portId*/, bool /*enable*/) { Return<void> HdmiCec::enableAudioReturnChannel(int32_t portId __unused, bool enable __unused) {
return Void(); return Void();
} }
Return<bool> HdmiCecDefault::isConnected(int32_t portId) { Return<bool> HdmiCec::isConnected(int32_t portId __unused) {
uint16_t addr; uint16_t addr = CEC_PHYS_ADDR_INVALID;
if (portId < 0 || portId >= mHdmiCecPorts.size()) {
LOG(ERROR) << "Port id is out of bounds, portId = " << portId; int ret = ioctl(mHdmiCecPorts[0]->mCecFd, CEC_ADAP_G_PHYS_ADDR, &addr);
return false;
}
int ret = ioctl(mHdmiCecPorts[portId]->mCecFd, CEC_ADAP_G_PHYS_ADDR, &addr);
if (ret) { if (ret) {
LOG(ERROR) << "Is connected failed, Error = " << strerror(errno); LOG(ERROR) << "Is connected failed, Error = " << strerror(errno);
return false; return false;
} }
if (addr == CEC_PHYS_ADDR_INVALID) { if (addr == CEC_PHYS_ADDR_INVALID) {
return false; return false;
} }
return true; return true;
} }
int getPortId(string cecFilename) { // Initialise the cec file descriptor
int portId = stoi(cecFilename.substr(3)); Return<Result> HdmiCec::init() {
if (portId >= MIN_PORT_ID && portId <= MAX_PORT_ID) { string cecDevice = GetProperty(PROPERTY_CEC_DEVICE, "cec0");
return portId; if (cecDevice != "cec0" && cecDevice != "cec1") {
} else { LOG(ERROR) << "Invalid CEC device " << cecDevice;
return -1;
}
}
// Initialise the cec file descriptors
Return<Result> HdmiCecDefault::init() {
const char* parentPath = "/dev/";
DIR* dir = opendir(parentPath);
const char* cecFilename = "cec";
while (struct dirent* dirEntry = readdir(dir)) {
string filename = dirEntry->d_name;
if (filename.compare(0, 3, cecFilename, 0, 3) == 0) {
int portId = getPortId(filename);
if (portId == -1) {
continue;
}
shared_ptr<HdmiCecPort> hdmiCecPort(new HdmiCecPort(portId));
string filepath = parentPath + filename;
Result result = hdmiCecPort->init(filepath.c_str());
if (result != Result::SUCCESS) {
continue;
}
thread eventThread(&HdmiCecDefault::event_thread, this, hdmiCecPort.get());
mEventThreads.push_back(std::move(eventThread));
mHdmiCecPorts.push_back(std::move(hdmiCecPort));
}
}
if (mHdmiCecPorts.empty()) {
return Result::FAILURE_NOT_SUPPORTED; return Result::FAILURE_NOT_SUPPORTED;
} }
string devicePath = "/dev/" + cecDevice;
int portId = stoi(cecDevice.substr(3));
shared_ptr<HdmiCecPort> hdmiCecPort(new HdmiCecPort(portId));
Result result = hdmiCecPort->init(devicePath.c_str());
if (result != Result::SUCCESS) {
return Result::FAILURE_NOT_SUPPORTED;
}
thread eventThread(&HdmiCec::event_thread, this, hdmiCecPort.get());
mEventThreads.push_back(std::move(eventThread));
mHdmiCecPorts.push_back(std::move(hdmiCecPort));
LOG(INFO) << "Using CEC device " << devicePath;
mCecEnabled = true; mCecEnabled = true;
mWakeupEnabled = true; mWakeupEnabled = true;
mCecControlEnabled = true; mCecControlEnabled = true;
return Result::SUCCESS; return Result::SUCCESS;
} }
Return<void> HdmiCecDefault::release() { Return<void> HdmiCec::release() {
mCecEnabled = false; mCecEnabled = false;
mWakeupEnabled = false; mWakeupEnabled = false;
mCecControlEnabled = false; mCecControlEnabled = false;
for (thread& eventThread : mEventThreads) { for (thread& eventThread : mEventThreads) {
if (eventThread.joinable()) { if (eventThread.joinable()) {
eventThread.join(); eventThread.join();
@@ -349,10 +328,11 @@ Return<void> HdmiCecDefault::release() {
setCallback(nullptr); setCallback(nullptr);
mHdmiCecPorts.clear(); mHdmiCecPorts.clear();
mEventThreads.clear(); mEventThreads.clear();
return Void(); return Void();
} }
void HdmiCecDefault::event_thread(HdmiCecPort* hdmiCecPort) { void HdmiCec::event_thread(HdmiCecPort* hdmiCecPort) {
struct pollfd ufds[3] = { struct pollfd ufds[3] = {
{hdmiCecPort->mCecFd, POLLIN, 0}, {hdmiCecPort->mCecFd, POLLIN, 0},
{hdmiCecPort->mCecFd, POLLERR, 0}, {hdmiCecPort->mCecFd, POLLERR, 0},
@@ -445,11 +425,11 @@ void HdmiCecDefault::event_thread(HdmiCecPort* hdmiCecPort) {
} }
} }
int HdmiCecDefault::getOpcode(cec_msg message) { int HdmiCec::getOpcode(cec_msg message) {
return static_cast<uint8_t>(message.msg[1]); return static_cast<uint8_t>(message.msg[1]);
} }
bool HdmiCecDefault::isWakeupMessage(cec_msg message) { bool HdmiCec::isWakeupMessage(cec_msg message) {
int opcode = getOpcode(message); int opcode = getOpcode(message);
switch (opcode) { switch (opcode) {
case CEC_MESSAGE_TEXT_VIEW_ON: case CEC_MESSAGE_TEXT_VIEW_ON:
@@ -460,7 +440,7 @@ bool HdmiCecDefault::isWakeupMessage(cec_msg message) {
} }
} }
bool HdmiCecDefault::isTransferableInSleep(cec_msg message) { bool HdmiCec::isTransferableInSleep(cec_msg message) {
int opcode = getOpcode(message); int opcode = getOpcode(message);
switch (opcode) { switch (opcode) {
case CEC_MESSAGE_ABORT: case CEC_MESSAGE_ABORT:
@@ -487,11 +467,11 @@ bool HdmiCecDefault::isTransferableInSleep(cec_msg message) {
} }
} }
int HdmiCecDefault::getFirstParam(cec_msg message) { int HdmiCec::getFirstParam(cec_msg message) {
return static_cast<uint8_t>(message.msg[2]); return static_cast<uint8_t>(message.msg[2]);
} }
bool HdmiCecDefault::isPowerUICommand(cec_msg message) { bool HdmiCec::isPowerUICommand(cec_msg message) {
int uiCommand = getFirstParam(message); int uiCommand = getFirstParam(message);
switch (uiCommand) { switch (uiCommand) {
case CEC_OP_UI_CMD_POWER: case CEC_OP_UI_CMD_POWER:
@@ -503,7 +483,7 @@ bool HdmiCecDefault::isPowerUICommand(cec_msg message) {
} }
} }
Return<SendMessageResult> HdmiCecDefault::getSendMessageResult(int tx_status) { Return<SendMessageResult> HdmiCec::getSendMessageResult(int tx_status) {
switch (tx_status) { switch (tx_status) {
case CEC_TX_STATUS_OK: case CEC_TX_STATUS_OK:
return SendMessageResult::SUCCESS; return SendMessageResult::SUCCESS;
@@ -515,6 +495,7 @@ Return<SendMessageResult> HdmiCecDefault::getSendMessageResult(int tx_status) {
return SendMessageResult::FAIL; return SendMessageResult::FAIL;
} }
} }
} // namespace implementation } // namespace implementation
} // namespace V1_0 } // namespace V1_0
} // namespace cec } // namespace cec

View File

@@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2021 The Android Open Source Project * Copyright (C) 2021 The Android Open Source Project
* Copyright (C) 2025 KonstaKANG
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -13,6 +14,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include <hardware/hdmi_cec.h> #include <hardware/hdmi_cec.h>
#include <linux/cec.h> #include <linux/cec.h>
#include <thread> #include <thread>
@@ -30,10 +32,10 @@ using std::shared_ptr;
using std::thread; using std::thread;
using std::vector; using std::vector;
class HdmiCecDefault : public IHdmiCec, public hidl_death_recipient { class HdmiCec : public IHdmiCec, public hidl_death_recipient {
public: public:
HdmiCecDefault(); HdmiCec();
~HdmiCecDefault(); ~HdmiCec();
// Methods from ::android::hardware::tv::cec::V1_0::IHdmiCec follow. // Methods from ::android::hardware::tv::cec::V1_0::IHdmiCec follow.
Return<Result> addLogicalAddress(CecLogicalAddress addr) override; Return<Result> addLogicalAddress(CecLogicalAddress addr) override;
Return<void> clearLogicalAddress() override; Return<void> clearLogicalAddress() override;
@@ -81,8 +83,10 @@ class HdmiCecDefault : public IHdmiCec, public hidl_death_recipient {
* True by default after initialization. * True by default after initialization.
*/ */
bool mCecControlEnabled; bool mCecControlEnabled;
sp<IHdmiCecCallback> mCallback; sp<IHdmiCecCallback> mCallback;
}; };
} // namespace implementation } // namespace implementation
} // namespace V1_0 } // namespace V1_0
} // namespace cec } // namespace cec

5
cec/HdmiCecPort.cpp Executable file → Normal file
View File

@@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2021 The Android Open Source Project * Copyright (C) 2021 The Android Open Source Project
* Copyright (C) 2025 KonstaKANG
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -13,7 +14,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#define LOG_TAG "android.hardware.tv.cec@1.0-impl"
#define LOG_TAG "android.hardware.tv.cec@1.0-service.rpi"
#include <android-base/logging.h> #include <android-base/logging.h>
#include <errno.h> #include <errno.h>
@@ -93,6 +95,7 @@ Return<void> HdmiCecPort::release() {
} }
return Void(); return Void();
} }
} // namespace implementation } // namespace implementation
} // namespace V1_0 } // namespace V1_0
} // namespace cec } // namespace cec

2
cec/HdmiCecPort.h Executable file → Normal file
View File

@@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2021 The Android Open Source Project * Copyright (C) 2021 The Android Open Source Project
* Copyright (C) 2025 KonstaKANG
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -13,6 +14,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include <android/hardware/tv/cec/1.0/IHdmiCec.h> #include <android/hardware/tv/cec/1.0/IHdmiCec.h>
namespace android { namespace android {

View File

@@ -1,4 +1,4 @@
service vendor.cec-hal-1-0 /vendor/bin/hw/android.hardware.tv.cec@1.0-service service vendor.cec-hal-1-0-rpi /vendor/bin/hw/android.hardware.tv.cec@1.0-service.rpi
interface android.hardware.tv.cec@1.0::IHdmiCec default interface android.hardware.tv.cec@1.0::IHdmiCec default
class hal class hal
user system user system

View File

@@ -0,0 +1,11 @@
<manifest version="1.0" type="device">
<hal format="hidl">
<name>android.hardware.tv.cec</name>
<transport>hwbinder</transport>
<version>1.0</version>
<interface>
<name>IHdmiCec</name>
<instance>default</instance>
</interface>
</hal>
</manifest>

View File

@@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2016 The Android Open Source Project * Copyright (C) 2019 The Android Open Source Project
* Copyright (C) 2025 KonstaKANG
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -14,14 +15,35 @@
* limitations under the License. * limitations under the License.
*/ */
#define LOG_TAG "android.hardware.tv.cec@1.0-service" #define LOG_TAG "android.hardware.tv.cec@1.0-service-rpi"
#include <android/hardware/tv/cec/1.0/IHdmiCec.h> #include <android/hardware/tv/cec/1.0/IHdmiCec.h>
#include <hidl/LegacySupport.h> #include <hidl/LegacySupport.h>
#include "HdmiCec.h"
using android::hardware::configureRpcThreadpool;
using android::hardware::joinRpcThreadpool;
using android::hardware::tv::cec::V1_0::IHdmiCec; using android::hardware::tv::cec::V1_0::IHdmiCec;
using android::hardware::defaultPassthroughServiceImplementation; using android::hardware::tv::cec::V1_0::implementation::HdmiCec;
using android::OK;
using android::status_t;
int main() { int main() {
return defaultPassthroughServiceImplementation<IHdmiCec>(); configureRpcThreadpool(1, true /* callerWillJoin */);
android::sp<IHdmiCec> service = new HdmiCec();
status_t status = service->registerAsService();
if (status != OK) {
ALOGE("Cannot register HDMI-CEC HAL service.");
return 1;
}
ALOGI("HDMI-CEC HAL ready.");
joinRpcThreadpool();
// Under normal cases, execution will not reach this line.
ALOGE("HDMI-CEC HAL failed to join thread pool.");
return 1;
} }

View File

@@ -133,6 +133,13 @@ PRODUCT_COPY_FILES += \
PRODUCT_COPY_FILES += \ PRODUCT_COPY_FILES += \
$(DEVICE_PATH)/camera/media_profiles_V1_0.xml:$(TARGET_COPY_OUT_VENDOR)/etc/media_profiles_V1_0.xml $(DEVICE_PATH)/camera/media_profiles_V1_0.xml:$(TARGET_COPY_OUT_VENDOR)/etc/media_profiles_V1_0.xml
# CEC
PRODUCT_PACKAGES += \
android.hardware.tv.cec@1.0-service.rpi
PRODUCT_COPY_FILES += \
frameworks/native/data/etc/android.hardware.hdmi.cec.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.hdmi.cec.xml
# Debugfs # Debugfs
PRODUCT_SET_DEBUGFS_RESTRICTIONS := false PRODUCT_SET_DEBUGFS_RESTRICTIONS := false

View File

@@ -429,6 +429,12 @@ key 657 MACRO_2
key 658 MACRO_3 key 658 MACRO_3
key 659 MACRO_4 key 659 MACRO_4
# CEC
key 352 ENTER
key 618 HOME
key 141 POWER
key 174 BACK
# Keys defined by HID usages # Keys defined by HID usages
key usage 0x0c0067 WINDOW FALLBACK_USAGE_MAPPING key usage 0x0c0067 WINDOW FALLBACK_USAGE_MAPPING
key usage 0x0c006F BRIGHTNESS_UP FALLBACK_USAGE_MAPPING key usage 0x0c006F BRIGHTNESS_UP FALLBACK_USAGE_MAPPING

View File

@@ -117,4 +117,8 @@
--> -->
<integer name="config_defaultNightMode">2</integer> <integer name="config_defaultNightMode">2</integer>
<!-- CEC Configuration -->
<bool name="config_cecTvSendStandbyOnSleepEnabled_default">false</bool>
<bool name="config_cecTvSendStandbyOnSleepDisabled_default">true</bool>
</resources> </resources>

View File

@@ -55,4 +55,8 @@
--> -->
<integer name="config_longPressOnPowerBehavior">1</integer> <integer name="config_longPressOnPowerBehavior">1</integer>
<!-- CEC Configuration -->
<bool name="config_cecTvSendStandbyOnSleepEnabled_default">false</bool>
<bool name="config_cecTvSendStandbyOnSleepDisabled_default">true</bool>
</resources> </resources>

View File

@@ -6,6 +6,10 @@
/dev/v4l-subdev* 0660 system camera /dev/v4l-subdev* 0660 system camera
/dev/video* 0660 system camera /dev/video* 0660 system camera
# CEC
/dev/cec0 0660 system graphics
/dev/cec1 0660 system graphics
# DMA # DMA
/dev/dma_heap/linux,cma 0666 system graphics /dev/dma_heap/linux,cma 0666 system graphics

1
sepolicy/device.te Normal file
View File

@@ -0,0 +1 @@
type cec_device, dev_type;

View File

@@ -1,6 +1,11 @@
# Bluetooth # Bluetooth
/sys/class/rfkill/rfkill[0-9]/state u:object_r:sysfs_bluetooth_writable:s0 /sys/class/rfkill/rfkill[0-9]/state u:object_r:sysfs_bluetooth_writable:s0
# CEC
/dev/cec0 u:object_r:cec_device:s0
/dev/cec1 u:object_r:cec_device:s0
/vendor/bin/hw/android\.hardware\.tv\.cec@1\.0-service\.rpi u:object_r:hal_tv_cec_default_exec:s0
# DRM # DRM
/vendor/bin/hw/android\.hardware\.drm-service\.clearkey u:object_r:hal_drm_clearkey_exec:s0 /vendor/bin/hw/android\.hardware\.drm-service\.clearkey u:object_r:hal_drm_clearkey_exec:s0
/vendor/bin/hw/android\.hardware\.drm-service\.widevine(.*)? u:object_r:hal_drm_widevine_exec:s0 /vendor/bin/hw/android\.hardware\.drm-service\.widevine(.*)? u:object_r:hal_drm_widevine_exec:s0

View File

@@ -0,0 +1 @@
allow hal_tv_cec_default cec_device:chr_file rw_file_perms;

View File

@@ -36,6 +36,10 @@ persist.bluetooth.a2dp_aac.vbr_supported=true
media.settings.xml=/vendor/etc/media_profiles_V1_0.xml media.settings.xml=/vendor/etc/media_profiles_V1_0.xml
ro.hardware.camera=libcamera ro.hardware.camera=libcamera
# CEC
persist.hdmi.cec_device=cec0
ro.hdmi.device_type=4
# Display # Display
debug.drm.mode.force=1920x1080 debug.drm.mode.force=1920x1080