Pass isFactory bit from host to Microdroid via payload metadata

The isolated compilation usecase demands that isFactory bit of an APEX
is the same across VM and host. This is because the bit is encoded in
the compiled artifact (in the VM), and matched against the same bit on
the host side.

This is now done by (1) reading isFactory bit from
/apex/apex-info-list.xml and (2) send the bit to the VM by writing it to
payload metadata. (3) On the VM side, apexd records the bit to
/apex/apex-info-list.xml. (See the other CL in the same topic for the
last step).

Bug: 210998761
Test: adb shell /apex/com.android.compos/bin/composd_cmd staged-apex-compile
Change-Id: I69dd73357132812766867db13f0f5cb9958bb113
Test: (1) build any APEX (e.g. com.android.virt) and install it
(2) add the name of the APEX to vm_config.json of the test app.
(3) run the test app and adb shell into the VM
(4) check /apex/apex-info-list.xml has isFactory="false" for the apex.

Change-Id: Iaed1e2c9b232a6e9a58a0624adb5044d06d88d2b
diff --git a/virtualizationservice/src/payload.rs b/virtualizationservice/src/payload.rs
index 65adc25..e4a763c 100644
--- a/virtualizationservice/src/payload.rs
+++ b/virtualizationservice/src/payload.rs
@@ -66,6 +66,9 @@
     // The field claims to be milliseconds but is actually seconds.
     #[serde(rename = "lastUpdateMillis")]
     last_update_seconds: u64,
+
+    #[serde(rename = "isFactory")]
+    is_factory: bool,
 }
 
 impl ApexInfoList {
@@ -137,6 +140,8 @@
                         let metadata = metadata(&apex_info.path)?;
                         apex_info.last_update_seconds =
                             metadata.modified()?.duration_since(SystemTime::UNIX_EPOCH)?.as_secs();
+                        // by definition, staged apex can't be a factory apex.
+                        apex_info.is_factory = false;
                     }
                 }
             }
@@ -158,10 +163,12 @@
             .iter()
             .enumerate()
             .map(|(i, apex_name)| {
+                let apex_info = apex_list.get(apex_name)?;
                 Ok(ApexPayload {
                     name: apex_name.clone(),
                     partition_name: format!("microdroid-apex-{}", i),
-                    last_update_seconds: apex_list.get(apex_name)?.last_update_seconds,
+                    last_update_seconds: apex_info.last_update_seconds,
+                    is_factory: apex_info.is_factory,
                     ..Default::default()
                 })
             })
@@ -411,12 +418,14 @@
                     path: PathBuf::from("path0"),
                     has_classpath_jar: false,
                     last_update_seconds: 12345678,
+                    is_factory: true,
                 },
                 ApexInfo {
                     name: "has_classpath".to_string(),
                     path: PathBuf::from("path1"),
                     has_classpath_jar: true,
                     last_update_seconds: 87654321,
+                    is_factory: false,
                 },
             ],
         };