Android Property System

Android System Property 解析 一 System Property       今天在折腾HDMI 显示,为Setting提供接口,遇到很多跟Android系统属性相关的问题.因此,顺便分析和总结一些.   android的代码中大量存在:SystemProperties.set()/SystemProperties.get();通过这两个接口可以对系统的属性进行读取/设置,  顾名思义系统属性,肯定 阅读详情

    Every property has a name and value. Both name and value are text strings. Property is heavily used in Android to record system setting or exchange information between processes. The property is globally visible in the whole system. Every process can get/set a property.

    On system initialization, Android will allocates a block of shared memory for storing the properties. This is done in “init” daemon whose source code is at: device/system/init . The “init” daemon will start a Property Service. The Property Service is running in the process of “init” daemon. Every client that wants to SET property needs to connect to the Property Service and send message to Property Service. Property Service will update/create the property in shared memory. Any client that wants to GET property can read the property from the shared memory directly. This promotes the read performance.

    The client application can invoke the API function exposed from libcutils to GET/SET a property. The source code of libcutils locates at: device/libs/cutils .

    The API function is:

    int property_get(const char *key, char *value, const char *default_value);
    int property_set(const char *key, const char *value);

    The libcutils is in turn calling the __system_property_xxx function in libc to get a property from the shared memory. The source code of libc is at: device/system/bionic .

    The Property Service is also in turn calling the __system_property_init function in libc to initiate the shared memory for properties. When starting the Property Service will

load the default properties from below files:

  /default.prop
  /system/build.prop
  /system/default.prop
  /data/local.prop


    The properties are loaded in the above order. Later loaded properties will override the previous values. After those properties are loaded, the last loaded is the persistent properties which is persisted in /data/property .

Special Properties

    If a property's name begins with "ro.", then this property is treated as a read-only property. Once set, the value of the property can't be changed.
    If a property's name begins with "persist.", then when setting this property, the value will be written to /data/property, too.
    If a property's name begins with "net.", when when setting this property, the "net.change" property will be set automatically to contain the name of the last updated property. (It's tricky. The netresolve module uses this property to track if there is any change on the net.* properties.)

    The property "ctrl.start" and "ctrl.stop" is used to start and stop a service. Every service must be defined in /init.rc. On system startup, the init daemon will parse the init.rc and start the Property Service. Once received a request to set the property of "ctrl.start", the Property Service will use the property value as the service name to find the service and then start the service. The service starting result is then put to the property "init.svc.<service name> ". The client application can poll the value of that property to determine the result.

Android toolbox

  The Android toolbox provides two applets: setprop and getprop to get and set properties. The usage is:

  getprop <property name>
  setprop <property name> <property value>

Java
    The java application can use the System.getProperty() and System.setProperty() function to Get and Set the property.

Action
    By default the set property will only cause "init" daemon to write to shared memory, it won't execute any script or binary. But you can add your actions to correspond to property change in init.rc. For example, in the default init.rc, you can find.

  # adbd on at boot in emulator
  on property:ro.kernel.qemu=1
      start adbd

  on property:persist.service.adb.enable=1
      start adbd

  on property:persist.service.adb.enable=0
      stop adbd

    So if you set persist.service.adb.enable to 1, the "init" daemon knows it has actions to do, then it will start adbd service.

=================================================================================

    每个属性都有一个名称和值,他们都是字符串格式。属性被大量使用在Android系统中,用来记录系统设置或进程之间的信息交换。属性是在整个系统中全局可见的。每个进程可以get/set属性。

    在系统初始化时,Android将分配一个共享内存区来存储的属性。这些是由“init”守护进程完成的,其源代码位于:device/system /init。“init”守护进程将启动一个属性服务。属性服务在

“init”守护进程中运行。每一个客户端想要设置属性时,必须连接属性服务,再向其发送信息。属性服务将会在共享内存区中修改和创建属性。任何客户端想获得属性信息,可以从共享内存直接读取

。这提高了读取性能。

    客户端应用程序可以调用libcutils中的API函数以GET/SET属性信息。libcutils的源代码位于:device/libs/cutils。API函数是:

    int property_get(const char *key, char *value, const char *default_value);
    int property_set(const char *key, const char *value);

    而libcutils又调用libc中的 __system_property_xxx 函数获得共享内存中的属性。libc的源代码位于:device/system/bionic。

    属性服务调用libc中的__system_property_init函数来初始化属性系统的共享内存。当启动属性服务时,将从以下文件中加载默认属性:

    /default.prop
    /system/build.prop
    /system/default.prop
    /data/local.prop

    属性将会以上述顺序加载。后加载的属性将覆盖原先的值。这些属性加载之后,最后加载的属性会被保持在/data/property中。

特别属性

    如果属性名称以 "ro." 开头,那么这个属性被视为只读属性。一旦设置,属性值不能改变。
    如果属性名称以 "persist." 开头,当设置这个属性时,其值也将写入/data/property。
    如果属性名称以 "net." 开头,当设置这个属性时,"net.change" 属性将会自动设置,以加入到最后修改的属性名。(这是很巧妙的。netresolve模块的使用这个属性来追踪在net.*属性上的任何变

化。)

    属性 "ctrl.start" 和 "ctrl.stop" 是用来启动和停止服务。每一项服务必须在/init.rc中定义。系统启动时,与init守护进程将解析init.rc和启动属性服务。一旦收到设置 "ctrl.start" 属性

的请求,属性服务将使用该属性值作为服务名找到该服务,启动该服务。这项服务的启动结果将会放入 "init.svc.<服务名>" 属性中 。客户端应用程序可以轮询那个属性值,以确定结果。

Android toolbox程序

    Android toolbox程序提供了两个工具:setprop和getprop获取和设置属性。其使用方法:
    getprop <属性名>
    setprop <属性名><属性值>

Java
    在Java应用程序可以使用System.getProperty()和System.setProperty()函数获取和设置属性。
    注意:如果调用以上两个函数的话需要import java.util.Properties;虽然这两个函数实质包含在java.lang.System里面。但是它并不需要被包含,只需要包含前者即可。

Action
    默认情况下,设置属性只会使 "init" 守护程序写入共享内存,它不会执行任何脚本或二进制程序。但是,您可以将您的想要的实现的操作与init.rc中某个属性的变化相关联。例如,在默认的

init.rc中有:

    # adbd on at boot in emulator
    on property:ro.kernel.qemu=1
       start adbd
    on property:persist.service.adb.enable=1
       start adbd
    on property:persist.service.adb.enable=0
       stop adbd

    这样,如果你设置persist.service.adb.enable为1,"init" 守护程序就知道需要采取行动:开启adbd服务。

    文章中提到的共享内存就是Android特有的共享方式:ashmen。Ashmem是一个匿名共享内存(Anonymous SHared MEMory)系统,该系统增加了接口,因此进程间可以共享具名内存块。举一个例子,系统可以利用Ashmem存储图标,当绘制用户界面的时候多个进程也可以访问。Ashmem优于传统Linux共享内存表现在当共享内存块不再被用的时候,它为Kernel提供一种回收这些共享内存块的手段。如果一个程序尝试访问Kernel释放的一个共享内存块,它将会收到一个错误提示,然后重新分配内存并重载数据。

Android system property运作流程源码分析 属性是在整个系统中全局可见的。如果属性是有“net.”字符串开头,当设置这种属性的时候,“net.change”这条属性也会被自动设置,其内容设为最后更新过的属性名,用来记录net.*属性上面的变化。由/bionic/libc/bionic/system_properties.c中的__system_properties_init()来初始化属性系统的共享内存。在/system/core/include/private/android_filesystem_config.h中有各种权限的定义。 阅读详情

相关推荐

Neurocomputing 投稿指南

Generation Information:选择论文所属领域。上传附件(利益声明,手稿,摘要)审稿人偏好:可以选择期待的审稿人。

qq_41174671的博客 2万+

android system property,AndroidPropertySystem|Android属性系统

网址:原作者写的非常好,翻译的也非常好1、当编写本地应用程序时,可以使用property_get和property_set这两个API来读取/设置属性。要使用它们,我们需要includecutils/properties.h,并链接libcutils库。即:#include 在Android.mk里添加LOCAL_STATIC_LIBRARIES:=libcutils2、"Android在Java...

weixin_31265041的博客 397

速腾R128雷达+海康全景相机ROS数据采集避坑实录:从‘雷达不转’到MATLAB标定的完整流程

本文详细记录了速腾R128激光雷达与海康威视全景相机在ROS环境下的数据采集与MATLAB标定全流程。从硬件配置的常见陷阱(如雷达旋转参数设置)、驱动编译的依赖管理,到多传感器同步的实战技巧和MATLAB标定方法,提供了完整的避坑指南和技术方案。特别针对RoboSense R128雷达和海康相机的特殊需求给出了具体解决方案。

weixin_28717807的博客 1219

Android system property赋值和sepolicy定义

android system property sepolicy selinux

Railshiqian的博客 485

FreeRTOS移植实战:从零开始在STM32上搭建多任务系统(含Proteus仿真配置)

本文详细介绍了如何在STM32平台上从零开始移植FreeRTOS,并搭建多任务系统,包含Proteus仿真配置。通过环境准备、源码移植、多任务设计到仿真调试的全流程实战,帮助开发者快速掌握FreeRTOS在STM32上的应用技巧,提升嵌入式开发效率。

weixin_33737134的博客 231

RK3576平台部署NanoTrack:边缘AI视觉跟踪实战指南

边缘AI部署是将深度学习模型在资源受限的嵌入式设备上高效运行的关键技术,其核心在于模型压缩、硬件适配与软件栈优化。通过INT8量化、算子融合与内存优化等原理,能显著降低模型计算量与内存占用,从而在嵌入式NPU上实现实时推理。这项技术的价值在于为安防监控、无人机视觉、工业检测等场景提供低功耗、高响应的智能感知能力。以瑞芯微RK3576平台部署轻量级视觉跟踪模型NanoTrack为例,其过程涉及模型结构分析、RKNN工具链转换、C++推理程序开发及多线程性能优化,完整展现了从算法到产品的工程化路径,为开发者提供

weixin_31887307的博客 426

android system property,Android Property System

Every property has a name and value. Both name and value are text strings. Property is heavily used in Android to record system setting or exchange information between processes. The property is globa...

weixin_36130547的博客 130

UniApp实战:5分钟搞定后台持续定位与轨迹实时更新(附完整代码)

本文详细介绍了在UniApp中实现后台持续定位与动态轨迹地图系统的完整方案。针对物流配送、运动健身等场景,文章深入讲解了权限申请、坐标系选择、定位防抖优化、地图轨迹线(polyline)实时绘制等核心步骤,并提供了可复用的完整代码,帮助开发者高效解决App切后台定位停止、轨迹漂移等常见难题。

weixin_29266679的博客 483

【Android】System Property

【写在前面】 网上资料梳理,侵删烦请联系。或有表达错误,欢迎指出纠正。 【参考引用】 https://www.cnblogs.com/bhlsheji/p/5069100.html 系统属性System Propertiesframework访问系统服务流程 android代码中大量存在:SystemProperties.set()与SystemProperties.get();通过这两个接口能够对系统的属性进行读取/设置,且对整个系统全局共享。 System Properties 是什么 andro.

尚拙的博客 642

DaVinci Developer中枚举类型变量的创建与实战应用

本文详细介绍了在DaVinci Developer中创建和使用枚举类型变量的方法与实战应用。通过智能温控系统的案例,阐述了枚举类型在嵌入式开发中的核心价值,包括提升代码可读性、类型安全性和维护便捷性。文章还提供了枚举类型在状态机实现和多模块协同中的高级应用技巧,以及调试与优化的实用建议。

ik678901234的博客 511

材料仿真软件:Quantum Espresso_(15).声子与振动模式计算

通过上述步骤和代码示例,您应该能够使用 Quantum Espresso 进行声子与振动模式的计算。声子计算是材料科学研究中的重要工具,可以帮助我们更好地理解和设计材料的性能。希望本节内容对您有所帮助。

kkchenjj的博客 1181

Android System Property

 Android System Property 一 System Property   代码中大量存在:SystemProperties.set()/SystemProperties.get();通过这两个接口可以对系统的属性进行读取/设置, 顾名思义系统属性,肯定对整个系统全局共享。通常程序的执行以进程为单位各自相互独立,如何实现全局共享呢? System Properties是

kc58236582的博客 1067

PCB铺铜技巧如何铺铜经验总结

铺铜是指在PCB电气层添加整块的铜皮;铺铜包括电源层铺铜,地层铺铜和信号走线层空闲区域铺铜;铺铜是PCB设计的一个重要的环节。

fydar的博客 1万+

Android Property System | Android属性系统

<br />网址:<br />http://blog.youkuaiyun.com/jackyu613/archive/2011/01/13/6136620.aspx<br /> <br />原作者写的非常好,翻译的也非常好<br /> <br /> <br />1、当编写本地应用程序时,可以使用property_get和property_set 这两个API来读取/设置属性。要使用它们,我们需要include cutils/properties.h,并链接libcutils库。<br />即:<br />#inc

Droger (卓哥) 9052

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

Android System Property分析(2):property_service

ssss

This is bright 830

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

Android系统属性System Property

Android System Property 一 System Property   代码中大量存在:SystemProperties.set()/SystemProperties.get();通过这两个接口可以对系统的属性进行读取/设置, 顾名思义系统属性,肯定对整个系统全局共享。通常程序的执行以进程为单位各自相互独立,如何实现全局共享呢? System Properties是怎么一回

cheng20150809的博客 822

Android系统属性服务:platform_system_core中property_service实现原理

Android系统属性服务是维持系统正常运行的核心组件,它负责管理系统级别的配置参数和运行时状态。在platform_system_core项目中,property_service模块通过高效的机制实现了属性的注册、获取和监听功能,为应用层与系统层之间提供了关键的通信桥梁。 ## 一、property_service的核心功能与架构 property_service模块主要实现三大功能:**属

gitblog_00578的博客 827

Android system property系统属性服务详解

1 libc中的实现 首先在init进程启动的时候 property_init()->__system_property_area_init()->map_prop_area_rw() 以读写的形式打开/dev/__properties__ 这个文件 const int fd = open(property_filename, ...

流水mpc 568

android system property,Android的系统属性SystemProperties

创建与修改android属性用Systemproperties.set(name, value)获取android属性用Systemproperties.get(name)注意:android属性的名称是有一定的格式要求的,如下:前缀必须用systemcoreinitproperty_service.c中定义的前缀,进行系统属性设置的程序也必须有system或root权限提升到system权限的方...

weixin_39924779的博客 695

Android Property System | Android属性系统(文章写的很好。)

Android Property System | Android属性系统 分类: Android frameworks2012-05-16 16:01 196人阅读 评论(0) 收藏 举报   从shell中得到属性值: getprop  属性系统是android的一个重要特性。它作为一个服务运行,管理系统配置和状态。所有这些配置和状态都是属性。每个

视频拼接器 7425

Android System Property分析(3):property接口实现

无论是命令行,java层最后都是调用c层的接口来实现,property_set, property_get,property_list。     ./system/core/libcutils/properties.c中有三种实现方式,在我们的平台中定义了HAVE_LIBC_SYSTEM_PROPERTIES,这里以HAVE_LIBC_SYSTEM_PROPERTIES为例。     ./bu

This is bright 1626

Android 系统属性分析及属性设置获取,System Property

原文:https://www.cnblogs.com/bastard/archive/2012/10/11/2720314.html Android System Property 一 System Property   代码中大量存在:SystemProperti...

huangweiqing80的博客 5441

Android Property System 属性系统详解

先来段英文的介绍吧: Everyproperty has a name and value. Both name and value are text strings.Property is heavily used in Android to record system setting orexchange information between processes. The pr

小明的专栏 1399

Android - failed to set system property

进程将解析init.rc和启动属性服务。一旦收到设置“ ctrl.start ”属性的请求,属性服务将使用该属性值作为服务。如果属性名称以“net.”开头,当设置这个属性时,“net.change”属性将会自动设置,以加入到最后修改的属性名。如果属性名称以“persist.”开头,当设置这个属性时,其值也将写入/data/property。如果属性名称以“ro.”开头,那么这个属性被视为只读属性。发现确实不好使,然后意识到这个 ro开头的貌似是只读属性的,去网上确认了下,确实如此。

感觉不怎么会的博客 1854
上一篇: android横竖屏总结
下一篇: Android 的属性系统
eustoma
博客等级 码龄18年 79粉丝 54原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值