int mb__system_property_get(const char* name, char* value) {
  const prop_info* pi = mb__system_property_find(name);

  if (pi != 0) {
    return mb__system_property_read(pi, nullptr, value);
  } else {
    value[0] = 0;
    return 0;
  }
}
static int property_set_impl(const char *name, const char *value)
{
    size_t namelen = strlen(name);
    size_t valuelen = strlen(value);

    if (!is_legal_property_name(name, namelen)) {
        return -1;
    }
    if (valuelen >= PROP_VALUE_MAX) {
        return -1;
    }

    prop_info *pi = (prop_info *) mb__system_property_find(name);

    if (pi != 0) {
        /* ro.* properties may NEVER be modified once set */
        if (!strncmp(name, "ro.", 3)) {
            return -1;
        }

        mb__system_property_update(pi, value, valuelen);
    } else {
        int rc = mb__system_property_add(name, namelen, value, valuelen);
        if (rc < 0) {
            return rc;
        }
    }
    /* If name starts with "net." treat as a DNS property. */
    if (strncmp("net.", name, strlen("net.")) == 0)  {
        if (strcmp("net.change", name) == 0) {
            return 0;
        }
        /*
         * The 'net.change' property is a special property used track when any
         * 'net.*' property name is updated. It is _ONLY_ updated here. Its value
         * contains the last updated 'net.*' property.
         */
        property_set("net.change", name);
    } else if (persistent_properties_loaded
            && strncmp("persist.", name, strlen("persist.")) == 0) {
        /*
         * Don't write properties to disk until after we have read all default properties
         * to prevent them from being overwritten by default values.
         */
        write_persistent_property(name, value);
    }
    return 0;
}
Esempio n. 3
0
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;
}
Esempio n. 4
0
const prop_info *libc_system_property_find(const char *name)
{
    initialize_properties();

    return mb__system_property_find(name);
}