简介
可以说,前面分析的OTA升级的各部分代码都是在搭一个舞台,而主角现在终于登场,它就是updater. Google的代码架构设计非常好,各部分尽量松耦合。前面介绍升级脚本时,可知有两种类型的脚本,amend& edify. 他们各自对应一个updater. 这里,我们主要关注新的edify的updater.
源码文件
tree12345678.├── Android.mk├── blockimg.c├── blockimg.h├── install.c├── install.h├── updater.c└── updater.h
入口函数 main
- 处理version 参数
- 获取命令管道
Set up the pipe for sending commands back to the parent process.
- 读入脚本
mzFindZipEntry(&za, SCRIPT_NAME);
- 注册语句处理函数
Configure edify’s functions.
- 解析脚本命令
Parse the script.
- 执行脚本
核心函数是 Evaluate。它会调用其他callback函数,而这些callback函数又会调用Evaluate去解析不同的脚本片段。
主流程的代码非常简单,因为细节隐藏在那些 callback 函数里。
callback函数
- RegisterBuiltins
|
|
RegisterInstallFunctions
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354void RegisterInstallFunctions() {RegisterFunction("mount", MountFn);RegisterFunction("is_mounted", IsMountedFn);RegisterFunction("unmount", UnmountFn);RegisterFunction("format", FormatFn);RegisterFunction("show_progress", ShowProgressFn);RegisterFunction("set_progress", SetProgressFn);RegisterFunction("delete", DeleteFn);RegisterFunction("delete_recursive", DeleteFn);RegisterFunction("package_extract_dir", PackageExtractDirFn);RegisterFunction("package_extract_file", PackageExtractFileFn);RegisterFunction("symlink", SymlinkFn);// Usage:// set_metadata("filename", "key1", "value1", "key2", "value2", ...)// Example:// set_metadata("/system/bin/netcfg", "uid", 0, "gid", 3003, "mode", 02750, "selabel", "u:object_r:system_file:s0", "capabilities", 0x0);RegisterFunction("set_metadata", SetMetadataFn);// Usage:// set_metadata_recursive("dirname", "key1", "value1", "key2", "value2", ...)// Example:// set_metadata_recursive("/system", "uid", 0, "gid", 0, "fmode", 0644, "dmode", 0755, "selabel", "u:object_r:system_file:s0", "capabilities", 0x0);RegisterFunction("set_metadata_recursive", SetMetadataFn);RegisterFunction("getprop", GetPropFn);RegisterFunction("file_getprop", FileGetPropFn);RegisterFunction("write_raw_image", WriteRawImageFn);RegisterFunction("write_raw_parameter_image", WriteRawParameterImageFn);RegisterFunction("clear_misc_command", ClearMiscCommandFn);RegisterFunction("apply_patch", ApplyPatchFn);RegisterFunction("apply_patch_check", ApplyPatchCheckFn);RegisterFunction("apply_patch_space", ApplyPatchSpaceFn);RegisterFunction("wipe_block_device", WipeBlockDeviceFn);RegisterFunction("read_file", ReadFileFn);RegisterFunction("sha1_check", Sha1CheckFn);RegisterFunction("rename", RenameFn);RegisterFunction("wipe_cache", WipeCacheFn);RegisterFunction("ui_print", UIPrintFn);RegisterFunction("run_program", RunProgramFn);RegisterFunction("reboot_now", RebootNowFn);RegisterFunction("get_stage", GetStageFn);RegisterFunction("set_stage", SetStageFn);RegisterFunction("enable_reboot", EnableRebootFn);RegisterFunction("tune2fs", Tune2FsFn);}RegisterBlockImageFunctions
|
|
FinishRegistration
123void FinishRegistration() {qsort(fn_table, fn_entries, sizeof(NamedFunction), fn_entry_compare);}