Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3a19b424 authored by Shraddha Basantwani's avatar Shraddha Basantwani
Browse files

CEC: Add methods to get device types

Test: atest VtsHalTvCecV1_0TargetTest
Bug: 172316717
Change-Id: I4dd0c73865b9d12d4b0588cd92f4087cc0c556b4
parent b75639ca
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -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*/,