[Android]关于Android 唯一设备号(ro.serialno)

1.ro.serialno不存在于任何属性文件,比如build.prop, default.prop等,而是在/system/core/init/init.c里由ro.boot.serialno 转换而来,见export_kernel_boot_props()。

2.而ro.boot.serialno的来源是/proc/cmdline,也就是linux kernel启动时被传入的cmdline, 由bootloader传入。
bootloader传进来的是androidboot.serialno, 而不是ro.boot.serialno,因为还要解析过cmdline
3.ro.serialno的用处是来保存唯一设备号,在settings->about->status里会显示,也会用在USB device name里。
about->status 里获取serialno的流程:
Build.SERIAL
->getString(“ro.serialno”)
->SystemProperties.get()
->SystemProperties.native_get()
->SystemProperties_getSS() in android_os_SystemProperties.cpp
->property_get() in Properties.c
->__system_property_get() in System_properties.c in bionic

获取到的前提是之前已经有设置好,也就是有调用property_set() in init.c

4.其他类似ro属性还有:
ro.boot.mode
ro.boot.baseband
ro.boot.bootloader
ro.boot.hardware

static void export_kernel_boot_props(void)
{

char tmp[PROP_VALUE_MAX];
int ret;
unsigned i;
struct {
    const char *src_prop;
    const char *dest_prop;
    const char *def_val;
} prop_map[] = {
    { "ro.boot.serialno", "ro.serialno", "", },
    { "ro.boot.mode", "ro.bootmode", "unknown", },
    { "ro.boot.baseband", "ro.baseband", "unknown", },
    { "ro.boot.bootloader", "ro.bootloader", "unknown", },
};

for (i = 0; i < ARRAY_SIZE(prop_map); i++) {
    ret = property_get(prop_map[i].src_prop, tmp);
    if (ret > 0)
        property_set(prop_map[i].dest_prop, tmp);
    else
        property_set(prop_map[i].dest_prop, prop_map[i].def_val);
}

ret = property_get("ro.boot.console", tmp);
if (ret)
    strlcpy(console, tmp, sizeof(console));

/* save a copy for init's usage during boot */
property_get("ro.bootmode", tmp);
strlcpy(bootmode, tmp, sizeof(bootmode));

/* if this was given on kernel command line, override what we read
 * before (e.g. from /proc/cpuinfo), if anything */
ret = property_get("ro.boot.hardware", tmp);
if (ret)
    strlcpy(hardware, tmp, sizeof(hardware));
property_set("ro.hardware", hardware);

snprintf(tmp, PROP_VALUE_MAX, "%d", revision);
property_set("ro.revision", tmp);

摘自Android Kitkat 4.4

你可能感兴趣的:([Android]关于Android 唯一设备号(ro.serialno))