From 71693e6683cd925b8fdf06c2431b6fe187df6f40 Mon Sep 17 00:00:00 2001 From: Jaekyun Seok Date: Thu, 18 May 2017 00:10:57 +0900 Subject: [PATCH] Add a function to verify if idmap is made from given target/overlay packages "--verify" will be used to verify if idmap corresponding to given fd is maded from given target and overlay packages. Test: building succeeded and tested on sailfish. Bug: 37179531 Change-Id: Id19bdfd9c61670437f3e1a5c29762ce93586590f --- cmds/idmap/create.cpp | 6 ++++++ cmds/idmap/idmap.cpp | 31 +++++++++++++++++++++++++++++++ cmds/idmap/idmap.h | 2 ++ 3 files changed, 39 insertions(+) diff --git a/cmds/idmap/create.cpp b/cmds/idmap/create.cpp index c13d318f74495..524db14f7aabb 100644 --- a/cmds/idmap/create.cpp +++ b/cmds/idmap/create.cpp @@ -221,3 +221,9 @@ int idmap_create_fd(const char *target_apk_path, const char *overlay_apk_path, i return create_and_write_idmap(target_apk_path, overlay_apk_path, fd, true) == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } + +int idmap_verify_fd(const char *target_apk_path, const char *overlay_apk_path, int fd) +{ + return !is_idmap_stale_fd(target_apk_path, overlay_apk_path, fd) ? + EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/cmds/idmap/idmap.cpp b/cmds/idmap/idmap.cpp index 3a237ffda775a..8f86ed8f7d326 100644 --- a/cmds/idmap/idmap.cpp +++ b/cmds/idmap/idmap.cpp @@ -16,6 +16,7 @@ SYNOPSIS \n\ idmap --scan target-package-name-to-look-for path-to-target-apk dir-to-hold-idmaps \\\ dir-to-scan [additional-dir-to-scan [additional-dir-to-scan [...]]]\n\ idmap --inspect idmap \n\ + idmap --verify target overlay fd \n\ \n\ DESCRIPTION \n\ Idmap files play an integral part in the runtime resource overlay framework. An idmap \n\ @@ -56,6 +57,9 @@ OPTIONS \n\ \n\ --inspect: decode the binary format of 'idmap' (path) and display the contents in a \n\ debug-friendly format. \n\ +\n\ + --verify: verify if idmap corresponding to file descriptor 'fd' (integer) is made from \n\ + target package 'target' (path to apk) and overlay package 'overlay'. \n\ \n\ EXAMPLES \n\ Create an idmap file: \n\ @@ -167,6 +171,29 @@ NOTES \n\ return idmap_create_path(target_apk_path, overlay_apk_path, idmap_path); } + int maybe_verify_fd(const char *target_apk_path, const char *overlay_apk_path, + const char *idmap_str) + { + char *endptr; + int idmap_fd = strtol(idmap_str, &endptr, 10); + if (*endptr != '\0') { + fprintf(stderr, "error: failed to parse file descriptor argument %s\n", idmap_str); + return -1; + } + + if (!verify_file_readable(target_apk_path)) { + ALOGD("error: failed to read apk %s: %s\n", target_apk_path, strerror(errno)); + return -1; + } + + if (!verify_file_readable(overlay_apk_path)) { + ALOGD("error: failed to read apk %s: %s\n", overlay_apk_path, strerror(errno)); + return -1; + } + + return idmap_verify_fd(target_apk_path, overlay_apk_path, idmap_fd); + } + int maybe_scan(const char *target_package_name, const char *target_apk_path, const char *idmap_dir, const android::Vector *overlay_dirs) { @@ -235,6 +262,10 @@ int main(int argc, char **argv) return maybe_create_path(argv[2], argv[3], argv[4]); } + if (argc == 5 && !strcmp(argv[1], "--verify")) { + return maybe_verify_fd(argv[2], argv[3], argv[4]); + } + if (argc >= 6 && !strcmp(argv[1], "--scan")) { android::Vector v; for (int i = 5; i < argc; i++) { diff --git a/cmds/idmap/idmap.h b/cmds/idmap/idmap.h index 8d4210bcb4430..5962108c9f7e3 100644 --- a/cmds/idmap/idmap.h +++ b/cmds/idmap/idmap.h @@ -25,6 +25,8 @@ int idmap_create_path(const char *target_apk_path, const char *overlay_apk_path, int idmap_create_fd(const char *target_apk_path, const char *overlay_apk_path, int fd); +int idmap_verify_fd(const char *target_apk_path, const char *overlay_apk_path, int fd); + // Regarding target_package_name: the idmap_scan implementation should // be able to extract this from the manifest in target_apk_path, // simplifying the external API.