Merge changes from topic "cec_hal_11" into sc-dev

* changes:
  Add VTS for tv.cec@1.1
  Add default implementation for tv.cec@1.1
  Add CEC HAL v1.1 to compatibility matrix
  Add TV CEC HAL v1.1
This commit is contained in:
TreeHugger Robot
2021-02-17 09:06:39 +00:00
committed by Android (Google) Code Review
13 changed files with 951 additions and 1 deletions

View File

@@ -561,7 +561,7 @@
</hal>
<hal format="hidl" optional="true">
<name>android.hardware.tv.cec</name>
<version>1.0</version>
<version>1.0-1</version>
<interface>
<name>IHdmiCec</name>
<instance>default</instance>

16
tv/cec/1.1/Android.bp Normal file
View File

@@ -0,0 +1,16 @@
// This file is autogenerated by hidl-gen -Landroidbp.
hidl_interface {
name: "android.hardware.tv.cec@1.1",
root: "android.hardware",
srcs: [
"types.hal",
"IHdmiCec.hal",
"IHdmiCecCallback.hal",
],
interfaces: [
"android.hardware.tv.cec@1.0",
"android.hidl.base@1.0",
],
gen_java: true,
}

70
tv/cec/1.1/IHdmiCec.hal Normal file
View File

@@ -0,0 +1,70 @@
/*
* Copyright (C) 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.hardware.tv.cec@1.1;
import @1.0::IHdmiCec;
import @1.0::Result;
import @1.0::SendMessageResult;
import IHdmiCecCallback;
/**
* HDMI-CEC HAL interface definition.
*/
interface IHdmiCec extends @1.0::IHdmiCec {
/**
* Passes the logical address that must be used in this system.
*
* HAL must use it to configure the hardware so that the CEC commands
* addressed the given logical address can be filtered in. This method must
* be able to be called as many times as necessary in order to support
* multiple logical devices.
*
* @param addr Logical address that must be used in this system. It must be
* in the range of valid logical addresses for the call to succeed.
* @return result Result status of the operation. SUCCESS if successful,
* FAILURE_INVALID_ARGS if the given logical address is invalid,
* FAILURE_BUSY if device or resource is busy
*/
addLogicalAddress_1_1(CecLogicalAddress addr) generates (Result result);
/**
* Transmits HDMI-CEC message to other HDMI device.
*
* The method must be designed to return in a certain amount of time and not
* hanging forever which may happen if CEC signal line is pulled low for
* some reason.
*
* It must try retransmission at least once as specified in the section '7.1
* Frame Re-transmissions' of the CEC Spec 1.4b.
*
* @param message CEC message to be sent to other HDMI device.
* @return result Result status of the operation. SUCCESS if successful,
* NACK if the sent message is not acknowledged,
* BUSY if the CEC bus is busy.
*/
sendMessage_1_1(CecMessage message) generates (SendMessageResult result);
/**
* Sets a callback that HDMI-CEC HAL must later use for incoming CEC
* messages or internal HDMI events.
*
* @param callback Callback object to pass hdmi events to the system. The
* previously registered callback must be replaced with this one.
*/
setCallback_1_1(IHdmiCecCallback callback);
};

View File

@@ -0,0 +1,30 @@
/*
* Copyright (C) 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.hardware.tv.cec@1.1;
import @1.0::IHdmiCecCallback;
/**
* Callbacks from the HAL implementation to notify the system of new events.
*/
interface IHdmiCecCallback extends @1.0::IHdmiCecCallback {
/**
* The callback function that must be called by HAL implementation to notify
* the system of new CEC message arrival.
*/
oneway onCecMessage_1_1(CecMessage message);
};

View File

@@ -0,0 +1,23 @@
cc_binary {
name: "android.hardware.tv.cec@1.1-service",
defaults: ["hidl_defaults"],
vintf_fragments: ["android.hardware.tv.cec@1.1-service.xml"],
relative_install_path: "hw",
vendor: true,
init_rc: ["android.hardware.tv.cec@1.1-service.rc"],
srcs: [
"serviceMock.cpp",
"HdmiCecMock.cpp",
],
shared_libs: [
"liblog",
"libcutils",
"libbase",
"libutils",
"libhardware",
"libhidlbase",
"android.hardware.tv.cec@1.0",
"android.hardware.tv.cec@1.1",
],
}

View File

@@ -0,0 +1,371 @@
/*
* Copyright (C) 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "android.hardware.tv.cec@1.1"
#include <android-base/logging.h>
#include <utils/Log.h>
#include <hardware/hardware.h>
#include <hardware/hdmi_cec.h>
#include "HdmiCecMock.h"
namespace android {
namespace hardware {
namespace tv {
namespace cec {
namespace V1_1 {
namespace implementation {
class WrappedCallback : public ::android::hardware::tv::cec::V1_1::IHdmiCecCallback {
public:
WrappedCallback(sp<::android::hardware::tv::cec::V1_0::IHdmiCecCallback> callback) {
mCallback = callback;
}
Return<void> onCecMessage(const ::android::hardware::tv::cec::V1_0::CecMessage& message) {
mCallback->onCecMessage(message);
return Void();
}
Return<void> onCecMessage_1_1(const ::android::hardware::tv::cec::V1_1::CecMessage& message) {
::android::hardware::tv::cec::V1_0::CecMessage cecMessage;
cecMessage.initiator =
::android::hardware::tv::cec::V1_0::CecLogicalAddress(message.initiator);
cecMessage.destination =
::android::hardware::tv::cec::V1_0::CecLogicalAddress(message.destination);
cecMessage.body = message.body;
mCallback->onCecMessage(cecMessage);
return Void();
}
Return<void> onHotplugEvent(const ::android::hardware::tv::cec::V1_0::HotplugEvent& event) {
mCallback->onHotplugEvent(event);
return Void();
}
private:
sp<::android::hardware::tv::cec::V1_0::IHdmiCecCallback> mCallback;
};
/*
* (*set_option)() passes flags controlling the way HDMI-CEC service works down
* to HAL implementation. Those flags will be used in case the feature needs
* update in HAL itself, firmware or microcontroller.
*/
void HdmiCecMock::cec_set_option(int flag, int value) {
// maintain options and set them accordingly
switch (flag) {
case HDMI_OPTION_WAKEUP:
mOptionWakeUp = value;
break;
case HDMI_OPTION_ENABLE_CEC:
mOptionEnableCec = value;
break;
case HDMI_OPTION_SYSTEM_CEC_CONTROL:
mOptionSystemCecControl = value;
break;
case HDMI_OPTION_SET_LANG:
mOptionLanguage = value;
break;
}
}
// Methods from ::android::hardware::tv::cec::V1_0::IHdmiCec follow.
Return<Result> HdmiCecMock::addLogicalAddress(CecLogicalAddress addr) {
return addLogicalAddress_1_1(::android::hardware::tv::cec::V1_1::CecLogicalAddress(addr));
}
Return<void> HdmiCecMock::clearLogicalAddress() {
// remove logical address from the list
mLogicalAddresses = {};
return Void();
}
Return<void> HdmiCecMock::getPhysicalAddress(getPhysicalAddress_cb _hidl_cb) {
// maintain a physical address and return it
// default 0xFFFF, update on hotplug event
_hidl_cb(Result::SUCCESS, mPhysicalAddress);
return Void();
}
Return<SendMessageResult> HdmiCecMock::sendMessage(const CecMessage& message) {
::android::hardware::tv::cec::V1_1::CecMessage cecMessage;
cecMessage.initiator = ::android::hardware::tv::cec::V1_1::CecLogicalAddress(message.initiator);
cecMessage.destination =
::android::hardware::tv::cec::V1_1::CecLogicalAddress(message.destination);
cecMessage.body = message.body;
return sendMessage_1_1(cecMessage);
}
Return<void> HdmiCecMock::setCallback(const sp<IHdmiCecCallback>& callback) {
return setCallback_1_1(new WrappedCallback(callback));
}
Return<int32_t> HdmiCecMock::getCecVersion() {
// maintain a cec version and return it
return mCecVersion;
}
Return<uint32_t> HdmiCecMock::getVendorId() {
return mCecVendorId;
}
Return<void> HdmiCecMock::getPortInfo(getPortInfo_cb _hidl_cb) {
// TODO ready port info from device specific config
_hidl_cb(mPortInfo);
return Void();
}
Return<void> HdmiCecMock::setOption(OptionKey key, bool value) {
cec_set_option(static_cast<int>(key), value ? 1 : 0);
return Void();
}
Return<void> HdmiCecMock::setLanguage(const hidl_string& language) {
if (language.size() != 3) {
LOG(ERROR) << "Wrong language code: expected 3 letters, but it was " << language.size()
<< ".";
return Void();
}
// TODO validate if language is a valid language code
const char* languageStr = language.c_str();
int convertedLanguage = ((languageStr[0] & 0xFF) << 16) | ((languageStr[1] & 0xFF) << 8) |
(languageStr[2] & 0xFF);
cec_set_option(HDMI_OPTION_SET_LANG, convertedLanguage);
return Void();
}
Return<void> HdmiCecMock::enableAudioReturnChannel(int32_t portId __unused, bool enable __unused) {
// Maintain ARC status
return Void();
}
Return<bool> HdmiCecMock::isConnected(int32_t portId) {
// maintain port connection status and update on hotplug event
if (portId < mTotalPorts && portId >= 0) {
return mPortConnectionStatus[portId];
}
return false;
}
// Methods from ::android::hardware::tv::cec::V1_1::IHdmiCec follow.
Return<Result> HdmiCecMock::addLogicalAddress_1_1(
::android::hardware::tv::cec::V1_1::CecLogicalAddress addr) {
// have a list to maintain logical addresses
int size = mLogicalAddresses.size();
mLogicalAddresses.resize(size + 1);
mLogicalAddresses[size + 1] = addr;
return Result::SUCCESS;
}
Return<SendMessageResult> HdmiCecMock::sendMessage_1_1(
const ::android::hardware::tv::cec::V1_1::CecMessage& message) {
if (message.body.size() == 0) {
return SendMessageResult::NACK;
}
sendMessageToFifo(message);
return SendMessageResult::SUCCESS;
}
Return<void> HdmiCecMock::setCallback_1_1(
const sp<::android::hardware::tv::cec::V1_1::IHdmiCecCallback>& callback) {
if (mCallback != nullptr) {
mCallback = nullptr;
}
if (callback != nullptr) {
mCallback = callback;
mCallback->linkToDeath(this, 0 /*cookie*/);
mInputFile = open(CEC_MSG_IN_FIFO, O_RDWR);
mOutputFile = open(CEC_MSG_OUT_FIFO, O_RDWR);
pthread_create(&mThreadId, NULL, __threadLoop, this);
pthread_setname_np(mThreadId, "hdmi_cec_loop");
}
return Void();
}
void* HdmiCecMock::__threadLoop(void* user) {
HdmiCecMock* const self = static_cast<HdmiCecMock*>(user);
self->threadLoop();
return 0;
}
int HdmiCecMock::readMessageFromFifo(unsigned char* buf, int msgCount) {
if (msgCount <= 0 || !buf) {
return 0;
}
int ret = -1;
/* maybe blocked at driver */
ret = read(mInputFile, buf, msgCount);
if (ret < 0) {
ALOGE("[halimp] read :%s failed, ret:%d\n", CEC_MSG_IN_FIFO, ret);
return -1;
}
return ret;
}
int HdmiCecMock::sendMessageToFifo(const ::android::hardware::tv::cec::V1_1::CecMessage& message) {
unsigned char msgBuf[CEC_MESSAGE_BODY_MAX_LENGTH];
int ret = -1;
memset(msgBuf, 0, sizeof(msgBuf));
msgBuf[0] = ((static_cast<uint8_t>(message.initiator) & 0xf) << 4) |
(static_cast<uint8_t>(message.destination) & 0xf);
size_t length = std::min(static_cast<size_t>(message.body.size()),
static_cast<size_t>(MaxLength::MESSAGE_BODY));
for (size_t i = 0; i < length; ++i) {
msgBuf[i + 1] = static_cast<unsigned char>(message.body[i]);
}
// open the output pipe for writing outgoing cec message
mOutputFile = open(CEC_MSG_OUT_FIFO, O_WRONLY);
if (mOutputFile < 0) {
ALOGD("[halimp] file open failed for writing");
return -1;
}
// write message into the output pipe
ret = write(mOutputFile, msgBuf, length + 1);
close(mOutputFile);
if (ret < 0) {
ALOGE("[halimp] write :%s failed, ret:%d\n", CEC_MSG_OUT_FIFO, ret);
return -1;
}
return ret;
}
void HdmiCecMock::printCecMsgBuf(const char* msg_buf, int len) {
char buf[64] = {};
int i, size = 0;
memset(buf, 0, sizeof(buf));
for (i = 0; i < len; i++) {
size += sprintf(buf + size, " %02x", msg_buf[i]);
}
ALOGD("[halimp] %s, msg:%s", __FUNCTION__, buf);
}
void HdmiCecMock::handleHotplugMessage(unsigned char* msgBuf) {
HotplugEvent hotplugEvent{.connected = ((msgBuf[3]) & 0xf) > 0,
.portId = static_cast<uint32_t>(msgBuf[0] & 0xf)};
if (hotplugEvent.portId >= mPortInfo.size()) {
ALOGD("[halimp] ignore hot plug message, id %x does not exist", hotplugEvent.portId);
return;
}
ALOGD("[halimp] hot plug port id %x, is connected %x", (msgBuf[0] & 0xf), (msgBuf[3] & 0xf));
if (mPortInfo[hotplugEvent.portId].type == HdmiPortType::OUTPUT) {
mPhysicalAddress =
((hotplugEvent.connected == 0) ? 0xffff : ((msgBuf[1] << 8) | (msgBuf[2])));
mPortInfo[hotplugEvent.portId].physicalAddress = mPhysicalAddress;
ALOGD("[halimp] hot plug physical address %x", mPhysicalAddress);
}
// todo update connection status
if (mCallback != nullptr) {
mCallback->onHotplugEvent(hotplugEvent);
}
}
void HdmiCecMock::handleCecMessage(unsigned char* msgBuf, int megSize) {
::android::hardware::tv::cec::V1_1::CecMessage message;
size_t length = std::min(static_cast<size_t>(megSize - 1),
static_cast<size_t>(MaxLength::MESSAGE_BODY));
message.body.resize(length);
for (size_t i = 0; i < length; ++i) {
message.body[i] = static_cast<uint8_t>(msgBuf[i + 1]);
ALOGD("[halimp] msg body %x", message.body[i]);
}
message.initiator = static_cast<::android::hardware::tv::cec::V1_1::CecLogicalAddress>(
(msgBuf[0] >> 4) & 0xf);
ALOGD("[halimp] msg init %x", message.initiator);
message.destination = static_cast<::android::hardware::tv::cec::V1_1::CecLogicalAddress>(
(msgBuf[0] >> 0) & 0xf);
ALOGD("[halimp] msg dest %x", message.destination);
// messageValidateAndHandle(&event);
if (mCallback != nullptr) {
mCallback->onCecMessage_1_1(message);
}
}
void HdmiCecMock::threadLoop() {
ALOGD("[halimp] threadLoop start.");
unsigned char msgBuf[CEC_MESSAGE_BODY_MAX_LENGTH];
int r = -1;
// open the input pipe
while (mInputFile < 0) {
usleep(1000 * 1000);
mInputFile = open(CEC_MSG_IN_FIFO, O_RDONLY);
}
ALOGD("[halimp] file open ok, fd = %d.", mInputFile);
while (mCecThreadRun) {
if (!mOptionSystemCecControl) {
usleep(1000 * 1000);
continue;
}
memset(msgBuf, 0, sizeof(msgBuf));
// try to get a message from dev.
// echo -n -e '\x04\x83' >> /dev/cec
r = readMessageFromFifo(msgBuf, CEC_MESSAGE_BODY_MAX_LENGTH);
if (r <= 1) {
// ignore received ping messages
continue;
}
printCecMsgBuf((const char*)msgBuf, r);
if (((msgBuf[0] >> 4) & 0xf) == 0xf) {
// the message is a hotplug event
handleHotplugMessage(msgBuf);
continue;
}
handleCecMessage(msgBuf, r);
}
ALOGD("[halimp] thread end.");
// mCecDevice.mExited = true;
}
HdmiCecMock::HdmiCecMock() {
ALOGE("[halimp] Opening a virtual HAL for testing and virtual machine.");
mCallback = nullptr;
mPortInfo.resize(mTotalPorts);
mPortConnectionStatus.resize(mTotalPorts);
mPortInfo[0] = {.type = HdmiPortType::OUTPUT,
.portId = static_cast<uint32_t>(1),
.cecSupported = true,
.arcSupported = false,
.physicalAddress = mPhysicalAddress};
mPortConnectionStatus[0] = false;
}
} // namespace implementation
} // namespace V1_1
} // namespace cec
} // namespace tv
} // namespace hardware
} // namespace android

View File

@@ -0,0 +1,125 @@
/*
* Copyright (C) 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <android/hardware/tv/cec/1.1/IHdmiCec.h>
#include <hidl/Status.h>
#include <algorithm>
#include <vector>
using namespace std;
namespace android {
namespace hardware {
namespace tv {
namespace cec {
namespace V1_1 {
namespace implementation {
using ::android::sp;
using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::hardware::tv::cec::V1_0::CecLogicalAddress;
using ::android::hardware::tv::cec::V1_0::CecMessage;
using ::android::hardware::tv::cec::V1_0::HdmiPortInfo;
using ::android::hardware::tv::cec::V1_0::HdmiPortType;
using ::android::hardware::tv::cec::V1_0::HotplugEvent;
using ::android::hardware::tv::cec::V1_0::IHdmiCecCallback;
using ::android::hardware::tv::cec::V1_0::MaxLength;
using ::android::hardware::tv::cec::V1_0::OptionKey;
using ::android::hardware::tv::cec::V1_0::Result;
using ::android::hardware::tv::cec::V1_0::SendMessageResult;
using ::android::hardware::tv::cec::V1_1::IHdmiCec;
#define CEC_MSG_IN_FIFO "/dev/cec_in_pipe"
#define CEC_MSG_OUT_FIFO "/dev/cec_out_pipe"
struct HdmiCecMock : public IHdmiCec, public hidl_death_recipient {
HdmiCecMock();
// Methods from ::android::hardware::tv::cec::V1_0::IHdmiCec follow.
Return<Result> addLogicalAddress(CecLogicalAddress addr) override;
Return<void> clearLogicalAddress() override;
Return<void> getPhysicalAddress(getPhysicalAddress_cb _hidl_cb) override;
Return<SendMessageResult> sendMessage(const CecMessage& message) override;
Return<void> setCallback(
const sp<::android::hardware::tv::cec::V1_0::IHdmiCecCallback>& callback) override;
Return<int32_t> getCecVersion() override;
Return<uint32_t> getVendorId() override;
Return<void> getPortInfo(getPortInfo_cb _hidl_cb) override;
Return<void> setOption(OptionKey key, bool value) override;
Return<void> setLanguage(const hidl_string& language) override;
Return<void> enableAudioReturnChannel(int32_t portId, bool enable) override;
Return<bool> isConnected(int32_t portId) override;
// Methods from ::android::hardware::tv::cec::V1_1::IHdmiCec follow.
Return<Result> addLogicalAddress_1_1(
::android::hardware::tv::cec::V1_1::CecLogicalAddress addr) override;
Return<SendMessageResult> sendMessage_1_1(
const ::android::hardware::tv::cec::V1_1::CecMessage& message) override;
Return<void> setCallback_1_1(
const sp<::android::hardware::tv::cec::V1_1::IHdmiCecCallback>& callback) override;
virtual void serviceDied(uint64_t /*cookie*/,
const wp<::android::hidl::base::V1_0::IBase>& /*who*/) {
setCallback(nullptr);
}
void cec_set_option(int flag, int value);
void printCecMsgBuf(const char* msg_buf, int len);
private:
static void* __threadLoop(void* data);
void threadLoop();
int readMessageFromFifo(unsigned char* buf, int msgCount);
int sendMessageToFifo(const ::android::hardware::tv::cec::V1_1::CecMessage& message);
void handleHotplugMessage(unsigned char* msgBuf);
void handleCecMessage(unsigned char* msgBuf, int length);
private:
sp<::android::hardware::tv::cec::V1_1::IHdmiCecCallback> mCallback;
// Variables for the virtual cec hal impl
uint16_t mPhysicalAddress = 0xFFFF;
vector<::android::hardware::tv::cec::V1_1::CecLogicalAddress> mLogicalAddresses;
int32_t mCecVersion = 0x06;
uint32_t mCecVendorId = 0x01;
// Port configuration
int mTotalPorts = 1;
hidl_vec<HdmiPortInfo> mPortInfo;
hidl_vec<bool> mPortConnectionStatus;
// CEC Option value
int mOptionWakeUp = 0;
int mOptionEnableCec = 0;
int mOptionSystemCecControl = 0;
int mOptionLanguage = 0;
// Testing variables
// Input file descriptor
int mInputFile;
// Output file descriptor
int mOutputFile;
bool mCecThreadRun = true;
pthread_t mThreadId = 0;
};
} // namespace implementation
} // namespace V1_1
} // namespace cec
} // namespace tv
} // namespace hardware
} // namespace android

View File

@@ -0,0 +1,6 @@
service vendor.cec-hal-1-1 /vendor/bin/hw/android.hardware.tv.cec@1.1-service
interface android.hardware.tv.cec@1.0::IHdmiCec default
interface android.hardware.tv.cec@1.1::IHdmiCec default
class hal
user system
group 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.1</version>
<interface>
<name>IHdmiCec</name>
<instance>default</instance>
</interface>
</hal>
</manifest>

View File

@@ -0,0 +1,40 @@
/*
* Copyright (C) 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "android.hardware.tv.cec@1.1-service-shim"
#include <android/hardware/tv/cec/1.1/IHdmiCec.h>
#include <hidl/LegacySupport.h>
#include "HdmiCecMock.h"
using android::hardware::configureRpcThreadpool;
using android::hardware::joinRpcThreadpool;
using android::hardware::tv::cec::V1_1::IHdmiCec;
using android::hardware::tv::cec::V1_1::implementation::HdmiCecMock;
int main() {
configureRpcThreadpool(8, true /* callerWillJoin */);
// Setup hwbinder service
android::sp<IHdmiCec> service = new HdmiCecMock();
android::status_t status;
status = service->registerAsService();
LOG_ALWAYS_FATAL_IF(status != android::OK, "Error while registering mock cec service: %d",
status);
joinRpcThreadpool();
return 0;
}

45
tv/cec/1.1/types.hal Normal file
View File

@@ -0,0 +1,45 @@
/*
* Copyright (C) 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.hardware.tv.cec@1.1;
import @1.0::CecLogicalAddress;
import @1.0::CecMessageType;
enum CecLogicalAddress : @1.0::CecLogicalAddress {
BACKUP_1 = 12,
BACKUP_2 = 13,
};
enum CecMessageType : @1.0::CecMessageType {
GIVE_FEATURES = 0xA5,
REPORT_FEATURES = 0xA6,
REQUEST_CURRENT_LATENCY = 0xA7,
REPORT_CURRENT_LATENCY = 0xA8,
};
struct CecMessage {
/** logical address of the initiator */
CecLogicalAddress initiator;
/** logical address of destination */
CecLogicalAddress destination;
/**
* The maximum size of body is 15 (MaxLength::MESSAGE_BODY) as specified in
* the section 6 of the CEC Spec 1.4b. Overflowed data must be ignored. */
vec<uint8_t> body;
};

View File

@@ -0,0 +1,14 @@
cc_test {
name: "VtsHalTvCecV1_1TargetTest",
defaults: ["VtsHalTargetTestDefaults"],
srcs: ["VtsHalTvCecV1_1TargetTest.cpp"],
static_libs: [
"android.hardware.tv.cec@1.1",
"android.hardware.tv.cec@1.0",
],
test_suites: [
"general-tests",
"vts",
],
disable_framework: true,
}

View File

@@ -0,0 +1,199 @@
/*
* Copyright (C) 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "HdmiCec_hal_test"
#include <android-base/logging.h>
#include <android/hardware/tv/cec/1.1/IHdmiCec.h>
#include <android/hardware/tv/cec/1.1/types.h>
#include <utils/Log.h>
#include <sstream>
#include <vector>
#include <gtest/gtest.h>
#include <hidl/GtestPrinter.h>
#include <hidl/ServiceManagement.h>
using ::android::sp;
using ::android::hardware::hidl_death_recipient;
using ::android::hardware::hidl_vec;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::hardware::tv::cec::V1_0::CecDeviceType;
using ::android::hardware::tv::cec::V1_0::HdmiPortInfo;
using ::android::hardware::tv::cec::V1_0::HdmiPortType;
using ::android::hardware::tv::cec::V1_0::HotplugEvent;
using ::android::hardware::tv::cec::V1_0::OptionKey;
using ::android::hardware::tv::cec::V1_0::Result;
using ::android::hardware::tv::cec::V1_0::SendMessageResult;
using ::android::hardware::tv::cec::V1_1::CecLogicalAddress;
using ::android::hardware::tv::cec::V1_1::CecMessage;
using ::android::hardware::tv::cec::V1_1::IHdmiCec;
using ::android::hardware::tv::cec::V1_1::IHdmiCecCallback;
#define CEC_VERSION 0x05
#define INCORRECT_VENDOR_ID 0x00
// The main test class for TV CEC HAL.
class HdmiCecTest : public ::testing::TestWithParam<std::string> {
public:
void SetUp() override {
hdmiCec = IHdmiCec::getService(GetParam());
ASSERT_NE(hdmiCec, nullptr);
ALOGI("%s: getService() for hdmiCec is %s", __func__,
hdmiCec->isRemote() ? "remote" : "local");
hdmiCec_death_recipient = new HdmiCecDeathRecipient();
hdmiCecCallback = new CecCallback();
ASSERT_NE(hdmiCec_death_recipient, nullptr);
ASSERT_TRUE(hdmiCec->linkToDeath(hdmiCec_death_recipient, 0).isOk());
}
std::vector<int> getDeviceTypes() {
std::vector<int> deviceTypes;
FILE* p = popen("getprop ro.hdmi.device_type", "re");
if (p) {
char* line = NULL;
size_t len = 0;
if (getline(&line, &len, p) > 0) {
std::istringstream stream(line);
std::string number{};
while (std::getline(stream, number, ',')) {
deviceTypes.push_back(stoi(number));
}
}
pclose(p);
}
return deviceTypes;
}
bool hasDeviceType(CecDeviceType type) {
std::vector<int> deviceTypes = getDeviceTypes();
return std::find(deviceTypes.begin(), deviceTypes.end(), (int)type) != deviceTypes.end();
}
class CecCallback : public IHdmiCecCallback {
public:
Return<void> onCecMessage(
const ::android::hardware::tv::cec::V1_0::CecMessage& /* message */) {
return Void();
}
Return<void> onCecMessage_1_1(
const ::android::hardware::tv::cec::V1_1::CecMessage& /* message */) {
return Void();
}
Return<void> onHotplugEvent(
const ::android::hardware::tv::cec::V1_0::HotplugEvent& /* event */) {
return Void();
}
};
class HdmiCecDeathRecipient : public hidl_death_recipient {
public:
void serviceDied(uint64_t /*cookie*/,
const android::wp<::android::hidl::base::V1_0::IBase>& /*who*/) override {
FAIL();
}
};
sp<IHdmiCec> hdmiCec;
sp<IHdmiCecCallback> hdmiCecCallback;
sp<HdmiCecDeathRecipient> hdmiCec_death_recipient;
};
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(HdmiCecTest);
INSTANTIATE_TEST_SUITE_P(
PerInstance, HdmiCecTest,
testing::ValuesIn(android::hardware::getAllHalInstanceNames(IHdmiCec::descriptor)),
android::hardware::PrintInstanceNameToString);
TEST_P(HdmiCecTest, ClearAddLogicalAddress) {
hdmiCec->clearLogicalAddress();
Return<Result> ret = hdmiCec->addLogicalAddress_1_1(CecLogicalAddress::PLAYBACK_3);
EXPECT_EQ(ret, Result::SUCCESS);
}
TEST_P(HdmiCecTest, SendMessage) {
CecMessage message;
message.initiator = CecLogicalAddress::PLAYBACK_1;
message.destination = CecLogicalAddress::BROADCAST;
message.body.resize(1);
message.body[0] = 131;
SendMessageResult ret = hdmiCec->sendMessage_1_1(message);
EXPECT_EQ(ret, SendMessageResult::SUCCESS);
}
TEST_P(HdmiCecTest, CecVersion) {
Return<int32_t> ret = hdmiCec->getCecVersion();
EXPECT_GE(ret, CEC_VERSION);
}
TEST_P(HdmiCecTest, SetCallback) {
Return<void> ret = hdmiCec->setCallback_1_1(new CecCallback());
ASSERT_TRUE(ret.isOk());
}
TEST_P(HdmiCecTest, VendorId) {
Return<uint32_t> ret = hdmiCec->getVendorId();
EXPECT_NE(ret, INCORRECT_VENDOR_ID);
}
TEST_P(HdmiCecTest, GetPortInfo) {
hidl_vec<HdmiPortInfo> ports;
Return<void> ret =
hdmiCec->getPortInfo([&ports](hidl_vec<HdmiPortInfo> list) { ports = list; });
ASSERT_TRUE(ret.isOk());
bool cecSupportedOnDevice = false;
for (size_t i = 0; i < ports.size(); ++i) {
EXPECT_TRUE((ports[i].type == HdmiPortType::OUTPUT) ||
(ports[i].type == HdmiPortType::INPUT));
if (ports[i].portId == 0) {
ALOGW("%s: Port id should start from 1", __func__);
}
cecSupportedOnDevice = cecSupportedOnDevice | ports[i].cecSupported;
}
EXPECT_NE(cecSupportedOnDevice, false) << "At least one port should support CEC";
}
TEST_P(HdmiCecTest, SetOption) {
Return<void> wakeup = hdmiCec->setOption(OptionKey::WAKEUP, false);
ASSERT_TRUE(wakeup.isOk());
Return<void> enableCec = hdmiCec->setOption(OptionKey::ENABLE_CEC, false);
ASSERT_TRUE(enableCec.isOk());
Return<void> systemCecControl = hdmiCec->setOption(OptionKey::SYSTEM_CEC_CONTROL, true);
ASSERT_TRUE(systemCecControl.isOk());
// Restore option keys to their default values
hdmiCec->setOption(OptionKey::WAKEUP, true);
hdmiCec->setOption(OptionKey::ENABLE_CEC, true);
hdmiCec->setOption(OptionKey::SYSTEM_CEC_CONTROL, false);
}
TEST_P(HdmiCecTest, SetLanguage) {
Return<void> ret = hdmiCec->setLanguage("eng");
ASSERT_TRUE(ret.isOk());
}
TEST_P(HdmiCecTest, EnableAudioReturnChannel) {
hidl_vec<HdmiPortInfo> ports;
Return<void> ret =
hdmiCec->getPortInfo([&ports](hidl_vec<HdmiPortInfo> list) { ports = list; });
for (size_t i = 0; i < ports.size(); ++i) {
if (ports[i].arcSupported) {
Return<void> ret = hdmiCec->enableAudioReturnChannel(ports[i].portId, true);
ASSERT_TRUE(ret.isOk());
}
}
}