Add maintenance as a lazy service

We need to advertise it as a lazy service to allow VS to be started
when it is needed.

To avoid having to have 4 variants of the .rc file, switch from
picking one to constructing it from fragments.

Bug: 294177871
Test: Builds, final .rc is correct
Change-Id: I10faf32249e41cab21a602f94231786f95e20d3d
diff --git a/apex/Android.bp b/apex/Android.bp
index cc59b16..f2badfa 100644
--- a/apex/Android.bp
+++ b/apex/Android.bp
@@ -139,6 +139,7 @@
         "microdroid_initrd_normal",
         "microdroid.json",
         "microdroid_kernel",
+        "com.android.virt.init.rc",
     ],
     host_required: [
         "vm_shell",
@@ -172,13 +173,9 @@
             ],
         },
         release_avf_enable_remote_attestation: {
-            prebuilts: ["com.android.virt.init_attestation_enabled.rc"],
             vintf_fragments: [
                 "virtualizationservice.xml",
             ],
-            conditions_default: {
-                prebuilts: ["com.android.virt.init.rc"],
-            },
         },
     },
 }
@@ -200,16 +197,35 @@
     certificate: "com.android.virt",
 }
 
-prebuilt_etc {
-    name: "com.android.virt.init.rc",
-    src: "virtualizationservice.rc",
-    filename: "virtualizationservice.rc",
-    installable: false,
+soong_config_module_type {
+    name: "avf_flag_aware_genrule",
+    module_type: "genrule",
+    config_namespace: "ANDROID",
+    bool_variables: [
+        "release_avf_enable_llpvm_changes",
+        "release_avf_enable_remote_attestation",
+    ],
+    properties: ["srcs"],
+}
+
+avf_flag_aware_genrule {
+    name: "virtualizationservice_rc_combined",
+    srcs: ["virtualizationservice.rc.base"],
+    soong_config_variables: {
+        release_avf_enable_llpvm_changes: {
+            srcs: ["virtualizationservice.rc.llpvm"],
+        },
+        release_avf_enable_remote_attestation: {
+            srcs: ["virtualizationservice.rc.ra"],
+        },
+    },
+    out: ["virtualizationservice.rc"],
+    cmd: "cat $(in) > $(out)",
 }
 
 prebuilt_etc {
-    name: "com.android.virt.init_attestation_enabled.rc",
-    src: "virtualizationservice_attestation_enabled.rc",
+    name: "com.android.virt.init.rc",
+    src: ":virtualizationservice_rc_combined",
     filename: "virtualizationservice.rc",
     installable: false,
 }
diff --git a/apex/virtualizationservice.rc b/apex/virtualizationservice.rc.base
similarity index 99%
rename from apex/virtualizationservice.rc
rename to apex/virtualizationservice.rc.base
index 02b2081..688db10 100644
--- a/apex/virtualizationservice.rc
+++ b/apex/virtualizationservice.rc.base
@@ -16,6 +16,6 @@
     class main
     user system
     group system
-    interface aidl android.system.virtualizationservice
     disabled
     oneshot
+    interface aidl android.system.virtualizationservice
diff --git a/apex/virtualizationservice.rc.llpvm b/apex/virtualizationservice.rc.llpvm
new file mode 100644
index 0000000..916d508
--- /dev/null
+++ b/apex/virtualizationservice.rc.llpvm
@@ -0,0 +1 @@
+    interface aidl android.system.virtualizationmaintenance
diff --git a/apex/virtualizationservice.rc.ra b/apex/virtualizationservice.rc.ra
new file mode 100644
index 0000000..3554259
--- /dev/null
+++ b/apex/virtualizationservice.rc.ra
@@ -0,0 +1 @@
+    interface aidl android.hardware.security.keymint.IRemotelyProvisionedComponent/avf
diff --git a/apex/virtualizationservice_attestation_enabled.rc b/apex/virtualizationservice_attestation_enabled.rc
deleted file mode 100644
index 8eaccae..0000000
--- a/apex/virtualizationservice_attestation_enabled.rc
+++ /dev/null
@@ -1,22 +0,0 @@
-# Copyright (C) 2021 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-service virtualizationservice /apex/com.android.virt/bin/virtualizationservice
-    class main
-    user system
-    group system
-    interface aidl android.system.virtualizationservice
-    interface aidl android.hardware.security.keymint.IRemotelyProvisionedComponent/avf
-    disabled
-    oneshot