Add zip-fd support in dexoptanalyzer
Test: installd flow(manual), oat_file_assistant_test
(cherry-picked from commit 89455b30a30de68d389cef68748a01e13ea1356)
Bug: 67111829
Change-Id: Icf24c671ee060c75ba53932a7ccbe422e0ceb2e0
diff --git a/runtime/oat_file_assistant.h b/runtime/oat_file_assistant.h
index 44d8bd8..6c01c1e 100644
--- a/runtime/oat_file_assistant.h
+++ b/runtime/oat_file_assistant.h
@@ -121,9 +121,17 @@
// executable code for this dex location.
OatFileAssistant(const char* dex_location,
const InstructionSet isa,
+ bool load_executable);
+
+ // Similar to this(const char*, const InstructionSet, bool), however, if a valid zip_fd is
+ // provided, vdex, oat, and zip files will be read from vdex_fd, oat_fd and zip_fd respectively.
+ // Otherwise, dex_location will be used to construct necessary filenames.
+ OatFileAssistant(const char* dex_location,
+ const InstructionSet isa,
bool load_executable,
- int vdex_fd = -1,
- int oat_fd = -1);
+ int vdex_fd,
+ int oat_fd,
+ int zip_fd);
~OatFileAssistant();
@@ -351,7 +359,7 @@
// Clear any cached information and switch to getting info about the oat
// file with the given filename.
- void Reset(const std::string& filename, int vdex_fd = -1, int oat_fd = -1);
+ void Reset(const std::string& filename, bool use_fd, int vdex_fd = -1, int oat_fd = -1);
// Release the loaded oat file for runtime use.
// Returns null if the oat file hasn't been loaded or is out of date.
@@ -390,6 +398,7 @@
int oat_fd_ = -1;
int vdex_fd_ = -1;
+ bool use_fd_ = false;
bool load_attempted_ = false;
std::unique_ptr<OatFile> file_;
@@ -420,6 +429,12 @@
// Return info for the best oat file.
OatFileInfo& GetBestInfo();
+ // Returns true when vdex/oat/odex files should be read from file descriptors.
+ // The method checks the value of zip_fd_, and if the value is valid, returns
+ // true. This is required to have a deterministic behavior around how different
+ // files are being read.
+ bool UseFdToReadFiles();
+
// Returns true if the dex checksums in the given vdex file are up to date
// with respect to the dex location. If the dex checksums are not up to
// date, error_msg is updated with a message describing the problem.
@@ -482,6 +497,9 @@
OatFileInfo odex_;
OatFileInfo oat_;
+ // File descriptor corresponding to apk, dex file, or zip.
+ int zip_fd_;
+
// Cached value of the image info.
// Use the GetImageInfo method rather than accessing these directly.
// TODO: The image info should probably be moved out of the oat file