diff --git a/src/layer/layer_settings_manager.cpp b/src/layer/layer_settings_manager.cpp index 1678e25..391d339 100644 --- a/src/layer/layer_settings_manager.cpp +++ b/src/layer/layer_settings_manager.cpp @@ -33,18 +33,35 @@ #include #if defined(__ANDROID__) +/* + * Use the __system_property_read_callback API that appeared in + * Android API level 26. If not avaible use the old __system_property_get function. + */ + +// Weak function declaration, used only when not decalered in the Android headers +void __system_property_read_callback(const prop_info *info, + void (*callback)(void *cookie, const char *name, const char *value, uint32_t serial), + void *cookie) __attribute__((weak)); static std::string GetAndroidProperty(const char *name) { std::string output; - const prop_info *pi = __system_property_find(name); - if (pi) { - __system_property_read_callback( - pi, - [](void *cookie, const char *name, const char *value, uint32_t serial) { - (void)name; - (void)serial; - reinterpret_cast(cookie)->assign(value); - }, - reinterpret_cast(&output)); + if (__system_property_read_callback != nullptr) { + const prop_info *pi = __system_property_find(name); + if (pi) { + __system_property_read_callback( + pi, + [](void *cookie, const char *name, const char *value, uint32_t serial) { + (void)name; + (void)serial; + reinterpret_cast(cookie)->assign(value); + }, + reinterpret_cast(&output)); + } + } else { + char value_buf[PROP_VALUE_MAX] = ""; + size_t len = static_cast(__system_property_get(name, value_buf)); + if (len > 0 && len < sizeof(value_buf)) { + output.assign(value_buf, len); + } } return output; }