updater-script简介:
updater-script是我们升级时所具体使用到的脚本文件,它主要用以控制升级流程的主要逻辑。具体位置位于更新包中/META-INFO/com/google/Android/目录下,在我们制作升级包的时候产生。
updater-script生成:
那么升级脚本updater-script是如何产生的呢,我们来看ota_from_target_file中的一条语句,这个之前有过介绍。
#在/build/tools/releasetools/目录下的模块edify_generator作为一个抽象的脚本生成器,用来生成edify脚本。这里的edify脚本指的就是updater-script-升级安装脚本,它是一个文本文件。而edify是用于从.zip文件中安装CyanogenMod和其它软件的简单脚本语言。edify脚本不一定是用于更新固件。它可以用来替换/添加/删除特定的文件,甚至格式分区。通常情况下,edify脚本运行于用户在恢复模式中选择“刷写zip”时。
script = edify_generator.EdifyGenerator(3, OPTIONS.info_dict)
那么updater-script中如何自动一步一步生成每一个脚本指令或者脚本语句呢,这里我们简单举几个例子给大家作为一个参考:
①对比更新包时间戳,只允许升级旧版本
下面这段代码是在ota_from_target_files中的语句
下面是对应edify_generator模块的中的相关方法:
那么我们从上面的代码中可以看到,这里呢在updater-script中追加了这样的一段语句:
那么实际在脚本中是这样子的,如:
那么这段话我们在执行updater-script脚本的时候具体逻辑是指当更新包中版本低于当前手机中的版本时终止安装更新。那么在安装的时候具体如何操作的呢,我们随后再详细描述。
②显示进度
那么这里调用了edify_generator模块中的ShowProgress(0.05,0):
而实际在updater-script中的逻辑如下:
③格式化分区
那么这里调用了edify_generator模块中的FormatPartition()函数:
④挂载分区
那么这里调用了edify_generator模块中的Mount()函数:
⑤释放文件夹内容到指定文件夹下,注意这里被释放的文件夹是指在OTA package中也就是更新包中的对应的文件夹,也就是下面函数中的第一个参数
那么这里调用了edify_generator模块中的UnpackPackageDir()函数
⑥建立符号链接
edify_generator模块中相对应的MakeSymlinks()函数
⑦权限设置
具体函数如:
⑧写入分区
具体相对应函数如下:
下面贴出updater-script简单语法供大家参考:
1、mount
语法:
mount(type, location, mount_point);这里表示挂载,其中type="MTD" location="<partition>" 挂载yaffs2文件系统分区;
type="vfat" location="/dev/block/<whatever>" 挂载设备。如:mount("MTD", "system", "/system");挂载system分区,设置返回指针"/system”
mount("vfat", "/dev/block/mmcblk1p2", "/system");
挂载/dev/block/mmcblk1p2,返回指针"/system”
2、Unmount
语法:
unmount(mount_point);指mount_point是mount所设置产生的指针。其作用与挂载相对应,卸载分区或设备。此函数与mount配套使用。如;unmount("/system");
卸载/system分区
3、Format
语法:
format(type, location);这里的type="MTD" location=partition(分区),格式化location参数所代表的分区。如:format("MTD", "system");格式化system分区
4、Delete
语法:
delete(<path>);删除path路径下文件,如delete("/data/zipalign.log");删除文件/data/zipalign.log
5、delete_recursive
语法:
delete_recursive(<path>);删除path路径下文件夹;如:delete_recursive("/data/dalvik-cache");删除文件夹/data/dalvik-cache
6、show_progress
语法:
show_progress(<fraction>,<duration>);这个之前介绍过,用于显示进度条,进度条会根据<duration>进行前进<fraction>,如show_progress(0.1, 10);show_progress下面的操作可能进行10s,完成后进度条前进0.1(也就是10%)
7、package_extract_dir
语法:
package_extract_dir(package_path, destination_path);释放文件夹package_path至destination_path如:package_extract_dir("system", "/system");释放ROM包里system文件夹下所有文件和子文件夹至/system
8、package_extract_file
语法:
package_extract_file(package_path, destination_path);这里表示解压package_path文件至destination_path,如package_extract_dir("my.zip", "/system");解压ROM包里的my.zip文件至/system
9、Symlink
语法:
symlink(<target>, <src1>, <src2>,...);表示建立指向target符号链接src1,src2,……;如symlink("toolbox", "/system/bin/ps");建立指向toolbox的符号链接/system/bin/ps
10、set_perm
语法:
set_perm(<uid>, <gid>,<mode>, <path>);表示设置权限,设置<path>文件的用户为uid,用户组为gid,权限为mode;如:set_perm(1002, 1002, 0440, "/system/etc/dbus.conf");设置文件/system/etc/dbus.conf的所有者为1002,所属用户组为1002,权限为:所有者有读权限,所属用户组有读权限,其他无任何权限。
11、set_perm_recursive
语法:
set_perm_recursive(<uid>,<gid>,<dir-mode>,<file-mode>,<path>);表示设置文件夹和文件夹内文件的权限;如:set_perm_recursive(1000, 1000, 0771, 0644, "/data/app");设置/data/app的所有者和所属用户组为1000,app文件夹的权限是:所有者和所属组拥有全部权限,其他有执行权限;app文件夹下的文件权限是:所有者有读写权限,所属组有读权限,其他有读权限。
12、ui_print
语法:
ui_print("str");这里指屏幕打印输出"str";如:ui_print("It's ready!");屏幕打印It’s ready!
13、run_program
语法:
run_program(<path>);指运行<path>脚本。如:run_program("/sbin/busybox","mount","/system");
14、write_raw_image
语法:
write_raw_image(<path>, partition);写入<path>至partition分区;如:write_raw_image("/tmp/boot.img", "boot")将yaffs2格式的boot包直接写入boot分区
15、assert
语法:
assert(<sub1>,<sub2>,<sub3>);这里如果执行sub1不返回错误则执行sub2,如果sub2不返回错误则执行sub3以此类推;如:assert(package_extract_file("boot.img", "/tmp/boot.img"),
write_raw_image("/tmp/boot.img", "boot"),
delete("/tmp/boot.img"));执行package_extract_file,如果不返回错误则执行write_raw_image,如果write_raw_image不出错则执行delete[1]
16、getprop()
语法:getprop("key"):通过指定key的值来获取对应的属性信息。如:getprop(“ro.product.device”)获取ro.product.device的属性值。