设为首页 加入收藏

TOP

安卓ro.serialno产生的整个流程(一)
2023-07-23 13:30:17 】 浏览:137
Tags:安卓 ro.serialno

前言:

关于ro.serialno这个属性,相信大家都不陌生了,应用层的Build.getSerial()Build.SERIAL等均是直接或间接的获取了这个属性值。接下来从boot到系统应用,小小的分析一下它的整个流程:

由于是APP经常使用,那我们从应用层分析到底层kernel/boot

一,framework层

好的,我们进入安卓源码目录,grep查找一下:

xxxx@server01:~/workspace/rk3128_tablet$ grep -nrw "SERIAL" frameworks/base/
frameworks/base/docs/html/about/versions/android-4.2.jd:364:address or the {@link android.os.Build#SERIAL} number), they will provide the same value for each
frameworks/base/api/test-current.txt:28614:    field public static final java.lang.String SERIAL;
frameworks/base/api/system-current.txt:31035:    field public static final java.lang.String SERIAL;
frameworks/base/api/current.txt:28540:    field public static final java.lang.String SERIAL;
frameworks/base/core/java/android/os/Build.java:102:    public static final String SERIAL = getString("ro.serialno");
frameworks/base/tests/AccessoryDisplay/sink/src/com/android/accessorydisplay/sink/SinkActivity.java:61:    private static final String SERIAL = "0000000012345678";
frameworks/base/tests/AccessoryDisplay/sink/src/com/android/accessorydisplay/sink/SinkActivity.java:254:            sendString(conn, UsbAccessoryConstants.ACCESSORY_STRING_SERIAL, SERIAL);
xxxx@server01:~/workspace/rk3128_tablet$ 

成功的在Build.java找到了这个SERIAL属性,我们继续往下跟getString这个方法大概在871行。

.....
/**
     * Returns the version string for the radio firmware.  May return
     * null (if, for instance, the radio is not currently on).
     */
    public static String getRadioVersion() {
        return SystemProperties.get(TelephonyProperties.PROPERTY_BASEBAND_VERSION, null);
    }

	private static String getString(String property) {
        return SystemProperties.get(property, UNKNOWN);
    }

	private static String[] getStringList(String property, String separator) {
        String value = SystemProperties.get(property);
        if (value.isEmpty()) {
            return new String[0];
        } else {
            return value.split(separator);
        }
    }
.....

SystemProperties大家应该很熟了

可以看出,getString是传入的"ro.serialno"这个字串去获取的属性中的值,其效果在命令行上相当于getprop ro.serialno

好的,framework分析到这。

二,系统层

我们从第一个程序init开始,源码路径:

your_pro/system/core/init/init.cpp

根据关键字ro.serialno找到了地方,大概在464行:


static void export_kernel_boot_props() {
    char cmdline[1024];
    char* s1;
    char* s2;
    char* s3;
    char* s4;

    struct {
        const char *src_prop;
        const char *dst_prop;
        const char *default_value;
    } prop_map[] = {
        { "ro.boot.serialno",   "ro.serialno",   "", },//就是这了,根据ro.boot.serialno的值设置ro.serialno的值
        { "ro.boot.mode",       "ro.bootmode",   "unknown", },
        { "ro.boot.baseband",   "ro.baseband",   "unknown", },
        { "ro.boot.bootloader", "ro.bootloader", "unknown", },
        { "ro.boot.hardware",   "ro.hardware",   "unknown", },
        { "ro.boot.revision",   "ro.revision",   "0", },
    };

    //if storagemedia is emmc, so we will wait emmc init finish
    for (int i = 0; i < EMMC_RETRY_COUNT; i++) {
        proc_read( "/proc/cmdline", cmdline, sizeof(cmdline) );
        s1 = strstr(cmdline, STORAGE_MEDIA);
        s2 = strstr(cmdline, "androidboot.mode=emmc");
	s3 = strstr(cmdline, "storagemedia=nvme");
	s4 = strstr(cmdline, "androidboot.mode=nv
首页 上一页 1 2 3 4 5 6 7 下一页 尾页 1/7/7
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇仅需30行代码,轻松集成HMS Core.. 下一篇uniapp解决未配置appkey成功运行..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目