diff options
author | Tianjie Xu | 2016-06-08 16:30:04 -0500 |
---|---|---|
committer | Tianjie Xu | 2016-06-09 19:29:04 -0500 |
commit | b0ddae55e53c90880212caf0e19e439a3898abfd (patch) | |
tree | 4f78ff9875706dca3c4422b834cb6de9a5fe8feb /install.cpp | |
parent | 771b6eb8d9fb53c7fc2a3beb0e29d3e2619f35fd (diff) | |
download | platform-bootable-recovery-b0ddae55e53c90880212caf0e19e439a3898abfd.tar.gz platform-bootable-recovery-b0ddae55e53c90880212caf0e19e439a3898abfd.tar.xz platform-bootable-recovery-b0ddae55e53c90880212caf0e19e439a3898abfd.zip |
Log source/target build version to last_install
Parse the build.version.incremental from the metadata of the update
package; and log it to last_install.
Example:
In metadata we read:
post-build-incremental=2951741
pre-build-incremental=2943039
In last install we log:
source_build: 2943039
target_build: 2951741
Bug: 28658632
Change-Id: I0a9cc2d01644846e18bda31f4193ff40e8924486
Diffstat (limited to 'install.cpp')
-rw-r--r-- | install.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/install.cpp b/install.cpp index d5c55830..5a439a1d 100644 --- a/install.cpp +++ b/install.cpp | |||
@@ -27,6 +27,7 @@ | |||
27 | #include <string> | 27 | #include <string> |
28 | #include <vector> | 28 | #include <vector> |
29 | 29 | ||
30 | #include <android-base/parseint.h> | ||
30 | #include <android-base/stringprintf.h> | 31 | #include <android-base/stringprintf.h> |
31 | #include <android-base/strings.h> | 32 | #include <android-base/strings.h> |
32 | 33 | ||
@@ -46,6 +47,7 @@ extern RecoveryUI* ui; | |||
46 | 47 | ||
47 | #define ASSUMED_UPDATE_BINARY_NAME "META-INF/com/google/android/update-binary" | 48 | #define ASSUMED_UPDATE_BINARY_NAME "META-INF/com/google/android/update-binary" |
48 | #define PUBLIC_KEYS_FILE "/res/keys" | 49 | #define PUBLIC_KEYS_FILE "/res/keys" |
50 | static constexpr const char* METADATA_PATH = "META-INF/com/android/metadata"; | ||
49 | 51 | ||
50 | // Default allocation of progress bar segments to operations | 52 | // Default allocation of progress bar segments to operations |
51 | static const int VERIFICATION_PROGRESS_TIME = 60; | 53 | static const int VERIFICATION_PROGRESS_TIME = 60; |
@@ -53,11 +55,64 @@ static const float VERIFICATION_PROGRESS_FRACTION = 0.25; | |||
53 | static const float DEFAULT_FILES_PROGRESS_FRACTION = 0.4; | 55 | static const float DEFAULT_FILES_PROGRESS_FRACTION = 0.4; |
54 | static const float DEFAULT_IMAGE_PROGRESS_FRACTION = 0.1; | 56 | static const float DEFAULT_IMAGE_PROGRESS_FRACTION = 0.1; |
55 | 57 | ||
58 | // This function parses and returns the build.version.incremental | ||
59 | static int parse_build_number(std::string str) { | ||
60 | size_t pos = str.find("="); | ||
61 | if (pos != std::string::npos) { | ||
62 | std::string num_string = android::base::Trim(str.substr(pos+1)); | ||
63 | int build_number; | ||
64 | if (android::base::ParseInt(num_string.c_str(), &build_number, 0)) { | ||
65 | return build_number; | ||
66 | } | ||
67 | } | ||
68 | |||
69 | LOGE("Failed to parse build number in %s.\n", str.c_str()); | ||
70 | return -1; | ||
71 | } | ||
72 | |||
73 | // Read the build.version.incremental of src/tgt from the metadata and log it to last_install. | ||
74 | static void read_source_target_build(ZipArchive* zip, std::vector<std::string>& log_buffer) { | ||
75 | const ZipEntry* meta_entry = mzFindZipEntry(zip, METADATA_PATH); | ||
76 | if (meta_entry == nullptr) { | ||
77 | LOGE("Failed to find %s in update package.\n", METADATA_PATH); | ||
78 | return; | ||
79 | } | ||
80 | |||
81 | std::string meta_data(meta_entry->uncompLen, '\0'); | ||
82 | if (!mzReadZipEntry(zip, meta_entry, &meta_data[0], meta_entry->uncompLen)) { | ||
83 | LOGE("Failed to read metadata in update package.\n"); | ||
84 | return; | ||
85 | } | ||
86 | |||
87 | // Examples of the pre-build and post-build strings in metadata: | ||
88 | // pre-build-incremental=2943039 | ||
89 | // post-build-incremental=2951741 | ||
90 | std::vector<std::string> lines = android::base::Split(meta_data, "\n"); | ||
91 | for (const std::string& line : lines) { | ||
92 | std::string str = android::base::Trim(line); | ||
93 | if (android::base::StartsWith(str, "pre-build-incremental")){ | ||
94 | int source_build = parse_build_number(str); | ||
95 | if (source_build != -1) { | ||
96 | log_buffer.push_back(android::base::StringPrintf("source_build: %d", | ||
97 | source_build)); | ||
98 | } | ||
99 | } else if (android::base::StartsWith(str, "post-build-incremental")) { | ||
100 | int target_build = parse_build_number(str); | ||
101 | if (target_build != -1) { | ||
102 | log_buffer.push_back(android::base::StringPrintf("target_build: %d", | ||
103 | target_build)); | ||
104 | } | ||
105 | } | ||
106 | } | ||
107 | } | ||
108 | |||
56 | // If the package contains an update binary, extract it and run it. | 109 | // If the package contains an update binary, extract it and run it. |
57 | static int | 110 | static int |
58 | try_update_binary(const char* path, ZipArchive* zip, bool* wipe_cache, | 111 | try_update_binary(const char* path, ZipArchive* zip, bool* wipe_cache, |
59 | std::vector<std::string>& log_buffer, int retry_count) | 112 | std::vector<std::string>& log_buffer, int retry_count) |
60 | { | 113 | { |
114 | read_source_target_build(zip, log_buffer); | ||
115 | |||
61 | const ZipEntry* binary_entry = | 116 | const ZipEntry* binary_entry = |
62 | mzFindZipEntry(zip, ASSUMED_UPDATE_BINARY_NAME); | 117 | mzFindZipEntry(zip, ASSUMED_UPDATE_BINARY_NAME); |
63 | if (binary_entry == NULL) { | 118 | if (binary_entry == NULL) { |