The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 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 | |
Elliott Hughes | 28c2f7d | 2024-07-29 18:39:08 +0000 | [diff] [blame] | 29 | #pragma once |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 30 | |
Elliott Hughes | 203e13d | 2016-07-22 14:56:18 -0700 | [diff] [blame] | 31 | #include <sys/cdefs.h> |
Elliott Hughes | a0d374d | 2017-02-10 18:13:46 -0800 | [diff] [blame] | 32 | #include <stdint.h> |
Elliott Hughes | 203e13d | 2016-07-22 14:56:18 -0700 | [diff] [blame] | 33 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 34 | #ifndef _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ |
| 35 | #error you should #include <sys/system_properties.h> instead |
Elliott Hughes | f8562c5 | 2017-01-26 16:48:57 -0800 | [diff] [blame] | 36 | #endif |
| 37 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 38 | #include <sys/system_properties.h> |
| 39 | |
Colin Cross | 5cf32de | 2013-01-23 23:07:06 -0800 | [diff] [blame] | 40 | __BEGIN_DECLS |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 41 | |
Elliott Hughes | 28c2f7d | 2024-07-29 18:39:08 +0000 | [diff] [blame] | 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 | |
Elliott Hughes | f8562c5 | 2017-01-26 16:48:57 -0800 | [diff] [blame] | 94 | #define PROP_SERVICE_NAME "property_service" |
Paul Lawrence | 71ade01 | 2023-07-18 08:49:44 -0700 | [diff] [blame] | 95 | #define PROP_SERVICE_FOR_SYSTEM_NAME "property_service_for_system" |
Nate Myren | ae7f33d | 2023-08-28 16:46:39 -0700 | [diff] [blame] | 96 | #define PROP_DIRNAME "/dev/__properties__" |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 97 | |
Elliott Hughes | 28c2f7d | 2024-07-29 18:39:08 +0000 | [diff] [blame] | 98 | // Messages sent to init. |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 99 | #define PROP_MSG_SETPROP 1 |
Dimitry Ivanov | 16b2a4d | 2017-01-24 20:43:29 +0000 | [diff] [blame] | 100 | #define PROP_MSG_SETPROP2 0x00020001 |
| 101 | |
Elliott Hughes | 28c2f7d | 2024-07-29 18:39:08 +0000 | [diff] [blame] | 102 | // Status codes returned by init (but not passed from libc to the caller). |
Dimitry Ivanov | 16b2a4d | 2017-01-24 20:43:29 +0000 | [diff] [blame] | 103 | #define PROP_SUCCESS 0 |
| 104 | #define PROP_ERROR_READ_CMD 0x0004 |
| 105 | #define PROP_ERROR_READ_DATA 0x0008 |
| 106 | #define PROP_ERROR_READ_ONLY_PROPERTY 0x000B |
| 107 | #define PROP_ERROR_INVALID_NAME 0x0010 |
| 108 | #define PROP_ERROR_INVALID_VALUE 0x0014 |
| 109 | #define PROP_ERROR_PERMISSION_DENIED 0x0018 |
| 110 | #define PROP_ERROR_INVALID_CMD 0x001B |
| 111 | #define PROP_ERROR_HANDLE_CONTROL_MESSAGE 0x0020 |
| 112 | #define PROP_ERROR_SET_FAILED 0x0024 |
Andres Morales | 9d9ebc5 | 2015-01-13 18:00:56 -0800 | [diff] [blame] | 113 | |
Elliott Hughes | 28c2f7d | 2024-07-29 18:39:08 +0000 | [diff] [blame] | 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 | */ |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 122 | int __system_property_area_init(void); |
Colin Cross | 5cf32de | 2013-01-23 23:07:06 -0800 | [diff] [blame] | 123 | |
Elliott Hughes | 28c2f7d | 2024-07-29 18:39:08 +0000 | [diff] [blame] | 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 | */ |
zijunzhao | a505b2d | 2023-05-17 00:20:12 +0000 | [diff] [blame] | 132 | int __system_property_add(const char* _Nonnull __name, unsigned int __name_length, const char* _Nonnull __value, unsigned int __value_length); |
Colin Cross | 5cf32de | 2013-01-23 23:07:06 -0800 | [diff] [blame] | 133 | |
Elliott Hughes | 28c2f7d | 2024-07-29 18:39:08 +0000 | [diff] [blame] | 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. |
| 139 | * |
| 140 | * Returns 0 on success, -1 if the parameters are incorrect. |
| 141 | */ |
zijunzhao | a505b2d | 2023-05-17 00:20:12 +0000 | [diff] [blame] | 142 | int __system_property_update(prop_info* _Nonnull __pi, const char* _Nonnull __value, unsigned int __value_length); |
Colin Cross | 5cf32de | 2013-01-23 23:07:06 -0800 | [diff] [blame] | 143 | |
Elliott Hughes | 28c2f7d | 2024-07-29 18:39:08 +0000 | [diff] [blame] | 144 | /** |
| 145 | * Reloads the system properties from disk. |
| 146 | * Not intended for use by any apps except the Zygote. |
| 147 | * Should only be called from the main thread. |
| 148 | * |
| 149 | * Pointers received from functions such as __system_property_find() |
| 150 | * may be invalidated by calls to this function. |
Narayan Kamath | c9ae21a | 2014-02-19 17:59:05 +0000 | [diff] [blame] | 151 | * |
| 152 | * Returns 0 on success, -1 otherwise. |
Nate Myren | ae7f33d | 2023-08-28 16:46:39 -0700 | [diff] [blame] | 153 | * |
Elliott Hughes | 28c2f7d | 2024-07-29 18:39:08 +0000 | [diff] [blame] | 154 | * Available since API level 35. |
Nate Myren | ae7f33d | 2023-08-28 16:46:39 -0700 | [diff] [blame] | 155 | */ |
Elliott Hughes | 28c2f7d | 2024-07-29 18:39:08 +0000 | [diff] [blame] | 156 | int __system_properties_zygote_reload(void) __INTRODUCED_IN(35); |
Nate Myren | ae7f33d | 2023-08-28 16:46:39 -0700 | [diff] [blame] | 157 | |
Elliott Hughes | 28c2f7d | 2024-07-29 18:39:08 +0000 | [diff] [blame] | 158 | // |
| 159 | // Deprecated functions. |
| 160 | // |
| 161 | |
| 162 | /** Deprecated: use __system_property_wait instead. */ |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 163 | uint32_t __system_property_wait_any(uint32_t __old_serial); |
Elliott Hughes | 40c885a | 2017-02-16 17:13:04 -0800 | [diff] [blame] | 164 | |
Elliott Hughes | 28c2f7d | 2024-07-29 18:39:08 +0000 | [diff] [blame] | 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); |
Colin Cross | 5cf32de | 2013-01-23 23:07:06 -0800 | [diff] [blame] | 171 | |
Elliott Hughes | 28c2f7d | 2024-07-29 18:39:08 +0000 | [diff] [blame] | 172 | __END_DECLS |