syspara系统属性组件
系统参数简介
syspara系统为各系统服务提供简单易用的键值对访问接口,使得各个系统服务可以通过各自的系统参数来进行业务功能的配置。系统参数的访问和操作有以下几个基本原语
表 1 系统参数操作原语说明
系统参数名称采用点分格式由多段组成,每一段由字母、数字、下划线组成,总长度不超过96字节;系统参数名称分为两类:
表 2 系统参数名称
系统参数一共分为三大类:
表 3 系统参数分类
每个系统参数名称总体格式如下:[const|persist].$sub_system.$desc。
$sub_system为子系统或模块的名称。
$desc为子系统或模块下参数的描述字符,可以为点分格式进行分级描述。
系统参数定义规则
每个子系统定义各自模块的系统参数,包括系统参数名称、默认值以及系统参数的权限访问信息。
系统参数值定义文件
系统参数值定义文件后缀名为**".para"**,其格式示例如下:
# This is comment
const.product.name=OHOS-PRODUCT
const.os.version.api=26
const.telephony.enable=false|true
const.test.withblank=My Value
注意:系统参数值不支持注释及换行。
# 不支持
const.test.withcomment=MyValue # This should be ommitted
# 不支持
const.test.multiline="This is a multiline parameter.
Line2 value.
Last line."
系统参数必须通过完整的系统参数命令来赋值,赋值方式分为三大类:
表 4 系统参数赋值方式
系统参数DAC访问控制定义文件
当前系统参数的访问权限控制通过自主访问控制(Discretionary Access Control)方式管理,访问权限定义文件后缀名为**".para.dac"**,示例如下:
const.product.="root:root:660"
如上所示,可以通过参数路径为相同前缀的所有系统参数定义一类访问权限信息;DAC信息通过":"分三段来描述,分别为参数的user,group以及UGO规则信息。
UGO规则信息每一位的定义如下:
系统参数定义文件安装方法
.para和.para.dac文件都安装到/etc/param/目录下,GN脚本示例如下:
ohos_prebuilt_etc("ohos.para") {
source = "//base/startup/init_lite/services/etc/ohos.para"
part_name = "init"
module_install_dir = "etc/param"
}
ohos_prebuilt_etc("ohos.para.dac") {
source = "//base/startup/init_lite/services/etc/ohos.para.dac"
part_name = "init"
module_install_dir = "etc/param"
}
系统参数值定义文件的加载顺序
系统参数值的加载顺序如下:
表 5 系统参数加载顺序
shell命令使用说明
通过shell命令中可直接操作系统参数:
表 6 系统参数shell命令说明
同步等待指定key名称的系统参数值与value匹配。value可支持模糊匹配,如"*"表示任何值,"val*"表示只匹配前三个val字符。 |
|
syspara系统接口说明
表 7 系统属性接口说明
int GetParameter(const char* key, const char* def, char* value, unsigned int len) |
|
开发实例
系统属性使用实例
// set && get
char key1[] = "rw.sys.version";
char value1[] = "10.1.0";
int ret = SetParameter(key1, value1);
char valueGet1[128] = {0};
ret = GetParameter(key1, "version=10.1.0", valueGet1, 128);
// get sysparm
char* value1 = GetDeviceType();
printf("Product type =%s\n", value1);
free(value1);
char* value2 = GetManufacture();
printf("Manufacture =%s\n", value2);
free(value2);
char* value3 = GetBrand();
printf("GetBrand =%s\n", value3);
free(value3);
char* value4 = GetMarketName();
printf("MarketName =%s\n", value4);
free(value4);
char* value5 = GetProductSeries();
printf("ProductSeries =%s\n", value5);
free(value5);
char* value6 = GetProductModel();
printf("ProductModel =%s\n", value6);
free(value6);
char* value7 = GetSoftwareModel();
printf("SoftwareModel =%s\n", value7);
free(value7);
char* value8 = GetHardwareModel();
printf("HardwareModel =%s\n", value8);
free(value8);
char* value9 = GetHardwareProfile();
printf("Software profile =%s\n", value9);
free(value9);
char* value10 = GetSerial();
printf("Serial =%s\n", value10);
free(value10);
char* value11 = GetOSFullName();
printf("OS name =%s\n", value11);
free(value11);
char* value12 = GetDisplayVersion();
printf("Display version =%s\n", value12);
free(value12);
char* value13 = GetBootloaderVersion();
printf("bootloader version =%s\n", value13);
free(value13);
char* value14 = GetSecurityPatchTag();
printf("secure patch level =%s\n", value14);
free(value14);
char* value15 = GetAbiList();
printf("abi list =%s\n", value15);
free(value15);
int value16 = GetFirstApiVersion();
printf("first api level =%d\n", value16);
free(value16);
char* value17 = GetIncrementalVersion();
printf("Incremental version = %s\n", value17);
free(value17);
char* value18 = GetVersionId();
printf("formal id =%s\n", value18);
free(value18);
char* value19 = GetBuildType();
printf("build type =%s\n", value19);
free(value19);
char* value20 = GetBuildUser();
printf("build user =%s\n", value20);
free(value20);
char* value21 = GetBuildHost();
printf("Build host = %s\n", value21);
free(value21);
char* value22 = GetBuildTime();
printf("build time =%s\n", value22);
free(value22);
char* value23 = GetBuildRootHash();
printf("build root later..., %s\n", value23);
free(value23);
char* value24 = GetOsReleaseType();
printf("OS release type =%s\n", value24);
free(value24);
char* value25 = GetOsReleaseType();
printf("OS release type =%s\n", value25);
free(value25);
char value26[65] = {0};
GetDevUdid(value26, 65);
printf("device udid =%s\n", value26);
free(value26);