Clean up UpdateOatFile for app images

Check that for the there is only one oat file name for the app image
case.

Avoid calling GetOatElfInformation unless necessary.

Bug: 22858531
Change-Id: I88d258a1cc2823956ecc4fca9a6f7b2d3c4b986e
diff --git a/compiler/image_writer.cc b/compiler/image_writer.cc
index 8b7fbf6..60dfcfb 100644
--- a/compiler/image_writer.cc
+++ b/compiler/image_writer.cc
@@ -2276,10 +2276,10 @@
 
 void ImageWriter::UpdateOatFile(File* oat_file, const char* oat_filename) {
   DCHECK(oat_file != nullptr);
-  size_t oat_loaded_size = 0;
-  size_t oat_data_offset = 0;
-  ElfWriter::GetOatElfInformation(oat_file, &oat_loaded_size, &oat_data_offset);
-
+  if (compile_app_image_) {
+    CHECK_EQ(oat_filenames_.size(), 1u) << "App image should have no next image.";
+    return;
+  }
   ImageInfo& cur_image_info = GetImageInfo(oat_filename);
 
   // Update the oat_offset of the next image info.
@@ -2288,6 +2288,9 @@
 
   it++;
   if (it != oat_filenames_.end()) {
+    size_t oat_loaded_size = 0;
+    size_t oat_data_offset = 0;
+    ElfWriter::GetOatElfInformation(oat_file, &oat_loaded_size, &oat_data_offset);
     // There is a following one.
     ImageInfo& next_image_info = GetImageInfo(*it);
     next_image_info.oat_offset_ = cur_image_info.oat_offset_ + oat_loaded_size;