CEC: Add methods to get device types

Test: atest VtsHalTvCecV1_0TargetTest
Bug: 172316717
Change-Id: I4dd0c73865b9d12d4b0588cd92f4087cc0c556b4
diff --git a/tv/cec/1.0/vts/functional/VtsHalTvCecV1_0TargetTest.cpp b/tv/cec/1.0/vts/functional/VtsHalTvCecV1_0TargetTest.cpp
index fcd1df8..9cd6884 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 <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::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 @@
         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*/,