Update VMRuntime.isBootClassPathOnDisk()...

... for the new boot image location specification.
In particular, use only the first component and, if there is
no path, use path from the first boot class path component.

Test: aosp_taimen-userdebug boots
Test: adb root && \
      adb shell stop && \
      adb shell setprop dalvik.vm.boot-image \
          'boot.art:boot-framework.art' &&
      adb shell start  # Starts correctly.
Test: adb root && \
      adb shell stop && \
      adb shell setprop dalvik.vm.boot-image \
          'boot.art:/system/framework/boot-framework.art' &&
      adb shell start  # Starts correctly.
Bug: 119868597
Change-Id: Ifae2a005b7c6b8625d744eca2df763e3f6f5d0fb
diff --git a/runtime/gc/space/image_space.cc b/runtime/gc/space/image_space.cc
index b3d5c31..948debf 100644
--- a/runtime/gc/space/image_space.cc
+++ b/runtime/gc/space/image_space.cc
@@ -296,45 +296,6 @@
   return hdr;
 }
 
-std::unique_ptr<ImageHeader> ImageSpace::ReadImageHeader(const char* image_location,
-                                                         const InstructionSet image_isa,
-                                                         ImageSpaceLoadingOrder order,
-                                                         std::string* error_msg) {
-  std::string system_filename;
-  bool has_system = false;
-  std::string cache_filename;
-  bool has_cache = false;
-  bool dalvik_cache_exists = false;
-  bool is_global_cache = false;
-  if (FindImageFilename(image_location,
-                        image_isa,
-                        &system_filename,
-                        &has_system,
-                        &cache_filename,
-                        &dalvik_cache_exists,
-                        &has_cache,
-                        &is_global_cache)) {
-    if (order == ImageSpaceLoadingOrder::kSystemFirst) {
-      if (has_system) {
-        return ReadSpecificImageHeader(system_filename.c_str(), error_msg);
-      }
-      if (has_cache) {
-        return ReadSpecificImageHeader(cache_filename.c_str(), error_msg);
-      }
-    } else {
-      if (has_cache) {
-        return ReadSpecificImageHeader(cache_filename.c_str(), error_msg);
-      }
-      if (has_system) {
-        return ReadSpecificImageHeader(system_filename.c_str(), error_msg);
-      }
-    }
-  }
-
-  *error_msg = StringPrintf("Unable to find image file for %s", image_location);
-  return nullptr;
-}
-
 static bool CanWriteToDalvikCache(const InstructionSet isa) {
   const std::string dalvik_cache = GetDalvikCache(GetInstructionSetString(isa));
   if (access(dalvik_cache.c_str(), O_RDWR) == 0) {
@@ -3321,6 +3282,40 @@
   return true;
 }
 
+bool ImageSpace::IsBootClassPathOnDisk(InstructionSet image_isa) {
+  Runtime* runtime = Runtime::Current();
+  BootImageLayout layout(runtime->GetImageLocation(),
+                         ArrayRef<const std::string>(runtime->GetBootClassPath()),
+                         ArrayRef<const std::string>(runtime->GetBootClassPathLocations()));
+  const std::string image_location = layout.GetPrimaryImageLocation();
+  ImageSpaceLoadingOrder order = runtime->GetImageSpaceLoadingOrder();
+  std::unique_ptr<ImageHeader> image_header;
+  std::string error_msg;
+
+  std::string system_filename;
+  bool has_system = false;
+  std::string cache_filename;
+  bool has_cache = false;
+  bool dalvik_cache_exists = false;
+  bool is_global_cache = false;
+  if (FindImageFilename(image_location.c_str(),
+                        image_isa,
+                        &system_filename,
+                        &has_system,
+                        &cache_filename,
+                        &dalvik_cache_exists,
+                        &has_cache,
+                        &is_global_cache)) {
+    DCHECK(has_system || has_cache);
+    const std::string& filename = (order == ImageSpaceLoadingOrder::kSystemFirst)
+        ? (has_system ? system_filename : cache_filename)
+        : (has_cache ? cache_filename : system_filename);
+    image_header = ReadSpecificImageHeader(filename.c_str(), &error_msg);
+  }
+
+  return image_header != nullptr;
+}
+
 static constexpr uint64_t kLowSpaceValue = 50 * MB;
 static constexpr uint64_t kTmpFsSentinelValue = 384 * MB;
 
diff --git a/runtime/gc/space/image_space.h b/runtime/gc/space/image_space.h
index 2a90d8b..2b42381 100644
--- a/runtime/gc/space/image_space.h
+++ b/runtime/gc/space/image_space.h
@@ -137,13 +137,8 @@
                                                         std::string* error_msg)
       REQUIRES_SHARED(Locks::mutator_lock_);
 
-  // Reads the image header from the specified image location for the
-  // instruction set image_isa. Returns null on failure, with
-  // reason in error_msg.
-  static std::unique_ptr<ImageHeader> ReadImageHeader(const char* image_location,
-                                                      InstructionSet image_isa,
-                                                      ImageSpaceLoadingOrder order,
-                                                      std::string* error_msg);
+  // Checks whether we have a primary boot image on the disk.
+  static bool IsBootClassPathOnDisk(InstructionSet image_isa);
 
   // Give access to the OatFile.
   const OatFile* GetOatFile() const;
diff --git a/runtime/native/dalvik_system_VMRuntime.cc b/runtime/native/dalvik_system_VMRuntime.cc
index bb05e60..a4dc042 100644
--- a/runtime/native/dalvik_system_VMRuntime.cc
+++ b/runtime/native/dalvik_system_VMRuntime.cc
@@ -679,11 +679,7 @@
     env->ThrowNew(iae.get(), message.c_str());
     return JNI_FALSE;
   }
-  std::string error_msg;
-  Runtime* runtime = Runtime::Current();
-  std::unique_ptr<ImageHeader> image_header(gc::space::ImageSpace::ReadImageHeader(
-      runtime->GetImageLocation().c_str(), isa, runtime->GetImageSpaceLoadingOrder(), &error_msg));
-  return image_header.get() != nullptr;
+  return gc::space::ImageSpace::IsBootClassPathOnDisk(isa);
 }
 
 static jstring VMRuntime_getCurrentInstructionSet(JNIEnv* env, jclass) {