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

Use system_properties.h api instead of getprop #1233

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
30 changes: 14 additions & 16 deletions framework/util/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
#include <sys/mman.h>
#endif // WIN32

#if defined(__ANDROID__)
#include <sys/system_properties.h>
#endif

GFXRECON_BEGIN_NAMESPACE(gfxrecon)
GFXRECON_BEGIN_NAMESPACE(util)
GFXRECON_BEGIN_NAMESPACE(platform)
Expand Down Expand Up @@ -290,26 +294,20 @@ inline void* GetProcAddress(LibraryHandle handle, const char* name)

inline std::string GetEnv(const char* name)
{
std::string env_value;
std::string env_value;

#if defined(__ANDROID__)
std::string command = "getprop ";
command += name;
const prop_info* pi = __system_property_find(name);

FILE* pipe = popen(command.c_str(), "r");
if (pipe != nullptr)
if (pi)
{
char result[kMaxPropertyLength];
result[0] = '\0';

fgets(result, kMaxPropertyLength, pipe);
pclose(pipe);

size_t count = strcspn(result, "\r\n");
if (count > 0)
{
env_value = std::string(result, count);
}
__system_property_read_callback(
pi,
[](void* cookie, const char* name, const char* value, uint32_t serial) {
std::string* prop = reinterpret_cast<std::string*>(cookie);
*prop = value;
},
&env_value);
}
#else
const char* ret_value = getenv(name);
Expand Down