From 3a19b4246fc1273bc33157bef4da2eaa15cdc63f Mon Sep 17 00:00:00 2001 From: Shraddha Basantwani Date: Thu, 28 Jan 2021 16:35:10 +0530 Subject: [PATCH] CEC: Add methods to get device types Test: atest VtsHalTvCecV1_0TargetTest Bug: 172316717 Change-Id: I4dd0c73865b9d12d4b0588cd92f4087cc0c556b4 --- .../functional/VtsHalTvCecV1_0TargetTest.cpp | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tv/cec/1.0/vts/functional/VtsHalTvCecV1_0TargetTest.cpp b/tv/cec/1.0/vts/functional/VtsHalTvCecV1_0TargetTest.cpp index fcd1df8543..9cd6884ef2 100644 --- a/tv/cec/1.0/vts/functional/VtsHalTvCecV1_0TargetTest.cpp +++ b/tv/cec/1.0/vts/functional/VtsHalTvCecV1_0TargetTest.cpp @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include #include @@ -29,6 +31,7 @@ using ::android::sp; using ::android::hardware::hidl_death_recipient; using ::android::hardware::hidl_vec; using ::android::hardware::Return; +using ::android::hardware::tv::cec::V1_0::CecDeviceType; using ::android::hardware::tv::cec::V1_0::CecLogicalAddress; using ::android::hardware::tv::cec::V1_0::CecMessage; using ::android::hardware::tv::cec::V1_0::HdmiPortInfo; @@ -55,6 +58,34 @@ class HdmiCecTest : public ::testing::TestWithParam { ASSERT_TRUE(hdmiCec->linkToDeath(hdmiCec_death_recipient, 0).isOk()); } + std::vector getDeviceTypes() { + std::vector 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 deviceTypes = getDeviceTypes(); + for (auto deviceType = deviceTypes.begin(); deviceType != deviceTypes.end(); ++deviceType) { + if (*deviceType == (int)type) { + return true; + } + } + return false; + } + class HdmiCecDeathRecipient : public hidl_death_recipient { public: void serviceDied(uint64_t /*cookie*/,