Do not try to compile resource-only dex files.

This changes behavior in the case where we are asked to load a dex
file that does not exist or has no classes.dex entry.

Previously we would run dex2oat, which would log an error message and
fail. Now we skip running dex2oat, we report the DexOptStatus as
kNoDexOptNeeded, and we do not try to fall back to the missing
original dex files.

Bug: 21722039
(cherry picked from commit cb44b11a926696e34b3dc44288e762b4303cc128)

Change-Id: I84a85dc9ece54bcc0a5283f871e09bf68471c6e7
diff --git a/runtime/oat_file_assistant.cc b/runtime/oat_file_assistant.cc
index 094d8b7..b28adf9 100644
--- a/runtime/oat_file_assistant.cc
+++ b/runtime/oat_file_assistant.cc
@@ -151,7 +151,7 @@
     return kSelfPatchOatNeeded;
   }
 
-  return kDex2OatNeeded;
+  return HasOriginalDexFiles() ? kDex2OatNeeded : kNoDexOptNeeded;
 }
 
 bool OatFileAssistant::MakeUpToDate(std::string* error_msg) {
@@ -241,6 +241,14 @@
   return dex_files;
 }
 
+bool OatFileAssistant::HasOriginalDexFiles() {
+  // Ensure GetRequiredDexChecksum has been run so that
+  // has_original_dex_files_ is initialized. We don't care about the result of
+  // GetRequiredDexChecksum.
+  GetRequiredDexChecksum();
+  return has_original_dex_files_;
+}
+
 const std::string* OatFileAssistant::OdexFileName() {
   if (!cached_odex_file_name_attempted_) {
     CHECK(dex_location_ != nullptr) << "OatFileAssistant: null dex location";
@@ -817,17 +825,19 @@
 }
 
 const uint32_t* OatFileAssistant::GetRequiredDexChecksum() {
-  if (!required_dex_checksum_attempted) {
-    required_dex_checksum_attempted = true;
-    required_dex_checksum_found = false;
+  if (!required_dex_checksum_attempted_) {
+    required_dex_checksum_attempted_ = true;
+    required_dex_checksum_found_ = false;
     std::string error_msg;
     CHECK(dex_location_ != nullptr) << "OatFileAssistant provided no dex location";
-    if (DexFile::GetChecksum(dex_location_, &cached_required_dex_checksum, &error_msg)) {
-      required_dex_checksum_found = true;
+    if (DexFile::GetChecksum(dex_location_, &cached_required_dex_checksum_, &error_msg)) {
+      required_dex_checksum_found_ = true;
+      has_original_dex_files_ = true;
     } else {
       // This can happen if the original dex file has been stripped from the
       // apk.
       VLOG(oat) << "OatFileAssistant: " << error_msg;
+      has_original_dex_files_ = false;
 
       // Get the checksum from the odex if we can.
       const OatFile* odex_file = GetOdexFile();
@@ -835,13 +845,13 @@
         const OatFile::OatDexFile* odex_dex_file = odex_file->GetOatDexFile(
             dex_location_, nullptr, false);
         if (odex_dex_file != nullptr) {
-          cached_required_dex_checksum = odex_dex_file->GetDexFileLocationChecksum();
-          required_dex_checksum_found = true;
+          cached_required_dex_checksum_ = odex_dex_file->GetDexFileLocationChecksum();
+          required_dex_checksum_found_ = true;
         }
       }
     }
   }
-  return required_dex_checksum_found ? &cached_required_dex_checksum : nullptr;
+  return required_dex_checksum_found_ ? &cached_required_dex_checksum_ : nullptr;
 }
 
 const OatFile* OatFileAssistant::GetOdexFile() {