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 @@ ...@@ -10,6 +10,10 @@
#include <stdlib.h> #include <stdlib.h>
#if defined(ANGLE_PLATFORM_ANDROID)
# include <sys/system_properties.h>
#endif
namespace angle namespace angle
{ {
std::string GetExecutableName() std::string GetExecutableName()
...@@ -48,33 +52,24 @@ std::string GetEnvironmentVarOrAndroidProperty(const char *variableName, const c ...@@ -48,33 +52,24 @@ std::string GetEnvironmentVarOrAndroidProperty(const char *variableName, const c
std::string GetEnvironmentVarOrUnCachedAndroidProperty(const char *variableName, std::string GetEnvironmentVarOrUnCachedAndroidProperty(const char *variableName,
const char *propertyName) const char *propertyName)
{ {
#if defined(ANGLE_PLATFORM_ANDROID) && __ANDROID_API__ >= 21 #if defined(ANGLE_PLATFORM_ANDROID) && __ANDROID_API__ >= 26
std::string sanitizedPropertyName = propertyName; std::string propertyValue;
sanitizedPropertyName.erase(
std::remove(sanitizedPropertyName.begin(), sanitizedPropertyName.end(), '\''),
sanitizedPropertyName.end());
std::string command("getprop '"); const prop_info *propertyInfo = __system_property_find(propertyName);
command += sanitizedPropertyName; if (propertyInfo != nullptr)
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)
{ {
fgets(stream, kStreamSize, pipe); __system_property_read_callback(
pclose(pipe); 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. // Set the environment variable with the value.
SetEnvironmentVar(variableName, value.c_str()); SetEnvironmentVar(variableName, propertyValue.c_str());
return value; return propertyValue;
#endif // ANGLE_PLATFORM_ANDROID #endif // ANGLE_PLATFORM_ANDROID
// Return the environment variable's value. // Return the environment variable's value.
return GetEnvironmentVar(variableName); 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