odrefresh: Run with background threads/cpu_set in CompOS

odrefresh unconditionally sets the number of threads and cpu set
arguments of dex2oat to 'dalvik.vm.boot-dex2oat-threads' and
'dalvik.vm.boot-dex2oat-cpu-set', respectively (if set).

However, Compilation OS does not invoke odrefresh during boot, but
rather in idle and charging mode. Select the '.background-' variant
of the sysprops in that mode.

If the first prop is empty, fall back to the generic, non-prefixed
property.

Test: atest ComposHostTestCases
Change-Id: I19b558b40d8a92d3711c383e05debcf58882444b
diff --git a/odrefresh/odrefresh.cc b/odrefresh/odrefresh.cc
index c65c986..601d21d 100644
--- a/odrefresh/odrefresh.cc
+++ b/odrefresh/odrefresh.cc
@@ -390,21 +390,38 @@
   return true;
 }
 
-bool AddDex2OatConcurrencyArguments(/*inout*/ std::vector<std::string>& args) {
-  std::string threads = android::base::GetProperty("dalvik.vm.boot-dex2oat-threads", "");
+bool AddDex2OatConcurrencyArguments(/*inout*/ std::vector<std::string>& args,
+                                    bool is_compilation_os) {
+  std::string threads;
+  if (is_compilation_os) {
+    threads = android::base::GetProperty("dalvik.vm.background-dex2oat-threads", "");
+    if (threads.empty()) {
+      threads = android::base::GetProperty("dalvik.vm.dex2oat-threads", "");
+    }
+  } else {
+    threads = android::base::GetProperty("dalvik.vm.boot-dex2oat-threads", "");
+  }
   if (!threads.empty()) {
     args.push_back("-j" + threads);
   }
 
-  std::string cpu_set = android::base::GetProperty("dalvik.vm.boot-dex2oat-cpu-set", "");
-  if (cpu_set.empty()) {
-    return true;
+  std::string cpu_set;
+  if (is_compilation_os) {
+    cpu_set = android::base::GetProperty("dalvik.vm.background-dex2oat-cpu-set", "");
+    if (cpu_set.empty()) {
+      cpu_set = android::base::GetProperty("dalvik.vm.dex2oat-cpu-set", "");
+    }
+  } else {
+    cpu_set = android::base::GetProperty("dalvik.vm.boot-dex2oat-cpu-set", "");
   }
-  if (!IsCpuSetSpecValid(cpu_set)) {
-    LOG(ERROR) << "Invalid CPU set spec: " << cpu_set;
-    return false;
+  if (!cpu_set.empty()) {
+    if (!IsCpuSetSpecValid(cpu_set)) {
+      LOG(ERROR) << "Invalid CPU set spec: " << cpu_set;
+      return false;
+    }
+    args.push_back("--cpu-set=" + cpu_set);
   }
-  args.push_back("--cpu-set=" + cpu_set);
+
   return true;
 }
 
@@ -1480,7 +1497,7 @@
   AddDex2OatCommonOptions(args);
   AddDex2OatDebugInfo(args);
   AddDex2OatInstructionSet(args, isa);
-  if (!AddDex2OatConcurrencyArguments(args)) {
+  if (!AddDex2OatConcurrencyArguments(args, config_.GetCompilationOsMode())) {
     return false;
   }
 
@@ -1650,7 +1667,7 @@
     AddDex2OatCommonOptions(args);
     AddDex2OatDebugInfo(args);
     AddDex2OatInstructionSet(args, isa);
-    if (!AddDex2OatConcurrencyArguments(args)) {
+    if (!AddDex2OatConcurrencyArguments(args, config_.GetCompilationOsMode())) {
       return false;
     }