Merge "Start to add a function to compile staged APEXes"
diff --git a/virtualizationservice/.gitignore b/.gitignore
similarity index 100%
rename from virtualizationservice/.gitignore
rename to .gitignore
diff --git a/compos/service/java/com/android/server/compos/IsolatedCompilationJobService.java b/compos/service/java/com/android/server/compos/IsolatedCompilationJobService.java
index 60da96c..685d60c 100644
--- a/compos/service/java/com/android/server/compos/IsolatedCompilationJobService.java
+++ b/compos/service/java/com/android/server/compos/IsolatedCompilationJobService.java
@@ -68,20 +68,21 @@
         CompilationJob newJob = new CompilationJob(callback);
         mCurrentJob.set(newJob);
 
-        try {
-            // This can take some time - we need to start up a VM - so we do it on a separate
-            // thread. This thread exits as soon as the compilation Ttsk has been started (or
-            // there's a failure), and then compilation continues in composd and the VM.
-            new Thread("IsolatedCompilationJob_starter") {
-                @Override
-                public void run() {
+        // This can take some time - we need to start up a VM - so we do it on a separate
+        // thread. This thread exits as soon as the compilation Task has been started (or
+        // there's a failure), and then compilation continues in composd and the VM.
+        new Thread("IsolatedCompilationJob_starter") {
+            @Override
+            public void run() {
+                try {
                     newJob.start();
+                } catch (RuntimeException e) {
+                    Log.e(TAG, "Starting CompilationJob failed", e);
+                    newJob.stop(); // Just in case it managed to start before failure
+                    jobFinished(params, /*wantReschedule=*/ false);
                 }
-            }.start();
-        } catch (RuntimeException e) {
-            Log.e(TAG, "Starting CompilationJob failed", e);
-            return false; // We're finished
-        }
+            }
+        }.start();
         return true; // Job is running in the background
     }
 
diff --git a/compos/src/compilation.rs b/compos/src/compilation.rs
index b726a1e..44b4049 100644
--- a/compos/src/compilation.rs
+++ b/compos/src/compilation.rs
@@ -86,14 +86,20 @@
     android_root.push("system");
     env::set_var("ANDROID_ROOT", &android_root);
 
+    let mut art_apex_data = mountpoint.clone();
+    art_apex_data.push(output_dir_fd.to_string());
+    env::set_var("ART_APEX_DATA", &art_apex_data);
+
     let mut staging_dir = mountpoint;
     staging_dir.push(output_dir_fd.to_string());
     staging_dir.push("staging");
-    create_dir(&staging_dir).context("Create staging directory")?;
+    create_dir(&staging_dir)
+        .with_context(|| format!("Create staging directory {}", staging_dir.display()))?;
 
     let args = vec![
         "odrefresh".to_string(),
         format!("--zygote-arch={}", zygote_arch),
+        "--no-refresh".to_string(),
         format!("--staging-dir={}", staging_dir.display()),
         "--force-compile".to_string(),
     ];
@@ -103,7 +109,7 @@
         // TODO(161471326): On success, sign all files in the output directory.
         Ok(()) => Ok(CompilerOutput::ExitCode(0)),
         Err(minijail::Error::ReturnCode(exit_code)) => {
-            error!("dex2oat failed with exit code {}", exit_code);
+            error!("odrefresh failed with exit code {}", exit_code);
             Ok(CompilerOutput::ExitCode(exit_code as i8))
         }
         Err(e) => {