blob: ae94db56c221376d08fbba65a821a1d448bb9c93 [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/*
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 Hughes3772ae42024-05-16 18:45:03 +000029#pragma once
30
31/**
32 * @file system_properties.h
33 * @brief System properties.
34 */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080035
David 'Digit' Turner49f0a8f2010-02-09 14:05:43 -080036#include <sys/cdefs.h>
Dimitry Ivanov41a3a6f2017-02-16 15:34:21 -080037#include <stdbool.h>
Dimitry Ivanov16b2a4d2017-01-24 20:43:29 +000038#include <stddef.h>
Elliott Hughesa0d374d2017-02-10 18:13:46 -080039#include <stdint.h>
David 'Digit' Turner49f0a8f2010-02-09 14:05:43 -080040
41__BEGIN_DECLS
42
Elliott Hughes3772ae42024-05-16 18:45:03 +000043/** An opaque structure representing a system property. */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080044typedef struct prop_info prop_info;
45
Elliott Hughes3772ae42024-05-16 18:45:03 +000046/**
47 * The limit on the length of a property value.
48 * (See PROP_NAME_MAX for property names.)
49 */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080050#define PROP_VALUE_MAX 92
51
Elliott Hughes3772ae42024-05-16 18:45:03 +000052/**
Elliott Hughesff26a162017-08-17 22:34:21 +000053 * Sets system property `name` to `value`, creating the system property if it doesn't already exist.
Elliott Hughes3772ae42024-05-16 18:45:03 +000054 *
55 * Returns 0 on success, or -1 on failure.
Elliott Hughesa0d374d2017-02-10 18:13:46 -080056 */
zijunzhaoa505b2d2023-05-17 00:20:12 +000057int __system_property_set(const char* _Nonnull __name, const char* _Nonnull __value);
Brad Fitzpatrick4399df82011-03-10 15:52:49 -080058
Elliott Hughes3772ae42024-05-16 18:45:03 +000059/**
Elliott Hughesa0d374d2017-02-10 18:13:46 -080060 * Returns a `prop_info` corresponding system property `name`, or nullptr if it doesn't exist.
Elliott Hughes3772ae42024-05-16 18:45:03 +000061 * Use __system_property_read_callback() to query the current value.
Elliott Hughesa0d374d2017-02-10 18:13:46 -080062 *
Elliott Hughes3772ae42024-05-16 18:45:03 +000063 * Property lookup is expensive, so it can be useful to cache the result of this
64 * function rather than using __system_property_get().
Elliott Hughesa0d374d2017-02-10 18:13:46 -080065 */
zijunzhaoa505b2d2023-05-17 00:20:12 +000066const prop_info* _Nullable __system_property_find(const char* _Nonnull __name);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080067
Elliott Hughes3772ae42024-05-16 18:45:03 +000068/**
69 * Calls `callback` with a consistent trio of name, value, and serial number
70 * for property `pi`.
71 *
72 * Available since API level 26.
Elliott Hughesa0d374d2017-02-10 18:13:46 -080073 */
zijunzhaoa505b2d2023-05-17 00:20:12 +000074void __system_property_read_callback(const prop_info* _Nonnull __pi,
75 void (* _Nonnull __callback)(void* _Nullable __cookie, const char* _Nonnull __name, const char* _Nonnull __value, uint32_t __serial),
76 void* _Nullable __cookie) __INTRODUCED_IN(26);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080077
Elliott Hughes3772ae42024-05-16 18:45:03 +000078/**
Elliott Hughesa0d374d2017-02-10 18:13:46 -080079 * Passes a `prop_info` for each system property to the provided
Elliott Hughes3772ae42024-05-16 18:45:03 +000080 * callback. Use __system_property_read_callback() to read the value of
81 * any of the properties.
Elliott Hughesa0d374d2017-02-10 18:13:46 -080082 *
83 * This method is for inspecting and debugging the property system, and not generally useful.
Elliott Hughes3772ae42024-05-16 18:45:03 +000084 *
85 * Returns 0 on success, or -1 on failure.
Elliott Hughesa0d374d2017-02-10 18:13:46 -080086 */
Elliott Hughes655e4302023-06-16 12:39:33 -070087int __system_property_foreach(void (* _Nonnull __callback)(const prop_info* _Nonnull __pi, void* _Nullable __cookie), void* _Nullable __cookie);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080088
Elliott Hughes3772ae42024-05-16 18:45:03 +000089/**
Dimitry Ivanov41a3a6f2017-02-16 15:34:21 -080090 * Waits for the specific system property identified by `pi` to be updated
91 * past `old_serial`. Waits no longer than `relative_timeout`, or forever
zijunzhaoa505b2d2023-05-17 00:20:12 +000092 * if `relative_timeout` is null.
Dimitry Ivanov41a3a6f2017-02-16 15:34:21 -080093 *
94 * If `pi` is null, waits for the global serial number instead.
95 *
96 * If you don't know the current serial, use 0.
97 *
98 * Returns true and updates `*new_serial_ptr` on success, or false if the call
99 * timed out.
Elliott Hughes3772ae42024-05-16 18:45:03 +0000100 *
101 * Available since API level 26.
Dimitry Ivanov41a3a6f2017-02-16 15:34:21 -0800102 */
103struct timespec;
zijunzhaoa505b2d2023-05-17 00:20:12 +0000104bool __system_property_wait(const prop_info* _Nullable __pi, uint32_t __old_serial, uint32_t* _Nonnull __new_serial_ptr, const struct timespec* _Nullable __relative_timeout)
Josh Gao2e8e5e62017-04-20 12:58:31 -0700105 __INTRODUCED_IN(26);
Dimitry Ivanov41a3a6f2017-02-16 15:34:21 -0800106
Elliott Hughes3772ae42024-05-16 18:45:03 +0000107/**
108 * Deprecated: there's no limit on the length of a property name since
109 * API level 26, though the limit on property values (PROP_VALUE_MAX) remains.
110 */
Elliott Hughesa0d374d2017-02-10 18:13:46 -0800111#define PROP_NAME_MAX 32
Elliott Hughes3772ae42024-05-16 18:45:03 +0000112
113/** Deprecated. Use __system_property_read_callback() instead. */
zijunzhaoa505b2d2023-05-17 00:20:12 +0000114int __system_property_read(const prop_info* _Nonnull __pi, char* _Nullable __name, char* _Nonnull __value);
Elliott Hughes3772ae42024-05-16 18:45:03 +0000115/** Deprecated. Use __system_property_read_callback() instead. */
zijunzhaoa505b2d2023-05-17 00:20:12 +0000116int __system_property_get(const char* _Nonnull __name, char* _Nonnull __value);
Elliott Hughes3772ae42024-05-16 18:45:03 +0000117/** Deprecated. Use __system_property_foreach() instead. */
zijunzhaoa505b2d2023-05-17 00:20:12 +0000118const prop_info* _Nullable __system_property_find_nth(unsigned __n);
Elliott Hughesa0d374d2017-02-10 18:13:46 -0800119
David 'Digit' Turner49f0a8f2010-02-09 14:05:43 -0800120__END_DECLS