Skip to content

Commit 9c63222

Browse files
committed
Add bindings for querying and setting Android System Properties
The Android System Property API might not be very useful for most apps even though it still provides a read-only view of all properties but no rights to set any. Since this is accessible via the NDK this crate should provide a clean and complete (including UB-free) wrapper implementation either way. This requires bumping `thiserror` to `1.0.29` which introduced proper impl bounds in https://togithub.com/dtolnay/thiserror/pull/148 such that no `Debug` bound needs to be written anywhere that `GetError<>` is used. As a second advantage, this error type can still be used with `FromStr` implementations whose `Err` type does not implement `Error`/`Debug`, those just cannot be `.unwrap()`ped.
1 parent ec624f2 commit 9c63222

11 files changed

+627
-3
lines changed

ndk-sys/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Unreleased
22

33
- Regenerate bindings with `bindgen 0.71.1`. (#487)
4+
- Include API bindings from `sys/system_properties.h`. (#495)
45

56
# 0.6.0 (2024-04-26)
67

ndk-sys/src/ffi_aarch64.rs

+62
Original file line numberDiff line numberDiff line change
@@ -1410,6 +1410,8 @@ pub const PROPERTY_VERSION: &[u8; 8] = b"version\0";
14101410
pub const PROPERTY_DESCRIPTION: &[u8; 12] = b"description\0";
14111411
pub const PROPERTY_ALGORITHMS: &[u8; 11] = b"algorithms\0";
14121412
pub const PROPERTY_DEVICE_UNIQUE_ID: &[u8; 15] = b"deviceUniqueId\0";
1413+
pub const PROP_VALUE_MAX: u32 = 92;
1414+
pub const PROP_NAME_MAX: u32 = 32;
14131415
extern "C" {
14141416
pub fn android_get_application_target_sdk_version() -> ::std::os::raw::c_int;
14151417
}
@@ -21844,4 +21846,64 @@ extern "C" {
2184421846
extern "C" {
2184521847
pub fn AMediaMuxer_getTrackFormat(muxer: *mut AMediaMuxer, idx: usize) -> *mut AMediaFormat;
2184621848
}
21849+
#[repr(C)]
21850+
#[derive(Debug, Copy, Clone)]
21851+
pub struct prop_info {
21852+
_unused: [u8; 0],
21853+
}
21854+
extern "C" {
21855+
pub fn __system_property_set(
21856+
__name: *const ::std::os::raw::c_char,
21857+
__value: *const ::std::os::raw::c_char,
21858+
) -> ::std::os::raw::c_int;
21859+
}
21860+
extern "C" {
21861+
pub fn __system_property_find(__name: *const ::std::os::raw::c_char) -> *const prop_info;
21862+
}
21863+
extern "C" {
21864+
pub fn __system_property_read_callback(
21865+
__pi: *const prop_info,
21866+
__callback: ::std::option::Option<
21867+
unsafe extern "C" fn(
21868+
__cookie: *mut ::std::os::raw::c_void,
21869+
__name: *const ::std::os::raw::c_char,
21870+
__value: *const ::std::os::raw::c_char,
21871+
__serial: u32,
21872+
),
21873+
>,
21874+
__cookie: *mut ::std::os::raw::c_void,
21875+
);
21876+
}
21877+
extern "C" {
21878+
pub fn __system_property_foreach(
21879+
__callback: ::std::option::Option<
21880+
unsafe extern "C" fn(__pi: *const prop_info, __cookie: *mut ::std::os::raw::c_void),
21881+
>,
21882+
__cookie: *mut ::std::os::raw::c_void,
21883+
) -> ::std::os::raw::c_int;
21884+
}
21885+
extern "C" {
21886+
pub fn __system_property_wait(
21887+
__pi: *const prop_info,
21888+
__old_serial: u32,
21889+
__new_serial_ptr: *mut u32,
21890+
__relative_timeout: *const timespec,
21891+
) -> bool;
21892+
}
21893+
extern "C" {
21894+
pub fn __system_property_read(
21895+
__pi: *const prop_info,
21896+
__name: *mut ::std::os::raw::c_char,
21897+
__value: *mut ::std::os::raw::c_char,
21898+
) -> ::std::os::raw::c_int;
21899+
}
21900+
extern "C" {
21901+
pub fn __system_property_get(
21902+
__name: *const ::std::os::raw::c_char,
21903+
__value: *mut ::std::os::raw::c_char,
21904+
) -> ::std::os::raw::c_int;
21905+
}
21906+
extern "C" {
21907+
pub fn __system_property_find_nth(__n: ::std::os::raw::c_uint) -> *const prop_info;
21908+
}
2184721909
pub type __uint128_t = u128;

ndk-sys/src/ffi_arm.rs

+62
Original file line numberDiff line numberDiff line change
@@ -1463,6 +1463,8 @@ pub const PROPERTY_VERSION: &[u8; 8] = b"version\0";
14631463
pub const PROPERTY_DESCRIPTION: &[u8; 12] = b"description\0";
14641464
pub const PROPERTY_ALGORITHMS: &[u8; 11] = b"algorithms\0";
14651465
pub const PROPERTY_DEVICE_UNIQUE_ID: &[u8; 15] = b"deviceUniqueId\0";
1466+
pub const PROP_VALUE_MAX: u32 = 92;
1467+
pub const PROP_NAME_MAX: u32 = 32;
14661468
extern "C" {
14671469
pub fn android_get_application_target_sdk_version() -> ::std::os::raw::c_int;
14681470
}
@@ -22294,3 +22296,63 @@ extern "C" {
2229422296
extern "C" {
2229522297
pub fn AMediaMuxer_getTrackFormat(muxer: *mut AMediaMuxer, idx: usize) -> *mut AMediaFormat;
2229622298
}
22299+
#[repr(C)]
22300+
#[derive(Debug, Copy, Clone)]
22301+
pub struct prop_info {
22302+
_unused: [u8; 0],
22303+
}
22304+
extern "C" {
22305+
pub fn __system_property_set(
22306+
__name: *const ::std::os::raw::c_char,
22307+
__value: *const ::std::os::raw::c_char,
22308+
) -> ::std::os::raw::c_int;
22309+
}
22310+
extern "C" {
22311+
pub fn __system_property_find(__name: *const ::std::os::raw::c_char) -> *const prop_info;
22312+
}
22313+
extern "C" {
22314+
pub fn __system_property_read_callback(
22315+
__pi: *const prop_info,
22316+
__callback: ::std::option::Option<
22317+
unsafe extern "C" fn(
22318+
__cookie: *mut ::std::os::raw::c_void,
22319+
__name: *const ::std::os::raw::c_char,
22320+
__value: *const ::std::os::raw::c_char,
22321+
__serial: u32,
22322+
),
22323+
>,
22324+
__cookie: *mut ::std::os::raw::c_void,
22325+
);
22326+
}
22327+
extern "C" {
22328+
pub fn __system_property_foreach(
22329+
__callback: ::std::option::Option<
22330+
unsafe extern "C" fn(__pi: *const prop_info, __cookie: *mut ::std::os::raw::c_void),
22331+
>,
22332+
__cookie: *mut ::std::os::raw::c_void,
22333+
) -> ::std::os::raw::c_int;
22334+
}
22335+
extern "C" {
22336+
pub fn __system_property_wait(
22337+
__pi: *const prop_info,
22338+
__old_serial: u32,
22339+
__new_serial_ptr: *mut u32,
22340+
__relative_timeout: *const timespec,
22341+
) -> bool;
22342+
}
22343+
extern "C" {
22344+
pub fn __system_property_read(
22345+
__pi: *const prop_info,
22346+
__name: *mut ::std::os::raw::c_char,
22347+
__value: *mut ::std::os::raw::c_char,
22348+
) -> ::std::os::raw::c_int;
22349+
}
22350+
extern "C" {
22351+
pub fn __system_property_get(
22352+
__name: *const ::std::os::raw::c_char,
22353+
__value: *mut ::std::os::raw::c_char,
22354+
) -> ::std::os::raw::c_int;
22355+
}
22356+
extern "C" {
22357+
pub fn __system_property_find_nth(__n: ::std::os::raw::c_uint) -> *const prop_info;
22358+
}

ndk-sys/src/ffi_i686.rs

+62
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,8 @@ pub const PROPERTY_VERSION: &[u8; 8] = b"version\0";
13271327
pub const PROPERTY_DESCRIPTION: &[u8; 12] = b"description\0";
13281328
pub const PROPERTY_ALGORITHMS: &[u8; 11] = b"algorithms\0";
13291329
pub const PROPERTY_DEVICE_UNIQUE_ID: &[u8; 15] = b"deviceUniqueId\0";
1330+
pub const PROP_VALUE_MAX: u32 = 92;
1331+
pub const PROP_NAME_MAX: u32 = 32;
13301332
extern "C" {
13311333
pub fn android_get_application_target_sdk_version() -> ::std::os::raw::c_int;
13321334
}
@@ -23011,4 +23013,64 @@ extern "C" {
2301123013
extern "C" {
2301223014
pub fn AMediaMuxer_getTrackFormat(muxer: *mut AMediaMuxer, idx: usize) -> *mut AMediaFormat;
2301323015
}
23016+
#[repr(C)]
23017+
#[derive(Debug, Copy, Clone)]
23018+
pub struct prop_info {
23019+
_unused: [u8; 0],
23020+
}
23021+
extern "C" {
23022+
pub fn __system_property_set(
23023+
__name: *const ::std::os::raw::c_char,
23024+
__value: *const ::std::os::raw::c_char,
23025+
) -> ::std::os::raw::c_int;
23026+
}
23027+
extern "C" {
23028+
pub fn __system_property_find(__name: *const ::std::os::raw::c_char) -> *const prop_info;
23029+
}
23030+
extern "C" {
23031+
pub fn __system_property_read_callback(
23032+
__pi: *const prop_info,
23033+
__callback: ::std::option::Option<
23034+
unsafe extern "C" fn(
23035+
__cookie: *mut ::std::os::raw::c_void,
23036+
__name: *const ::std::os::raw::c_char,
23037+
__value: *const ::std::os::raw::c_char,
23038+
__serial: u32,
23039+
),
23040+
>,
23041+
__cookie: *mut ::std::os::raw::c_void,
23042+
);
23043+
}
23044+
extern "C" {
23045+
pub fn __system_property_foreach(
23046+
__callback: ::std::option::Option<
23047+
unsafe extern "C" fn(__pi: *const prop_info, __cookie: *mut ::std::os::raw::c_void),
23048+
>,
23049+
__cookie: *mut ::std::os::raw::c_void,
23050+
) -> ::std::os::raw::c_int;
23051+
}
23052+
extern "C" {
23053+
pub fn __system_property_wait(
23054+
__pi: *const prop_info,
23055+
__old_serial: u32,
23056+
__new_serial_ptr: *mut u32,
23057+
__relative_timeout: *const timespec,
23058+
) -> bool;
23059+
}
23060+
extern "C" {
23061+
pub fn __system_property_read(
23062+
__pi: *const prop_info,
23063+
__name: *mut ::std::os::raw::c_char,
23064+
__value: *mut ::std::os::raw::c_char,
23065+
) -> ::std::os::raw::c_int;
23066+
}
23067+
extern "C" {
23068+
pub fn __system_property_get(
23069+
__name: *const ::std::os::raw::c_char,
23070+
__value: *mut ::std::os::raw::c_char,
23071+
) -> ::std::os::raw::c_int;
23072+
}
23073+
extern "C" {
23074+
pub fn __system_property_find_nth(__n: ::std::os::raw::c_uint) -> *const prop_info;
23075+
}
2301423076
pub type __builtin_va_list = *mut ::std::os::raw::c_char;

ndk-sys/src/ffi_x86_64.rs

+62
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,8 @@ pub const PROPERTY_VERSION: &[u8; 8] = b"version\0";
13721372
pub const PROPERTY_DESCRIPTION: &[u8; 12] = b"description\0";
13731373
pub const PROPERTY_ALGORITHMS: &[u8; 11] = b"algorithms\0";
13741374
pub const PROPERTY_DEVICE_UNIQUE_ID: &[u8; 15] = b"deviceUniqueId\0";
1375+
pub const PROP_VALUE_MAX: u32 = 92;
1376+
pub const PROP_NAME_MAX: u32 = 32;
13751377
extern "C" {
13761378
pub fn android_get_application_target_sdk_version() -> ::std::os::raw::c_int;
13771379
}
@@ -23049,6 +23051,66 @@ extern "C" {
2304923051
extern "C" {
2305023052
pub fn AMediaMuxer_getTrackFormat(muxer: *mut AMediaMuxer, idx: usize) -> *mut AMediaFormat;
2305123053
}
23054+
#[repr(C)]
23055+
#[derive(Debug, Copy, Clone)]
23056+
pub struct prop_info {
23057+
_unused: [u8; 0],
23058+
}
23059+
extern "C" {
23060+
pub fn __system_property_set(
23061+
__name: *const ::std::os::raw::c_char,
23062+
__value: *const ::std::os::raw::c_char,
23063+
) -> ::std::os::raw::c_int;
23064+
}
23065+
extern "C" {
23066+
pub fn __system_property_find(__name: *const ::std::os::raw::c_char) -> *const prop_info;
23067+
}
23068+
extern "C" {
23069+
pub fn __system_property_read_callback(
23070+
__pi: *const prop_info,
23071+
__callback: ::std::option::Option<
23072+
unsafe extern "C" fn(
23073+
__cookie: *mut ::std::os::raw::c_void,
23074+
__name: *const ::std::os::raw::c_char,
23075+
__value: *const ::std::os::raw::c_char,
23076+
__serial: u32,
23077+
),
23078+
>,
23079+
__cookie: *mut ::std::os::raw::c_void,
23080+
);
23081+
}
23082+
extern "C" {
23083+
pub fn __system_property_foreach(
23084+
__callback: ::std::option::Option<
23085+
unsafe extern "C" fn(__pi: *const prop_info, __cookie: *mut ::std::os::raw::c_void),
23086+
>,
23087+
__cookie: *mut ::std::os::raw::c_void,
23088+
) -> ::std::os::raw::c_int;
23089+
}
23090+
extern "C" {
23091+
pub fn __system_property_wait(
23092+
__pi: *const prop_info,
23093+
__old_serial: u32,
23094+
__new_serial_ptr: *mut u32,
23095+
__relative_timeout: *const timespec,
23096+
) -> bool;
23097+
}
23098+
extern "C" {
23099+
pub fn __system_property_read(
23100+
__pi: *const prop_info,
23101+
__name: *mut ::std::os::raw::c_char,
23102+
__value: *mut ::std::os::raw::c_char,
23103+
) -> ::std::os::raw::c_int;
23104+
}
23105+
extern "C" {
23106+
pub fn __system_property_get(
23107+
__name: *const ::std::os::raw::c_char,
23108+
__value: *mut ::std::os::raw::c_char,
23109+
) -> ::std::os::raw::c_int;
23110+
}
23111+
extern "C" {
23112+
pub fn __system_property_find_nth(__n: ::std::os::raw::c_uint) -> *const prop_info;
23113+
}
2305223114
pub type __builtin_va_list = [__va_list_tag; 1usize];
2305323115
#[repr(C)]
2305423116
#[derive(Debug, Copy, Clone)]

ndk-sys/wrapper.h

+2
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,5 @@
8989
#include <media/NdkMediaExtractor.h>
9090
#include <media/NdkMediaFormat.h>
9191
#include <media/NdkMediaMuxer.h>
92+
93+
#include <sys/system_properties.h>

ndk/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Unreleased
22

33
- image_reader: Add `ImageReader::new_with_data_space()` constructor and `ImageReader::data_space()` getter from API level 34. (#474)
4+
- Add bindings for querying and setting Android System Properties. (#495)
45

56
# 0.9.0 (2024-04-26)
67

ndk/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ num_enum = "0.7"
4646
rwh_04 = { package = "raw-window-handle", version = "0.4", optional = true }
4747
rwh_05 = { package = "raw-window-handle", version = "0.5", optional = true }
4848
rwh_06 = { package = "raw-window-handle", version = "0.6", optional = true }
49-
thiserror = "1.0.23"
49+
thiserror = "1.0.29" # At least .29 for Debug impl bounds
5050

5151
[dependencies.jni]
5252
version = "0.21"

ndk/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ pub mod native_window;
2929
pub mod shared_memory;
3030
pub mod surface_texture;
3131
pub mod sync;
32+
pub mod system_properties;
3233
pub mod trace;
3334
mod utils;

0 commit comments

Comments
 (0)