2626 * SUCH DAMAGE.
2727 */
2828
29- #ifndef _INCLUDE_SYS__SYSTEM_PROPERTIES_H
30- #define _INCLUDE_SYS__SYSTEM_PROPERTIES_H
29+ #pragma once
3130
3231#include <sys/cdefs.h>
3332#include <stdint.h>
4039
4140__BEGIN_DECLS
4241
42+ /**
43+ * Reads the global serial number of the system properties _area_.
44+ *
45+ * Called to predict if a series of cached __system_property_find()
46+ * objects will have seen __system_property_serial() values change.
47+ * Also aids the converse, as changes in the global serial can
48+ * also be used to predict if a failed __system_property_find()
49+ * could in turn now find a new object; thus preventing the
50+ * cycles of effort to poll __system_property_find().
51+ *
52+ * Typically called at beginning of a cache cycle to signal if _any_ possible
53+ * changes have occurred since last. If there is, one may check each individual
54+ * __system_property_serial() to confirm dirty, or __system_property_find()
55+ * to check if the property now exists. If a call to __system_property_add()
56+ * or __system_property_update() has completed between two calls to
57+ * __system_property_area_serial() then the second call will return a larger
58+ * value than the first call. Beware of race conditions as changes to the
59+ * properties are not atomic, the main value of this call is to determine
60+ * whether the expensive __system_property_find() is worth retrying to see if
61+ * a property now exists.
62+ *
63+ * Returns the serial number on success, -1 on error.
64+ */
65+ uint32_t __system_property_area_serial (void );
66+
67+ /**
68+ * Reads the serial number of a specific system property previously returned by
69+ * __system_property_find(). This is a cheap way to check whether a system
70+ * property has changed or not.
71+ *
72+ * Returns the serial number on success, -1 on error.
73+ */
74+ uint32_t __system_property_serial (const prop_info * _Nonnull __pi );
75+
76+ //
77+ // libc implementation detail.
78+ //
79+
80+ /**
81+ * Initializes the system properties area in read-only mode.
82+ *
83+ * This is called automatically during libc initialization,
84+ * so user code should never need to call this.
85+ *
86+ * Returns 0 on success, -1 otherwise.
87+ */
88+ int __system_properties_init (void );
89+
90+ //
91+ // init implementation details.
92+ //
93+
4394#define PROP_SERVICE_NAME "property_service"
4495#define PROP_SERVICE_FOR_SYSTEM_NAME "property_service_for_system"
4596#define PROP_DIRNAME "/dev/__properties__"
4697
98+ // Messages sent to init.
4799#define PROP_MSG_SETPROP 1
48100#define PROP_MSG_SETPROP2 0x00020001
49101
102+ // Status codes returned by init (but not passed from libc to the caller).
50103#define PROP_SUCCESS 0
51104#define PROP_ERROR_READ_CMD 0x0004
52105#define PROP_ERROR_READ_DATA 0x0008
@@ -58,93 +111,62 @@ __BEGIN_DECLS
58111#define PROP_ERROR_HANDLE_CONTROL_MESSAGE 0x0020
59112#define PROP_ERROR_SET_FAILED 0x0024
60113
61- /*
62- ** This was previously for testing, but now that SystemProperties is its own testable class,
63- ** there is never a reason to call this function and its implementation simply returns -1.
64- */
65- int __system_property_set_filename (const char * __unused __filename );
66-
67- /*
68- ** Initialize the area to be used to store properties. Can
69- ** only be done by a single process that has write access to
70- ** the property area.
71- */
114+ /**
115+ * Initializes the area to be used to store properties.
116+ *
117+ * Can only be done by the process that has write access to the property area,
118+ * typically init.
119+ *
120+ * See __system_properties_init() for the equivalent for all other processes.
121+ */
72122int __system_property_area_init (void );
73123
74- /* Read the global serial number of the system properties
75- **
76- ** Called to predict if a series of cached __system_property_find
77- ** objects will have seen __system_property_serial values change.
78- ** But also aids the converse, as changes in the global serial can
79- ** also be used to predict if a failed __system_property_find
80- ** could in-turn now find a new object; thus preventing the
81- ** cycles of effort to poll __system_property_find.
82- **
83- ** Typically called at beginning of a cache cycle to signal if _any_ possible
84- ** changes have occurred since last. If there is, one may check each individual
85- ** __system_property_serial to confirm dirty, or __system_property_find
86- ** to check if the property now exists. If a call to __system_property_add
87- ** or __system_property_update has completed between two calls to
88- ** __system_property_area_serial then the second call will return a larger
89- ** value than the first call. Beware of race conditions as changes to the
90- ** properties are not atomic, the main value of this call is to determine
91- ** whether the expensive __system_property_find is worth retrying to see if
92- ** a property now exists.
93- **
94- ** Returns the serial number on success, -1 on error.
95- */
96- uint32_t __system_property_area_serial (void );
97-
98- /* Add a new system property. Can only be done by a single
99- ** process that has write access to the property area, and
100- ** that process must handle sequencing to ensure the property
101- ** does not already exist and that only one property is added
102- ** or updated at a time.
103- **
104- ** Returns 0 on success, -1 if the property area is full.
105- */
124+ /**
125+ * Adds a new system property.
126+ * Can only be done by the process that has write access to the property area --
127+ * typically init -- which must handle sequencing to ensure that only one property is
128+ * updated at a time.
129+ *
130+ * Returns 0 on success, -1 if the property area is full.
131+ */
106132int __system_property_add (const char * _Nonnull __name , unsigned int __name_length , const char * _Nonnull __value , unsigned int __value_length );
107133
108- /* Update the value of a system property returned by
109- ** __system_property_find. Can only be done by a single process
110- ** that has write access to the property area, and that process
111- ** must handle sequencing to ensure that only one property is
112- ** updated at a time.
113- **
114- ** Returns 0 on success, -1 if the parameters are incorrect.
115- */
116- int __system_property_update (prop_info * _Nonnull __pi , const char * _Nonnull __value , unsigned int __value_length );
117-
118- /* Read the serial number of a system property returned by
119- ** __system_property_find.
120- **
121- ** Returns the serial number on success, -1 on error.
122- */
123- uint32_t __system_property_serial (const prop_info * _Nonnull __pi );
124-
125- /* Initialize the system properties area in read only mode.
126- * Should be done by all processes that need to read system
127- * properties.
134+ /**
135+ * Updates the value of a system property returned by __system_property_find().
136+ * Can only be done by the process that has write access to the property area --
137+ * typically init -- which must handle sequencing to ensure that only one property is
138+ * updated at a time.
128139 *
129- * Returns 0 on success, -1 otherwise .
140+ * Returns 0 on success, -1 if the parameters are incorrect .
130141 */
131- int __system_properties_init ( void );
142+ int __system_property_update ( prop_info * _Nonnull __pi , const char * _Nonnull __value , unsigned int __value_length );
132143
133- /*
144+ /**
134145 * Reloads the system properties from disk.
135- * Not intended for use by any apps except the Zygote. Should only be called from the main thread.
146+ * Not intended for use by any apps except the Zygote.
147+ * Should only be called from the main thread.
136148 *
137- * NOTE: Any pointers received from methods such as __system_property_find should be assumed to be
138- * invalid after this method is called .
149+ * Pointers received from functions such as __system_property_find()
150+ * may be invalidated by calls to this function .
139151 *
140- * Returns 0 on success, -1 if the system properties failed to re-initialize (same conditions as
141- * __system properties_init)
152+ * Returns 0 on success, -1 otherwise.
153+ *
154+ * Available since API level 35.
142155 */
143- int __system_properties_zygote_reload (void ) __INTRODUCED_IN (__ANDROID_API_V__ );
156+ int __system_properties_zygote_reload (void ) __INTRODUCED_IN (35 );
157+
158+ //
159+ // Deprecated functions.
160+ //
144161
145- /* Deprecated: use __system_property_wait instead. */
162+ /** Deprecated: use __system_property_wait instead. */
146163uint32_t __system_property_wait_any (uint32_t __old_serial );
147164
148- __END_DECLS
165+ /**
166+ * Deprecated: previously for testing, but now that SystemProperties is its own
167+ * testable class, there is never a reason to call this function and its
168+ * implementation simply returns -1.
169+ */
170+ int __system_property_set_filename (const char * __unused __filename );
149171
150- #endif
172+ __END_DECLS
0 commit comments