Add C++ Host support on sysprop_library am: b1e8c10159 am: 5afe96bb34
Change-Id: I16631dc64358ea4930c4b9f7beaeab898b8e0421
diff --git a/CppGen.cpp b/CppGen.cpp
index 9c75eed..842bd5d 100644
--- a/CppGen.cpp
+++ b/CppGen.cpp
@@ -54,7 +54,15 @@
#include <utility>
#include <strings.h>
+#ifdef __BIONIC__
#include <sys/system_properties.h>
+#else
+#include <android-base/properties.h>
+static int __system_property_set(const char* key, const char* value) {
+ android::base::SetProperty(key, value);
+ return 0;
+}
+#endif
#include <android-base/parseint.h>
#include <log/log.h>
@@ -184,6 +192,7 @@
template <typename T>
T GetProp(const char* key) {
+#ifdef __BIONIC__
T ret;
auto pi = __system_property_find(key);
if (pi != nullptr) {
@@ -192,6 +201,9 @@
}, &ret);
}
return ret;
+#else
+ return TryParse<T>(android::base::GetProperty(key, "").c_str());
+#endif
}
)";
diff --git a/tests/CppGenTest.cpp b/tests/CppGenTest.cpp
index 0d8c4f8..6fc6466 100644
--- a/tests/CppGenTest.cpp
+++ b/tests/CppGenTest.cpp
@@ -207,7 +207,15 @@
#include <utility>
#include <strings.h>
+#ifdef __BIONIC__
#include <sys/system_properties.h>
+#else
+#include <android-base/properties.h>
+static int __system_property_set(const char* key, const char* value) {
+ android::base::SetProperty(key, value);
+ return 0;
+}
+#endif
#include <android-base/parseint.h>
#include <log/log.h>
@@ -398,6 +406,7 @@
template <typename T>
T GetProp(const char* key) {
+#ifdef __BIONIC__
T ret;
auto pi = __system_property_find(key);
if (pi != nullptr) {
@@ -406,6 +415,9 @@
}, &ret);
}
return ret;
+#else
+ return TryParse<T>(android::base::GetProperty(key, "").c_str());
+#endif
}
} // namespace