Merge "Adjust ResolveRelativeEncodedDexLocation."
diff --git a/build/Android.gtest.mk b/build/Android.gtest.mk
index f00da9c..3dab025 100644
--- a/build/Android.gtest.mk
+++ b/build/Android.gtest.mk
@@ -198,7 +198,7 @@
ART_GTEST_oat_file_assistant_test_DEX_DEPS := $(ART_GTEST_dex2oat_environment_tests_DEX_DEPS)
ART_GTEST_dexoptanalyzer_test_DEX_DEPS := $(ART_GTEST_dex2oat_environment_tests_DEX_DEPS)
ART_GTEST_image_space_test_DEX_DEPS := $(ART_GTEST_dex2oat_environment_tests_DEX_DEPS)
-ART_GTEST_oat_file_test_DEX_DEPS := Main MultiDex MainUncompressed MultiDexUncompressed
+ART_GTEST_oat_file_test_DEX_DEPS := Main MultiDex MainUncompressed MultiDexUncompressed MainStripped Nested MultiDexModifiedSecondary
ART_GTEST_oat_test_DEX_DEPS := Main
ART_GTEST_oat_writer_test_DEX_DEPS := Main
ART_GTEST_object_test_DEX_DEPS := ProtoCompare ProtoCompare2 StaticsFromCode XandY
diff --git a/runtime/oat_file.cc b/runtime/oat_file.cc
index f4a8c50..e433cbc 100644
--- a/runtime/oat_file.cc
+++ b/runtime/oat_file.cc
@@ -1410,20 +1410,23 @@
std::string OatFile::ResolveRelativeEncodedDexLocation(
const char* abs_dex_location, const std::string& rel_dex_location) {
- // For host, we still do resolution as the rel_dex_location might be absolute
- // for a target dex (for example /system/foo/foo.apk).
- if (abs_dex_location != nullptr && (rel_dex_location[0] != '/' || !kIsTargetBuild)) {
- // Strip :classes<N>.dex used for secondary multidex files.
+ if (abs_dex_location != nullptr) {
std::string base = DexFileLoader::GetBaseLocation(rel_dex_location);
+ // Strip :classes<N>.dex used for secondary multidex files.
std::string multidex_suffix = DexFileLoader::GetMultiDexSuffix(rel_dex_location);
-
- // Check if the base is a suffix of the provided abs_dex_location.
- std::string target_suffix = ((rel_dex_location[0] != '/') ? "/" : "") + base;
- std::string abs_location(abs_dex_location);
- if (abs_location.size() > target_suffix.size()) {
- size_t pos = abs_location.size() - target_suffix.size();
- if (abs_location.compare(pos, std::string::npos, target_suffix) == 0) {
- return abs_location + multidex_suffix;
+ if (!kIsTargetBuild) {
+ // For host, we still do resolution as the rel_dex_location might be absolute
+ // for a target dex (for example /system/foo/foo.apk).
+ return std::string(abs_dex_location) + multidex_suffix;
+ } else if (rel_dex_location[0] != '/') {
+ // Check if the base is a suffix of the provided abs_dex_location.
+ std::string target_suffix = ((rel_dex_location[0] != '/') ? "/" : "") + base;
+ std::string abs_location(abs_dex_location);
+ if (abs_location.size() > target_suffix.size()) {
+ size_t pos = abs_location.size() - target_suffix.size();
+ if (abs_location.compare(pos, std::string::npos, target_suffix) == 0) {
+ return abs_location + multidex_suffix;
+ }
}
}
}
diff --git a/runtime/oat_file_test.cc b/runtime/oat_file_test.cc
index b547113..ce09da4d 100644
--- a/runtime/oat_file_test.cc
+++ b/runtime/oat_file_test.cc
@@ -35,10 +35,6 @@
OatFile::ResolveRelativeEncodedDexLocation(
nullptr, "/data/app/foo/base.apk"));
- EXPECT_EQ(std::string("/system/framework/base.apk"),
- OatFile::ResolveRelativeEncodedDexLocation(
- "/data/app/foo/base.apk", "/system/framework/base.apk"));
-
EXPECT_EQ(std::string("/data/app/foo/base.apk"),
OatFile::ResolveRelativeEncodedDexLocation(
"/data/app/foo/base.apk", "base.apk"));
@@ -55,13 +51,29 @@
OatFile::ResolveRelativeEncodedDexLocation(
"/data/app/foo/base.apk", "base.apk!classes11.dex"));
- EXPECT_EQ(std::string("base.apk"),
- OatFile::ResolveRelativeEncodedDexLocation(
- "/data/app/foo/sludge.apk", "base.apk"));
-
- EXPECT_EQ(std::string("o/base.apk"),
- OatFile::ResolveRelativeEncodedDexLocation(
- "/data/app/foo/base.apk", "o/base.apk"));
+ // Host and target differ in their way of handling locations
+ // that are prefix of one another, due to boot image files.
+ if (kIsTargetBuild) {
+ EXPECT_EQ(std::string("/system/framework/base.apk"),
+ OatFile::ResolveRelativeEncodedDexLocation(
+ "/data/app/foo/base.apk", "/system/framework/base.apk"));
+ EXPECT_EQ(std::string("base.apk"),
+ OatFile::ResolveRelativeEncodedDexLocation(
+ "/data/app/foo/sludge.apk", "base.apk"));
+ EXPECT_EQ(std::string("o/base.apk"),
+ OatFile::ResolveRelativeEncodedDexLocation(
+ "/data/app/foo/base.apk", "o/base.apk"));
+ } else {
+ EXPECT_EQ(std::string("/data/app/foo/base.apk"),
+ OatFile::ResolveRelativeEncodedDexLocation(
+ "/data/app/foo/base.apk", "/system/framework/base.apk"));
+ EXPECT_EQ(std::string("/data/app/foo/sludge.apk"),
+ OatFile::ResolveRelativeEncodedDexLocation(
+ "/data/app/foo/sludge.apk", "base.apk"));
+ EXPECT_EQ(std::string("/data/app/foo/base.apk"),
+ OatFile::ResolveRelativeEncodedDexLocation(
+ "/data/app/foo/base.apk", "o/base.apk"));
+ }
}
TEST_F(OatFileTest, LoadOat) {