Support compiling partial system server jars.

Before this change, odrefresh compiles system server jars atomically.
After this change, odrefresh can compile only the system server jars
whose artifacts are missing. This can benefit users in couple ways:
1. When a previous odrefresh run failed due to low storage space,
subsequent runs can continue from the failure point instead of starting
over.
2. When we update odrefresh to compile more things before a change has
been made to the build system to preopt those things at build-time
(e.g., b/203198541), this change can avoid too much regression on the
first boot time by not compiling things that are already preopted.
3. When some artifacts are missing from the system image for unknown
reasons, this change can avoid too much regression on the first boot
time. (This should rarely happen because artifacts' existence is checked
at built-time.)

This CL also includes some minor changes:
1. Introduce a struct `CompilationOptions` to represent what to compile
in a more structured way.
2. Update the comments about compilation space estimation based on the
latest observation.
3. Improve the boot animation progress reporting to reflect the real
number of compilations.
4. Fix the exit code returned on low storage space. (Was `kOkay`, which
was wrong because odsign does not sign artifacts on `kOkay`)

Bug: 203198541
Test: atest art_standalone_odrefresh_tests
Test: odsign_e2e_tests
Change-Id: Id13fa26fa2327a82daff8d8d6fdefe11cd0928a2
diff --git a/odrefresh/odrefresh.h b/odrefresh/odrefresh.h
index 54791d6..17003ee 100644
--- a/odrefresh/odrefresh.h
+++ b/odrefresh/odrefresh.h
@@ -18,8 +18,10 @@
 #define ART_ODREFRESH_ODREFRESH_H_
 
 #include <ctime>
+#include <functional>
 #include <memory>
 #include <optional>
+#include <set>
 #include <string>
 #include <vector>
 
@@ -36,6 +38,14 @@
 namespace art {
 namespace odrefresh {
 
+struct CompilationOptions {
+  // If not empty, compile the bootclasspath extensions for ISAs in the list.
+  std::vector<InstructionSet> compile_boot_extensions_for_isas;
+
+  // If not empty, compile the system server jars in the list.
+  std::set<std::string> system_server_jars_to_compile;
+};
+
 class OnDeviceRefresh final {
  public:
   explicit OnDeviceRefresh(const OdrConfig& config);
@@ -50,15 +60,18 @@
   // boolean indicating whether the system server should be compiled.
   WARN_UNUSED ExitCode
   CheckArtifactsAreUpToDate(OdrMetrics& metrics,
-                            /*out*/ std::vector<InstructionSet>* compile_boot_extensions,
-                            /*out*/ bool* compile_system_server) const;
+                            /*out*/ CompilationOptions* compilation_options) const;
 
   WARN_UNUSED ExitCode Compile(OdrMetrics& metrics,
-                               const std::vector<InstructionSet>& compile_boot_extensions,
-                               bool compile_system_server) const;
+                               const CompilationOptions& compilation_options) const;
 
   WARN_UNUSED bool RemoveArtifactsDirectory() const;
 
+  // Returns a set of all system server jars.
+  std::set<std::string> AllSystemServerJars() const {
+    return {systemserver_compilable_jars_.begin(), systemserver_compilable_jars_.end()};
+  }
+
  private:
   time_t GetExecutionTimeUsed() const;
 
@@ -75,8 +88,6 @@
   // Write ART APEX cache information to `kOnDeviceRefreshOdrefreshArtifactDirectory`.
   void WriteCacheInfo() const;
 
-  void ReportNextBootAnimationProgress(uint32_t current_compilation) const;
-
   std::vector<com::android::art::Component> GenerateBootClasspathComponents() const;
 
   std::vector<com::android::art::Component> GenerateBootExtensionCompilableComponents() const;
@@ -106,10 +117,12 @@
 
   // Checks whether all system_server artifacts are present. The artifacts are checked in their
   // order of compilation. Returns true if all are present, false otherwise.
+  // Adds the paths to the jars that are missing artifacts in `jars_with_missing_artifacts`.
   // If `checked_artifacts` is present, adds checked artifacts to `checked_artifacts`.
   WARN_UNUSED bool SystemServerArtifactsExist(
       bool on_system,
       /*out*/ std::string* error_msg,
+      /*out*/ std::set<std::string>* jars_missing_artifacts,
       /*out*/ std::vector<std::string>* checked_artifacts = nullptr) const;
 
   // Checks whether all boot extension artifacts are up to date. Returns true if all are present,
@@ -124,23 +137,27 @@
 
   // Checks whether all system_server artifacts are up to date. The artifacts are checked in their
   // order of compilation. Returns true if all are present, false otherwise.
+  // Adds the paths to the jars that needs to be compiled in `jars_to_compile`.
   // If `checked_artifacts` is present, adds checked artifacts to `checked_artifacts`.
-  WARN_UNUSED bool CheckSystemServerArtifactsAreUpToDate(
+  bool CheckSystemServerArtifactsAreUpToDate(
       OdrMetrics& metrics,
       const std::vector<com::android::apex::ApexInfo>& apex_info_list,
       const std::optional<com::android::art::CacheInfo>& cache_info,
+      /*out*/ std::set<std::string>* jars_to_compile,
       /*out*/ std::vector<std::string>* checked_artifacts) const;
 
   WARN_UNUSED bool CompileBootExtensionArtifacts(const InstructionSet isa,
                                                  const std::string& staging_dir,
                                                  OdrMetrics& metrics,
-                                                 uint32_t* dex2oat_invocation_count,
+                                                 const std::function<void()>& on_dex2oat_success,
                                                  std::string* error_msg) const;
 
-  WARN_UNUSED bool CompileSystemServerArtifacts(const std::string& staging_dir,
-                                                OdrMetrics& metrics,
-                                                uint32_t* dex2oat_invocation_count,
-                                                std::string* error_msg) const;
+  WARN_UNUSED bool CompileSystemServerArtifacts(
+      const std::string& staging_dir,
+      OdrMetrics& metrics,
+      const std::set<std::string>& system_server_jars_to_compile,
+      const std::function<void()>& on_dex2oat_success,
+      std::string* error_msg) const;
 
   // Configuration to use.
   const OdrConfig& config_;