int mb__system_properties_init() { if (initialized) { list_foreach(contexts, [](context_node* l) { l->reset_access(); }); return 0; } if (is_dir(property_filename)) { if (!initialize_properties()) { return -1; } if (!map_system_property_area(false, nullptr)) { free_and_unmap_contexts(); return -1; } } else { mb__system_property_area__ = map_prop_area(property_filename, true); if (!mb__system_property_area__) { return -1; } list_add(&contexts, "legacy_system_prop_area", mb__system_property_area__); list_add_after_len(&prefixes, "*", contexts); } initialized = true; return 0; }
int libc_system_property_foreach( void (*propfn)(const prop_info *pi, void *cookie), void *cookie) { initialize_properties(); return mb__system_property_foreach(propfn, cookie); }
bool libc_system_property_wait(const prop_info *pi, uint32_t old_serial, uint32_t *new_serial_ptr, const struct timespec *relative_timeout) { initialize_properties(); return mb__system_property_wait(pi, old_serial, new_serial_ptr, relative_timeout); }
void libc_system_property_read_callback( const prop_info *pi, void (*callback)(void *cookie, const char *name, const char *value, uint32_t serial), void *cookie) { initialize_properties(); return mb__system_property_read_callback(pi, callback, cookie); }
bool property_set_direct(const std::string &key, const std::string &value) { initialize_properties(); prop_info *pi = const_cast<prop_info *>( mb__system_property_find(key.c_str())); int ret; if (pi) { ret = mb__system_property_update(pi, value.c_str(), static_cast<unsigned int>(value.size())); } else { ret = mb__system_property_add(key.c_str(), static_cast<unsigned int>(key.size()), value.c_str(), static_cast<unsigned int>(value.size())); } return ret == 0; }
int mb__system_property_area_init() { free_and_unmap_contexts(); mkdir(property_filename, S_IRWXU | S_IXGRP | S_IXOTH); if (!initialize_properties()) { return -1; } bool open_failed = false; bool fsetxattr_failed = false; list_foreach(contexts, [&fsetxattr_failed, &open_failed](context_node* l) { if (!l->open(true, &fsetxattr_failed)) { open_failed = true; } }); if (open_failed || !map_system_property_area(true, &fsetxattr_failed)) { free_and_unmap_contexts(); return -1; } initialized = true; return fsetxattr_failed ? -2 : 0; }
const prop_info *libc_system_property_find(const char *name) { initialize_properties(); return mb__system_property_find(name); }
int libc_system_property_set(const char *key, const char *value) { initialize_properties(); return mb__system_property_set(key, value); }