Introduce VMRuntime.isValidClassLoaderContext
In the PackageManager server we need to validate class loader contexts
that we receive from an untrusted process. In order to keep class loader
context parsing logic centralized within the runtime let's create an API
which returns whether or not the runtime can parse the encoded class
loader context.
Test: Build system image, open app using secondary dex
Test: atest atest com.android.server.pm.dex.DexManagerTests
Test: m test-art-host-gtest-class_loader_context_test
Change-Id: Ied676e3239f70a8ab9d066df79f377b7036b28b7
diff --git a/runtime/class_loader_context.h b/runtime/class_loader_context.h
index 73b8476..42ecd3d 100644
--- a/runtime/class_loader_context.h
+++ b/runtime/class_loader_context.h
@@ -202,6 +202,10 @@
static std::map<std::string, std::string> EncodeClassPathContextsForClassLoader(
jobject class_loader);
+ // Returns whether `encoded_class_loader_context` is a valid encoded ClassLoaderContext or
+ // EncodedUnsupportedClassLoaderContext.
+ static bool IsValidEncoding(const std::string& possible_encoded_class_loader_context);
+
struct ClassLoaderInfo {
// The type of this class loader.
ClassLoaderType type;