blob: 5811314198d2c87c87988d140eb38882139c9b8f [file] [log] [blame]
Jooyung Han21e9b922021-06-26 04:14:16 +09001// 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
Jaewan Kim61f86142023-03-28 15:12:52 +090017use crate::debug_config::DebugConfig;
Andrew Walbrancc0db522021-07-12 17:03:42 +000018use android_system_virtualizationservice::aidl::android::system::virtualizationservice::{
Alan Stokes0d1ef782022-09-27 13:46:35 +010019 DiskImage::DiskImage,
20 Partition::Partition,
21 VirtualMachineAppConfig::DebugLevel::DebugLevel,
22 VirtualMachineAppConfig::{Payload::Payload, VirtualMachineAppConfig},
Andrew Walbrancc0db522021-07-12 17:03:42 +000023 VirtualMachineRawConfig::VirtualMachineRawConfig,
24};
Inseob Kima5a262f2021-11-17 19:41:03 +090025use anyhow::{anyhow, bail, Context, Result};
Alan Stokes0e82b502022-08-08 14:44:48 +010026use binder::{wait_for_interface, ParcelFileDescriptor};
Alan Stokesbf20c6a2022-01-04 12:30:50 +000027use log::{info, warn};
Alan Stokes0d1ef782022-09-27 13:46:35 +010028use microdroid_metadata::{ApexPayload, ApkPayload, Metadata, PayloadConfig, PayloadMetadata};
Jooyung Han5dc42172021-10-05 16:43:47 +090029use microdroid_payload_config::{ApexConfig, VmPayloadConfig};
Jooyung Han9900f3d2021-07-06 10:27:54 +090030use once_cell::sync::OnceCell;
Jooyung Han743e0d62022-11-07 20:57:48 +090031use packagemanager_aidl::aidl::android::content::pm::{
32 IPackageManagerNative::IPackageManagerNative, StagedApexInfo::StagedApexInfo,
33};
Alan Stokesbf20c6a2022-01-04 12:30:50 +000034use regex::Regex;
Jooyung Han44b02ab2021-07-16 03:19:13 +090035use serde::Deserialize;
36use serde_xml_rs::from_reader;
Alan Stokesbf20c6a2022-01-04 12:30:50 +000037use std::collections::HashSet;
Inseob Kimecde8c02024-09-03 13:11:08 +090038use std::ffi::OsStr;
Andrew Walbran40be9d52022-01-19 14:32:53 +000039use std::fs::{metadata, File, OpenOptions};
Jooyung Han21e9b922021-06-26 04:14:16 +090040use std::path::{Path, PathBuf};
Alan Stokesbf20c6a2022-01-04 12:30:50 +000041use std::process::Command;
Andrew Walbran40be9d52022-01-19 14:32:53 +000042use std::time::SystemTime;
Andrew Walbrancc0db522021-07-12 17:03:42 +000043use vmconfig::open_parcel_file;
44
Jooyung Han44b02ab2021-07-16 03:19:13 +090045const APEX_INFO_LIST_PATH: &str = "/apex/apex-info-list.xml";
46
Jooyung Han5dc42172021-10-05 16:43:47 +090047const PACKAGE_MANAGER_NATIVE_SERVICE: &str = "package_native";
48
Jooyung Han73bac242021-07-02 10:25:49 +090049/// Represents the list of APEXes
Jooyung Han743e0d62022-11-07 20:57:48 +090050#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
Jooyung Han9900f3d2021-07-06 10:27:54 +090051struct ApexInfoList {
Jooyung Han44b02ab2021-07-16 03:19:13 +090052 #[serde(rename = "apex-info")]
Jooyung Han73bac242021-07-02 10:25:49 +090053 list: Vec<ApexInfo>,
54}
55
Jooyung Han5ce867a2022-01-28 03:18:38 +090056#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)]
Jooyung Han73bac242021-07-02 10:25:49 +090057struct ApexInfo {
Jooyung Han44b02ab2021-07-16 03:19:13 +090058 #[serde(rename = "moduleName")]
Jooyung Han73bac242021-07-02 10:25:49 +090059 name: String,
Jooyung Hancaa995c2022-11-08 16:35:50 +090060 #[serde(rename = "versionCode")]
61 version: u64,
Jooyung Han44b02ab2021-07-16 03:19:13 +090062 #[serde(rename = "modulePath")]
Jooyung Han73bac242021-07-02 10:25:49 +090063 path: PathBuf,
Jooyung Han9d7cd7d2021-10-12 17:44:14 +090064
65 #[serde(default)]
Alan Stokes46ac3862021-12-21 15:31:47 +000066 has_classpath_jar: bool,
Andrew Walbran40be9d52022-01-19 14:32:53 +000067
68 // The field claims to be milliseconds but is actually seconds.
69 #[serde(rename = "lastUpdateMillis")]
70 last_update_seconds: u64,
Jiyong Parkd6502352022-01-27 01:07:30 +090071
72 #[serde(rename = "isFactory")]
73 is_factory: bool,
Jooyung Hanec788042022-01-27 22:28:37 +090074
75 #[serde(rename = "isActive")]
76 is_active: bool,
Jooyung Han5ce867a2022-01-28 03:18:38 +090077
78 #[serde(rename = "provideSharedApexLibs")]
79 provide_shared_apex_libs: bool,
Nikita Ioffed4551e12023-07-14 16:01:03 +010080
81 #[serde(rename = "preinstalledModulePath")]
82 preinstalled_path: PathBuf,
Jooyung Han73bac242021-07-02 10:25:49 +090083}
84
85impl ApexInfoList {
86 /// Loads ApexInfoList
Jooyung Han9900f3d2021-07-06 10:27:54 +090087 fn load() -> Result<&'static ApexInfoList> {
88 static INSTANCE: OnceCell<ApexInfoList> = OnceCell::new();
89 INSTANCE.get_or_try_init(|| {
Jooyung Han44b02ab2021-07-16 03:19:13 +090090 let apex_info_list = File::open(APEX_INFO_LIST_PATH)
91 .context(format!("Failed to open {}", APEX_INFO_LIST_PATH))?;
Jooyung Han9d7cd7d2021-10-12 17:44:14 +090092 let mut apex_info_list: ApexInfoList = from_reader(apex_info_list)
Jooyung Han44b02ab2021-07-16 03:19:13 +090093 .context(format!("Failed to parse {}", APEX_INFO_LIST_PATH))?;
Jooyung Han9d7cd7d2021-10-12 17:44:14 +090094
Alan Stokesbf20c6a2022-01-04 12:30:50 +000095 // For active APEXes, we run derive_classpath and parse its output to see if it
96 // contributes to the classpath(s). (This allows us to handle any new classpath env
97 // vars seamlessly.)
Inseob Kimecde8c02024-09-03 13:11:08 +090098 if !cfg!(early) {
99 let classpath_vars = run_derive_classpath()?;
100 let classpath_apexes = find_apex_names_in_classpath(&classpath_vars)?;
Alan Stokesbf20c6a2022-01-04 12:30:50 +0000101
Inseob Kimecde8c02024-09-03 13:11:08 +0900102 for apex_info in apex_info_list.list.iter_mut() {
103 apex_info.has_classpath_jar = classpath_apexes.contains(&apex_info.name);
104 }
Jooyung Han9d7cd7d2021-10-12 17:44:14 +0900105 }
Alan Stokesbf20c6a2022-01-04 12:30:50 +0000106
Jooyung Han44b02ab2021-07-16 03:19:13 +0900107 Ok(apex_info_list)
Jooyung Han9900f3d2021-07-06 10:27:54 +0900108 })
Jooyung Han73bac242021-07-02 10:25:49 +0900109 }
Jooyung Han743e0d62022-11-07 20:57:48 +0900110
111 // Override apex info with the staged one
112 fn override_staged_apex(&mut self, staged_apex_info: &StagedApexInfo) -> Result<()> {
113 let mut need_to_add: Option<ApexInfo> = None;
114 for apex_info in self.list.iter_mut() {
115 if staged_apex_info.moduleName == apex_info.name {
116 if apex_info.is_active && apex_info.is_factory {
117 // Copy the entry to the end as factory/non-active after the loop
118 // to keep the factory version. Typically this step is unncessary,
119 // but some apexes (like sharedlibs) need to be kept even if it's inactive.
120 need_to_add.replace(ApexInfo { is_active: false, ..apex_info.clone() });
121 // And make this one as non-factory. Note that this one is still active
122 // and overridden right below.
123 apex_info.is_factory = false;
124 }
125 // Active one is overridden with the staged one.
126 if apex_info.is_active {
Jooyung Hancaa995c2022-11-08 16:35:50 +0900127 apex_info.version = staged_apex_info.versionCode as u64;
Jooyung Han743e0d62022-11-07 20:57:48 +0900128 apex_info.path = PathBuf::from(&staged_apex_info.diskImagePath);
129 apex_info.has_classpath_jar = staged_apex_info.hasClassPathJars;
130 apex_info.last_update_seconds = last_updated(&apex_info.path)?;
131 }
132 }
133 }
134 if let Some(info) = need_to_add {
135 self.list.push(info);
136 }
137 Ok(())
138 }
139}
140
141fn last_updated<P: AsRef<Path>>(path: P) -> Result<u64> {
142 let metadata = metadata(path)?;
143 Ok(metadata.modified()?.duration_since(SystemTime::UNIX_EPOCH)?.as_secs())
Jooyung Hanec788042022-01-27 22:28:37 +0900144}
Jooyung Han73bac242021-07-02 10:25:49 +0900145
Jooyung Hanec788042022-01-27 22:28:37 +0900146impl ApexInfo {
147 fn matches(&self, apex_config: &ApexConfig) -> bool {
148 // Match with pseudo name "{CLASSPATH}" which represents APEXes contributing
149 // to any derive_classpath environment variable
150 if apex_config.name == "{CLASSPATH}" && self.has_classpath_jar {
151 return true;
152 }
153 if apex_config.name == self.name {
154 return true;
155 }
156 false
Jooyung Han73bac242021-07-02 10:25:49 +0900157 }
Jooyung Han21e9b922021-06-26 04:14:16 +0900158}
159
Jooyung Han5dc42172021-10-05 16:43:47 +0900160struct PackageManager {
Jooyung Han5dc42172021-10-05 16:43:47 +0900161 apex_info_list: &'static ApexInfoList,
162}
163
164impl PackageManager {
165 fn new() -> Result<Self> {
Jooyung Han5dc42172021-10-05 16:43:47 +0900166 let apex_info_list = ApexInfoList::load()?;
Jooyung Han53cf7992021-10-18 19:38:41 +0900167 Ok(Self { apex_info_list })
Jooyung Han5dc42172021-10-05 16:43:47 +0900168 }
169
Jooyung Han9d7cd7d2021-10-12 17:44:14 +0900170 fn get_apex_list(&self, prefer_staged: bool) -> Result<ApexInfoList> {
Jooyung Han53cf7992021-10-18 19:38:41 +0900171 // get the list of active apexes
Jooyung Han9d7cd7d2021-10-12 17:44:14 +0900172 let mut list = self.apex_info_list.clone();
Jooyung Han53cf7992021-10-18 19:38:41 +0900173 // When prefer_staged, we override ApexInfo by consulting "package_native"
Jooyung Han5dc42172021-10-05 16:43:47 +0900174 if prefer_staged {
Inseob Kimecde8c02024-09-03 13:11:08 +0900175 if cfg!(early) {
176 return Err(anyhow!("Can't turn on prefer_staged on early boot VMs"));
177 }
Jooyung Han53cf7992021-10-18 19:38:41 +0900178 let pm =
179 wait_for_interface::<dyn IPackageManagerNative>(PACKAGE_MANAGER_NATIVE_SERVICE)
180 .context("Failed to get service when prefer_staged is set.")?;
Jooyung Hana94e92d2024-10-11 14:16:27 +0900181 let staged = pm.getStagedApexInfos().context("getStagedApexInfos failed")?;
182 for apex in staged {
183 list.override_staged_apex(&apex)?;
Jooyung Han5dc42172021-10-05 16:43:47 +0900184 }
185 }
Jooyung Han9d7cd7d2021-10-12 17:44:14 +0900186 Ok(list)
Jooyung Han5dc42172021-10-05 16:43:47 +0900187 }
188}
189
Andrew Walbrancc0db522021-07-12 17:03:42 +0000190fn make_metadata_file(
Alan Stokes0d1ef782022-09-27 13:46:35 +0100191 app_config: &VirtualMachineAppConfig,
Jooyung Hanec788042022-01-27 22:28:37 +0900192 apex_infos: &[&ApexInfo],
Jooyung Han21e9b922021-06-26 04:14:16 +0900193 temporary_directory: &Path,
Andrew Walbrancc0db522021-07-12 17:03:42 +0000194) -> Result<ParcelFileDescriptor> {
Alan Stokes0d1ef782022-09-27 13:46:35 +0100195 let payload_metadata = match &app_config.payload {
Ludovic Barman93ee3082023-06-20 12:18:43 +0000196 Payload::PayloadConfig(payload_config) => PayloadMetadata::Config(PayloadConfig {
Alan Stokes8f12f2b2023-01-09 09:19:20 +0000197 payload_binary_name: payload_config.payloadBinaryName.clone(),
Alan Stokesfda70842023-12-20 17:50:14 +0000198 extra_apk_count: payload_config.extraApks.len().try_into()?,
199 special_fields: Default::default(),
Alan Stokes0d1ef782022-09-27 13:46:35 +0100200 }),
201 Payload::ConfigPath(config_path) => {
Ludovic Barman93ee3082023-06-20 12:18:43 +0000202 PayloadMetadata::ConfigPath(format!("/mnt/apk/{}", config_path))
Alan Stokes0d1ef782022-09-27 13:46:35 +0100203 }
204 };
205
Jooyung Han21e9b922021-06-26 04:14:16 +0900206 let metadata = Metadata {
Andrew Walbrancc0db522021-07-12 17:03:42 +0000207 version: 1,
Jooyung Hanec788042022-01-27 22:28:37 +0900208 apexes: apex_infos
Jooyung Han21e9b922021-06-26 04:14:16 +0900209 .iter()
Jooyung Han19c1d6c2021-08-06 14:08:16 +0900210 .enumerate()
Jooyung Hanec788042022-01-27 22:28:37 +0900211 .map(|(i, apex_info)| {
Andrew Walbran40be9d52022-01-19 14:32:53 +0000212 Ok(ApexPayload {
Jooyung Hanec788042022-01-27 22:28:37 +0900213 name: apex_info.name.clone(),
Andrew Walbran40be9d52022-01-19 14:32:53 +0000214 partition_name: format!("microdroid-apex-{}", i),
Jiyong Parkd6502352022-01-27 01:07:30 +0900215 last_update_seconds: apex_info.last_update_seconds,
216 is_factory: apex_info.is_factory,
Andrew Walbran40be9d52022-01-19 14:32:53 +0000217 ..Default::default()
218 })
Jooyung Han19c1d6c2021-08-06 14:08:16 +0900219 })
Andrew Walbran40be9d52022-01-19 14:32:53 +0000220 .collect::<Result<_>>()?,
Jooyung Han21e9b922021-06-26 04:14:16 +0900221 apk: Some(ApkPayload {
Jooyung Han35edb8f2021-07-01 16:17:16 +0900222 name: "apk".to_owned(),
223 payload_partition_name: "microdroid-apk".to_owned(),
224 idsig_partition_name: "microdroid-apk-idsig".to_owned(),
Jooyung Han21e9b922021-06-26 04:14:16 +0900225 ..Default::default()
226 })
227 .into(),
Alan Stokes0d1ef782022-09-27 13:46:35 +0100228 payload: Some(payload_metadata),
Jooyung Han21e9b922021-06-26 04:14:16 +0900229 ..Default::default()
230 };
Andrew Walbrancc0db522021-07-12 17:03:42 +0000231
232 // Write metadata to file.
Alan Stokes0d1ef782022-09-27 13:46:35 +0100233 let metadata_path = temporary_directory.join("metadata");
Andrew Walbrancc0db522021-07-12 17:03:42 +0000234 let mut metadata_file = OpenOptions::new()
235 .create_new(true)
236 .read(true)
237 .write(true)
238 .open(&metadata_path)
239 .with_context(|| format!("Failed to open metadata file {:?}", metadata_path))?;
Jooyung Han21e9b922021-06-26 04:14:16 +0900240 microdroid_metadata::write_metadata(&metadata, &mut metadata_file)?;
241
Andrew Walbrancc0db522021-07-12 17:03:42 +0000242 // Re-open the metadata file as read-only.
243 open_parcel_file(&metadata_path, false)
244}
245
246/// Creates a DiskImage with partitions:
Alan Stokes53cc5ca2022-08-30 14:28:19 +0100247/// payload-metadata: metadata
Andrew Walbrancc0db522021-07-12 17:03:42 +0000248/// microdroid-apex-0: apex 0
249/// microdroid-apex-1: apex 1
250/// ..
251/// microdroid-apk: apk
252/// microdroid-apk-idsig: idsig
Inseob Kima5a262f2021-11-17 19:41:03 +0900253/// extra-apk-0: additional apk 0
254/// extra-idsig-0: additional idsig 0
255/// extra-apk-1: additional apk 1
256/// extra-idsig-1: additional idsig 1
257/// ..
Andrew Walbrancc0db522021-07-12 17:03:42 +0000258fn make_payload_disk(
Inseob Kima5a262f2021-11-17 19:41:03 +0900259 app_config: &VirtualMachineAppConfig,
Jaewan Kim61f86142023-03-28 15:12:52 +0900260 debug_config: &DebugConfig,
Andrew Walbrancc0db522021-07-12 17:03:42 +0000261 apk_file: File,
262 idsig_file: File,
Alan Stokesfda70842023-12-20 17:50:14 +0000263 extra_apk_files: Vec<File>,
Jooyung Han9d7cd7d2021-10-12 17:44:14 +0900264 vm_payload_config: &VmPayloadConfig,
Andrew Walbrancc0db522021-07-12 17:03:42 +0000265 temporary_directory: &Path,
266) -> Result<DiskImage> {
Alan Stokesfda70842023-12-20 17:50:14 +0000267 if extra_apk_files.len() != app_config.extraIdsigs.len() {
Inseob Kima5a262f2021-11-17 19:41:03 +0900268 bail!(
269 "payload config has {} apks, but app config has {} idsigs",
270 vm_payload_config.extra_apks.len(),
271 app_config.extraIdsigs.len()
272 );
273 }
274
Jooyung Han9d7cd7d2021-10-12 17:44:14 +0900275 let pm = PackageManager::new()?;
276 let apex_list = pm.get_apex_list(vm_payload_config.prefer_staged)?;
277
Jooyung Hanec788042022-01-27 22:28:37 +0900278 // collect APEXes from config
Nikita Ioffed4551e12023-07-14 16:01:03 +0100279 let mut apex_infos = collect_apex_infos(&apex_list, &vm_payload_config.apexes, debug_config)?;
Jooyung Hancaa995c2022-11-08 16:35:50 +0900280
281 // Pass sorted list of apexes. Sorting key shouldn't use `path` because it will change after
282 // reboot with prefer_staged. `last_update_seconds` is added to distinguish "samegrade"
283 // update.
284 apex_infos.sort_by_key(|info| (&info.name, &info.version, &info.last_update_seconds));
Jooyung Hanec788042022-01-27 22:28:37 +0900285 info!("Microdroid payload APEXes: {:?}", apex_infos.iter().map(|ai| &ai.name));
Jooyung Han9d7cd7d2021-10-12 17:44:14 +0900286
Alan Stokes0d1ef782022-09-27 13:46:35 +0100287 let metadata_file = make_metadata_file(app_config, &apex_infos, temporary_directory)?;
Jooyung Han21e9b922021-06-26 04:14:16 +0900288 // put metadata at the first partition
289 let mut partitions = vec![Partition {
Jooyung Han14e5a8e2021-07-06 20:48:38 +0900290 label: "payload-metadata".to_owned(),
Jooyung Han631d5882021-07-29 06:34:05 +0900291 image: Some(metadata_file),
Jooyung Han21e9b922021-06-26 04:14:16 +0900292 writable: false,
Jiyong Park3f9b5092024-07-10 13:38:29 +0900293 guid: None,
Jooyung Han21e9b922021-06-26 04:14:16 +0900294 }];
295
Jooyung Hanec788042022-01-27 22:28:37 +0900296 for (i, apex_info) in apex_infos.iter().enumerate() {
Inseob Kimecde8c02024-09-03 13:11:08 +0900297 let path = if cfg!(early) {
298 let path = &apex_info.preinstalled_path;
299 if path.extension().and_then(OsStr::to_str).unwrap_or("") != "apex" {
300 bail!("compressed APEX {} not supported", path.display());
301 }
302 path
303 } else {
304 &apex_info.path
305 };
306 let apex_file = open_parcel_file(path, false)?;
Jooyung Han95884632021-07-06 22:27:54 +0900307 partitions.push(Partition {
308 label: format!("microdroid-apex-{}", i),
Jooyung Han631d5882021-07-29 06:34:05 +0900309 image: Some(apex_file),
Jooyung Han95884632021-07-06 22:27:54 +0900310 writable: false,
Jiyong Park3f9b5092024-07-10 13:38:29 +0900311 guid: None,
Jooyung Han95884632021-07-06 22:27:54 +0900312 });
Jooyung Han21e9b922021-06-26 04:14:16 +0900313 }
Jooyung Han95884632021-07-06 22:27:54 +0900314 partitions.push(Partition {
315 label: "microdroid-apk".to_owned(),
Jooyung Han631d5882021-07-29 06:34:05 +0900316 image: Some(ParcelFileDescriptor::new(apk_file)),
Jooyung Han95884632021-07-06 22:27:54 +0900317 writable: false,
Jiyong Park3f9b5092024-07-10 13:38:29 +0900318 guid: None,
Jooyung Han95884632021-07-06 22:27:54 +0900319 });
320 partitions.push(Partition {
321 label: "microdroid-apk-idsig".to_owned(),
Jooyung Han631d5882021-07-29 06:34:05 +0900322 image: Some(ParcelFileDescriptor::new(idsig_file)),
Jooyung Han95884632021-07-06 22:27:54 +0900323 writable: false,
Jiyong Park3f9b5092024-07-10 13:38:29 +0900324 guid: None,
Jooyung Han95884632021-07-06 22:27:54 +0900325 });
Jooyung Han21e9b922021-06-26 04:14:16 +0900326
Inseob Kima5a262f2021-11-17 19:41:03 +0900327 // we've already checked that extra_apks and extraIdsigs are in the same size.
Inseob Kima5a262f2021-11-17 19:41:03 +0900328 let extra_idsigs = &app_config.extraIdsigs;
Alan Stokesfda70842023-12-20 17:50:14 +0000329 for (i, (extra_apk_file, extra_idsig)) in
330 extra_apk_files.into_iter().zip(extra_idsigs.iter()).enumerate()
331 {
Inseob Kima5a262f2021-11-17 19:41:03 +0900332 partitions.push(Partition {
Alan Stokesfda70842023-12-20 17:50:14 +0000333 label: format!("extra-apk-{i}"),
334 image: Some(ParcelFileDescriptor::new(extra_apk_file)),
Inseob Kima5a262f2021-11-17 19:41:03 +0900335 writable: false,
Jiyong Park3f9b5092024-07-10 13:38:29 +0900336 guid: None,
Inseob Kima5a262f2021-11-17 19:41:03 +0900337 });
338
339 partitions.push(Partition {
Alan Stokesfda70842023-12-20 17:50:14 +0000340 label: format!("extra-idsig-{i}"),
Victor Hsieh14497f02022-09-21 10:10:16 -0700341 image: Some(ParcelFileDescriptor::new(
342 extra_idsig
343 .as_ref()
344 .try_clone()
Alan Stokesfda70842023-12-20 17:50:14 +0000345 .with_context(|| format!("Failed to clone the extra idsig #{i}"))?,
Victor Hsieh14497f02022-09-21 10:10:16 -0700346 )),
Inseob Kima5a262f2021-11-17 19:41:03 +0900347 writable: false,
Jiyong Park3f9b5092024-07-10 13:38:29 +0900348 guid: None,
Inseob Kima5a262f2021-11-17 19:41:03 +0900349 });
350 }
351
Jooyung Han21e9b922021-06-26 04:14:16 +0900352 Ok(DiskImage { image: None, partitions, writable: false })
353}
Andrew Walbrancc0db522021-07-12 17:03:42 +0000354
Alan Stokesbf20c6a2022-01-04 12:30:50 +0000355fn run_derive_classpath() -> Result<String> {
356 let result = Command::new("/apex/com.android.sdkext/bin/derive_classpath")
357 .arg("/proc/self/fd/1")
358 .output()
359 .context("Failed to run derive_classpath")?;
360
361 if !result.status.success() {
362 bail!("derive_classpath returned {}", result.status);
363 }
364
365 String::from_utf8(result.stdout).context("Converting derive_classpath output")
366}
367
368fn find_apex_names_in_classpath(classpath_vars: &str) -> Result<HashSet<String>> {
369 // Each line should be in the format "export <var name> <paths>", where <paths> is a
370 // colon-separated list of paths to JARs. We don't care about the var names, and we're only
371 // interested in paths that look like "/apex/<apex name>/<anything>" so we know which APEXes
372 // contribute to at least one var.
373 let mut apexes = HashSet::new();
374
375 let pattern = Regex::new(r"^export [^ ]+ ([^ ]+)$").context("Failed to construct Regex")?;
376 for line in classpath_vars.lines() {
377 if let Some(captures) = pattern.captures(line) {
378 if let Some(paths) = captures.get(1) {
379 apexes.extend(paths.as_str().split(':').filter_map(|path| {
380 let path = path.strip_prefix("/apex/")?;
381 Some(path[..path.find('/')?].to_owned())
382 }));
383 continue;
384 }
385 }
386 warn!("Malformed line from derive_classpath: {}", line);
387 }
388
389 Ok(apexes)
Jooyung Han5e0f2062021-10-12 14:00:46 +0900390}
391
Nikita Ioffed4551e12023-07-14 16:01:03 +0100392fn check_apexes_are_from_allowed_partitions(requested_apexes: &Vec<&ApexInfo>) -> Result<()> {
393 const ALLOWED_PARTITIONS: [&str; 2] = ["/system", "/system_ext"];
394 for apex in requested_apexes {
395 if !ALLOWED_PARTITIONS.iter().any(|p| apex.preinstalled_path.starts_with(p)) {
396 bail!("Non-system APEX {} is not supported in Microdroid", apex.name);
397 }
398 }
399 Ok(())
400}
401
Jooyung Hanec788042022-01-27 22:28:37 +0900402// Collect ApexInfos from VM config
403fn collect_apex_infos<'a>(
404 apex_list: &'a ApexInfoList,
405 apex_configs: &[ApexConfig],
Jaewan Kim61f86142023-03-28 15:12:52 +0900406 debug_config: &DebugConfig,
Nikita Ioffed4551e12023-07-14 16:01:03 +0100407) -> Result<Vec<&'a ApexInfo>> {
Alan Stokesf7260f12023-08-30 17:25:21 +0100408 // APEXes which any Microdroid VM needs.
409 // TODO(b/192200378) move this to microdroid.json?
410 let required_apexes: &[_] =
411 if debug_config.should_include_debug_apexes() { &["com.android.adbd"] } else { &[] };
Jooyung Hanec788042022-01-27 22:28:37 +0900412
Nikita Ioffed4551e12023-07-14 16:01:03 +0100413 let apex_infos = apex_list
Jooyung Hanec788042022-01-27 22:28:37 +0900414 .list
415 .iter()
416 .filter(|ai| {
417 apex_configs.iter().any(|cfg| ai.matches(cfg) && ai.is_active)
Alan Stokesf7260f12023-08-30 17:25:21 +0100418 || required_apexes.iter().any(|name| name == &ai.name && ai.is_active)
Jooyung Han5ce867a2022-01-28 03:18:38 +0900419 || ai.provide_shared_apex_libs
Jooyung Hanec788042022-01-27 22:28:37 +0900420 })
Nikita Ioffed4551e12023-07-14 16:01:03 +0100421 .collect();
422
423 check_apexes_are_from_allowed_partitions(&apex_infos)?;
424 Ok(apex_infos)
Jooyung Han5e0f2062021-10-12 14:00:46 +0900425}
426
Nikita Ioffe5dfddf22023-06-29 16:11:26 +0100427pub fn add_microdroid_vendor_image(vendor_image: File, vm_config: &mut VirtualMachineRawConfig) {
428 vm_config.disks.push(DiskImage {
429 image: None,
430 writable: false,
431 partitions: vec![Partition {
432 label: "microdroid-vendor".to_owned(),
433 image: Some(ParcelFileDescriptor::new(vendor_image)),
434 writable: false,
Jiyong Park3f9b5092024-07-10 13:38:29 +0900435 guid: None,
Nikita Ioffe5dfddf22023-06-29 16:11:26 +0100436 }],
437 })
438}
439
Shikha Panwar22e70452022-10-10 18:32:55 +0000440pub fn add_microdroid_system_images(
Andrew Walbrancc0db522021-07-12 17:03:42 +0000441 config: &VirtualMachineAppConfig,
Jiyong Park8d081812021-07-23 17:45:04 +0900442 instance_file: File,
Shikha Panwar22e70452022-10-10 18:32:55 +0000443 storage_image: Option<File>,
Inseob Kim172f9eb2023-11-06 17:02:08 +0900444 os_name: &str,
Andrew Walbrancc0db522021-07-12 17:03:42 +0000445 vm_config: &mut VirtualMachineRawConfig,
446) -> Result<()> {
Shikha Panwared8ace42022-09-28 12:52:16 +0000447 let debug_suffix = match config.debugLevel {
448 DebugLevel::NONE => "normal",
Seungjae Yooe85831e2022-12-12 09:34:58 +0900449 DebugLevel::FULL => "debuggable",
Shikha Panwared8ace42022-09-28 12:52:16 +0000450 _ => return Err(anyhow!("unsupported debug level: {:?}", config.debugLevel)),
451 };
Inseob Kim172f9eb2023-11-06 17:02:08 +0900452 let initrd = format!("/apex/com.android.virt/etc/{os_name}_initrd_{debug_suffix}.img");
Shikha Panwared8ace42022-09-28 12:52:16 +0000453 vm_config.initrd = Some(open_parcel_file(Path::new(&initrd), false)?);
454
Shikha Panwar22e70452022-10-10 18:32:55 +0000455 let mut writable_partitions = vec![Partition {
Shikha Panwared8ace42022-09-28 12:52:16 +0000456 label: "vm-instance".to_owned(),
457 image: Some(ParcelFileDescriptor::new(instance_file)),
458 writable: true,
Jiyong Park3f9b5092024-07-10 13:38:29 +0900459 guid: None,
Shikha Panwar22e70452022-10-10 18:32:55 +0000460 }];
461
462 if let Some(file) = storage_image {
463 writable_partitions.push(Partition {
Shikha Panwar566c9672022-11-15 14:39:58 +0000464 label: "encryptedstore".to_owned(),
Shikha Panwar22e70452022-10-10 18:32:55 +0000465 image: Some(ParcelFileDescriptor::new(file)),
466 writable: true,
Jiyong Park3f9b5092024-07-10 13:38:29 +0900467 guid: None,
Shikha Panwar22e70452022-10-10 18:32:55 +0000468 });
469 }
470
471 vm_config.disks.push(DiskImage {
472 image: None,
473 partitions: writable_partitions,
474 writable: true,
475 });
476
477 Ok(())
478}
479
Alan Stokesfda70842023-12-20 17:50:14 +0000480#[allow(clippy::too_many_arguments)] // TODO: Fewer arguments
Shikha Panwar22e70452022-10-10 18:32:55 +0000481pub fn add_microdroid_payload_images(
482 config: &VirtualMachineAppConfig,
Jaewan Kim61f86142023-03-28 15:12:52 +0900483 debug_config: &DebugConfig,
Shikha Panwar22e70452022-10-10 18:32:55 +0000484 temporary_directory: &Path,
485 apk_file: File,
486 idsig_file: File,
Alan Stokesfda70842023-12-20 17:50:14 +0000487 extra_apk_files: Vec<File>,
Shikha Panwar22e70452022-10-10 18:32:55 +0000488 vm_payload_config: &VmPayloadConfig,
489 vm_config: &mut VirtualMachineRawConfig,
490) -> Result<()> {
Andrew Walbrancc0db522021-07-12 17:03:42 +0000491 vm_config.disks.push(make_payload_disk(
Inseob Kima5a262f2021-11-17 19:41:03 +0900492 config,
Jaewan Kim61f86142023-03-28 15:12:52 +0900493 debug_config,
Andrew Walbrancc0db522021-07-12 17:03:42 +0000494 apk_file,
495 idsig_file,
Alan Stokesfda70842023-12-20 17:50:14 +0000496 extra_apk_files,
Jooyung Han9d7cd7d2021-10-12 17:44:14 +0900497 vm_payload_config,
Andrew Walbrancc0db522021-07-12 17:03:42 +0000498 temporary_directory,
499 )?);
500
Andrew Walbrancc0db522021-07-12 17:03:42 +0000501 Ok(())
502}
Jooyung Han5e0f2062021-10-12 14:00:46 +0900503
504#[cfg(test)]
505mod tests {
506 use super::*;
Alan Stokesf7260f12023-08-30 17:25:21 +0100507 use std::collections::HashMap;
Jooyung Han743e0d62022-11-07 20:57:48 +0900508 use tempfile::NamedTempFile;
Andrew Walbranc1a5f5a2022-01-19 13:38:13 +0000509
Jooyung Han5e0f2062021-10-12 14:00:46 +0900510 #[test]
Alan Stokesbf20c6a2022-01-04 12:30:50 +0000511 fn test_find_apex_names_in_classpath() {
512 let vars = r#"
513export FOO /apex/unterminated
514export BAR /apex/valid.apex/something
515wrong
516export EMPTY
517export OTHER /foo/bar:/baz:/apex/second.valid.apex/:gibberish:"#;
518 let expected = vec!["valid.apex", "second.valid.apex"];
519 let expected: HashSet<_> = expected.into_iter().map(ToString::to_string).collect();
520
521 assert_eq!(find_apex_names_in_classpath(vars).unwrap(), expected);
Jooyung Han5e0f2062021-10-12 14:00:46 +0900522 }
Andrew Walbranc1a5f5a2022-01-19 13:38:13 +0000523
524 #[test]
Nikita Ioffed4551e12023-07-14 16:01:03 +0100525 fn test_collect_apexes() -> Result<()> {
Alan Stokesf7260f12023-08-30 17:25:21 +0100526 let apex_infos_for_test = [
527 (
528 "adbd",
Andrew Walbranc1a5f5a2022-01-19 13:38:13 +0000529 ApexInfo {
Jooyung Hanec788042022-01-27 22:28:37 +0900530 name: "com.android.adbd".to_string(),
531 path: PathBuf::from("adbd"),
Nikita Ioffed4551e12023-07-14 16:01:03 +0100532 preinstalled_path: PathBuf::from("/system/adbd"),
Andrew Walbranc1a5f5a2022-01-19 13:38:13 +0000533 has_classpath_jar: false,
Andrew Walbran40be9d52022-01-19 14:32:53 +0000534 last_update_seconds: 12345678,
Jiyong Parkd6502352022-01-27 01:07:30 +0900535 is_factory: true,
Jooyung Hanec788042022-01-27 22:28:37 +0900536 is_active: false,
Jooyung Han5ce867a2022-01-28 03:18:38 +0900537 ..Default::default()
Jooyung Hanec788042022-01-27 22:28:37 +0900538 },
Alan Stokesf7260f12023-08-30 17:25:21 +0100539 ),
540 (
541 "adbd_updated",
Jooyung Hanec788042022-01-27 22:28:37 +0900542 ApexInfo {
Alan Stokesf7260f12023-08-30 17:25:21 +0100543 name: "com.android.adbd".to_string(),
544 path: PathBuf::from("adbd"),
545 preinstalled_path: PathBuf::from("/system/adbd"),
Jooyung Hanec788042022-01-27 22:28:37 +0900546 has_classpath_jar: false,
547 last_update_seconds: 12345678 + 1,
548 is_factory: false,
549 is_active: true,
Jooyung Han5ce867a2022-01-28 03:18:38 +0900550 ..Default::default()
Jooyung Hanec788042022-01-27 22:28:37 +0900551 },
Alan Stokesf7260f12023-08-30 17:25:21 +0100552 ),
553 (
554 "no_classpath",
Jooyung Hanec788042022-01-27 22:28:37 +0900555 ApexInfo {
Jooyung Hanec788042022-01-27 22:28:37 +0900556 name: "no_classpath".to_string(),
557 path: PathBuf::from("no_classpath"),
558 has_classpath_jar: false,
559 last_update_seconds: 12345678,
560 is_factory: true,
561 is_active: true,
Jooyung Han5ce867a2022-01-28 03:18:38 +0900562 ..Default::default()
Jooyung Hanec788042022-01-27 22:28:37 +0900563 },
Alan Stokesf7260f12023-08-30 17:25:21 +0100564 ),
565 (
566 "has_classpath",
Jooyung Hanec788042022-01-27 22:28:37 +0900567 ApexInfo {
Andrew Walbranc1a5f5a2022-01-19 13:38:13 +0000568 name: "has_classpath".to_string(),
Jooyung Hanec788042022-01-27 22:28:37 +0900569 path: PathBuf::from("has_classpath"),
Andrew Walbranc1a5f5a2022-01-19 13:38:13 +0000570 has_classpath_jar: true,
Andrew Walbran40be9d52022-01-19 14:32:53 +0000571 last_update_seconds: 87654321,
Jooyung Hanec788042022-01-27 22:28:37 +0900572 is_factory: true,
573 is_active: false,
Jooyung Han5ce867a2022-01-28 03:18:38 +0900574 ..Default::default()
Jooyung Hanec788042022-01-27 22:28:37 +0900575 },
Alan Stokesf7260f12023-08-30 17:25:21 +0100576 ),
577 (
578 "has_classpath_updated",
Jooyung Hanec788042022-01-27 22:28:37 +0900579 ApexInfo {
Jooyung Hanec788042022-01-27 22:28:37 +0900580 name: "has_classpath".to_string(),
581 path: PathBuf::from("has_classpath/updated"),
Nikita Ioffed4551e12023-07-14 16:01:03 +0100582 preinstalled_path: PathBuf::from("/system/has_classpath"),
Jooyung Hanec788042022-01-27 22:28:37 +0900583 has_classpath_jar: true,
584 last_update_seconds: 87654321 + 1,
Jiyong Parkd6502352022-01-27 01:07:30 +0900585 is_factory: false,
Jooyung Hanec788042022-01-27 22:28:37 +0900586 is_active: true,
Jooyung Han5ce867a2022-01-28 03:18:38 +0900587 ..Default::default()
Jooyung Hanec788042022-01-27 22:28:37 +0900588 },
Alan Stokesf7260f12023-08-30 17:25:21 +0100589 ),
590 (
591 "apex-foo",
Jooyung Hanec788042022-01-27 22:28:37 +0900592 ApexInfo {
Jooyung Hanec788042022-01-27 22:28:37 +0900593 name: "apex-foo".to_string(),
594 path: PathBuf::from("apex-foo"),
Nikita Ioffed4551e12023-07-14 16:01:03 +0100595 preinstalled_path: PathBuf::from("/system/apex-foo"),
Jooyung Hanec788042022-01-27 22:28:37 +0900596 has_classpath_jar: false,
597 last_update_seconds: 87654321,
598 is_factory: true,
599 is_active: false,
Jooyung Han5ce867a2022-01-28 03:18:38 +0900600 ..Default::default()
Jooyung Hanec788042022-01-27 22:28:37 +0900601 },
Alan Stokesf7260f12023-08-30 17:25:21 +0100602 ),
603 (
604 "apex-foo-updated",
Jooyung Hanec788042022-01-27 22:28:37 +0900605 ApexInfo {
Jooyung Hanec788042022-01-27 22:28:37 +0900606 name: "apex-foo".to_string(),
607 path: PathBuf::from("apex-foo/updated"),
Nikita Ioffed4551e12023-07-14 16:01:03 +0100608 preinstalled_path: PathBuf::from("/system/apex-foo"),
Jooyung Hanec788042022-01-27 22:28:37 +0900609 has_classpath_jar: false,
610 last_update_seconds: 87654321 + 1,
611 is_factory: false,
612 is_active: true,
Jooyung Han5ce867a2022-01-28 03:18:38 +0900613 ..Default::default()
614 },
Alan Stokesf7260f12023-08-30 17:25:21 +0100615 ),
616 (
617 "sharedlibs",
Jooyung Han5ce867a2022-01-28 03:18:38 +0900618 ApexInfo {
Jooyung Han5ce867a2022-01-28 03:18:38 +0900619 name: "sharedlibs".to_string(),
620 path: PathBuf::from("apex-foo"),
Nikita Ioffed4551e12023-07-14 16:01:03 +0100621 preinstalled_path: PathBuf::from("/system/apex-foo"),
Jooyung Han5ce867a2022-01-28 03:18:38 +0900622 last_update_seconds: 87654321,
623 is_factory: true,
624 provide_shared_apex_libs: true,
625 ..Default::default()
626 },
Alan Stokesf7260f12023-08-30 17:25:21 +0100627 ),
628 (
629 "sharedlibs-updated",
Jooyung Han5ce867a2022-01-28 03:18:38 +0900630 ApexInfo {
Jooyung Han5ce867a2022-01-28 03:18:38 +0900631 name: "sharedlibs".to_string(),
632 path: PathBuf::from("apex-foo/updated"),
Nikita Ioffed4551e12023-07-14 16:01:03 +0100633 preinstalled_path: PathBuf::from("/system/apex-foo"),
Jooyung Han5ce867a2022-01-28 03:18:38 +0900634 last_update_seconds: 87654321 + 1,
635 is_active: true,
636 provide_shared_apex_libs: true,
637 ..Default::default()
Andrew Walbranc1a5f5a2022-01-19 13:38:13 +0000638 },
Alan Stokesf7260f12023-08-30 17:25:21 +0100639 ),
640 ];
641 let apex_info_list = ApexInfoList {
642 list: apex_infos_for_test.iter().map(|(_, info)| info).cloned().collect(),
Andrew Walbranc1a5f5a2022-01-19 13:38:13 +0000643 };
Alan Stokesf7260f12023-08-30 17:25:21 +0100644 let apex_info_map = HashMap::from(apex_infos_for_test);
Jooyung Hanec788042022-01-27 22:28:37 +0900645 let apex_configs = vec![
646 ApexConfig { name: "apex-foo".to_string() },
Andrew Walbranc1a5f5a2022-01-19 13:38:13 +0000647 ApexConfig { name: "{CLASSPATH}".to_string() },
648 ];
649 assert_eq!(
Nikita Ioffed4551e12023-07-14 16:01:03 +0100650 collect_apex_infos(
651 &apex_info_list,
652 &apex_configs,
Jaewan Kimf3143242024-03-15 06:56:31 +0000653 &DebugConfig::new_with_debug_level(DebugLevel::FULL)
Nikita Ioffed4551e12023-07-14 16:01:03 +0100654 )?,
Andrew Walbranc1a5f5a2022-01-19 13:38:13 +0000655 vec![
Jooyung Han5ce867a2022-01-28 03:18:38 +0900656 // Pass active/required APEXes
Alan Stokesf7260f12023-08-30 17:25:21 +0100657 &apex_info_map["adbd_updated"],
Jooyung Han5ce867a2022-01-28 03:18:38 +0900658 // Pass active APEXes specified in the config
Alan Stokesf7260f12023-08-30 17:25:21 +0100659 &apex_info_map["has_classpath_updated"],
660 &apex_info_map["apex-foo-updated"],
Jooyung Han5ce867a2022-01-28 03:18:38 +0900661 // Pass both preinstalled(inactive) and updated(active) for "sharedlibs" APEXes
Alan Stokesf7260f12023-08-30 17:25:21 +0100662 &apex_info_map["sharedlibs"],
663 &apex_info_map["sharedlibs-updated"],
Andrew Walbranc1a5f5a2022-01-19 13:38:13 +0000664 ]
665 );
Nikita Ioffed4551e12023-07-14 16:01:03 +0100666 Ok(())
667 }
668
669 #[test]
670 fn test_check_allowed_partitions_vendor_not_allowed() -> Result<()> {
671 let apex_info_list = ApexInfoList {
672 list: vec![ApexInfo {
673 name: "apex-vendor".to_string(),
674 path: PathBuf::from("apex-vendor"),
675 preinstalled_path: PathBuf::from("/vendor/apex-vendor"),
676 is_active: true,
677 ..Default::default()
678 }],
679 };
680 let apex_configs = vec![ApexConfig { name: "apex-vendor".to_string() }];
681
Jaewan Kimf3143242024-03-15 06:56:31 +0000682 let ret = collect_apex_infos(
683 &apex_info_list,
684 &apex_configs,
685 &DebugConfig::new_with_debug_level(DebugLevel::NONE),
686 );
Nikita Ioffed4551e12023-07-14 16:01:03 +0100687 assert!(ret
688 .is_err_and(|ret| ret.to_string()
689 == "Non-system APEX apex-vendor is not supported in Microdroid"));
690
691 Ok(())
692 }
693
694 #[test]
695 fn test_check_allowed_partitions_system_ext_allowed() -> Result<()> {
696 let apex_info_list = ApexInfoList {
697 list: vec![ApexInfo {
698 name: "apex-system_ext".to_string(),
699 path: PathBuf::from("apex-system_ext"),
700 preinstalled_path: PathBuf::from("/system_ext/apex-system_ext"),
701 is_active: true,
702 ..Default::default()
703 }],
704 };
705
706 let apex_configs = vec![ApexConfig { name: "apex-system_ext".to_string() }];
707
708 assert_eq!(
709 collect_apex_infos(
710 &apex_info_list,
711 &apex_configs,
Jaewan Kimf3143242024-03-15 06:56:31 +0000712 &DebugConfig::new_with_debug_level(DebugLevel::NONE)
Nikita Ioffed4551e12023-07-14 16:01:03 +0100713 )?,
714 vec![&apex_info_list.list[0]]
715 );
716
717 Ok(())
Andrew Walbranc1a5f5a2022-01-19 13:38:13 +0000718 }
Jooyung Han743e0d62022-11-07 20:57:48 +0900719
720 #[test]
721 fn test_prefer_staged_apex_with_factory_active_apex() {
722 let single_apex = ApexInfo {
723 name: "foo".to_string(),
Jooyung Hancaa995c2022-11-08 16:35:50 +0900724 version: 1,
Jooyung Han743e0d62022-11-07 20:57:48 +0900725 path: PathBuf::from("foo.apex"),
726 is_factory: true,
727 is_active: true,
728 ..Default::default()
729 };
730 let mut apex_info_list = ApexInfoList { list: vec![single_apex.clone()] };
731
732 let staged = NamedTempFile::new().unwrap();
733 apex_info_list
734 .override_staged_apex(&StagedApexInfo {
735 moduleName: "foo".to_string(),
Jooyung Hancaa995c2022-11-08 16:35:50 +0900736 versionCode: 2,
Jooyung Han743e0d62022-11-07 20:57:48 +0900737 diskImagePath: staged.path().to_string_lossy().to_string(),
738 ..Default::default()
739 })
740 .expect("should be ok");
741
742 assert_eq!(
743 apex_info_list,
744 ApexInfoList {
745 list: vec![
746 ApexInfo {
Jooyung Hancaa995c2022-11-08 16:35:50 +0900747 version: 2,
Jooyung Han743e0d62022-11-07 20:57:48 +0900748 is_factory: false,
749 path: staged.path().to_owned(),
750 last_update_seconds: last_updated(staged.path()).unwrap(),
751 ..single_apex.clone()
752 },
753 ApexInfo { is_active: false, ..single_apex },
754 ],
755 }
756 );
757 }
758
759 #[test]
760 fn test_prefer_staged_apex_with_factory_and_inactive_apex() {
761 let factory_apex = ApexInfo {
762 name: "foo".to_string(),
Jooyung Hancaa995c2022-11-08 16:35:50 +0900763 version: 1,
Jooyung Han743e0d62022-11-07 20:57:48 +0900764 path: PathBuf::from("foo.apex"),
765 is_factory: true,
766 ..Default::default()
767 };
768 let active_apex = ApexInfo {
769 name: "foo".to_string(),
Jooyung Hancaa995c2022-11-08 16:35:50 +0900770 version: 2,
Jooyung Han743e0d62022-11-07 20:57:48 +0900771 path: PathBuf::from("foo.downloaded.apex"),
772 is_active: true,
773 ..Default::default()
774 };
775 let mut apex_info_list =
776 ApexInfoList { list: vec![factory_apex.clone(), active_apex.clone()] };
777
778 let staged = NamedTempFile::new().unwrap();
779 apex_info_list
780 .override_staged_apex(&StagedApexInfo {
781 moduleName: "foo".to_string(),
Jooyung Hancaa995c2022-11-08 16:35:50 +0900782 versionCode: 3,
Jooyung Han743e0d62022-11-07 20:57:48 +0900783 diskImagePath: staged.path().to_string_lossy().to_string(),
784 ..Default::default()
785 })
786 .expect("should be ok");
787
788 assert_eq!(
789 apex_info_list,
790 ApexInfoList {
791 list: vec![
792 // factory apex isn't touched
793 factory_apex,
794 // update active one
795 ApexInfo {
Jooyung Hancaa995c2022-11-08 16:35:50 +0900796 version: 3,
Jooyung Han743e0d62022-11-07 20:57:48 +0900797 path: staged.path().to_owned(),
798 last_update_seconds: last_updated(staged.path()).unwrap(),
799 ..active_apex
800 },
801 ],
802 }
803 );
804 }
Jooyung Han5e0f2062021-10-12 14:00:46 +0900805}