CEC: Add methods to get device types am: 3a19b4246f
am: 4a74ccc749
Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/1577106 Change-Id: Id416da8c1121fecbcd28fa15dc73af626814512f
This commit is contained in:
commit
f38c8a53f2
1 changed files with 31 additions and 0 deletions
|
@ -20,6 +20,8 @@
|
|||
#include <android/hardware/tv/cec/1.0/IHdmiCec.h>
|
||||
#include <android/hardware/tv/cec/1.0/types.h>
|
||||
#include <utils/Log.h>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <hidl/GtestPrinter.h>
|
||||
|
@ -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<std::string> {
|
|||
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();
|
||||
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*/,
|
||||
|
|
Loading…
Reference in a new issue