(1)系统启动时设置属性
//vendor/mediatek/proprietary/bootable/bootloader/lk/app/mt_boot/mt_boot.c
int boot_linux_fdt(void *kernel, unsigned *tags,
unsigned machtype,
void *ramdisk, unsigned ramdisk_sz)
{
void *fdt = tags;
int ret;
int offset;
char tmpbuf[TMPBUF_SIZE];
dt_dram_info mem_reg_property[128];
//...
//add start
snprintf(tmpbuf, TMPBUF_SIZE, "hct_cts_flag=%d", read_hct_cts_info());
cmdline_append(tmpbuf);
pal_log_info("dxf_ tmpbuf %sn",tmpbuf);
if(strstr(tmpbuf, "hct_cts_flag=1") != NULL) {
cmdline_append(tmpbuf);
}
//add end
//add start
snprintf(tmpbuf, TMPBUF_SIZE, "androidboot.cts.flag=%s","true");
cmdline_append(tmpbuf);
//add end
//...
}
(2)不同的语言读取属性
在系统启动时会在init.cpp文件中调用property_service.cpp的PropertyInit函数,进而调用ProcessKernelCmdline函数并将androidboot.替换成ro.boot.来进行使用。
//system/core/init/property_service.cpp
static void ProcessKernelCmdline() {
bool for_emulator = false;
importKernelCmdline([&](const std::string& key, const std::string& value) {
if (key == "qemu") {
for_emulator = true;
} else if (StartsWith(key, "androidboot.")) {
InitPropertySet("ro.boot." + key.substr(12), value);
}
});
if (for_emulator) {
importKernelCmdline([&](const std::string& key, const std::string& value) {
// In the emulator, export any kernel option with the "ro.kernel." prefix.
InitPropertySet("ro.kernel." + key, value);
});
}
}
可以参考如下使用:
(A)C++中使用
CUSTOM_CFG *pCustomCfg;
char value[PROPERTY_VALUE_MAX] = {' '};
//这里被替换成ro.boot.属性进行使用
int debugDumpSize = property_get("ro.boot.cts.flag",value, NULL);
ALOGE("dxf_%s: property_get: %d ,%s", __FUNCTION__, debugDumpSize, value);
if (debugDumpSize == 4) {
pCustomCfg = &gCustomCfgCts[IMGSENSOR_SENSOR_IDX_MIN_NUM];
} else {
pCustomCfg = &gCustomCfg[IMGSENSOR_SENSOR_IDX_MIN_NUM];
}
(B)Java中使用
import android.os.SystemProperties;
SystemProperties.getBoolean("ro.boot.cts.flag", false);



