Write an attribute as a parameter in Android init

Source: Internet
Author: User
Tags prototype definition

Tian haili @ csdn

 

History: The adb id of many Android systems is fixed. the ID of each device is the same once the driver is written. Some requirements require that the ID of ADB be different for each device.

The adb id is the ID of the device viewed by the command ADB devices.

This has been implemented in android4.0, andKey Points of implementationAs follows:

1. the kernel's adb usb driver exposes the interface/sys/class/android_usb/android0/iserial, which can be used to write specific ID values;

2. The Sn in the mobile phone is the identification number of the device, and there is a property value (Ro. serialno) to record, can be used as a flag to distinguish adbid;

The Sn is also passed through the kernel in the system-started init.

3. In the system startup phase (propertyservice has been started and available, the boot phase should be a good choice, so it can be written in the on bootsection of init. Rc:

Write/sys/class/android_usb/android0/iserial $ {Ro. serialno}

4. Write is a command that init. RC parses, but does not support attributes as parameters.

 

This article describes how to use attributes as the write parameter in earlier versions.

 

1. Add the prototype definition of expand_props () to/system/CORE/init/int_parser.h.

Int expand_props (char * DST, const char * SRC, int Len );

2. Porting expand_props () from Android 4.0 in/system/CORE/init/int_parser.c.

Expand_props () mainly implements parsing the attributes included in '$': When $ (PROP) is encountered, it is directly converted to get the attribute value.

Because expand_props () also uses push_chars (), push_chars () is also transplanted.

3. porting the do_write () function to/system/CORE/init/builtins. C.

Do_write () is the implementation of the write command in the init. RC Script.

 

The original implementation:

int do_write(int nargs, char **args){    returnwrite_file(args[1], args[2]);}

 

Change

int do_write(int nargs, char **args){    constchar *path = args[1];    constchar *value = args[2];    charprop_val[PROP_VALUE_MAX];    intret;     ret =expand_props(prop_val, value, sizeof(prop_val));    if(ret) {       ERROR("cannot expand '%s' while writing to '%s'\n", value,path);       return -EINVAL;    }    returnwrite_file(path, prop_val);}

You can parse $ (PROP) in the write command in init. RC.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.