summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cppreopts/cppreopts.sh26
-rw-r--r--preopt2cachename/preopt2cachename.cpp70
2 files changed, 51 insertions, 45 deletions
diff --git a/cppreopts/cppreopts.sh b/cppreopts/cppreopts.sh
index 87982067..9f21ac78 100644
--- a/cppreopts/cppreopts.sh
+++ b/cppreopts/cppreopts.sh
@@ -19,20 +19,20 @@ umask 022
# Helper function to copy files
function do_copy() {
- odex_file=$1
+ source_file=$1
dest_name=$2
# Move to a temporary file so we can do a rename and have the preopted file
# appear atomically in the filesystem.
temp_dest_name=${dest_name}.tmp
- if ! cp ${odex_file} ${temp_dest_name} ; then
- log -p w -t cppreopts "Unable to copy odex file ${odex_file} to ${temp_dest_name}!"
+ if ! cp ${source_file} ${temp_dest_name} ; then
+ log -p w -t cppreopts "Unable to copy file ${source_file} to ${temp_dest_name}!"
else
- log -p i -t cppreopts "Copied odex file from ${odex_file} to ${temp_dest_name}"
+ log -p i -t cppreopts "Copied file from ${source_file} to ${temp_dest_name}"
sync
if ! mv ${temp_dest_name} ${dest_name} ; then
- log -p w -t cppreopts "Unable to rename temporary odex file from ${temp_dest_name} to ${dest_name}"
+ log -p w -t cppreopts "Unable to rename temporary file from ${temp_dest_name} to ${dest_name}"
else
- log -p i -t cppreopts "Renamed temporary odex file from ${temp_dest_name} to ${dest_name}"
+ log -p i -t cppreopts "Renamed temporary file from ${temp_dest_name} to ${dest_name}"
fi
fi
}
@@ -42,23 +42,23 @@ if [ $# -eq 1 ]; then
mountpoint=$1
if ! test -f ${mountpoint}/system-other-odex-marker ; then
- log -p i -t cppreopts "system_other partition does not appear have been built to contain preopted files."
+ log -p i -t cppreopts "system_other partition does not appear to have been built to contain preopted files."
exit 1
fi
log -p i -t cppreopts "cppreopts from ${mountpoint}"
- # For each odex file do the copy task
+ # For each odex and vdex file do the copy task
# NOTE: this implementation will break in any path with spaces to favor
# background copy tasks
- for odex_file in $(find ${mountpoint} -type f -name "*.odex"); do
- real_odex_name=${odex_file/${mountpoint}/\/system}
- dest_name=$(preopt2cachename ${real_odex_name})
+ for file in $(find ${mountpoint} -type f -name "*.odex" -o -type f -name "*.vdex"); do
+ real_name=${file/${mountpoint}/\/system}
+ dest_name=$(preopt2cachename ${real_name})
if ! test $? -eq 0 ; then
- log -p i -t cppreopts "Unable to figure out destination for ${odex_file}"
+ log -p i -t cppreopts "Unable to figure out destination for ${file}"
continue
fi
# Copy files in background to speed things up
- do_copy ${odex_file} ${dest_name} &
+ do_copy ${file} ${dest_name} &
done
# Wait for jobs to finish
wait
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;