Specify odrefresh timeout by flags

Bug: 202830861
Test: atest android.compos.test.ComposTestCase#testOdrefresh
Change-Id: I5aa7d99dc58ecb40b4bf5519b658c2a828fec567
diff --git a/compos/composd/Android.bp b/compos/composd/Android.bp
index 9887483..2a24b7a 100644
--- a/compos/composd/Android.bp
+++ b/compos/composd/Android.bp
@@ -19,6 +19,7 @@
         "libcomposd_native_rust",
         "libnum_traits",
         "liblog_rust",
+        "librustutils",
     ],
     proc_macros: ["libnum_derive"],
     apex_available: [
diff --git a/compos/composd/src/odrefresh.rs b/compos/composd/src/odrefresh.rs
index 2dfc3a1..8c3febf 100644
--- a/compos/composd/src/odrefresh.rs
+++ b/compos/composd/src/odrefresh.rs
@@ -20,6 +20,7 @@
 use compos_common::VMADDR_CID_ANY;
 use num_derive::FromPrimitive;
 use num_traits::FromPrimitive;
+use rustutils::system_properties;
 use std::process::Command;
 
 // TODO: What if this changes?
@@ -37,14 +38,23 @@
     CleanupFailed = EX_MAX + 4,
 }
 
+fn need_extra_time() -> Result<bool> {
+    // Special case to add more time in nested VM
+    let value = system_properties::read("ro.build.product")?;
+    Ok(value == "vsoc_x86_64" || value == "vsoc_x86")
+}
+
 pub fn run_forced_compile(target_dir: &str) -> Result<ExitCode> {
     // We don`t need to capture stdout/stderr - odrefresh writes to the log
-    let mut odrefresh = Command::new(ODREFRESH_BIN)
+    let mut cmdline = Command::new(ODREFRESH_BIN);
+    if need_extra_time()? {
+        cmdline.arg("--max-execution-seconds=480").arg("--max-child-process-seconds=150");
+    }
+    cmdline
         .arg(format!("--use-compilation-os={}", VMADDR_CID_ANY as i32))
         .arg(format!("--dalvik-cache={}", target_dir))
-        .arg("--force-compile")
-        .spawn()
-        .context("Running odrefresh")?;
+        .arg("--force-compile");
+    let mut odrefresh = cmdline.spawn().context("Running odrefresh")?;
 
     // TODO: timeout?
     let status = odrefresh.wait()?;