summaryrefslogtreecommitdiffstats
path: root/base/properties.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'base/properties.cpp')
-rw-r--r--base/properties.cpp59
1 files changed, 39 insertions, 20 deletions
diff --git a/base/properties.cpp b/base/properties.cpp
index 6cf43f9e2..d5a5918ce 100644
--- a/base/properties.cpp
+++ b/base/properties.cpp
@@ -14,16 +14,18 @@
* limitations under the License.
*/
-#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
-
#include "android-base/properties.h"
+#if defined(__BIONIC__)
+#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
#include <sys/system_properties.h>
#include <sys/_system_properties.h>
+#endif
#include <algorithm>
#include <chrono>
#include <limits>
+#include <map>
#include <string>
#include <android-base/parseint.h>
@@ -31,24 +33,6 @@
namespace android {
namespace base {
-std::string GetProperty(const std::string& key, const std::string& default_value) {
- const prop_info* pi = __system_property_find(key.c_str());
- if (pi == nullptr) return default_value;
-
- std::string property_value;
- __system_property_read_callback(pi,
- [](void* cookie, const char*, const char* value, unsigned) {
- auto property_value = reinterpret_cast<std::string*>(cookie);
- *property_value = value;
- },
- &property_value);
-
- // If the property exists but is empty, also return the default value.
- // Since we can't remove system properties, "empty" is traditionally
- // the same as "missing" (this was true for cutils' property_get).
- return property_value.empty() ? default_value : property_value;
-}
-
bool GetBoolProperty(const std::string& key, bool default_value) {
std::string value = GetProperty(key, "");
if (value == "1" || value == "y" || value == "yes" || value == "on" || value == "true") {
@@ -85,10 +69,43 @@ template uint16_t GetUintProperty(const std::string&, uint16_t, uint16_t);
template uint32_t GetUintProperty(const std::string&, uint32_t, uint32_t);
template uint64_t GetUintProperty(const std::string&, uint64_t, uint64_t);
+#if !defined(__BIONIC__)
+static std::map<std::string, std::string>& g_properties = *new std::map<std::string, std::string>;
+static int __system_property_set(const char* key, const char* value) {
+ g_properties[key] = value;
+ return 0;
+}
+#endif
+
+std::string GetProperty(const std::string& key, const std::string& default_value) {
+ std::string property_value;
+#if defined(__BIONIC__)
+ const prop_info* pi = __system_property_find(key.c_str());
+ if (pi == nullptr) return default_value;
+
+ __system_property_read_callback(pi,
+ [](void* cookie, const char*, const char* value, unsigned) {
+ auto property_value = reinterpret_cast<std::string*>(cookie);
+ *property_value = value;
+ },
+ &property_value);
+#else
+ auto it = g_properties.find(key);
+ if (it == g_properties.end()) return default_value;
+ property_value = it->second;
+#endif
+ // If the property exists but is empty, also return the default value.
+ // Since we can't remove system properties, "empty" is traditionally
+ // the same as "missing" (this was true for cutils' property_get).
+ return property_value.empty() ? default_value : property_value;
+}
+
bool SetProperty(const std::string& key, const std::string& value) {
return (__system_property_set(key.c_str(), value.c_str()) == 0);
}
+#if defined(__BIONIC__)
+
struct WaitForPropertyData {
bool done;
const std::string* expected_value;
@@ -175,5 +192,7 @@ bool WaitForPropertyCreation(const std::string& key,
return (WaitForPropertyCreation(key, relative_timeout, start_time) != nullptr);
}
+#endif
+
} // namespace base
} // namespace android