I know how to access the Android system properties from the application layer.
开发者_运维问答In framework layerandroid.os.SystemProperties
class take the responsibility to
get all the properties. But internally it calls some C code for getting
the properties like native_get(key,value)
.
Anyone please tell me which file is basically referred in the C code?Native code for that methods located in the file android_os_SystemProperties.cpp
. It delegates them to the Bionic libc library /bionic/libc/bionic/system_properties.c
which reads property value from the shared memory.
Here is the quote from the "Android property system" article (I suggest you to read it all if you wish to understand how Android properties work):
init process will load properties from following files:
/default.prop /system/build.prop /system/default.prop /data/local.prop
The next step is start property service. In this step, a unix domain socket server is created. This socket's pathname is
"/dev/socket/property_service"
which is well known to other client processes.
Finally, init process calls poll to wait for connect event on the socket.On the consumer side, when it initializes libc (
bionic/libc/bionic/libc_common.c __libc_init_common function
). It will retrieve the fd and size from environment variable, and map the shared memory into its own space (bionic/libc/bionic/system_properties.c __system_properties_init function
). After that, libcutils can read property just as normal memory for the consumer.
These are not part of the SDK APIs.
精彩评论