• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *  * Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  *  * Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in
12  *    the documentation and/or other materials provided with the
13  *    distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #ifndef _INCLUDE_SYS__SYSTEM_PROPERTIES_H
30 #define _INCLUDE_SYS__SYSTEM_PROPERTIES_H
31 
32 #include <sys/cdefs.h>
33 #include <stdint.h>
34 
35 #ifndef _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
36 #error you should #include <sys/system_properties.h> instead
37 #endif
38 
39 #include <sys/system_properties.h>
40 
41 __BEGIN_DECLS
42 
43 #define PROP_SERVICE_NAME "property_service"
44 #define PROP_SERVICE_FOR_SYSTEM_NAME "property_service_for_system"
45 #define PROP_DIRNAME "/dev/__properties__"
46 
47 #define PROP_MSG_SETPROP 1
48 #define PROP_MSG_SETPROP2 0x00020001
49 
50 #define PROP_SUCCESS 0
51 #define PROP_ERROR_READ_CMD 0x0004
52 #define PROP_ERROR_READ_DATA 0x0008
53 #define PROP_ERROR_READ_ONLY_PROPERTY 0x000B
54 #define PROP_ERROR_INVALID_NAME 0x0010
55 #define PROP_ERROR_INVALID_VALUE 0x0014
56 #define PROP_ERROR_PERMISSION_DENIED 0x0018
57 #define PROP_ERROR_INVALID_CMD 0x001B
58 #define PROP_ERROR_HANDLE_CONTROL_MESSAGE 0x0020
59 #define PROP_ERROR_SET_FAILED 0x0024
60 
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 */
72 int __system_property_area_init(void);
73 
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 */
106 int __system_property_add(const char* _Nonnull __name, unsigned int __name_length, const char* _Nonnull __value, unsigned int __value_length);
107 
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.
128  *
129  * Returns 0 on success, -1 otherwise.
130  */
131 int __system_properties_init(void);
132 
133 /*
134  * 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.
136  *
137  * NOTE: Any pointers received from methods such as __system_property_find should be assumed to be
138  * invalid after this method is called.
139  *
140  * Returns 0 on success, -1 if the system properties failed to re-initialize (same conditions as
141  * __system properties_init)
142  */
143 int __system_properties_zygote_reload(void) __INTRODUCED_IN(__ANDROID_API_V__);
144 
145 /* Deprecated: use __system_property_wait instead. */
146 uint32_t __system_property_wait_any(uint32_t __old_serial);
147 
148 __END_DECLS
149 
150 #endif
151