当前位置: 首页 > news >正文

[Android] libcutils - native 获取/设置 property

前言:

Android 的property系统类似于linux的环境变量,但是更加精细。可以通过adb 设置和读取 property,同时也可以在代码 (JAVA/C++/C) 中设置和获取属性。这有助于我们在运行时控制代码执行逻辑。比如打开 测试开关 或者 dump源数据文件。

工程关联:

库文件:libcutils

头文件:#include <cutils/properties.h>

使用:

/* property_get: returns the length of the value which will never be
** greater than PROPERTY_VALUE_MAX - 1 and will always be zero terminated.
** (the length does not include the terminating zero).
**
** If the property read fails or returns an empty value, the default
** value is used (if nonnull).
*/
int property_get(const char* key, char* value, const char* default_value);/* property_get_bool: returns the value of key coerced into a
** boolean. If the property is not set, then the default value is returned.
**
* The following is considered to be true (1):
**   "1", "true", "y", "yes", "on"
**
** The following is considered to be false (0):
**   "0", "false", "n", "no", "off"
**
** The conversion is whitespace-sensitive (e.g. " off" will not be false).
**
** If no property with this key is set (or the key is NULL) or the boolean
** conversion fails, the default value is returned.
**/
int8_t property_get_bool(const char *key, int8_t default_value);/* property_get_int64: returns the value of key truncated and coerced into a
** int64_t. If the property is not set, then the default value is used.
**
** The numeric conversion is identical to strtoimax with the base inferred:
** - All digits up to the first non-digit characters are read
** - The longest consecutive prefix of digits is converted to a long
**
** Valid strings of digits are:
** - An optional sign character + or -
** - An optional prefix indicating the base (otherwise base 10 is assumed)
**   -- 0 prefix is octal
**   -- 0x / 0X prefix is hex
**
** Leading/trailing whitespace is ignored. Overflow/underflow will cause
** numeric conversion to fail.
**
** If no property with this key is set (or the key is NULL) or the numeric
** conversion fails, the default value is returned.
**/
int64_t property_get_int64(const char *key, int64_t default_value);/* property_get_int32: returns the value of key truncated and coerced into an
** int32_t. If the property is not set, then the default value is used.
**
** The numeric conversion is identical to strtoimax with the base inferred:
** - All digits up to the first non-digit characters are read
** - The longest consecutive prefix of digits is converted to a long
**
** Valid strings of digits are:
** - An optional sign character + or -
** - An optional prefix indicating the base (otherwise base 10 is assumed)
**   -- 0 prefix is octal
**   -- 0x / 0X prefix is hex
**
** Leading/trailing whitespace is ignored. Overflow/underflow will cause
** numeric conversion to fail.
**
** If no property with this key is set (or the key is NULL) or the numeric
** conversion fails, the default value is returned.
**/
int32_t property_get_int32(const char *key, int32_t default_value);/* property_set: returns 0 on success, < 0 on failure
*/
int property_set(const char *key, const char *value);int property_list(void (*propfn)(const char *key, const char *value, void *cookie), void *cookie);

http://www.lryc.cn/news/232924.html

相关文章:

  • Matlab 方位角计算之二
  • Postman工具简介
  • 2023.11.17 -hivesql调优,数据压缩,数据存储
  • 基于Vue+SpringBoot的大学计算机课程管理平台 开源项目
  • 2.c++基础语法
  • applicationContext.getBean 为null
  • 无线WiFi安全渗透与攻防(六)之WEP破解-Gerix-wifi-cracker自动化破解WEP加密
  • 华为OD机试 - 环中最长子串(Java JS Python C)
  • bug-跨域访问问题
  • Babyk勒索病毒数据集恢复,计算机服务器中了babyk勒索病毒怎么办?
  • (.htaccess文件特性)[MRCTF2020]你传你呢 1
  • 微软Ignite 2023大盘点:GPT-4 Turbo、DALL-E 3等
  • 应用架构的演进 I 使用无服务器保证数据一致性
  • jupyter修改默认打开目录
  • HTML5学习系列之标题和正文、描述性信息
  • 互联网医院系统:数字化时代中医疗服务的未来
  • (C语言)输入一个序列,判断是否为奇偶交叉数
  • 蓝桥杯模拟赛:最远滑行距离 ← dfs
  • 广东电信手机号余额查询接口
  • 这次轮到微软炸场了;5000+AI工具调研报告 (500万字);狂打一星开喷AI聊天机器人;CMU LLM课程;AI创业的方向与时机 | ShowMeAI日报
  • --max-old-space-size=8192报错
  • 单区域OSPF配置
  • VsCode 安装 GitHub Copilot插件 (最新)
  • 人工智能基础_机器学习039_sigmoid函数_逻辑回归_逻辑斯蒂回归_分类神器_代码实现逻辑回归图---人工智能工作笔记0079
  • 购买阿里云服务器需要多少钱?活动价3000元-5000元的阿里云服务器汇总
  • CentOS修改root用户密码
  • Android消息机制(Handler、Looper、MessageQueue)
  • Pikachu漏洞练习平台之XXE(XML外部实体注入)
  • ubuntu中/etc/rc.local和/etc/init.d/rc.local的区别是什么
  • vue项目中 commonJS转es6