summaryrefslogtreecommitdiff
path: root/libartbase/base/file_utils.h
diff options
context:
space:
mode:
author Orion Hodson <oth@google.com> 2021-02-10 13:52:40 +0000
committer Treehugger Robot <treehugger-gerrit@google.com> 2021-02-17 11:41:42 +0000
commitd6e00a754bb5a7f041a4506b0602293fd9cce0e0 (patch)
tree605c24f4b0d1d72f3c3dd633d3ad1c8bad6e2f4e /libartbase/base/file_utils.h
parent3d2b93e6acb4e7ac6fc808f17813975f250dbf89 (diff)
libartbase: add utilities for on-device signing files
Bug: 160683548 Test: art_file_utils_test.cc Change-Id: I17967eebda0a565c033b095fb1deb6ceeaa3760d
Diffstat (limited to 'libartbase/base/file_utils.h')
-rw-r--r--libartbase/base/file_utils.h67
1 files changed, 48 insertions, 19 deletions
diff --git a/libartbase/base/file_utils.h b/libartbase/base/file_utils.h
index bcab28826a..67caaa6cee 100644
--- a/libartbase/base/file_utils.h
+++ b/libartbase/base/file_utils.h
@@ -28,9 +28,12 @@
namespace art {
static constexpr const char* kAndroidArtApexDefaultPath = "/apex/com.android.art";
+static constexpr const char* kArtApexDataDefaultPath = "/data/misc/apexdata/com.android.art";
static constexpr const char* kAndroidConscryptApexDefaultPath = "/apex/com.android.conscrypt";
static constexpr const char* kAndroidI18nApexDefaultPath = "/apex/com.android.i18n";
+static constexpr const char* kArtImageExtension = "art";
+
// These methods return the Android Root, which is the historical location of
// the Android "system" directory, containing the built Android artifacts. On
// target, this is normally "/system". On host this is usually a directory under
@@ -62,30 +65,53 @@ std::string GetAndroidData();
// Find $ANDROID_DATA, /data, or return an empty string.
std::string GetAndroidDataSafe(/*out*/ std::string* error_msg);
+// Find $ART_APEX_DATA, /data/misc/apexdata/com.android.art, or abort.
+std::string GetArtApexData();
+
// Returns the default boot image location (ANDROID_ROOT/framework/boot.art).
// Returns an empty string if ANDROID_ROOT is not set.
std::string GetDefaultBootImageLocation(std::string* error_msg);
-// Returns the default boot image location, based on the passed android root.
+// Returns the default boot image location, based on the passed `android_root`.
std::string GetDefaultBootImageLocation(const std::string& android_root);
-// Returns the dalvik-cache location, with subdir appended. Returns the empty string if the cache
-// could not be found.
-std::string GetDalvikCache(const char* subdir);
-
// Return true if we found the dalvik cache and stored it in the dalvik_cache argument.
-// have_android_data will be set to true if we have an ANDROID_DATA that exists,
-// dalvik_cache_exists will be true if there is a dalvik-cache directory that is present.
-// The flag is_global_cache tells whether this cache is /data/dalvik-cache.
+// `have_android_data` will be set to true if we have an ANDROID_DATA that exists,
+// `dalvik_cache_exists` will be true if there is a dalvik-cache directory that is present.
+// The flag `is_global_cache` tells whether this cache is /data/dalvik-cache.
void GetDalvikCache(const char* subdir, bool create_if_absent, std::string* dalvik_cache,
bool* have_android_data, bool* dalvik_cache_exists, bool* is_global_cache);
// Returns the absolute dalvik-cache path for a DexFile or OatFile. The path returned will be
-// rooted at cache_location.
-bool GetDalvikCacheFilename(const char* file_location, const char* cache_location,
+// rooted at `cache_location`.
+bool GetDalvikCacheFilename(const char* location, const char* cache_location,
std::string* filename, std::string* error_msg);
-// Returns the system location for an image
+// Gets the oat location in the ART APEX data directory for a DEX file installed anywhere other
+// than in an APEX. Returns the oat filename if `location` is valid, empty string otherwise.
+std::string GetApexDataOatFilename(std::string_view location, InstructionSet isa);
+
+// Gets the odex location in the ART APEX data directory for a DEX file installed anywhere other
+// than in an APEX. Returns the odex filename if `location` is valid, empty string otherwise.
+std::string GetApexDataOdexFilename(std::string_view location, InstructionSet isa);
+
+// Gets the boot image in the ART APEX data directory for a DEX file installed anywhere other
+// than in an APEX. Returns the image location if `dex_location` is valid, empty string otherwise.
+std::string GetApexDataBootImage(std::string_view dex_location);
+
+// Gets the image in the ART APEX data directory for a DEX file installed installed anywhere other
+// than in an APEX. Returns the image location if `dex_location` is valid, empty string otherwise.
+std::string GetApexDataImage(std::string_view dex_location);
+
+// Gets the name of a file in the ART APEX directory dalvik-cache. This method assumes the
+// `dex_location` is for an application and that the `dex_location` is not within an APEX.
+// Returns the location of the file in the dalvik-cache
+std::string GetApexDataDalvikCacheFilename(std::string_view dex_location,
+ InstructionSet isa,
+ std::string_view file_extension);
+
+// Returns the system location for an image. This method inserts the `isa` between the
+// dirname and basename of `location`.
std::string GetSystemImageFilename(const char* location, InstructionSet isa);
// Returns the vdex filename for the given oat filename.
@@ -96,28 +122,31 @@ std::string GetVdexFilename(const std::string& oat_filename);
// a period, and `new_extension`.
// Example: ReplaceFileExtension("foo.bar", "abc") == "foo.abc"
// ReplaceFileExtension("foo", "abc") == "foo.abc"
-std::string ReplaceFileExtension(const std::string& filename, const std::string& new_extension);
+std::string ReplaceFileExtension(std::string_view filename, std::string_view new_extension);
// Return whether the location is on /apex/com.android.art
-bool LocationIsOnArtModule(const char* location);
+bool LocationIsOnArtModule(std::string_view location);
+
+// Return whether the location is on /data/misc/apexdata/com.android.art/.
+bool LocationIsOnArtApexData(std::string_view location);
// Return whether the location is on /apex/com.android.conscrypt
-bool LocationIsOnConscryptModule(const char* location);
+bool LocationIsOnConscryptModule(std::string_view location);
// Return whether the location is on /apex/com.android.i18n
-bool LocationIsOnI18nModule(const char* location);
+bool LocationIsOnI18nModule(std::string_view location);
// Return whether the location is on system (i.e. android root).
bool LocationIsOnSystem(const char* location);
-// Return whether the location is on system/framework (i.e. android_root/framework).
-bool LocationIsOnSystemFramework(const char* location);
+// Return whether the location is on system/framework (i.e. $ANDROID_ROOT/framework).
+bool LocationIsOnSystemFramework(std::string_view location);
// Return whether the location is on system_ext/framework
-bool LocationIsOnSystemExtFramework(const char* location);
+bool LocationIsOnSystemExtFramework(std::string_view location);
// Return whether the location is on /apex/.
-bool LocationIsOnApex(const char* location);
+bool LocationIsOnApex(std::string_view location);
// Compare the ART module root against android root. Returns true if they are
// both known and distinct. This is meant to be a proxy for 'running with apex'.