diff options
author | Nicolas Geoffray <ngeoffray@google.com> | 2016-10-20 16:58:52 +0100 |
---|---|---|
committer | Nicolas Geoffray <ngeoffray@google.com> | 2016-10-21 13:43:11 +0100 |
commit | 986ae62325751fcd74e6efc825a4f09470b94aac (patch) | |
tree | 3de1abc5a245b723afce4cb57727120f9c056af2 /preopt2cachename | |
parent | db9fd64f5e21a5164cd8a1a0d942f4fefb3e5713 (diff) | |
download | extras-986ae62325751fcd74e6efc825a4f09470b94aac.tar.gz |
Also move vdex files from system_b.
Both .odex and .vdex files are needed to avoid doing dexopt
at first boot.
bug:32224338
bug:29278988
Test: flash pixel device, check no dex2oat of prebuilts is done.
Change-Id: Iafaeae64efd4e044590ef23d813aa0e2642c1226
Diffstat (limited to 'preopt2cachename')
-rw-r--r-- | preopt2cachename/preopt2cachename.cpp | 70 |
1 files changed, 38 insertions, 32 deletions
diff --git a/preopt2cachename/preopt2cachename.cpp b/preopt2cachename/preopt2cachename.cpp index dfdc63f3..f9a12ff4 100644 --- a/preopt2cachename/preopt2cachename.cpp +++ b/preopt2cachename/preopt2cachename.cpp @@ -24,37 +24,38 @@ #endif static const char* kDalvikCacheDir = "/data/dalvik-cache/"; -static const char* kCacheSuffix = "@classes.dex"; +static const char* kOdexCacheSuffix = "@classes.dex"; +static const char* kVdexCacheSuffix = "@classes.vdex"; -// Returns the ISA extracted from the odex_file_location. -// odex_file_location is formatted like /system/app/<app_name>/oat/<isa>/<app_name>.odex for all -// functions. We return an empty string "" in error cases. -static std::string ExtractISA(const std::string& odex_file_location) { - std::vector<std::string> split_file_location = android::base::Split(odex_file_location, "/"); +// Returns the ISA extracted from the file_location. +// file_location is formatted like /system/app/<app_name>/oat/<isa>/<app_name>.{odex,vdex} +// for all functions. We return an empty string "" in error cases. +static std::string ExtractISA(const std::string& file_location) { + std::vector<std::string> split_file_location = android::base::Split(file_location, "/"); if (split_file_location.size() <= 1) { return ""; } else if (split_file_location.size() != 7) { - LOG(WARNING) << "Unexpected length for odex-file-location. We expected 7 segments but found " + LOG(WARNING) << "Unexpected length for file-location. We expected 7 segments but found " << split_file_location.size(); } return split_file_location[split_file_location.size() - 2]; } -// Returns the apk name extracted from the odex_file_location. -// odex_file_location is formatted like /system/app/<app_name>/oat/<isa>/<app_name>.odex. We return -// the final <app_name> with the .odex replaced with .apk. -static std::string ExtractAPKName(const std::string& odex_file_location) { +// Returns the apk name extracted from the file_location. +// file_location is formatted like /system/app/<app_name>/oat/<isa>/<app_name>.{odex,vdex}. +// We return the final <app_name> with the .{odex,vdex} replaced with .apk. +static std::string ExtractAPKName(const std::string& file_location) { // Find and copy filename. - size_t file_location_start = odex_file_location.rfind('/'); + size_t file_location_start = file_location.rfind('/'); if (file_location_start == std::string::npos) { return ""; } - size_t ext_start = odex_file_location.rfind('.'); + size_t ext_start = file_location.rfind('.'); if (ext_start == std::string::npos || ext_start < file_location_start) { return ""; } - std::string apk_name = odex_file_location.substr(file_location_start + 1, - ext_start - file_location_start); + std::string apk_name = file_location.substr(file_location_start + 1, + ext_start - file_location_start); // Replace extension with .apk. apk_name += "apk"; @@ -62,18 +63,18 @@ static std::string ExtractAPKName(const std::string& odex_file_location) { } // The cache file name is /data/dalvik-cache/<isa>/ prior to this function -static bool OdexFilenameToCacheFile(const std::string& odex_file_location, - /*in-out*/std::string& cache_file) { - // Skip the first '/' in odex_file_location. - size_t initial_position = odex_file_location[0] == '/' ? 1 : 0; - size_t apk_position = odex_file_location.find("/oat", initial_position); +static bool SystemBFilenameToCacheFile(const std::string& file_location, + /*in-out*/std::string& cache_file) { + // Skip the first '/' in file_location. + size_t initial_position = file_location[0] == '/' ? 1 : 0; + size_t apk_position = file_location.find("/oat", initial_position); if (apk_position == std::string::npos) { LOG(ERROR) << "Unable to find oat directory!"; return false; } size_t cache_file_position = cache_file.size(); - cache_file += odex_file_location.substr(initial_position, apk_position); + cache_file += file_location.substr(initial_position, apk_position); // '/' -> '@' up to where the apk would be. cache_file_position = cache_file.find('/', cache_file_position); while (cache_file_position != std::string::npos) { @@ -82,28 +83,33 @@ static bool OdexFilenameToCacheFile(const std::string& odex_file_location, } // Add <apk_name>. - std::string apk_name = ExtractAPKName(odex_file_location); + std::string apk_name = ExtractAPKName(file_location); if (apk_name.empty()) { - LOG(ERROR) << "Unable to determine apk name from odex file name '" << odex_file_location << "'"; + LOG(ERROR) << "Unable to determine apk name from file name '" << file_location << "'"; return false; } cache_file += apk_name; - cache_file += kCacheSuffix; + if (file_location.size() >= 5 && + file_location.substr(file_location.size() - 5) == std::string(".vdex")) { + cache_file += kVdexCacheSuffix; + } else { + cache_file += kOdexCacheSuffix; + } return true; } -// Do the overall transformation from odex_file_location to output_file_location. Prior to this the +// Do the overall transformation from file_location to output_file_location. Prior to this the // output_file_location is empty. -static bool OdexToCacheFile(std::string& odex_file_location, - /*out*/std::string& output_file_location) { - std::string isa = ExtractISA(odex_file_location); +static bool SystemBFileToCacheFile(const std::string& file_location, + /*out*/std::string& output_file_location) { + std::string isa = ExtractISA(file_location); if (isa.empty()) { - LOG(ERROR) << "Unable to determine isa for odex file '" << odex_file_location << "', skipping"; + LOG(ERROR) << "Unable to determine isa for file '" << file_location << "', skipping"; return false; } output_file_location += isa; output_file_location += '/'; - return OdexFilenameToCacheFile(odex_file_location, output_file_location); + return SystemBFilenameToCacheFile(file_location, output_file_location); } // This program is used to determine where in the /data directory the runtime will search for an @@ -115,9 +121,9 @@ int main(int argc, char *argv[]) { LOG(ERROR) << "usage: preopt2cachename preopt-location"; return 2; } - std::string odex_file_location(argv[1]); + std::string file_location(argv[1]); std::string output_file_location(kDalvikCacheDir); - if (!OdexToCacheFile(odex_file_location, output_file_location)) { + if (!SystemBFileToCacheFile(file_location, output_file_location)) { return 1; } else { std::cout << output_file_location; |