summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jiakai Zhang <jiakaiz@google.com> 2024-11-06 17:33:14 +0000
committer Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2024-11-11 11:08:09 +0000
commita202343b6dd492bea383f9babc427dfa2e274b7d (patch)
tree98cf212e927aec26a85de79eba31a7e367f089e4
parent01df4b3a9bb31f21f451452f0ce47632dd8916ad (diff)
Consolidate the use of some constants.
Bug: 377474232 Test: atest ArtServiceTests Test: atest art_standalone_artd_tests Test: atest art_standalone_odrefresh_tests Test: atest art_standalone_libartbase_tests Test: atest art_standalone_runtime_tests Test: atest art_standalone_dex2oat_tests Change-Id: I66a29ea85176c6c6d676537fe6e4e64152360acc
-rw-r--r--artd/Android.bp2
-rw-r--r--artd/artd.cc5
-rw-r--r--artd/artd_test.cc10
-rw-r--r--artd/binder/com/android/server/art/ArtConstants.aidl37
-rw-r--r--artd/path_utils.cc35
-rw-r--r--dex2oat/dex2oat.cc8
-rw-r--r--libartbase/base/file_utils.cc36
-rw-r--r--libartbase/base/file_utils.h9
-rw-r--r--libartbase/base/file_utils_test.cc2
-rw-r--r--libartbase/base/systrace.h3
-rw-r--r--libartservice/service/java/com/android/server/art/DexMetadataHelper.java10
-rw-r--r--libprofile/Android.bp1
-rw-r--r--odrefresh/odr_artifacts.h8
-rw-r--r--odrefresh/odrefresh.cc8
-rw-r--r--runtime/oat/image.h16
-rw-r--r--runtime/oat/oat_file_assistant.cc6
-rw-r--r--runtime/runtime_image.cc2
17 files changed, 125 insertions, 73 deletions
diff --git a/artd/Android.bp b/artd/Android.bp
index 2aad3a7c72..72024c0eec 100644
--- a/artd/Android.bp
+++ b/artd/Android.bp
@@ -107,6 +107,7 @@ art_cc_test {
"libarttools",
"libbase",
"libdexfile",
+ "libprofile",
],
}
@@ -123,6 +124,7 @@ art_cc_test {
"libarttools",
"libbase",
"libdexfile",
+ "libprofile",
],
test_config_template: "art_standalone_artd_tests.xml",
}
diff --git a/artd/artd.cc b/artd/artd.cc
index a6f9c70b8f..ee4f5588aa 100644
--- a/artd/artd.cc
+++ b/artd/artd.cc
@@ -45,6 +45,7 @@
#include <utility>
#include <vector>
+#include "aidl/com/android/server/art/ArtConstants.h"
#include "aidl/com/android/server/art/BnArtd.h"
#include "aidl/com/android/server/art/DexoptTrigger.h"
#include "aidl/com/android/server/art/IArtdCancellationSignal.h"
@@ -90,6 +91,7 @@ namespace artd {
namespace {
+using ::aidl::com::android::server::art::ArtConstants;
using ::aidl::com::android::server::art::ArtdDexoptResult;
using ::aidl::com::android::server::art::ArtifactsLocation;
using ::aidl::com::android::server::art::ArtifactsPath;
@@ -372,7 +374,8 @@ CopyAndRewriteProfileResult AnalyzeCopyAndRewriteProfileFailure(
if (zip_archive == nullptr) {
return bad_profile(error_msg);
}
- std::unique_ptr<ZipEntry> zip_entry(zip_archive->Find("primary.prof", &error_msg));
+ std::unique_ptr<ZipEntry> zip_entry(
+ zip_archive->Find(ArtConstants::DEX_METADATA_PROFILE_ENTRY, &error_msg));
if (zip_entry == nullptr || zip_entry->GetUncompressedLength() == 0) {
return no_profile;
}
diff --git a/artd/artd_test.cc b/artd/artd_test.cc
index 34950eee74..f4642b7488 100644
--- a/artd/artd_test.cc
+++ b/artd/artd_test.cc
@@ -61,10 +61,12 @@
#include "gtest/gtest.h"
#include "oat/oat_file.h"
#include "path_utils.h"
+#include "profile/profile_compilation_info.cc"
#include "profman/profman_result.h"
#include "testing.h"
#include "tools/binder_utils.h"
#include "tools/system_properties.h"
+#include "vdex_file.h"
#include "ziparchive/zip_writer.h"
extern char** environ;
@@ -582,7 +584,13 @@ class ArtdTest : public CommonArtTest {
}
};
-TEST_F(ArtdTest, ConstantsAreInSync) { EXPECT_STREQ(ArtConstants::REASON_VDEX, kReasonVdex); }
+TEST_F(ArtdTest, ConstantsAreInSync) {
+ EXPECT_STREQ(ArtConstants::REASON_VDEX, kReasonVdex);
+ EXPECT_STREQ(ArtConstants::DEX_METADATA_FILE_EXT, kDmExtension);
+ EXPECT_STREQ(ArtConstants::DEX_METADATA_PROFILE_ENTRY,
+ ProfileCompilationInfo::kDexMetadataProfileEntry);
+ EXPECT_STREQ(ArtConstants::DEX_METADATA_VDEX_ENTRY, VdexFile::kVdexNameInDmFile);
+}
TEST_F(ArtdTest, isAlive) {
bool result = false;
diff --git a/artd/binder/com/android/server/art/ArtConstants.aidl b/artd/binder/com/android/server/art/ArtConstants.aidl
index e9f702ef07..6e438f7efc 100644
--- a/artd/binder/com/android/server/art/ArtConstants.aidl
+++ b/artd/binder/com/android/server/art/ArtConstants.aidl
@@ -19,14 +19,47 @@ package com.android.server.art;
/**
* Constants used by ART Service Java code that must be kept in sync with those in ART native code.
*
+ * A test in art/artd/artd_test.cc checks that the constants are in sync.
+ *
* @hide
*/
parcelable ArtConstants {
/**
- * A special compilation reason to indicate that only the VDEX file is usable. Keep in sync with
- * {@code kReasonVdex} in art/runtime/oat_file.h.
+ * A special compilation reason to indicate that only the VDEX file is usable.
*
* This isn't a valid reason to feed into DexoptParams.
+ *
+ * Keep in sync with {@code kReasonVdex} in art/runtime/oat_file.h.
*/
const @utf8InCpp String REASON_VDEX = "vdex";
+
+ /**
+ * The file extension of the dex metadata file.
+ *
+ * Keep in sync with {@code kDmExtension} in art/libartbase/base/file_utils.h.
+ */
+ const @utf8InCpp String DEX_METADATA_FILE_EXT = ".dm";
+
+ /**
+ * The file extension of the profile file.
+ *
+ * Currently, there is no counterpart in the runtime code because the profile paths are passed
+ * from the framework.
+ */
+ const @utf8InCpp String PROFILE_FILE_EXT = ".prof";
+
+ /**
+ * The name of the profile entry in the dex metadata file.
+ *
+ * Keep in sync with {@code ProfileCompilationInfo::kDexMetadataProfileEntry} in
+ * art/libprofile/profile/profile_compilation_info.cc.
+ */
+ const @utf8InCpp String DEX_METADATA_PROFILE_ENTRY = "primary.prof";
+
+ /**
+ * The name of the vdex entry in the dex metadata file.
+ *
+ * Keep in sync with {@code VdexFile::kVdexNameInDmFile} in art/runtime/vdex_file.h.
+ */
+ const @utf8InCpp String DEX_METADATA_VDEX_ENTRY = "primary.vdex";
}
diff --git a/artd/path_utils.cc b/artd/path_utils.cc
index 8348a7605d..52bae7097e 100644
--- a/artd/path_utils.cc
+++ b/artd/path_utils.cc
@@ -20,6 +20,7 @@
#include <string>
#include <vector>
+#include "aidl/com/android/server/art/ArtConstants.h"
#include "aidl/com/android/server/art/BnArtd.h"
#include "android-base/errors.h"
#include "android-base/result.h"
@@ -37,6 +38,7 @@ namespace artd {
namespace {
+using ::aidl::com::android::server::art::ArtConstants;
using ::aidl::com::android::server::art::ArtifactsPath;
using ::aidl::com::android::server::art::DexMetadataPath;
using ::aidl::com::android::server::art::OutputArtifacts;
@@ -112,10 +114,10 @@ std::vector<std::string> ListManagedFiles(const std::string& android_data,
// we use more granular patterns to avoid accidentally deleting apps' files.
std::string secondary_oat_dir = data_dir + "/**/oat";
for (const char* suffix : {"", ".*.tmp", kPreRebootSuffix}) {
- patterns.push_back(secondary_oat_dir + "/*.prof" + suffix);
- patterns.push_back(secondary_oat_dir + "/*/*.odex" + suffix);
- patterns.push_back(secondary_oat_dir + "/*/*.vdex" + suffix);
- patterns.push_back(secondary_oat_dir + "/*/*.art" + suffix);
+ patterns.push_back(secondary_oat_dir + "/*" + ArtConstants::PROFILE_FILE_EXT + suffix);
+ patterns.push_back(secondary_oat_dir + "/*/*" + kOdexExtension + suffix);
+ patterns.push_back(secondary_oat_dir + "/*/*" + kVdexExtension + suffix);
+ patterns.push_back(secondary_oat_dir + "/*/*" + kArtExtension + suffix);
}
// Runtime image files.
patterns.push_back(RuntimeImage::GetRuntimeImageDir(data_dir) + "**");
@@ -183,8 +185,8 @@ Result<RawArtifactsPath> BuildArtifactsPath(const ArtifactsPath& artifacts_path)
}
}
- path.vdex_path = ReplaceFileExtension(path.oat_path, "vdex");
- path.art_path = ReplaceFileExtension(path.oat_path, "art");
+ path.vdex_path = ReplaceFileExtension(path.oat_path, kVdexExtension);
+ path.art_path = ReplaceFileExtension(path.oat_path, kArtExtension);
if (artifacts_path.isPreReboot) {
path.oat_path += kPreRebootSuffix;
@@ -199,36 +201,39 @@ Result<std::string> BuildPrimaryRefProfilePath(
const PrimaryRefProfilePath& primary_ref_profile_path) {
OR_RETURN(ValidatePathElement(primary_ref_profile_path.packageName, "packageName"));
OR_RETURN(ValidatePathElementSubstring(primary_ref_profile_path.profileName, "profileName"));
- return ART_FORMAT("{}/misc/profiles/ref/{}/{}.prof{}",
+ return ART_FORMAT("{}/misc/profiles/ref/{}/{}{}{}",
OR_RETURN(GetAndroidDataOrError()),
primary_ref_profile_path.packageName,
primary_ref_profile_path.profileName,
+ ArtConstants::PROFILE_FILE_EXT,
primary_ref_profile_path.isPreReboot ? kPreRebootSuffix : "");
}
Result<std::string> BuildPrebuiltProfilePath(const PrebuiltProfilePath& prebuilt_profile_path) {
OR_RETURN(ValidateDexPath(prebuilt_profile_path.dexPath));
- return prebuilt_profile_path.dexPath + ".prof";
+ return prebuilt_profile_path.dexPath + ArtConstants::PROFILE_FILE_EXT;
}
Result<std::string> BuildPrimaryCurProfilePath(
const PrimaryCurProfilePath& primary_cur_profile_path) {
OR_RETURN(ValidatePathElement(primary_cur_profile_path.packageName, "packageName"));
OR_RETURN(ValidatePathElementSubstring(primary_cur_profile_path.profileName, "profileName"));
- return ART_FORMAT("{}/misc/profiles/cur/{}/{}/{}.prof",
+ return ART_FORMAT("{}/misc/profiles/cur/{}/{}/{}{}",
OR_RETURN(GetAndroidDataOrError()),
primary_cur_profile_path.userId,
primary_cur_profile_path.packageName,
- primary_cur_profile_path.profileName);
+ primary_cur_profile_path.profileName,
+ ArtConstants::PROFILE_FILE_EXT);
}
Result<std::string> BuildSecondaryRefProfilePath(
const SecondaryRefProfilePath& secondary_ref_profile_path) {
OR_RETURN(ValidateDexPath(secondary_ref_profile_path.dexPath));
std::filesystem::path dex_path(secondary_ref_profile_path.dexPath);
- return ART_FORMAT("{}/oat/{}.prof{}",
+ return ART_FORMAT("{}/oat/{}{}{}",
dex_path.parent_path().string(),
dex_path.filename().string(),
+ ArtConstants::PROFILE_FILE_EXT,
secondary_ref_profile_path.isPreReboot ? kPreRebootSuffix : "");
}
@@ -236,8 +241,10 @@ Result<std::string> BuildSecondaryCurProfilePath(
const SecondaryCurProfilePath& secondary_cur_profile_path) {
OR_RETURN(ValidateDexPath(secondary_cur_profile_path.dexPath));
std::filesystem::path dex_path(secondary_cur_profile_path.dexPath);
- return ART_FORMAT(
- "{}/oat/{}.cur.prof", dex_path.parent_path().string(), dex_path.filename().string());
+ return ART_FORMAT("{}/oat/{}.cur{}",
+ dex_path.parent_path().string(),
+ dex_path.filename().string(),
+ ArtConstants::PROFILE_FILE_EXT);
}
Result<std::string> BuildWritableProfilePath(const WritableProfilePath& profile_path) {
@@ -265,7 +272,7 @@ Result<std::string> BuildTmpProfilePath(const TmpProfilePath& tmp_profile_path)
Result<std::string> BuildDexMetadataPath(const DexMetadataPath& dex_metadata_path) {
OR_RETURN(ValidateDexPath(dex_metadata_path.dexPath));
- return ReplaceFileExtension(dex_metadata_path.dexPath, "dm");
+ return ReplaceFileExtension(dex_metadata_path.dexPath, kDmExtension);
}
Result<std::string> BuildProfileOrDmPath(const ProfilePath& profile_path) {
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index 09dd6bc6e3..a8d3d9346c 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -1276,9 +1276,9 @@ class Dex2Oat final {
}
DCHECK_EQ(output_vdex_fd_, -1);
- std::string vdex_filename = output_vdex_.empty()
- ? ReplaceFileExtension(oat_filename, "vdex")
- : output_vdex_;
+ std::string vdex_filename = output_vdex_.empty() ?
+ ReplaceFileExtension(oat_filename, kVdexExtension) :
+ output_vdex_;
if (vdex_filename == input_vdex_ && output_vdex_.empty()) {
use_existing_vdex_ = true;
std::unique_ptr<File> vdex_file(OS::OpenFileForReading(vdex_filename.c_str()));
@@ -1333,7 +1333,7 @@ class Dex2Oat final {
}
DCHECK_NE(output_vdex_fd_, -1);
- std::string vdex_location = ReplaceFileExtension(oat_location_, "vdex");
+ std::string vdex_location = ReplaceFileExtension(oat_location_, kVdexExtension);
if (input_vdex_file_ != nullptr && output_vdex_fd_ == input_vdex_fd_) {
use_existing_vdex_ = true;
}
diff --git a/libartbase/base/file_utils.cc b/libartbase/base/file_utils.cc
index b784754313..1f09e7326e 100644
--- a/libartbase/base/file_utils.cc
+++ b/libartbase/base/file_utils.cc
@@ -72,6 +72,7 @@
namespace art {
+using android::base::ConsumePrefix;
using android::base::GetBoolProperty;
using android::base::GetProperty;
using android::base::StringPrintf;
@@ -427,8 +428,8 @@ std::string GetDefaultBootImageLocationSafe(const std::string& android_root,
// If an update for the ART module has been been installed, a single boot image for the entire
// bootclasspath is in the ART APEX data directory.
if (kIsTargetBuild && !deny_art_apex_data_files) {
- const std::string boot_image =
- GetApexDataDalvikCacheDirectory(InstructionSet::kNone) + "/" + kBootImageStem + ".art";
+ const std::string boot_image = GetApexDataDalvikCacheDirectory(InstructionSet::kNone) + "/" +
+ kBootImageStem + kArtExtension;
const std::string boot_image_filename = GetSystemImageFilename(boot_image.c_str(), kRuntimeISA);
if (OS::FileExists(boot_image_filename.c_str(), /*check_file_type=*/true)) {
// Boot image consists of two parts:
@@ -461,7 +462,7 @@ std::string GetDefaultBootImageLocationSafe(const std::string& android_root,
// ART module, when it fails to generate a single boot image for the entire bootclasspath (i.e.,
// full boot image). Use it if it exists.
const std::string minimal_boot_image = GetApexDataDalvikCacheDirectory(InstructionSet::kNone) +
- "/" + kMinimalBootImageStem + ".art";
+ "/" + kMinimalBootImageStem + kArtExtension;
const std::string minimal_boot_image_filename =
GetSystemImageFilename(minimal_boot_image.c_str(), kRuntimeISA);
if (OS::FileExists(minimal_boot_image_filename.c_str(), /*check_file_type=*/true)) {
@@ -634,7 +635,8 @@ static bool GetLocationEncodedFilename(std::string_view location,
*filename += location; // Including the leading slash.
size_t replace_start = cache_location.length() + /* skip the leading slash from `location` */ 1u;
std::replace(filename->begin() + replace_start, filename->end(), '/', '@');
- if (!location.ends_with(".dex") && !location.ends_with(".art") && !location.ends_with(".oat")) {
+ if (!location.ends_with(".dex") && !location.ends_with(kArtExtension) &&
+ !location.ends_with(kOatExtension)) {
*filename += "@";
*filename += kClassesDex;
}
@@ -683,26 +685,23 @@ static std::string GetApexDataDalvikCacheFilename(std::string_view dex_location,
}
std::string GetApexDataOatFilename(std::string_view location, InstructionSet isa) {
- return GetApexDataDalvikCacheFilename(location, isa, /*is_boot_classpath_location=*/true, "oat");
+ return GetApexDataDalvikCacheFilename(
+ location, isa, /*is_boot_classpath_location=*/true, kOatExtension);
}
std::string GetApexDataOdexFilename(std::string_view location, InstructionSet isa) {
return GetApexDataDalvikCacheFilename(
- location, isa, /*is_boot_classpath_location=*/false, "odex");
+ location, isa, /*is_boot_classpath_location=*/false, kOdexExtension);
}
std::string GetApexDataBootImage(std::string_view dex_location) {
- return GetApexDataDalvikCacheFilename(dex_location,
- InstructionSet::kNone,
- /*is_boot_classpath_location=*/true,
- kArtImageExtension);
+ return GetApexDataDalvikCacheFilename(
+ dex_location, InstructionSet::kNone, /*is_boot_classpath_location=*/true, kArtExtension);
}
std::string GetApexDataImage(std::string_view dex_location) {
- return GetApexDataDalvikCacheFilename(dex_location,
- InstructionSet::kNone,
- /*is_boot_classpath_location=*/false,
- kArtImageExtension);
+ return GetApexDataDalvikCacheFilename(
+ dex_location, InstructionSet::kNone, /*is_boot_classpath_location=*/false, kArtExtension);
}
std::string GetApexDataDalvikCacheFilename(std::string_view dex_location,
@@ -713,11 +712,11 @@ std::string GetApexDataDalvikCacheFilename(std::string_view dex_location,
}
std::string GetVdexFilename(const std::string& oat_location) {
- return ReplaceFileExtension(oat_location, "vdex");
+ return ReplaceFileExtension(oat_location, kVdexExtension);
}
std::string GetDmFilename(const std::string& dex_location) {
- return ReplaceFileExtension(dex_location, "dm");
+ return ReplaceFileExtension(dex_location, kDmExtension);
}
// check for the file in /system, followed by /system_ext
@@ -729,7 +728,7 @@ std::string GetSystemOdexFilenameForApex(std::string_view location, InstructionS
// This should never fail. The function fails only if the location is not absolute, and a location
// on /apex is always absolute.
DCHECK(ret) << error_msg;
- std::string path = ReplaceFileExtension(result, "odex");
+ std::string path = ReplaceFileExtension(result, kOdexExtension);
if (OS::FileExists(path.c_str(), /*check_file_type=*/true)) {
return path;
}
@@ -739,7 +738,7 @@ std::string GetSystemOdexFilenameForApex(std::string_view location, InstructionS
// This should never fail. The function fails only if the location is not absolute, and a location
// on /apex is always absolute.
DCHECK(ret) << error_msg;
- return ReplaceFileExtension(result, "odex");
+ return ReplaceFileExtension(result, kOdexExtension);
}
static void InsertIsaDirectory(const InstructionSet isa, std::string* filename) {
@@ -760,6 +759,7 @@ std::string GetSystemImageFilename(const char* location, const InstructionSet is
}
std::string ReplaceFileExtension(std::string_view filename, std::string_view new_extension) {
+ ConsumePrefix(&new_extension, ".");
const size_t last_ext = filename.find_last_of("./");
std::string result;
if (last_ext == std::string::npos || filename[last_ext] != '.') {
diff --git a/libartbase/base/file_utils.h b/libartbase/base/file_utils.h
index 205cc6115d..8a25fe1d9f 100644
--- a/libartbase/base/file_utils.h
+++ b/libartbase/base/file_utils.h
@@ -33,7 +33,11 @@ static constexpr const char kArtApexDataDefaultPath[] = "/data/misc/apexdata/com
static constexpr const char kAndroidConscryptApexDefaultPath[] = "/apex/com.android.conscrypt";
static constexpr const char kAndroidI18nApexDefaultPath[] = "/apex/com.android.i18n";
-static constexpr const char kArtImageExtension[] = "art";
+static constexpr const char* kOatExtension = ".oat";
+static constexpr const char* kOdexExtension = ".odex";
+static constexpr const char* kVdexExtension = ".vdex";
+static constexpr const char* kArtExtension = ".art";
+static constexpr const char* kDmExtension = ".dm";
// These methods return the Android Root, which is the historical location of
// the Android "system" directory, containing the built Android artifacts. On
@@ -176,8 +180,11 @@ std::string GetSystemOdexFilenameForApex(std::string_view location, InstructionS
// Returns `filename` with the text after the last occurrence of '.' replaced with
// `extension`. If `filename` does not contain a period, returns a string containing `filename`,
// a period, and `new_extension`.
+// A leading period in `new_extension`, if exists, is ignored.
// Example: ReplaceFileExtension("foo.bar", "abc") == "foo.abc"
// ReplaceFileExtension("foo", "abc") == "foo.abc"
+// ReplaceFileExtension("foo.bar", ".abc") == "foo.abc"
+// ReplaceFileExtension("foo", ".abc") == "foo.abc"
std::string ReplaceFileExtension(std::string_view filename, std::string_view new_extension);
// Return whether the location is on /apex/com.android.art
diff --git a/libartbase/base/file_utils_test.cc b/libartbase/base/file_utils_test.cc
index 6032555928..ff833cf770 100644
--- a/libartbase/base/file_utils_test.cc
+++ b/libartbase/base/file_utils_test.cc
@@ -175,6 +175,8 @@ TEST_F(FileUtilsTest, ReplaceFileExtension) {
EXPECT_EQ("/.directory/file.vdex", ReplaceFileExtension("/.directory/file.oat", "vdex"));
EXPECT_EQ("/directory/file.vdex", ReplaceFileExtension("/directory/file", "vdex"));
EXPECT_EQ("/.directory/file.vdex", ReplaceFileExtension("/.directory/file", "vdex"));
+ EXPECT_EQ("/directory/file.vdex", ReplaceFileExtension("/directory/file.oat", ".vdex"));
+ EXPECT_EQ("/directory/file.vdex", ReplaceFileExtension("/directory/file", ".vdex"));
}
TEST_F(FileUtilsTest, ArtApexDataPath) {
diff --git a/libartbase/base/systrace.h b/libartbase/base/systrace.h
index 6e5e0e013a..c42fe86737 100644
--- a/libartbase/base/systrace.h
+++ b/libartbase/base/systrace.h
@@ -95,9 +95,12 @@ class ScopedTraceNoStart {
};
};
+// Avoid the name clash with the one in gtest/gtest.h.
+#ifndef SCOPED_TRACE
#define SCOPED_TRACE \
::art::ScopedTraceNoStart APPEND_TOKENS_AFTER_EVAL(trace, __LINE__) ; \
(ATraceEnabled()) && ::art::ScopedTraceNoStart::ScopedTraceMessageHelper().stream()
+#endif // SCOPED_TRACE
} // namespace art
diff --git a/libartservice/service/java/com/android/server/art/DexMetadataHelper.java b/libartservice/service/java/com/android/server/art/DexMetadataHelper.java
index 237bb1878e..f5b2a81251 100644
--- a/libartservice/service/java/com/android/server/art/DexMetadataHelper.java
+++ b/libartservice/service/java/com/android/server/art/DexMetadataHelper.java
@@ -45,9 +45,6 @@ import java.util.zip.ZipFile;
public class DexMetadataHelper {
@NonNull private final Injector mInjector;
- private static final String PROFILE_DEX_METADATA = "primary.prof";
- private static final String VDEX_DEX_METADATA = "primary.vdex";
-
public DexMetadataHelper() {
this(new Injector());
}
@@ -91,12 +88,13 @@ public class DexMetadataHelper {
public static String getDmPath(@NonNull DexMetadataPath dmPath) {
String dexPath = dmPath.dexPath;
int pos = dexPath.lastIndexOf(".");
- return (pos != -1 ? dexPath.substring(0, pos) : dexPath) + ".dm";
+ return (pos != -1 ? dexPath.substring(0, pos) : dexPath)
+ + ArtConstants.DEX_METADATA_FILE_EXT;
}
private static @DexMetadata.Type int getType(@NonNull ZipFile zipFile) {
- var profile = zipFile.getEntry(PROFILE_DEX_METADATA);
- var vdex = zipFile.getEntry(VDEX_DEX_METADATA);
+ var profile = zipFile.getEntry(ArtConstants.DEX_METADATA_PROFILE_ENTRY);
+ var vdex = zipFile.getEntry(ArtConstants.DEX_METADATA_VDEX_ENTRY);
if (profile != null && vdex != null) {
return DexMetadata.TYPE_PROFILE_AND_VDEX;
diff --git a/libprofile/Android.bp b/libprofile/Android.bp
index 833ac2e040..91c5cbc9fd 100644
--- a/libprofile/Android.bp
+++ b/libprofile/Android.bp
@@ -45,6 +45,7 @@ cc_defaults {
"libziparchive",
],
export_shared_lib_headers: ["libbase"], // ART's macros.h depends on libbase's macros.h.
+ export_static_lib_headers: ["libmodules-utils-build"],
},
not_windows: {
shared_libs: [
diff --git a/odrefresh/odr_artifacts.h b/odrefresh/odr_artifacts.h
index 9b2e9731e7..1bed631f3b 100644
--- a/odrefresh/odr_artifacts.h
+++ b/odrefresh/odr_artifacts.h
@@ -20,7 +20,7 @@
#include <iosfwd>
#include <string>
-#include <base/file_utils.h>
+#include "base/file_utils.h"
namespace art {
namespace odrefresh {
@@ -29,11 +29,11 @@ namespace odrefresh {
class OdrArtifacts {
public:
static OdrArtifacts ForBootImage(const std::string& image_path) {
- return OdrArtifacts(image_path, /*image_kind=*/"image", /*aot_extension=*/"oat");
+ return OdrArtifacts(image_path, /*image_kind=*/"image", /*aot_extension=*/kOatExtension);
}
static OdrArtifacts ForSystemServer(const std::string& image_path) {
- return OdrArtifacts(image_path, /*image_kind=*/"app-image", /*aot_extension=*/"odex");
+ return OdrArtifacts(image_path, /*image_kind=*/"app-image", /*aot_extension=*/kOdexExtension);
}
const std::string& ImagePath() const { return image_path_; }
@@ -46,7 +46,7 @@ class OdrArtifacts {
: image_path_{image_path},
image_kind_{image_kind},
oat_path_{ReplaceFileExtension(image_path, aot_extension)},
- vdex_path_{ReplaceFileExtension(image_path, "vdex")} {}
+ vdex_path_{ReplaceFileExtension(image_path, kVdexExtension)} {}
OdrArtifacts() = delete;
OdrArtifacts(const OdrArtifacts&) = delete;
diff --git a/odrefresh/odrefresh.cc b/odrefresh/odrefresh.cc
index f0b8b44d23..bf3d62d0d0 100644
--- a/odrefresh/odrefresh.cc
+++ b/odrefresh/odrefresh.cc
@@ -526,7 +526,7 @@ std::string GetBootImageComponentBasename(const std::string& jar_path, bool is_f
return kFirstBootImageBasename;
}
std::string jar_name = Basename(jar_path);
- return "boot-" + ReplaceFileExtension(jar_name, "art");
+ return "boot-" + ReplaceFileExtension(jar_name, kArtExtension);
}
Result<void> AddCompiledBootClasspathFdsIfAny(
@@ -566,7 +566,7 @@ Result<void> AddCompiledBootClasspathFdsIfAny(
return ErrnoErrorf("Failed to open boot image file '{}'", image_path);
}
- std::string oat_path = ReplaceFileExtension(image_path, "oat");
+ std::string oat_path = ReplaceFileExtension(image_path, kOatExtension);
std::unique_ptr<File> oat_file(OS::OpenFileForReading(oat_path.c_str()));
if (oat_file != nullptr) {
bcp_oat_fds.push_back(std::to_string(oat_file->Fd()));
@@ -578,7 +578,7 @@ Result<void> AddCompiledBootClasspathFdsIfAny(
return ErrnoErrorf("Failed to open boot image file '{}'", oat_path);
}
- std::string vdex_path = ReplaceFileExtension(image_path, "vdex");
+ std::string vdex_path = ReplaceFileExtension(image_path, kVdexExtension);
std::unique_ptr<File> vdex_file(OS::OpenFileForReading(vdex_path.c_str()));
if (vdex_file != nullptr) {
bcp_vdex_fds.push_back(std::to_string(vdex_file->Fd()));
@@ -1017,7 +1017,7 @@ std::string OnDeviceRefresh::GetSystemServerImagePath(bool on_system,
return GetSystemOdexFilenameForApex(jar_path, config_.GetSystemServerIsa());
}
std::string jar_name = Basename(jar_path);
- std::string image_name = ReplaceFileExtension(jar_name, "art");
+ std::string image_name = ReplaceFileExtension(jar_name, kArtExtension);
const char* isa_str = GetInstructionSetString(config_.GetSystemServerIsa());
// Typically "/system/framework/oat/<isa>/services.art".
return ART_FORMAT("{}/oat/{}/{}", Dirname(jar_path), isa_str, image_name);
diff --git a/runtime/oat/image.h b/runtime/oat/image.h
index c21961d127..104143a1b5 100644
--- a/runtime/oat/image.h
+++ b/runtime/oat/image.h
@@ -19,6 +19,7 @@
#include <string.h>
+#include "base/file_utils.h"
#include "base/iteration_range.h"
#include "base/macros.h"
#include "base/os.h"
@@ -202,11 +203,11 @@ class PACKED(8) ImageHeader {
EXPORT PointerSize GetPointerSize() const;
static std::string GetOatLocationFromImageLocation(const std::string& image) {
- return GetLocationFromImageLocation(image, "oat");
+ return ReplaceFileExtension(image, kOatExtension);
}
static std::string GetVdexLocationFromImageLocation(const std::string& image) {
- return GetLocationFromImageLocation(image, "vdex");
+ return ReplaceFileExtension(image, kVdexExtension);
}
enum ImageMethod {
@@ -441,17 +442,6 @@ class PACKED(8) ImageHeader {
static const uint8_t kImageMagic[4];
static const uint8_t kImageVersion[4];
- static std::string GetLocationFromImageLocation(const std::string& image,
- const std::string& extension) {
- std::string filename = image;
- if (filename.length() <= 3) {
- filename += "." + extension;
- } else {
- filename.replace(filename.length() - 3, 3, extension);
- }
- return filename;
- }
-
uint8_t magic_[4];
uint8_t version_[4];
diff --git a/runtime/oat/oat_file_assistant.cc b/runtime/oat/oat_file_assistant.cc
index 0006ae8146..151c3a6ca9 100644
--- a/runtime/oat/oat_file_assistant.cc
+++ b/runtime/oat/oat_file_assistant.cc
@@ -61,8 +61,6 @@ using ::android::base::ConsumePrefix;
using ::android::base::StringPrintf;
static constexpr const char* kAnonymousDexPrefix = "Anonymous-DexFile@";
-static constexpr const char* kVdexExtension = ".vdex";
-static constexpr const char* kDmExtension = ".dm";
std::ostream& operator<<(std::ostream& stream, const OatFileAssistant::OatStatus status) {
switch (status) {
@@ -643,7 +641,7 @@ bool OatFileAssistant::DexLocationToOdexFilename(const std::string& location,
pos = file.rfind('.');
std::string base = pos != std::string::npos ? file.substr(0, pos) : file;
- *odex_filename = dir + "/" + base + ".odex";
+ *odex_filename = dir + "/" + base + kOdexExtension;
return true;
}
@@ -946,7 +944,7 @@ OatFileAssistant::OatFileInfo& OatFileAssistant::GetBestInfo() {
std::unique_ptr<gc::space::ImageSpace> OatFileAssistant::OpenImageSpace(const OatFile* oat_file) {
DCHECK(oat_file != nullptr);
- std::string art_file = ReplaceFileExtension(oat_file->GetLocation(), "art");
+ std::string art_file = ReplaceFileExtension(oat_file->GetLocation(), kArtExtension);
if (art_file.empty()) {
return nullptr;
}
diff --git a/runtime/runtime_image.cc b/runtime/runtime_image.cc
index fe1cf545ac..77548ee27e 100644
--- a/runtime/runtime_image.cc
+++ b/runtime/runtime_image.cc
@@ -1848,7 +1848,7 @@ std::string RuntimeImage::GetRuntimeImagePath(const std::string& app_data_dir,
const std::string& dex_location,
const std::string& isa) {
std::string basename = android::base::Basename(dex_location);
- std::string filename = ReplaceFileExtension(basename, "art");
+ std::string filename = ReplaceFileExtension(basename, kArtExtension);
return GetRuntimeImageDir(app_data_dir) + isa + "/" + filename;
}