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.