Crate rsproperties

Source
Expand description

§Android System Properties for Linux and Android both.

This crate provides a way to access system properties on Linux and Android.

§Features

  • Get system properties.
  • Set system properties.
  • Wait for system properties.
  • Serialize system properties.
  • Deserialize system properties.

§Usage

#[cfg(target_os = "android")]
{
    use rsproperties::{init, PropertyConfig};
    use std::path::PathBuf;

    // Initialize with defaults
    rsproperties::init(None);

    // Initialize with custom directories
    let config = PropertyConfig {
        properties_dir: Some(PathBuf::from("/custom/properties")),
        socket_dir: Some(PathBuf::from("/custom/socket")),
    };
    rsproperties::init(config);

    // Get a value of the property.
    let value = rsproperties::get_with_default("ro.build.version.sdk", "0");
    println!("ro.build.version.sdk: {}", value);

    // Set a value of the property.
    rsproperties::set("test.property", "test.value").unwrap();
}

Re-exports§

pub use errors::ContextWithLocation;
pub use errors::Error;
pub use errors::Result;

Modules§

errors

Structs§

PropertyConfig
Configuration for initializing the property system
PropertyConfigBuilder
Builder for PropertyConfig with validation
SystemProperties
System properties It can’t be created directly. Use system_properties() or system_properties_area() instead.

Constants§

PROPERTY_SERVICE_FOR_SYSTEM_SOCKET_NAME
PROPERTY_SERVICE_SOCKET_NAME
PROP_DIRNAME
PROP_VALUE_MAX

Functions§

get
Get a value of the property. If the property is not found, it returns an empty string. If an error occurs, it returns Err.
get_with_default
Get a value of the property. If the property is not found, it returns the default value. If an error occurs, it returns the default value.
get_with_result
init
Initialize system properties with flexible configuration options.
properties_dir
Get the system properties directory. Returns the configured directory if init() was called, otherwise returns the default PROP_DIRNAME (/dev/properties).
set
Set a value of the property. If an error occurs, it returns Err. It uses socket communication to set the property. Because it is designed for client applications,
socket_dir
Get the current socket directory. Returns the configured socket directory, environment variable, or default.
system_properties
Get the system properties. Before calling this function, init() must be called. It panics if init() is not called or the system properties cannot be opened.