Advanced AOSP Subsystems
2 min read

Property Service

Deep Dive: Property Service

The Android Property Service is a globally accessible, in-memory key-value store managed by the init process. It provides a lightweight mechanism for sharing state and configuration data across the entire system.

Android Properties: Key/Value System

Properties are simple strings mapping a key to a value. The system limits keys to 32 characters and values to 92 characters (traditionally), though modern Android versions have relaxed these limits slightly. Because properties are stored in a shared memory region, reading them is incredibly fast and does not require IPC (Inter-Process Communication).

Property Types

The prefix of a property key dictates its behavior and lifecycle:

  • ro.* (Read-Only): Once set, these properties cannot be changed during the current boot cycle. They are typically populated during early boot from files like /default.prop or /system/build.prop. Examples include ro.build.type or ro.hardware.
  • persist.*: Changes to these properties are written to non-volatile storage (specifically, the /data/property/ directory). They survive reboots.
  • sys.*: General system properties.
  • ctl.* (Control): A special prefix used to send commands to the init process. Setting ctl.start=myservice instructs init to start the service named myservice.

Property Namespaces and Access Control

To prevent unauthorized apps from reading sensitive data or altering system state, Android uses SELinux to enforce strict access control on properties.

Properties are grouped into namespaces (contexts). For example, network properties might be assigned the net_radio_prop context. SELinux policy dictates which processes (domains) can read or write to which property contexts.

Reading and Writing Properties

Developers and system administrators can interact with properties via the command line or code:

  • Command Line:

    # Read a property
    adb shell getprop ro.build.version.release
    
    # Write a property (requires root or specific SELinux permissions)
    adb shell setprop persist.sys.usb.config mtp,adb
    
  • Java/Kotlin API: The android.os.SystemProperties class is a hidden API used internally by the framework.

  • C/C++ API: The <cutils/properties.h> header provides property_get() and property_set().

Triggering Init Actions

Because init manages the property service, it natively monitors property changes. As discussed in the Triggers lesson, you can define actions in init.rc that fire exactly when a property reaches a specific state. This makes properties a powerful mechanism for async event signaling.