Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix usage of __system_property_read_callback for Android<26 #237

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions src/layer/layer_settings_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,38 @@
#include <algorithm>

#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<std::string *>(cookie)->assign(value);
},
reinterpret_cast<void *>(&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<std::string *>(cookie)->assign(value);
},
reinterpret_cast<void *>(&output));
}
} else {
char value_buf[PROP_VALUE_MAX] = "";
size_t len = static_cast<size_t>(__system_property_get(name, value_buf));
if (len > 0 && len < sizeof(value_buf)) {
output.assign(value_buf, len);
}
}
return output;
}
Expand Down
Loading