diff options
author | 2022-12-21 12:43:56 +0000 | |
---|---|---|
committer | 2023-02-10 18:11:41 +0000 | |
commit | 2061ae2d4558acd8b79256f16f7a8d79a5d396e1 (patch) | |
tree | 1ab13a4d388193907e03f933e4be34da66823ca1 /artd | |
parent | cfcf634de88e04748630b37f781b793976e53d81 (diff) |
Add a function to list all files managed by ART Service.
This is going to be used in the "sweep" phase of the GC.
Bug: 254013425
Test: m test-art-host-gtest-art_libarttools_tests
Test: m test-art-host-gtest-art_artd_tests
Test: atest art_standalone_libarttools_tests
Test: atest atest art_standalone_artd_tests
Ignore-AOSP-First: ART Services.
Change-Id: Ie7a5bd6f805c370aa3c2e3a1ab1d5408e4552f83
Diffstat (limited to 'artd')
-rw-r--r-- | artd/path_utils.cc | 43 | ||||
-rw-r--r-- | artd/path_utils.h | 6 |
2 files changed, 49 insertions, 0 deletions
diff --git a/artd/path_utils.cc b/artd/path_utils.cc index 295b023923..cac9444b97 100644 --- a/artd/path_utils.cc +++ b/artd/path_utils.cc @@ -17,6 +17,8 @@ #include "path_utils.h" #include <filesystem> +#include <string> +#include <vector> #include "aidl/com/android/server/art/BnArtd.h" #include "android-base/errors.h" @@ -27,6 +29,7 @@ #include "file_utils.h" #include "fmt/format.h" #include "oat_file_assistant.h" +#include "tools/tools.h" namespace art { namespace artd { @@ -99,6 +102,15 @@ Result<std::string> GetAndroidDataOrError() { return result; } +Result<std::string> GetAndroidExpandOrError() { + std::string error_msg; + std::string result = GetAndroidExpandSafe(&error_msg); + if (!error_msg.empty()) { + return Error() << error_msg; + } + return result; +} + Result<std::string> GetArtRootOrError() { std::string error_msg; std::string result = GetArtRootSafe(&error_msg); @@ -110,6 +122,37 @@ Result<std::string> GetArtRootOrError() { } // namespace +Result<std::vector<std::string>> ListManagedFiles() { + std::string android_data = OR_RETURN(GetAndroidDataOrError()); + std::string android_expand = OR_RETURN(GetAndroidExpandOrError()); + + // See `art::tools::Glob` for the syntax. + std::vector<std::string> patterns = { + // Profiles for primary dex files. + android_data + "/misc/profiles/**", + // Artifacts for primary dex files. + android_data + "/dalvik-cache/**", + }; + + for (const std::string& data_root : {android_data, android_expand + "/*"}) { + // Artifacts for primary dex files. + patterns.push_back(data_root + "/app/*/*/oat/**"); + // Profiles and artifacts for secondary dex files. Those files are in app data directories, so + // we use more granular patterns to avoid accidentally deleting apps' files. + for (const char* user_dir : {"/user", "/user_de"}) { + std::string secondary_oat_dir = data_root + user_dir + "/*/*/**/oat"; + for (const char* maybe_tmp_suffix : {"", ".*.tmp"}) { + patterns.push_back(secondary_oat_dir + "/*.prof" + maybe_tmp_suffix); + patterns.push_back(secondary_oat_dir + "/*/*.odex" + maybe_tmp_suffix); + patterns.push_back(secondary_oat_dir + "/*/*.vdex" + maybe_tmp_suffix); + patterns.push_back(secondary_oat_dir + "/*/*.art" + maybe_tmp_suffix); + } + } + } + + return tools::Glob(patterns); +} + Result<void> ValidateDexPath(const std::string& dex_path) { OR_RETURN(ValidateAbsoluteNormalPath(dex_path)); if (!EndsWith(dex_path, ".apk") && !EndsWith(dex_path, ".jar")) { diff --git a/artd/path_utils.h b/artd/path_utils.h index 0cc017ea83..1063f9118e 100644 --- a/artd/path_utils.h +++ b/artd/path_utils.h @@ -17,6 +17,9 @@ #ifndef ART_ARTD_PATH_UTILS_H_ #define ART_ARTD_PATH_UTILS_H_ +#include <string> +#include <vector> + #include "aidl/com/android/server/art/BnArtd.h" #include "android-base/result.h" #include "base/file_utils.h" @@ -24,6 +27,9 @@ namespace art { namespace artd { +// Returns all existing files that are managed by artd. +android::base::Result<std::vector<std::string>> ListManagedFiles(); + android::base::Result<void> ValidateDexPath(const std::string& dex_path); android::base::Result<std::string> BuildArtBinPath(const std::string& binary_name); |