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 | |
| 29 | #ifndef _INCLUDE_SYS_SYSTEM_PROPERTIES_H |
| 30 | #define _INCLUDE_SYS_SYSTEM_PROPERTIES_H |
| 31 | |
David 'Digit' Turner | 49f0a8f | 2010-02-09 14:05:43 -0800 | [diff] [blame] | 32 | #include <sys/cdefs.h> |
Dimitry Ivanov | 16b2a4d | 2017-01-24 20:43:29 +0000 | [diff] [blame] | 33 | #include <stddef.h> |
Elliott Hughes | a0d374d | 2017-02-10 18:13:46 -0800 | [diff] [blame^] | 34 | #include <stdint.h> |
David 'Digit' Turner | 49f0a8f | 2010-02-09 14:05:43 -0800 | [diff] [blame] | 35 | |
| 36 | __BEGIN_DECLS |
| 37 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 38 | typedef struct prop_info prop_info; |
| 39 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 40 | #define PROP_VALUE_MAX 92 |
| 41 | |
Elliott Hughes | a0d374d | 2017-02-10 18:13:46 -0800 | [diff] [blame^] | 42 | /* |
| 43 | * Sets system property `key` to `value`, creating the system property if it doesn't already exist. |
| 44 | */ |
Josh Gao | 46b4416 | 2016-05-27 11:14:16 -0700 | [diff] [blame] | 45 | int __system_property_set(const char* key, const char* value) __INTRODUCED_IN(12); |
Brad Fitzpatrick | 4399df8 | 2011-03-10 15:52:49 -0800 | [diff] [blame] | 46 | |
Elliott Hughes | a0d374d | 2017-02-10 18:13:46 -0800 | [diff] [blame^] | 47 | /* |
| 48 | * Returns a `prop_info` corresponding system property `name`, or nullptr if it doesn't exist. |
| 49 | * Use __system_property_read_callback to query the current value. |
| 50 | * |
| 51 | * Property lookup is expensive, so it can be useful to cache the result of this function. |
| 52 | */ |
| 53 | const prop_info* __system_property_find(const char* name); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 54 | |
Elliott Hughes | a0d374d | 2017-02-10 18:13:46 -0800 | [diff] [blame^] | 55 | /* |
| 56 | * Calls `callback` with a consistent trio of name, value, and serial number for property `pi`. |
| 57 | */ |
Dimitry Ivanov | 16b2a4d | 2017-01-24 20:43:29 +0000 | [diff] [blame] | 58 | void __system_property_read_callback(const prop_info *pi, |
Elliott Hughes | a0d374d | 2017-02-10 18:13:46 -0800 | [diff] [blame^] | 59 | void (*callback)(void* cookie, const char *name, const char *value, uint32_t serial), |
| 60 | void* cookie) __INTRODUCED_IN_FUTURE; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 61 | |
Elliott Hughes | a0d374d | 2017-02-10 18:13:46 -0800 | [diff] [blame^] | 62 | /* |
| 63 | * Passes a `prop_info` for each system property to the provided |
| 64 | * callback. Use __system_property_read_callback() to read the value. |
| 65 | * |
| 66 | * This method is for inspecting and debugging the property system, and not generally useful. |
| 67 | */ |
Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 68 | int __system_property_foreach(void (*propfn)(const prop_info* pi, void* cookie), void* cookie) |
Josh Gao | 46b4416 | 2016-05-27 11:14:16 -0700 | [diff] [blame] | 69 | __INTRODUCED_IN(19); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 70 | |
Elliott Hughes | a0d374d | 2017-02-10 18:13:46 -0800 | [diff] [blame^] | 71 | /* Deprecated. In Android O and above, there's no limit on property name length. */ |
| 72 | #define PROP_NAME_MAX 32 |
| 73 | /* Deprecated. Use __system_property_read_callback instead. */ |
| 74 | int __system_property_read(const prop_info *pi, char *name, char *value); |
| 75 | /* Deprecated. Use __system_property_read_callback instead. */ |
| 76 | int __system_property_get(const char *name, char *value); |
| 77 | /* Deprecated. Use __system_property_foreach instead. Aborts in Android O and above. */ |
| 78 | const prop_info *__system_property_find_nth(unsigned n) __REMOVED_IN(26); |
| 79 | |
David 'Digit' Turner | 49f0a8f | 2010-02-09 14:05:43 -0800 | [diff] [blame] | 80 | __END_DECLS |
| 81 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 82 | #endif |