Modify --compilation-os-mode to not omit APEX timestamps.

We are passing APEX timestamps to the VM now, so there is no need to
omit it any longer.

Bug: 211458160
Test: atest odsign_e2e_tests
Change-Id: Ia7b9626fda81668c5f99d10ba2b288fad71255d5
diff --git a/odrefresh/CacheInfo.xsd b/odrefresh/CacheInfo.xsd
index ff83914..1cbef8a 100644
--- a/odrefresh/CacheInfo.xsd
+++ b/odrefresh/CacheInfo.xsd
@@ -51,9 +51,8 @@
     <xs:attribute name="versionCode" type="xs:long" use="required" />
     <!-- Module versionName for the active APEX from `/apex/apex-info-list.xml`. -->
     <xs:attribute name="versionName" type="xs:string" use="required" />
-    <!-- Module lastUpdateMillis for the active APEX from `/apex/apex-info-list.xml`. This field is
-      not set if the cache info is generated in Compilation OS. -->
-    <xs:attribute name="lastUpdateMillis" type="xs:long" />
+    <!-- Module lastUpdateMillis for the active APEX from `/apex/apex-info-list.xml`. -->
+    <xs:attribute name="lastUpdateMillis" type="xs:long" use="required" />
   </xs:complexType>
 
   <!-- Components of a classpath. -->
diff --git a/odrefresh/odrefresh.cc b/odrefresh/odrefresh.cc
index 4a489f7..315f589 100644
--- a/odrefresh/odrefresh.cc
+++ b/odrefresh/odrefresh.cc
@@ -182,26 +182,24 @@
 
 // Returns cache provenance information based on the current APEX version and filesystem
 // information.
-art_apex::ModuleInfo GenerateModuleInfo(const apex::ApexInfo& apex_info,
-                                        bool include_last_update_millis) {
+art_apex::ModuleInfo GenerateModuleInfo(const apex::ApexInfo& apex_info) {
   // The lastUpdateMillis is an addition to ApexInfoList.xsd to support samegrade installs.
   int64_t last_update_millis =
       apex_info.hasLastUpdateMillis() ? apex_info.getLastUpdateMillis() : 0;
-  return art_apex::ModuleInfo{
-      apex_info.getModuleName(),
-      apex_info.getVersionCode(),
-      apex_info.getVersionName(),
-      include_last_update_millis ? std::make_optional(last_update_millis) : std::nullopt};
+  return art_apex::ModuleInfo{apex_info.getModuleName(),
+                              apex_info.getVersionCode(),
+                              apex_info.getVersionName(),
+                              last_update_millis};
 }
 
 // Returns cache provenance information for all APEXes.
 std::vector<art_apex::ModuleInfo> GenerateModuleInfoList(
-    const std::vector<apex::ApexInfo>& apex_info_list, bool include_last_update_millis) {
+    const std::vector<apex::ApexInfo>& apex_info_list) {
   std::vector<art_apex::ModuleInfo> module_info_list;
   std::transform(apex_info_list.begin(),
                  apex_info_list.end(),
                  std::back_inserter(module_info_list),
-                 std::bind(GenerateModuleInfo, std::placeholders::_1, include_last_update_millis));
+                 GenerateModuleInfo);
   return module_info_list;
 }
 
@@ -659,13 +657,9 @@
     return Errorf("Could not update {}: no ART APEX info", QuotePath(cache_info_filename_));
   }
 
-  // We don't write lastUpdateMillis to the cache info in Compilation OS because APEX timestamps
-  // inside the VM are different from those outside (b/211458160).
-  bool include_last_update_millis = !config_.GetCompilationOsMode();
-  art_apex::ModuleInfo art_module_info =
-      GenerateModuleInfo(art_apex_info.value(), include_last_update_millis);
+  art_apex::ModuleInfo art_module_info = GenerateModuleInfo(art_apex_info.value());
   std::vector<art_apex::ModuleInfo> module_info_list =
-      GenerateModuleInfoList(apex_info_list.value(), include_last_update_millis);
+      GenerateModuleInfoList(apex_info_list.value());
 
   std::optional<std::vector<art_apex::Component>> bcp_components =
       GenerateBootClasspathComponents();
@@ -888,21 +882,16 @@
     return false;
   }
 
-  // We don't check lastUpdateMillis if the cache info is generated in Compilation OS because APEX
-  // timestamps inside the VM are different from those outside (b/211458160). The cache info will be
-  // updated in the `--compile` phase to fill this field.
-  if (!(cache_info->hasCompilationOsMode() && cache_info->getCompilationOsMode())) {
-    // Check lastUpdateMillis for samegrade installs. If `cached_art_info` is missing the
-    // lastUpdateMillis field then it is not current with the schema used by this binary so treat
-    // it as a samegrade update. Otherwise check whether the lastUpdateMillis changed.
-    const int64_t cached_art_last_update_millis =
-        cached_art_info->hasLastUpdateMillis() ? cached_art_info->getLastUpdateMillis() : -1;
-    if (cached_art_last_update_millis != art_apex_info.getLastUpdateMillis()) {
-      LOG(INFO) << "ART APEX last update time mismatch (" << cached_art_last_update_millis
-                << " != " << art_apex_info.getLastUpdateMillis() << ").";
-      metrics.SetTrigger(OdrMetrics::Trigger::kApexVersionMismatch);
-      return false;
-    }
+  // Check lastUpdateMillis for samegrade installs. If `cached_art_info` is missing the
+  // lastUpdateMillis field then it is not current with the schema used by this binary so treat
+  // it as a samegrade update. Otherwise check whether the lastUpdateMillis changed.
+  const int64_t cached_art_last_update_millis =
+      cached_art_info->hasLastUpdateMillis() ? cached_art_info->getLastUpdateMillis() : -1;
+  if (cached_art_last_update_millis != art_apex_info.getLastUpdateMillis()) {
+    LOG(INFO) << "ART APEX last update time mismatch (" << cached_art_last_update_millis
+              << " != " << art_apex_info.getLastUpdateMillis() << ").";
+    metrics.SetTrigger(OdrMetrics::Trigger::kApexVersionMismatch);
+    return false;
   }
 
   // Check boot class components.
@@ -1039,15 +1028,13 @@
       return compile_all();
     }
 
-    if (!(cache_info->hasCompilationOsMode() && cache_info->getCompilationOsMode())) {
-      if (!cached_module_info->hasLastUpdateMillis() ||
-          cached_module_info->getLastUpdateMillis() != current_apex_info.getLastUpdateMillis()) {
-        LOG(INFO) << "APEX (" << apex_name << ") last update time mismatch ("
-                  << cached_module_info->getLastUpdateMillis()
-                  << " != " << current_apex_info.getLastUpdateMillis() << ").";
-        metrics.SetTrigger(OdrMetrics::Trigger::kApexVersionMismatch);
-        return compile_all();
-      }
+    if (!cached_module_info->hasLastUpdateMillis() ||
+        cached_module_info->getLastUpdateMillis() != current_apex_info.getLastUpdateMillis()) {
+      LOG(INFO) << "APEX (" << apex_name << ") last update time mismatch ("
+                << cached_module_info->getLastUpdateMillis()
+                << " != " << current_apex_info.getLastUpdateMillis() << ").";
+      metrics.SetTrigger(OdrMetrics::Trigger::kApexVersionMismatch);
+      return compile_all();
     }
   }
 
@@ -1313,18 +1300,6 @@
     return ExitCode::kCleanupFailed;
   }
 
-  // If the cache info was genereted in Compilation OS, update it to fill the lastUpdateMillis
-  // field.
-  if (!compilation_required && cache_info->hasCompilationOsMode() &&
-      cache_info->getCompilationOsMode()) {
-    compilation_options->update_cache_info_only = true;
-    // Return `kCompilationRequired` though there is nothing to compile. This is needed so that
-    // odsign will invoke `odrefresh --compile` and therefore we can update the cache info in that
-    // phase. We cannot update the cache info here because `odrefresh --check` should not modify any
-    // file. Otherwise, it will break odsign's signature verification.
-    compilation_required = true;
-  }
-
   return compilation_required ? ExitCode::kCompilationRequired : ExitCode::kOkay;
 }
 
@@ -1625,11 +1600,6 @@
     return ExitCode::kCleanupFailed;
   }
 
-  if (compilation_options.update_cache_info_only) {
-    metrics.SetStage(OdrMetrics::Stage::kComplete);
-    return ExitCode::kCompilationSuccess;
-  }
-
   if (!config_.GetStagingDir().empty()) {
     staging_dir = config_.GetStagingDir().c_str();
   } else {
diff --git a/odrefresh/odrefresh.h b/odrefresh/odrefresh.h
index 21e5f61..f8bfefb 100644
--- a/odrefresh/odrefresh.h
+++ b/odrefresh/odrefresh.h
@@ -39,9 +39,6 @@
 namespace odrefresh {
 
 struct CompilationOptions {
-  // If true, update the cache info only and do not compile anything.
-  bool update_cache_info_only = false;
-
   // If not empty, compile the bootclasspath jars for ISAs in the list.
   std::vector<InstructionSet> compile_boot_classpath_for_isas;
 
diff --git a/test/odsign/test-src/com/android/tests/odsign/OdrefreshHostTest.java b/test/odsign/test-src/com/android/tests/odsign/OdrefreshHostTest.java
index 7a5aa0d..67d45b3 100644
--- a/test/odsign/test-src/com/android/tests/odsign/OdrefreshHostTest.java
+++ b/test/odsign/test-src/com/android/tests/odsign/OdrefreshHostTest.java
@@ -188,7 +188,6 @@
 
         String cacheInfo = getDevice().pullFileContents(CACHE_INFO_FILE);
         assertThat(cacheInfo).contains("compilationOsMode=\"true\"");
-        assertThat(cacheInfo).doesNotContain("lastUpdateMillis=");
 
         // Compilation OS does not write the compilation log to the host.
         mTestUtils.removeCompilationLogToAvoidBackoff();
@@ -197,15 +196,9 @@
         timeMs = getCurrentTimeMs();
         getDevice().executeShellV2Command(ODREFRESH_COMMAND);
 
-        // odrefresh should not re-compile anything regardless of the missing `lastUpdateMillis`
-        // field.
+        // odrefresh should not re-compile anything.
         assertArtifactsNotModifiedAfter(getZygoteArtifacts(), timeMs);
         assertArtifactsNotModifiedAfter(getSystemServerArtifacts(), timeMs);
-
-        // The cache info should be updated.
-        cacheInfo = getDevice().pullFileContents(CACHE_INFO_FILE);
-        assertThat(cacheInfo).doesNotContain("compilationOsMode=\"true\"");
-        assertThat(cacheInfo).contains("lastUpdateMillis=");
     }
 
     /**