Jooyung Han | 21e9b92 | 2021-06-26 04:14:16 +0900 | [diff] [blame] | 1 | // Copyright 2021, The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | //! Payload disk image |
| 16 | |
Andrew Walbran | cc0db52 | 2021-07-12 17:03:42 +0000 | [diff] [blame] | 17 | use android_system_virtualizationservice::aidl::android::system::virtualizationservice::{ |
| 18 | DiskImage::DiskImage, Partition::Partition, VirtualMachineAppConfig::VirtualMachineAppConfig, |
| 19 | VirtualMachineRawConfig::VirtualMachineRawConfig, |
| 20 | }; |
| 21 | use android_system_virtualizationservice::binder::ParcelFileDescriptor; |
Jooyung Han | 44b02ab | 2021-07-16 03:19:13 +0900 | [diff] [blame] | 22 | use anyhow::{anyhow, Context, Result}; |
Jooyung Han | 5dc4217 | 2021-10-05 16:43:47 +0900 | [diff] [blame] | 23 | use binder::{wait_for_interface, Strong}; |
Jooyung Han | 5e0f206 | 2021-10-12 14:00:46 +0900 | [diff] [blame] | 24 | use log::{error, info}; |
Jooyung Han | 21e9b92 | 2021-06-26 04:14:16 +0900 | [diff] [blame] | 25 | use microdroid_metadata::{ApexPayload, ApkPayload, Metadata}; |
Jooyung Han | 5dc4217 | 2021-10-05 16:43:47 +0900 | [diff] [blame] | 26 | use microdroid_payload_config::{ApexConfig, VmPayloadConfig}; |
Jooyung Han | 9900f3d | 2021-07-06 10:27:54 +0900 | [diff] [blame] | 27 | use once_cell::sync::OnceCell; |
Jooyung Han | 5dc4217 | 2021-10-05 16:43:47 +0900 | [diff] [blame] | 28 | use packagemanager_aidl::aidl::android::content::pm::IPackageManagerNative::IPackageManagerNative; |
Jooyung Han | 44b02ab | 2021-07-16 03:19:13 +0900 | [diff] [blame] | 29 | use serde::Deserialize; |
| 30 | use serde_xml_rs::from_reader; |
Jooyung Han | 5e0f206 | 2021-10-12 14:00:46 +0900 | [diff] [blame] | 31 | use std::env; |
Jooyung Han | 44b02ab | 2021-07-16 03:19:13 +0900 | [diff] [blame] | 32 | use std::fs::{File, OpenOptions}; |
Jooyung Han | 21e9b92 | 2021-06-26 04:14:16 +0900 | [diff] [blame] | 33 | use std::path::{Path, PathBuf}; |
Andrew Walbran | cc0db52 | 2021-07-12 17:03:42 +0000 | [diff] [blame] | 34 | use vmconfig::open_parcel_file; |
| 35 | |
| 36 | /// The list of APEXes which microdroid requires. |
| 37 | // TODO(b/192200378) move this to microdroid.json? |
Jooyung Han | 1c2d758 | 2021-09-08 22:46:42 +0900 | [diff] [blame] | 38 | const MICRODROID_REQUIRED_APEXES: [&str; 2] = ["com.android.adbd", "com.android.os.statsd"]; |
Jooyung Han | 21e9b92 | 2021-06-26 04:14:16 +0900 | [diff] [blame] | 39 | |
Jooyung Han | 44b02ab | 2021-07-16 03:19:13 +0900 | [diff] [blame] | 40 | const APEX_INFO_LIST_PATH: &str = "/apex/apex-info-list.xml"; |
| 41 | |
Jooyung Han | 5dc4217 | 2021-10-05 16:43:47 +0900 | [diff] [blame] | 42 | const PACKAGE_MANAGER_NATIVE_SERVICE: &str = "package_native"; |
| 43 | |
Jooyung Han | 73bac24 | 2021-07-02 10:25:49 +0900 | [diff] [blame] | 44 | /// Represents the list of APEXes |
Jooyung Han | 9d7cd7d | 2021-10-12 17:44:14 +0900 | [diff] [blame] | 45 | #[derive(Clone, Debug, Deserialize)] |
Jooyung Han | 9900f3d | 2021-07-06 10:27:54 +0900 | [diff] [blame] | 46 | struct ApexInfoList { |
Jooyung Han | 44b02ab | 2021-07-16 03:19:13 +0900 | [diff] [blame] | 47 | #[serde(rename = "apex-info")] |
Jooyung Han | 73bac24 | 2021-07-02 10:25:49 +0900 | [diff] [blame] | 48 | list: Vec<ApexInfo>, |
| 49 | } |
| 50 | |
Jooyung Han | 9d7cd7d | 2021-10-12 17:44:14 +0900 | [diff] [blame] | 51 | #[derive(Clone, Debug, Deserialize)] |
Jooyung Han | 73bac24 | 2021-07-02 10:25:49 +0900 | [diff] [blame] | 52 | struct ApexInfo { |
Jooyung Han | 44b02ab | 2021-07-16 03:19:13 +0900 | [diff] [blame] | 53 | #[serde(rename = "moduleName")] |
Jooyung Han | 73bac24 | 2021-07-02 10:25:49 +0900 | [diff] [blame] | 54 | name: String, |
Jooyung Han | 44b02ab | 2021-07-16 03:19:13 +0900 | [diff] [blame] | 55 | #[serde(rename = "modulePath")] |
Jooyung Han | 73bac24 | 2021-07-02 10:25:49 +0900 | [diff] [blame] | 56 | path: PathBuf, |
Jooyung Han | 9d7cd7d | 2021-10-12 17:44:14 +0900 | [diff] [blame] | 57 | |
| 58 | #[serde(default)] |
| 59 | boot_classpath: bool, |
| 60 | #[serde(default)] |
| 61 | systemserver_classpath: bool, |
| 62 | #[serde(default)] |
| 63 | dex2oatboot_classpath: bool, |
Jooyung Han | 73bac24 | 2021-07-02 10:25:49 +0900 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | impl ApexInfoList { |
| 67 | /// Loads ApexInfoList |
Jooyung Han | 9900f3d | 2021-07-06 10:27:54 +0900 | [diff] [blame] | 68 | fn load() -> Result<&'static ApexInfoList> { |
| 69 | static INSTANCE: OnceCell<ApexInfoList> = OnceCell::new(); |
| 70 | INSTANCE.get_or_try_init(|| { |
Jooyung Han | 44b02ab | 2021-07-16 03:19:13 +0900 | [diff] [blame] | 71 | let apex_info_list = File::open(APEX_INFO_LIST_PATH) |
| 72 | .context(format!("Failed to open {}", APEX_INFO_LIST_PATH))?; |
Jooyung Han | 9d7cd7d | 2021-10-12 17:44:14 +0900 | [diff] [blame] | 73 | let mut apex_info_list: ApexInfoList = from_reader(apex_info_list) |
Jooyung Han | 44b02ab | 2021-07-16 03:19:13 +0900 | [diff] [blame] | 74 | .context(format!("Failed to parse {}", APEX_INFO_LIST_PATH))?; |
Jooyung Han | 9d7cd7d | 2021-10-12 17:44:14 +0900 | [diff] [blame] | 75 | |
| 76 | // For active APEXes, we refer env variables to see if it contributes to classpath |
| 77 | let boot_classpath_apexes = find_apex_names_in_classpath_env("BOOTCLASSPATH"); |
| 78 | let systemserver_classpath_apexes = |
| 79 | find_apex_names_in_classpath_env("SYSTEMSERVERCLASSPATH"); |
| 80 | let dex2oatboot_classpath_apexes = |
| 81 | find_apex_names_in_classpath_env("DEX2OATBOOTCLASSPATH"); |
| 82 | for apex_info in apex_info_list.list.iter_mut() { |
| 83 | apex_info.boot_classpath = boot_classpath_apexes.contains(&apex_info.name); |
| 84 | apex_info.systemserver_classpath = |
| 85 | systemserver_classpath_apexes.contains(&apex_info.name); |
| 86 | apex_info.dex2oatboot_classpath = |
| 87 | dex2oatboot_classpath_apexes.contains(&apex_info.name); |
| 88 | } |
Jooyung Han | 44b02ab | 2021-07-16 03:19:13 +0900 | [diff] [blame] | 89 | Ok(apex_info_list) |
Jooyung Han | 9900f3d | 2021-07-06 10:27:54 +0900 | [diff] [blame] | 90 | }) |
Jooyung Han | 73bac24 | 2021-07-02 10:25:49 +0900 | [diff] [blame] | 91 | } |
| 92 | |
Jooyung Han | 9d7cd7d | 2021-10-12 17:44:14 +0900 | [diff] [blame] | 93 | /// Returns the list of apex names matching with the predicate |
| 94 | fn get_matching(&self, predicate: fn(&ApexInfo) -> bool) -> Vec<String> { |
| 95 | self.list.iter().filter(|info| predicate(info)).map(|info| info.name.clone()).collect() |
| 96 | } |
| 97 | |
Jooyung Han | 73bac24 | 2021-07-02 10:25:49 +0900 | [diff] [blame] | 98 | fn get_path_for(&self, apex_name: &str) -> Result<PathBuf> { |
| 99 | Ok(self |
| 100 | .list |
| 101 | .iter() |
| 102 | .find(|apex| apex.name == apex_name) |
| 103 | .ok_or_else(|| anyhow!("{} not found.", apex_name))? |
| 104 | .path |
| 105 | .clone()) |
| 106 | } |
Jooyung Han | 21e9b92 | 2021-06-26 04:14:16 +0900 | [diff] [blame] | 107 | } |
| 108 | |
Jooyung Han | 5dc4217 | 2021-10-05 16:43:47 +0900 | [diff] [blame] | 109 | struct PackageManager { |
| 110 | service: Strong<dyn IPackageManagerNative>, |
| 111 | // TODO(b/199146189) use IPackageManagerNative |
| 112 | apex_info_list: &'static ApexInfoList, |
| 113 | } |
| 114 | |
| 115 | impl PackageManager { |
| 116 | fn new() -> Result<Self> { |
| 117 | let service = wait_for_interface(PACKAGE_MANAGER_NATIVE_SERVICE) |
| 118 | .context("Failed to find PackageManager")?; |
| 119 | let apex_info_list = ApexInfoList::load()?; |
| 120 | Ok(Self { service, apex_info_list }) |
| 121 | } |
| 122 | |
Jooyung Han | 9d7cd7d | 2021-10-12 17:44:14 +0900 | [diff] [blame] | 123 | fn get_apex_list(&self, prefer_staged: bool) -> Result<ApexInfoList> { |
| 124 | let mut list = self.apex_info_list.clone(); |
Jooyung Han | 5dc4217 | 2021-10-05 16:43:47 +0900 | [diff] [blame] | 125 | if prefer_staged { |
Jooyung Han | 9d7cd7d | 2021-10-12 17:44:14 +0900 | [diff] [blame] | 126 | // When prefer_staged, we override ApexInfo by consulting "package_native" |
| 127 | let staged = self.service.getStagedApexModuleNames()?; |
| 128 | for apex_info in list.list.iter_mut() { |
| 129 | if staged.contains(&apex_info.name) { |
| 130 | let staged_apex_info = self.service.getStagedApexInfo(&apex_info.name)?; |
| 131 | if let Some(staged_apex_info) = staged_apex_info { |
| 132 | apex_info.path = PathBuf::from(staged_apex_info.diskImagePath); |
| 133 | // TODO(b/201788989) copy bootclasspath/systemserverclasspath |
| 134 | } |
| 135 | } |
Jooyung Han | 5dc4217 | 2021-10-05 16:43:47 +0900 | [diff] [blame] | 136 | } |
| 137 | } |
Jooyung Han | 9d7cd7d | 2021-10-12 17:44:14 +0900 | [diff] [blame] | 138 | Ok(list) |
Jooyung Han | 5dc4217 | 2021-10-05 16:43:47 +0900 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | |
Andrew Walbran | cc0db52 | 2021-07-12 17:03:42 +0000 | [diff] [blame] | 142 | fn make_metadata_file( |
Jooyung Han | 21e9b92 | 2021-06-26 04:14:16 +0900 | [diff] [blame] | 143 | config_path: &str, |
Jooyung Han | 5e0f206 | 2021-10-12 14:00:46 +0900 | [diff] [blame] | 144 | apex_names: &[String], |
Jooyung Han | 21e9b92 | 2021-06-26 04:14:16 +0900 | [diff] [blame] | 145 | temporary_directory: &Path, |
Andrew Walbran | cc0db52 | 2021-07-12 17:03:42 +0000 | [diff] [blame] | 146 | ) -> Result<ParcelFileDescriptor> { |
Jooyung Han | 21e9b92 | 2021-06-26 04:14:16 +0900 | [diff] [blame] | 147 | let metadata_path = temporary_directory.join("metadata"); |
| 148 | let metadata = Metadata { |
Andrew Walbran | cc0db52 | 2021-07-12 17:03:42 +0000 | [diff] [blame] | 149 | version: 1, |
Jooyung Han | 5e0f206 | 2021-10-12 14:00:46 +0900 | [diff] [blame] | 150 | apexes: apex_names |
Jooyung Han | 21e9b92 | 2021-06-26 04:14:16 +0900 | [diff] [blame] | 151 | .iter() |
Jooyung Han | 19c1d6c | 2021-08-06 14:08:16 +0900 | [diff] [blame] | 152 | .enumerate() |
Jooyung Han | 5e0f206 | 2021-10-12 14:00:46 +0900 | [diff] [blame] | 153 | .map(|(i, apex_name)| ApexPayload { |
| 154 | name: apex_name.clone(), |
Jooyung Han | 19c1d6c | 2021-08-06 14:08:16 +0900 | [diff] [blame] | 155 | partition_name: format!("microdroid-apex-{}", i), |
| 156 | ..Default::default() |
| 157 | }) |
Jooyung Han | 21e9b92 | 2021-06-26 04:14:16 +0900 | [diff] [blame] | 158 | .collect(), |
| 159 | apk: Some(ApkPayload { |
Jooyung Han | 35edb8f | 2021-07-01 16:17:16 +0900 | [diff] [blame] | 160 | name: "apk".to_owned(), |
| 161 | payload_partition_name: "microdroid-apk".to_owned(), |
| 162 | idsig_partition_name: "microdroid-apk-idsig".to_owned(), |
Jooyung Han | 21e9b92 | 2021-06-26 04:14:16 +0900 | [diff] [blame] | 163 | ..Default::default() |
| 164 | }) |
| 165 | .into(), |
| 166 | payload_config_path: format!("/mnt/apk/{}", config_path), |
| 167 | ..Default::default() |
| 168 | }; |
Andrew Walbran | cc0db52 | 2021-07-12 17:03:42 +0000 | [diff] [blame] | 169 | |
| 170 | // Write metadata to file. |
| 171 | let mut metadata_file = OpenOptions::new() |
| 172 | .create_new(true) |
| 173 | .read(true) |
| 174 | .write(true) |
| 175 | .open(&metadata_path) |
| 176 | .with_context(|| format!("Failed to open metadata file {:?}", metadata_path))?; |
Jooyung Han | 21e9b92 | 2021-06-26 04:14:16 +0900 | [diff] [blame] | 177 | microdroid_metadata::write_metadata(&metadata, &mut metadata_file)?; |
| 178 | |
Andrew Walbran | cc0db52 | 2021-07-12 17:03:42 +0000 | [diff] [blame] | 179 | // Re-open the metadata file as read-only. |
| 180 | open_parcel_file(&metadata_path, false) |
| 181 | } |
| 182 | |
| 183 | /// Creates a DiskImage with partitions: |
| 184 | /// metadata: metadata |
| 185 | /// microdroid-apex-0: apex 0 |
| 186 | /// microdroid-apex-1: apex 1 |
| 187 | /// .. |
| 188 | /// microdroid-apk: apk |
| 189 | /// microdroid-apk-idsig: idsig |
| 190 | fn make_payload_disk( |
| 191 | apk_file: File, |
| 192 | idsig_file: File, |
| 193 | config_path: &str, |
Jooyung Han | 9d7cd7d | 2021-10-12 17:44:14 +0900 | [diff] [blame] | 194 | vm_payload_config: &VmPayloadConfig, |
Andrew Walbran | cc0db52 | 2021-07-12 17:03:42 +0000 | [diff] [blame] | 195 | temporary_directory: &Path, |
| 196 | ) -> Result<DiskImage> { |
Jooyung Han | 9d7cd7d | 2021-10-12 17:44:14 +0900 | [diff] [blame] | 197 | let pm = PackageManager::new()?; |
| 198 | let apex_list = pm.get_apex_list(vm_payload_config.prefer_staged)?; |
| 199 | |
| 200 | // collect APEX names from config |
| 201 | let apexes = collect_apex_names(&apex_list, &vm_payload_config.apexes); |
| 202 | info!("Microdroid payload APEXes: {:?}", apexes); |
| 203 | |
| 204 | let metadata_file = make_metadata_file(config_path, &apexes, temporary_directory)?; |
Jooyung Han | 21e9b92 | 2021-06-26 04:14:16 +0900 | [diff] [blame] | 205 | // put metadata at the first partition |
| 206 | let mut partitions = vec![Partition { |
Jooyung Han | 14e5a8e | 2021-07-06 20:48:38 +0900 | [diff] [blame] | 207 | label: "payload-metadata".to_owned(), |
Jooyung Han | 631d588 | 2021-07-29 06:34:05 +0900 | [diff] [blame] | 208 | image: Some(metadata_file), |
Jooyung Han | 21e9b92 | 2021-06-26 04:14:16 +0900 | [diff] [blame] | 209 | writable: false, |
| 210 | }]; |
| 211 | |
Jooyung Han | 21e9b92 | 2021-06-26 04:14:16 +0900 | [diff] [blame] | 212 | for (i, apex) in apexes.iter().enumerate() { |
Jooyung Han | 9d7cd7d | 2021-10-12 17:44:14 +0900 | [diff] [blame] | 213 | let apex_path = apex_list.get_path_for(apex)?; |
Andrew Walbran | cc0db52 | 2021-07-12 17:03:42 +0000 | [diff] [blame] | 214 | let apex_file = open_parcel_file(&apex_path, false)?; |
Jooyung Han | 9588463 | 2021-07-06 22:27:54 +0900 | [diff] [blame] | 215 | partitions.push(Partition { |
| 216 | label: format!("microdroid-apex-{}", i), |
Jooyung Han | 631d588 | 2021-07-29 06:34:05 +0900 | [diff] [blame] | 217 | image: Some(apex_file), |
Jooyung Han | 9588463 | 2021-07-06 22:27:54 +0900 | [diff] [blame] | 218 | writable: false, |
| 219 | }); |
Jooyung Han | 21e9b92 | 2021-06-26 04:14:16 +0900 | [diff] [blame] | 220 | } |
Jooyung Han | 9588463 | 2021-07-06 22:27:54 +0900 | [diff] [blame] | 221 | partitions.push(Partition { |
| 222 | label: "microdroid-apk".to_owned(), |
Jooyung Han | 631d588 | 2021-07-29 06:34:05 +0900 | [diff] [blame] | 223 | image: Some(ParcelFileDescriptor::new(apk_file)), |
Jooyung Han | 9588463 | 2021-07-06 22:27:54 +0900 | [diff] [blame] | 224 | writable: false, |
| 225 | }); |
| 226 | partitions.push(Partition { |
| 227 | label: "microdroid-apk-idsig".to_owned(), |
Jooyung Han | 631d588 | 2021-07-29 06:34:05 +0900 | [diff] [blame] | 228 | image: Some(ParcelFileDescriptor::new(idsig_file)), |
Jooyung Han | 9588463 | 2021-07-06 22:27:54 +0900 | [diff] [blame] | 229 | writable: false, |
| 230 | }); |
Jooyung Han | 21e9b92 | 2021-06-26 04:14:16 +0900 | [diff] [blame] | 231 | |
| 232 | Ok(DiskImage { image: None, partitions, writable: false }) |
| 233 | } |
Andrew Walbran | cc0db52 | 2021-07-12 17:03:42 +0000 | [diff] [blame] | 234 | |
Jooyung Han | 5e0f206 | 2021-10-12 14:00:46 +0900 | [diff] [blame] | 235 | fn find_apex_names_in_classpath_env(classpath_env_var: &str) -> Vec<String> { |
| 236 | let val = env::var(classpath_env_var).unwrap_or_else(|e| { |
| 237 | error!("Reading {} failed: {}", classpath_env_var, e); |
| 238 | String::from("") |
| 239 | }); |
| 240 | val.split(':') |
| 241 | .filter_map(|path| { |
| 242 | Path::new(path) |
| 243 | .strip_prefix("/apex/") |
| 244 | .map(|stripped| { |
| 245 | let first = stripped.iter().next().unwrap(); |
| 246 | first.to_str().unwrap().to_string() |
| 247 | }) |
| 248 | .ok() |
| 249 | }) |
| 250 | .collect() |
| 251 | } |
| 252 | |
| 253 | // Collect APEX names from config |
Jooyung Han | 9d7cd7d | 2021-10-12 17:44:14 +0900 | [diff] [blame] | 254 | fn collect_apex_names(apex_list: &ApexInfoList, apexes: &[ApexConfig]) -> Vec<String> { |
Jooyung Han | 5e0f206 | 2021-10-12 14:00:46 +0900 | [diff] [blame] | 255 | // Process pseudo names like "{BOOTCLASSPATH}". |
| 256 | // For now we have following pseudo APEX names: |
| 257 | // - {BOOTCLASSPATH}: represents APEXes contributing "BOOTCLASSPATH" environment variable |
| 258 | // - {DEX2OATBOOTCLASSPATH}: represents APEXes contributing "DEX2OATBOOTCLASSPATH" environment variable |
| 259 | // - {SYSTEMSERVERCLASSPATH}: represents APEXes contributing "SYSTEMSERVERCLASSPATH" environment variable |
| 260 | let mut apex_names: Vec<String> = apexes |
| 261 | .iter() |
| 262 | .flat_map(|apex| match apex.name.as_str() { |
Jooyung Han | 9d7cd7d | 2021-10-12 17:44:14 +0900 | [diff] [blame] | 263 | "{BOOTCLASSPATH}" => apex_list.get_matching(|apex| apex.boot_classpath), |
| 264 | "{DEX2OATBOOTCLASSPATH}" => apex_list.get_matching(|apex| apex.dex2oatboot_classpath), |
| 265 | "{SYSTEMSERVERCLASSPATH}" => apex_list.get_matching(|apex| apex.systemserver_classpath), |
Jooyung Han | 5e0f206 | 2021-10-12 14:00:46 +0900 | [diff] [blame] | 266 | _ => vec![apex.name.clone()], |
| 267 | }) |
| 268 | .collect(); |
| 269 | // Add required APEXes |
| 270 | apex_names.extend(MICRODROID_REQUIRED_APEXES.iter().map(|name| name.to_string())); |
| 271 | apex_names.sort(); |
| 272 | apex_names.dedup(); |
| 273 | apex_names |
| 274 | } |
| 275 | |
Andrew Walbran | cc0db52 | 2021-07-12 17:03:42 +0000 | [diff] [blame] | 276 | pub fn add_microdroid_images( |
| 277 | config: &VirtualMachineAppConfig, |
| 278 | temporary_directory: &Path, |
| 279 | apk_file: File, |
| 280 | idsig_file: File, |
Jiyong Park | 8d08181 | 2021-07-23 17:45:04 +0900 | [diff] [blame] | 281 | instance_file: File, |
Jooyung Han | 5dc4217 | 2021-10-05 16:43:47 +0900 | [diff] [blame] | 282 | vm_payload_config: &VmPayloadConfig, |
Andrew Walbran | cc0db52 | 2021-07-12 17:03:42 +0000 | [diff] [blame] | 283 | vm_config: &mut VirtualMachineRawConfig, |
| 284 | ) -> Result<()> { |
Andrew Walbran | cc0db52 | 2021-07-12 17:03:42 +0000 | [diff] [blame] | 285 | vm_config.disks.push(make_payload_disk( |
| 286 | apk_file, |
| 287 | idsig_file, |
| 288 | &config.configPath, |
Jooyung Han | 9d7cd7d | 2021-10-12 17:44:14 +0900 | [diff] [blame] | 289 | vm_payload_config, |
Andrew Walbran | cc0db52 | 2021-07-12 17:03:42 +0000 | [diff] [blame] | 290 | temporary_directory, |
| 291 | )?); |
| 292 | |
| 293 | if config.debug { |
| 294 | vm_config.disks[1].partitions.push(Partition { |
| 295 | label: "bootconfig".to_owned(), |
Jooyung Han | 631d588 | 2021-07-29 06:34:05 +0900 | [diff] [blame] | 296 | image: Some(open_parcel_file( |
Andrew Walbran | cc0db52 | 2021-07-12 17:03:42 +0000 | [diff] [blame] | 297 | Path::new("/apex/com.android.virt/etc/microdroid_bootconfig.debug"), |
| 298 | false, |
Jooyung Han | 631d588 | 2021-07-29 06:34:05 +0900 | [diff] [blame] | 299 | )?), |
Andrew Walbran | cc0db52 | 2021-07-12 17:03:42 +0000 | [diff] [blame] | 300 | writable: false, |
| 301 | }); |
| 302 | } |
| 303 | |
Jiyong Park | 8d08181 | 2021-07-23 17:45:04 +0900 | [diff] [blame] | 304 | // instance image is at the second partition in the second disk. |
| 305 | vm_config.disks[1].partitions.push(Partition { |
| 306 | label: "vm-instance".to_owned(), |
Jooyung Han | 631d588 | 2021-07-29 06:34:05 +0900 | [diff] [blame] | 307 | image: Some(ParcelFileDescriptor::new(instance_file)), |
Jiyong Park | 8d08181 | 2021-07-23 17:45:04 +0900 | [diff] [blame] | 308 | writable: true, |
| 309 | }); |
| 310 | |
Andrew Walbran | cc0db52 | 2021-07-12 17:03:42 +0000 | [diff] [blame] | 311 | Ok(()) |
| 312 | } |
Jooyung Han | 5e0f206 | 2021-10-12 14:00:46 +0900 | [diff] [blame] | 313 | |
| 314 | #[cfg(test)] |
| 315 | mod tests { |
| 316 | use super::*; |
| 317 | #[test] |
| 318 | fn test_find_apex_names_in_classpath_env() { |
| 319 | let key = "TEST_BOOTCLASSPATH"; |
| 320 | let classpath = "/apex/com.android.foo/javalib/foo.jar:/system/framework/framework.jar:/apex/com.android.bar/javalib/bar.jar"; |
| 321 | env::set_var(key, classpath); |
| 322 | assert_eq!( |
| 323 | find_apex_names_in_classpath_env(key), |
| 324 | vec!["com.android.foo".to_owned(), "com.android.bar".to_owned()] |
| 325 | ); |
| 326 | } |
| 327 | } |