From b419bfcb3d8d991f1b3d73eb466530a2dda59188 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E5=9B=BD=E4=BA=AE?= Date: Sat, 13 Sep 2025 11:41:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9harden=E5=B1=8F=E5=B9=95?= =?UTF-8?q?=E5=88=86=E8=BE=A8=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 牛国亮 --- .../device_command/collector/src/FPS.cpp | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/smartperf_device/device_command/collector/src/FPS.cpp b/smartperf_device/device_command/collector/src/FPS.cpp index a39458369..f823545d7 100644 --- a/smartperf_device/device_command/collector/src/FPS.cpp +++ b/smartperf_device/device_command/collector/src/FPS.cpp @@ -478,21 +478,28 @@ std::string FPS::FindFpsRefreshrate() std::string FPS::GetHardenRefreshrate(std::string &screenInfo) const { - if (screenInfo.empty()) { - SPUtils::LoadCmd(HIDUMPER_CMD_MAP.at(HidumperCmd::DUMPER_SCREEN), screenInfo); - } std::string value = ""; - std::string refreshrate = "refreshrate="; - size_t activeModePos = screenInfo.find("activeMode:"); - if (activeModePos != std::string::npos) { - size_t refreshRatePos = screenInfo.find(refreshrate, activeModePos); - if (refreshRatePos != std::string::npos) { - size_t endPos = screenInfo.find(" ", refreshRatePos); - if (endPos != std::string::npos) { - value = screenInfo.substr(refreshRatePos + refreshrate.length(), - endPos - refreshRatePos - refreshrate.length()); + if (screenInfo.empty()) { + FILE *fd = popen(HIDUMPER_CMD_MAP.at(HidumperCmd::DUMPER_SCREEN).c_str(), "r"); + if (fd == nullptr) { + LOGE("hidumper screen failed"); + return ""; + } + char buf[1024] = {'\0'}; + while (fgets(buf, sizeof(buf), fd) != nullptr) { + std::string line = buf; + if (line.find("activeMode") != std::string::npos) { + std::string rate = "refreshRate="; + size_t pos = line.find(rate); + pos += rate.length(); + value = line.substr(pos); + value.pop_back(); } } + if (pclose(fd) == -1) { + LOGE("Error : failed to close file"); + return ""; + } } return value; } -- Gitee