Only return the vdex file as an optimization file when we don't use the oat file.

Test: adb shell dumpsys pinner doesn't return duplicate vdex entries.
Bug: 217137351
Change-Id: If162da2acd3cbccc5fe4f06a5911c0fc0f49544b
diff --git a/runtime/native/dalvik_system_DexFile.cc b/runtime/native/dalvik_system_DexFile.cc
index f8ad7f1..d714206 100644
--- a/runtime/native/dalvik_system_DexFile.cc
+++ b/runtime/native/dalvik_system_DexFile.cc
@@ -820,6 +820,7 @@
   std::string vdex_filename;
   // Check if the file is in the boot classpath by looking at image spaces which
   // have oat files.
+  bool is_vdex_only = false;
   for (gc::space::ImageSpace* space : Runtime::Current()->GetHeap()->GetBootImageSpaces()) {
     const OatFile* oat_file = space->GetOatFile();
     if (oat_file != nullptr) {
@@ -829,6 +830,7 @@
                 filename.c_str()) {
           oat_filename = GetSystemImageFilename(oat_file->GetLocation().c_str(),
                                                 target_instruction_set);
+          is_vdex_only = oat_file->IsBackedByVdexOnly();
           break;
         }
       }
@@ -851,26 +853,33 @@
     }
 
     oat_filename = best_oat_file->GetLocation();
-  }
-  vdex_filename = GetVdexFilename(oat_filename);
-
-  ScopedLocalRef<jstring> jvdexFilename(env, env->NewStringUTF(vdex_filename.c_str()));
-  if (jvdexFilename.get() == nullptr) {
-    return nullptr;
+    is_vdex_only = best_oat_file->IsBackedByVdexOnly();
   }
   ScopedLocalRef<jstring> joatFilename(env, env->NewStringUTF(oat_filename.c_str()));
   if (joatFilename.get() == nullptr) {
     return nullptr;
   }
 
-  // Now create output array and copy the set into it.
-  jobjectArray result = env->NewObjectArray(2,
-                                            WellKnownClasses::java_lang_String,
-                                            nullptr);
-  env->SetObjectArrayElement(result, 0, jvdexFilename.get());
-  env->SetObjectArrayElement(result, 1, joatFilename.get());
+  if (is_vdex_only) {
+    jobjectArray result = env->NewObjectArray(1,
+                                              WellKnownClasses::java_lang_String,
+                                              nullptr);
+    env->SetObjectArrayElement(result, 0, joatFilename.get());
+    return result;
+  } else {
+    vdex_filename = GetVdexFilename(oat_filename);
+    ScopedLocalRef<jstring> jvdexFilename(env, env->NewStringUTF(vdex_filename.c_str()));
+    if (jvdexFilename.get() == nullptr) {
+      return nullptr;
+    }
 
-  return result;
+    jobjectArray result = env->NewObjectArray(2,
+                                              WellKnownClasses::java_lang_String,
+                                              nullptr);
+    env->SetObjectArrayElement(result, 0, jvdexFilename.get());
+    env->SetObjectArrayElement(result, 1, joatFilename.get());
+    return result;
+  }
 }
 
 static jlong DexFile_getStaticSizeOfDexFile(JNIEnv* env, jclass, jobject cookie) {