Support FDs for class loader context dex files
When compiling secondary dex files, dex2oat/dexoptanalyzer must open
all dex files in the given class loader context. However, these tools
do not have the SELinux permission to open app data files and instead
rely on installd to open them and pass file descriptors via command
line arguments.
This patch extends ClassLoaderContext::OpenDexFiles to support opening
dex files from a provided list of FDs, assuming the order corresponds
to the flattened class loader context. FDs can be passed to dex2oat/
dexoptanalyzer using a new '--class-loader-context-fds=' command line
argument. The format is a colon-separated list of integers.
dexoptanalyzer is also extended with a separate mode in which
dexopt-needed analysis is not performed, only the class loader context
is flattened and list of its dex files is printed to standard output
as a colon-separated list of paths. This mode is enabled with
'--flatten-class-loader-context' and is used by installd to obtain a
list of files it should open for dex2oat/dexoptanalyzer.
Bug: 126674985
Test: atest installd_dexopt_test
Change-Id: I46a671c90d14ad8615508c106a88ac1ee8a4ef28
diff --git a/runtime/oat_file_assistant.h b/runtime/oat_file_assistant.h
index def55b8..85e5917 100644
--- a/runtime/oat_file_assistant.h
+++ b/runtime/oat_file_assistant.h
@@ -146,7 +146,8 @@
int GetDexOptNeeded(CompilerFilter::Filter target_compiler_filter,
bool profile_changed = false,
bool downgrade = false,
- ClassLoaderContext* context = nullptr);
+ ClassLoaderContext* context = nullptr,
+ const std::vector<int>& context_fds = std::vector<int>());
// Returns true if there is up-to-date code for this dex location,
// irrespective of the compiler filter of the up-to-date code.
@@ -288,7 +289,8 @@
DexOptNeeded GetDexOptNeeded(CompilerFilter::Filter target_compiler_filter,
bool profile_changed,
bool downgrade,
- ClassLoaderContext* context);
+ ClassLoaderContext* context,
+ const std::vector<int>& context_fds);
// Returns the loaded file.
// Loads the file if needed. Returns null if the file failed to load.
@@ -329,7 +331,7 @@
// compiler filter.
bool CompilerFilterIsOkay(CompilerFilter::Filter target, bool profile_changed, bool downgrade);
- bool ClassLoaderContextIsOkay(ClassLoaderContext* context);
+ bool ClassLoaderContextIsOkay(ClassLoaderContext* context, const std::vector<int>& context_fds);
// Release the loaded oat file.
// Returns null if the oat file hasn't been loaded.