Apexd runs in microdroid

Previously, we ran only 'apexd-bootstrap' because 'apexd' crashes due to
the lack of /data/apex in microdroid.

Now apexd runs in "vm" mode. In vm mode, apexd only activates built-in
apexes and block apexes. No data apexes, no session handling.

Bug: 179342589
Test: MicrodroidTestCase
Change-Id: I8c6a16c3b08010fcb008d822d0ba0e311c0a9985
diff --git a/microdroid/init.rc b/microdroid/init.rc
index 14238a4..56b0065 100644
--- a/microdroid/init.rc
+++ b/microdroid/init.rc
@@ -12,11 +12,22 @@
 
 # Cgroups are mounted right before early-init using list from /etc/cgroups.json
 on early-init
-    start ueventd
 
-    # Generate ld.config.txt
-    exec -- /system/bin/bootstrap/linkerconfig --target /linkerconfig
-    chmod 644 /linkerconfig/ld.config.txt
+    # TODO(b/185991357) eliminate bootstrap mount namespace
+    # Set up linker config subdirectories based on mount namespaces
+    mkdir /linkerconfig/bootstrap 0755
+    mkdir /linkerconfig/default 0755
+
+    # Generate ld.config.txt for early executed processes
+    exec -- /system/bin/bootstrap/linkerconfig --target /linkerconfig/bootstrap
+    chmod 644 /linkerconfig/bootstrap/ld.config.txt
+    copy /linkerconfig/bootstrap/ld.config.txt /linkerconfig/default/ld.config.txt
+    chmod 644 /linkerconfig/default/ld.config.txt
+
+    # Mount bootstrap linker configuration as current
+    mount none /linkerconfig/bootstrap /linkerconfig bind rec
+
+    start ueventd
 
     # Run apexd-bootstrap so that APEXes that provide critical libraries
     # become available. Note that this is executed as exec_start to ensure that
@@ -87,11 +98,12 @@
     # The bind+remount combination allows this to work in containers.
     mount rootfs rootfs / remount bind ro nodev
 
-    # Currently, exec_start apexd-bootstrap is enough to run adb.
-    # TODO(b/179342589): uncomment after turning off APEX session on microdroid
-    # start apexd
-    # Wait for apexd to finish activating APEXes before starting more processes.
-    # wait_for_prop apexd.status activated
+    enter_default_mount_ns
+
+    # Start apexd in the VM mode to avoid unnecessary overhead of session management.
+    exec - root system -- /system/bin/apexd --vm
+
+    perform_apex_config
 
     start adbd