Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Determine x86_pkg_temp path Dynamically. #120

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion thermal/Thermal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

#include <cmath>
#include <set>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <glob.h>

#include <android-base/logging.h>
#include <hidl/HidlTransportSupport.h>
Expand Down Expand Up @@ -169,14 +174,59 @@ struct temp_info {
uint32_t temp;
};

std::vector<std::string> getThermalZonePaths() {
std::vector<std::string> thermalZonePaths;

glob_t globResult;
if (glob("/sys/class/thermal/thermal_zone*", 0, nullptr, &globResult) == 0) {
for (size_t i = 0; i < globResult.gl_pathc; ++i) {
thermalZonePaths.push_back(globResult.gl_pathv[i]);
}
globfree(&globResult);
}

return thermalZonePaths;
}

std::string readTypeAttribute(const std::string& thermalZonePath) {
std::ifstream typeFile(thermalZonePath + "/type");
if (!typeFile.is_open()) {
return "";
}

std::string type;
typeFile >> type;
typeFile.close();

return type;
}

std::string getThermalZoneCPUTemperaturePath(){
std::vector<std::string> thermalZonePaths = getThermalZonePaths();

for (const std::string& thermalZonePath : thermalZonePaths) {
std::string thermalType = readTypeAttribute(thermalZonePath);
if (!thermalType.empty()) {
if (thermalType == "x86_pkg_temp") {
return thermalZonePath + "/temp";
}
}
}
return "";
}

static int get_soc_pkg_temperature(float* temp)
{
float fTemp = 0;
int len = 0;
FILE *file = NULL;

file = fopen(SYSFS_TEMPERATURE_CPU, "r");
std::string thermalTypePath = getThermalZoneCPUTemperaturePath();
ALOGE("Thermal zone path Temp path for x86_pkg_temp:%s", thermalTypePath.c_str());
if(thermalTypePath.empty())
return -errno;

file = fopen(thermalTypePath.c_str(), "r");
if (file == NULL) {
ALOGE("%s: failed to open file: %s", __func__, strerror(errno));
return -errno;
Expand Down
Loading