Skip to content

Commit

Permalink
Use system_properties.h api instead of getprop
Browse files Browse the repository at this point in the history
Use the appropriate Android NDK Api to get property values instead of
launching a new process with popen("getprop ...");
  • Loading branch information
panos-lunarg committed Aug 24, 2023
1 parent 655fd55 commit 4fe54f0
Showing 1 changed file with 14 additions and 16 deletions.
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

0 comments on commit 4fe54f0

Please sign in to comment.