From e16e799dfdff5392d2bdc460f41353100d082e96 Mon Sep 17 00:00:00 2001 From: Tianjie Xu Date: Fri, 9 Sep 2016 10:55:44 -0700 Subject: save uncrypt status to last_install Save the uncrypt time cost to /cache/recovery/uncrypt_status. Recovery reads the file and saves its contents to last_install. Bug: 31383361 Test: Tested on angler and uncrypt_time reports correctly. (cherry picked from commit fe16b5ccaf80f6e04d5b722c37c1abd70457ad28) Change-Id: Id69681a35c7eb2f0eb21b48e3616dcda82ce41b8 --- uncrypt/uncrypt.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'uncrypt') diff --git a/uncrypt/uncrypt.cpp b/uncrypt/uncrypt.cpp index 5e804bcca..c73107cca 100644 --- a/uncrypt/uncrypt.cpp +++ b/uncrypt/uncrypt.cpp @@ -134,6 +134,7 @@ // devices, on which /cache partitions always exist. static const std::string CACHE_BLOCK_MAP = "/cache/recovery/block.map"; static const std::string UNCRYPT_PATH_FILE = "/cache/recovery/uncrypt_file"; +static const std::string UNCRYPT_STATUS = "/cache/recovery/uncrypt_status"; static const std::string UNCRYPT_SOCKET = "uncrypt"; static struct fstab* fstab = nullptr; @@ -466,12 +467,32 @@ static bool uncrypt_wrapper(const char* input_path, const char* map_file, const input_path = package.c_str(); } CHECK(map_file != nullptr); + +#define UNCRYPT_TIME_HOLDER 0x7FFFFFFF + // Intialize the uncrypt time cost to a huge number so that we can tell from + // the statistics if an uncrypt fails to finish. + if (!android::base::WriteStringToFile(android::base::StringPrintf( + "uncrypt_time: %d\n", UNCRYPT_TIME_HOLDER), UNCRYPT_STATUS)) { + PLOG(WARNING) << "failed to write to " << UNCRYPT_STATUS; + } + + auto start = std::chrono::system_clock::now(); int status = uncrypt(input_path, map_file, socket); if (status != 0) { write_status_to_socket(-1, socket); return false; } + + std::chrono::duration duration = std::chrono::system_clock::now() - start; + int count = static_cast(duration.count()); + // Overwrite the uncrypt_time if uncrypt finishes successfully. + if (!android::base::WriteStringToFile( + android::base::StringPrintf("uncrypt_time: %d\n", count), UNCRYPT_STATUS)) { + PLOG(WARNING) << "failed to write to " << UNCRYPT_STATUS; + } + write_status_to_socket(100, socket); + return true; } -- cgit v1.2.3