Add CompactDexFile
Add holder class for CompactDex. Add unit test.
Bug: 63756964
Test: test-art-host
Change-Id: I304d7cb0e38b20e51132ea2c155f3db7bd50028a
diff --git a/runtime/dex_file_loader.cc b/runtime/dex_file_loader.cc
index 8cab1a5..e300e0e 100644
--- a/runtime/dex_file_loader.cc
+++ b/runtime/dex_file_loader.cc
@@ -25,6 +25,7 @@
#include "base/stl_util.h"
#include "base/systrace.h"
#include "base/unix_file/fd_file.h"
+#include "cdex/compact_dex_file.h"
#include "dex_file.h"
#include "dex_file_verifier.h"
#include "standard_dex_file.h"
@@ -37,12 +38,23 @@
static constexpr OatDexFile* kNoOatDexFile = nullptr;
-bool DexFileLoader::IsValidMagic(uint32_t magic) {
- return IsValidMagic(reinterpret_cast<uint8_t*>(&magic));
+bool DexFileLoader::IsMagicValid(uint32_t magic) {
+ return IsMagicValid(reinterpret_cast<uint8_t*>(&magic));
}
-bool DexFileLoader::IsValidMagic(const uint8_t* magic) {
- return StandardDexFile::IsMagicValid(magic);
+bool DexFileLoader::IsMagicValid(const uint8_t* magic) {
+ return StandardDexFile::IsMagicValid(magic) ||
+ CompactDexFile::IsMagicValid(magic);
+}
+
+bool DexFileLoader::IsVersionAndMagicValid(const uint8_t* magic) {
+ if (StandardDexFile::IsMagicValid(magic)) {
+ return StandardDexFile::IsVersionValid(magic);
+ }
+ if (CompactDexFile::IsMagicValid(magic)) {
+ return CompactDexFile::IsVersionValid(magic);
+ }
+ return false;
}
bool DexFileLoader::GetMultiDexChecksums(const char* filename,
@@ -81,7 +93,7 @@
} while (zip_entry.get() != nullptr);
return true;
}
- if (IsValidMagic(magic)) {
+ if (IsMagicValid(magic)) {
std::unique_ptr<const DexFile> dex_file(
OpenFile(fd.Release(), filename, false, false, error_msg));
if (dex_file == nullptr) {
@@ -188,7 +200,7 @@
if (IsZipMagic(magic)) {
return OpenZip(fd.Release(), location, verify_checksum, error_msg, dex_files);
}
- if (IsValidMagic(magic)) {
+ if (IsMagicValid(magic)) {
std::unique_ptr<const DexFile> dex_file(OpenFile(fd.Release(),
location,
/* verify */ true,