page.title=Inside OTA Packages @jd:body
The system builds the updater binary from bootable/recovery/updater
and uses it in an OTA package.
ota_update.zip
, incremental_ota_update.zip
) that
contains the executable binary META-INF/com/google/android/update-binary
.
Updater contains several builtin functions and an interpreter for an
extensible scripting language (edify) that supports commands for typical
update-related tasks. Updater looks in the package .zip file for a script in the
file META-INF/com/google/android/updater-script
.
Note: Using the edify script and/or builtin functions is not a common activity, but can be helpful if you need to debug the update file.
An edify script is a single expression in which all values are strings. Empty strings are false in a Boolean context and all other strings are true. Edify supports the following operators (with the usual meanings):
(expr ) expr + expr # string concatenation, not integer addition expr == expr expr != expr expr && expr expr || expr ! expr if expr then expr endif if expr then expr else expr endif function_name(expr, expr,...) expr; expr
Any string of the characters a-z, A-Z, 0-9, _, :, /, . that isn't a reserved word is considered a string literal. (Reserved words are if else then endif.) String literals may also appear in double-quotes; this is how to create values with whitespace and other characters not in the above set. \n, \t, \", and \\ serve as escapes within quoted strings, as does \x##.
The && and || operators are short-circuiting; the right side is not evaluated if the logical result is determined by the left side. The following are equivalent:
e1 && e2 if e1 then e2 endif
The ; operator is a sequence point; it means to evaluate first the left side and then the right side. Its value is the value of the right-side expression. A semicolon can also appear after an expression, so the effect simulates C-style statements:
prepare(); do_other_thing("argument"); finish_up();
Most update functionality is contained in the functions available for
execution by scripts. (Strictly speaking these are macros rather than
functions in the Lisp sense, since they need not evaluate all of their
arguments.) Unless otherwise noted, functions return true on success
and false on error. If you want errors to abort execution of the
script, use the abort()
and/or assert()
functions.
The set of functions available in updater can also be extended to provide
device-specific
functionality.
abort([msg])
assert(expr[, expr, ...])
apply_patch(src_file, tgt_file, tgt_sha1,
tgt_size, patch1_sha1, patch1_blob, [...])
The patching is done in a safe manner that guarantees the target file either has the desired SHA1 hash and size, or it is untouched—it will not be left in an unrecoverable intermediate state. If the process is interrupted during patching, the target file may be in an intermediate state; a copy exists in the cache partition so restarting the update can successfully update the file.
Special syntax is supported to treat the contents of Memory Technology Device (MTD) partitions as files, allowing patching of raw partitions such as boot. To read an MTD partition, you must know how much data you want to read since the partition does not have an end-of-file notion. You can use the string "MTD:partition:size_1:sha1_1:size_2: sha1_2" as a filename to read the given partition. You must specify at least one (size, sha-1) pair; you can specify more than one if there are multiple possibilities for what you expect to read.
apply_patch_check(filename, sha1[, sha1, ...])
sha1_check(read_file(filename),
sha1 [, ...])
in that it knows to check the cache partition copy,
so apply_patch_check()
will succeed even if the file was corrupted
by an interrupted apply_patch() update
.apply_patch_space(bytes)
concat(expr[, expr, ...])
delete([filename, ...])
delete_recursive([dirname, ...])
file_getprop(filename, key)
/system/build.prop
), and returns the value of the given key
, or the empty string if key is not present.format(fs_type, partition_type, location,
fs_size, mount_point)
getprop(key)
greater_than_int(a, b)
ifelse(cond, e1[, e2])
is_mounted(mount_point)
is_substring(needle, haystack)
less_than_int(a, b)
mount(fs_type, partition_type, name,
mount_point)
/proc/mtd
on the device for a complete list).Recovery does not mount any filesystems by default (except the SD card if the user is doing a manual install of a package from the SD card); your script must mount any partitions it needs to modify.
package_extract_dir(package_dir, dest_dir)
package_extract_file(package_file[, dest_file])
read_file(filename)
rename(src_filename, tgt_filename)
rename("system/app/Hangouts/Hangouts.apk",
"system/priv-app/Hangouts/Hangouts.apk")
.run_program(path[, arg, ...])
set_metadata(filename, key1, value1[, key2
, value2, ...])
set_metadata("/system/bin/netcfg", "uid", 0, "gid", 3003, "mode", 02750,
"selabel", "u:object_r:system_file:s0", "capabilities", 0x0)
.set_metadata_recursive(dirname, key1, value1[,
key2, value2, ...])
set_metadata_recursive("/system", "uid",
0, "gid", 0, "fmode", 0644, "dmode", 0755, "selabel",
"u:object_r:system_file:s0", "capabilities", 0x0)
.set_progress(frac)
show_progress()
call. frac must be in the
range [0.0, 1.0]. The progress meter never moves backwards; attempts to make
it do so are ignored.sha1_check(blob[, sha1])
read_file()
or the one-argument form of package_extract_file()
. With no sha1 arguments, this function returns the SHA1 hash of
the blob (as a 40-digit hex string). With one or more sha1 arguments,
this function returns the SHA1 hash if it equals one of the arguments, or the
empty string if it does not equal any of them.show_progress(frac, secs)
set_progress()
function defined above.sleep(secs)
stdout(expr[, expr, ...])
symlink(target[, source, ...])
tune2fs(device[, arg, …])
ui_print([text, ...])
unmount(mount_point)
wipe_block_device(block_dev, len)
wipe_cache()
write_raw_image(filename_or_blob, partition)
write_raw_image(package_extract_file("zip_filename"), "partition_name");
Note: Prior to Android 4.1, only filenames were accepted, so to accomplish this the data first had to be unzipped into a temporary local file.