Commit d820ec7b by Jason Macnak Committed by Commit Bot

Use __system_property* to read Android props

... instead of popen to avoid needing shell_exec permission. Bug: b/179041465 Test: roll_aosp.sh && m && launch Cuttlefish w/ SwANGLE Test: aosp/1574848 presubmit Change-Id: Ie64d2730fd2ea00a1b5089459297ef7ffe98bc59 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2676271Reviewed-by: 's avatarCody Northrop <cnorthrop@google.com> Reviewed-by: 's avatarTim Van Patten <timvp@google.com> Reviewed-by: 's avatarIan Elliott <ianelliott@google.com> Commit-Queue: Jason Macnak <natsu@google.com>
parent 0bb520ad
......@@ -10,6 +10,10 @@
#include <stdlib.h>
#if defined(ANGLE_PLATFORM_ANDROID)
# include <sys/system_properties.h>
#endif
namespace angle
{
std::string GetExecutableName()
......@@ -48,33 +52,24 @@ std::string GetEnvironmentVarOrAndroidProperty(const char *variableName, const c
std::string GetEnvironmentVarOrUnCachedAndroidProperty(const char *variableName,
const char *propertyName)
{
#if defined(ANGLE_PLATFORM_ANDROID) && __ANDROID_API__ >= 21
std::string sanitizedPropertyName = propertyName;
sanitizedPropertyName.erase(
std::remove(sanitizedPropertyName.begin(), sanitizedPropertyName.end(), '\''),
sanitizedPropertyName.end());
#if defined(ANGLE_PLATFORM_ANDROID) && __ANDROID_API__ >= 26
std::string propertyValue;
std::string command("getprop '");
command += sanitizedPropertyName;
command += "'";
// Run the command and open a I/O stream to read the value
constexpr int kStreamSize = 64;
char stream[kStreamSize] = {};
FILE *pipe = popen(command.c_str(), "r");
if (pipe != nullptr)
const prop_info *propertyInfo = __system_property_find(propertyName);
if (propertyInfo != nullptr)
{
fgets(stream, kStreamSize, pipe);
pclose(pipe);
__system_property_read_callback(
propertyInfo,
[](void *cookie, const char *, const char *value, unsigned) {
auto propertyValue = reinterpret_cast<std::string *>(cookie);
*propertyValue = value;
},
&propertyValue);
}
// Right strip white space
std::string value(stream);
value.erase(value.find_last_not_of(" \n\r\t") + 1);
// Set the environment variable with the value.
SetEnvironmentVar(variableName, value.c_str());
return value;
SetEnvironmentVar(variableName, propertyValue.c_str());
return propertyValue;
#endif // ANGLE_PLATFORM_ANDROID
// Return the environment variable's value.
return GetEnvironmentVar(variableName);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment