blob: 82d9ba0f3d60bd89f9eb66f5488a0916c9156f98 [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;
Andrew Walbran40be9d52022-01-19 14:32:53 +000038use std::fs::{metadata, File, OpenOptions};
Jooyung Han21e9b922021-06-26 04:14:16 +090039use std::path::{Path, PathBuf};
Alan Stokesbf20c6a2022-01-04 12:30:50 +000040use std::process::Command;
Andrew Walbran40be9d52022-01-19 14:32:53 +000041use std::time::SystemTime;
Andrew Walbrancc0db522021-07-12 17:03:42 +000042use vmconfig::open_parcel_file;
43
Jooyung Han44b02ab2021-07-16 03:19:13 +090044const APEX_INFO_LIST_PATH: &str = "/apex/apex-info-list.xml";
45
Jooyung Han5dc42172021-10-05 16:43:47 +090046const PACKAGE_MANAGER_NATIVE_SERVICE: &str = "package_native";
47
Jooyung Han73bac242021-07-02 10:25:49 +090048/// Represents the list of APEXes
Jooyung Han743e0d62022-11-07 20:57:48 +090049#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
Jooyung Han9900f3d2021-07-06 10:27:54 +090050struct ApexInfoList {
Jooyung Han44b02ab2021-07-16 03:19:13 +090051 #[serde(rename = "apex-info")]
Jooyung Han73bac242021-07-02 10:25:49 +090052 list: Vec<ApexInfo>,
53}
54
Jooyung Han5ce867a2022-01-28 03:18:38 +090055#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)]
Jooyung Han73bac242021-07-02 10:25:49 +090056struct ApexInfo {
Jooyung Han44b02ab2021-07-16 03:19:13 +090057 #[serde(rename = "moduleName")]
Jooyung Han73bac242021-07-02 10:25:49 +090058 name: String,
Jooyung Hancaa995c2022-11-08 16:35:50 +090059 #[serde(rename = "versionCode")]
60 version: u64,
Jooyung Han44b02ab2021-07-16 03:19:13 +090061 #[serde(rename = "modulePath")]
Jooyung Han73bac242021-07-02 10:25:49 +090062 path: PathBuf,
Jooyung Han9d7cd7d2021-10-12 17:44:14 +090063
64 #[serde(default)]
Alan Stokes46ac3862021-12-21 15:31:47 +000065 has_classpath_jar: bool,
Andrew Walbran40be9d52022-01-19 14:32:53 +000066
67 // The field claims to be milliseconds but is actually seconds.
68 #[serde(rename = "lastUpdateMillis")]
69 last_update_seconds: u64,
Jiyong Parkd6502352022-01-27 01:07:30 +090070
71 #[serde(rename = "isFactory")]
72 is_factory: bool,
Jooyung Hanec788042022-01-27 22:28:37 +090073
74 #[serde(rename = "isActive")]
75 is_active: bool,
Jooyung Han5ce867a2022-01-28 03:18:38 +090076
77 #[serde(rename = "provideSharedApexLibs")]
78 provide_shared_apex_libs: bool,
Nikita Ioffed4551e12023-07-14 16:01:03 +010079
80 #[serde(rename = "preinstalledModulePath")]
81 preinstalled_path: PathBuf,
Jooyung Han73bac242021-07-02 10:25:49 +090082}
83
84impl ApexInfoList {
85 /// Loads ApexInfoList
Jooyung Han9900f3d2021-07-06 10:27:54 +090086 fn load() -> Result<&'static ApexInfoList> {
87 static INSTANCE: OnceCell<ApexInfoList> = OnceCell::new();
88 INSTANCE.get_or_try_init(|| {
Jooyung Han44b02ab2021-07-16 03:19:13 +090089 let apex_info_list = File::open(APEX_INFO_LIST_PATH)
90 .context(format!("Failed to open {}", APEX_INFO_LIST_PATH))?;
Jooyung Han9d7cd7d2021-10-12 17:44:14 +090091 let mut apex_info_list: ApexInfoList = from_reader(apex_info_list)
Jooyung Han44b02ab2021-07-16 03:19:13 +090092 .context(format!("Failed to parse {}", APEX_INFO_LIST_PATH))?;
Jooyung Han9d7cd7d2021-10-12 17:44:14 +090093
Alan Stokesbf20c6a2022-01-04 12:30:50 +000094 // For active APEXes, we run derive_classpath and parse its output to see if it
95 // contributes to the classpath(s). (This allows us to handle any new classpath env
96 // vars seamlessly.)
97 let classpath_vars = run_derive_classpath()?;
98 let classpath_apexes = find_apex_names_in_classpath(&classpath_vars)?;
99
Jooyung Han9d7cd7d2021-10-12 17:44:14 +0900100 for apex_info in apex_info_list.list.iter_mut() {
Alan Stokesbf20c6a2022-01-04 12:30:50 +0000101 apex_info.has_classpath_jar = classpath_apexes.contains(&apex_info.name);
Jooyung Han9d7cd7d2021-10-12 17:44:14 +0900102 }
Alan Stokesbf20c6a2022-01-04 12:30:50 +0000103
Jooyung Han44b02ab2021-07-16 03:19:13 +0900104 Ok(apex_info_list)
Jooyung Han9900f3d2021-07-06 10:27:54 +0900105 })
Jooyung Han73bac242021-07-02 10:25:49 +0900106 }
Jooyung Han743e0d62022-11-07 20:57:48 +0900107
108 // Override apex info with the staged one
109 fn override_staged_apex(&mut self, staged_apex_info: &StagedApexInfo) -> Result<()> {
110 let mut need_to_add: Option<ApexInfo> = None;
111 for apex_info in self.list.iter_mut() {
112 if staged_apex_info.moduleName == apex_info.name {
113 if apex_info.is_active && apex_info.is_factory {
114 // Copy the entry to the end as factory/non-active after the loop
115 // to keep the factory version. Typically this step is unncessary,
116 // but some apexes (like sharedlibs) need to be kept even if it's inactive.
117 need_to_add.replace(ApexInfo { is_active: false, ..apex_info.clone() });
118 // And make this one as non-factory. Note that this one is still active
119 // and overridden right below.
120 apex_info.is_factory = false;
121 }
122 // Active one is overridden with the staged one.
123 if apex_info.is_active {
Jooyung Hancaa995c2022-11-08 16:35:50 +0900124 apex_info.version = staged_apex_info.versionCode as u64;
Jooyung Han743e0d62022-11-07 20:57:48 +0900125 apex_info.path = PathBuf::from(&staged_apex_info.diskImagePath);
126 apex_info.has_classpath_jar = staged_apex_info.hasClassPathJars;
127 apex_info.last_update_seconds = last_updated(&apex_info.path)?;
128 }
129 }
130 }
131 if let Some(info) = need_to_add {
132 self.list.push(info);
133 }
134 Ok(())
135 }
136}
137
138fn last_updated<P: AsRef<Path>>(path: P) -> Result<u64> {
139 let metadata = metadata(path)?;
140 Ok(metadata.modified()?.duration_since(SystemTime::UNIX_EPOCH)?.as_secs())
Jooyung Hanec788042022-01-27 22:28:37 +0900141}
Jooyung Han73bac242021-07-02 10:25:49 +0900142
Jooyung Hanec788042022-01-27 22:28:37 +0900143impl ApexInfo {
144 fn matches(&self, apex_config: &ApexConfig) -> bool {
145 // Match with pseudo name "{CLASSPATH}" which represents APEXes contributing
146 // to any derive_classpath environment variable
147 if apex_config.name == "{CLASSPATH}" && self.has_classpath_jar {
148 return true;
149 }
150 if apex_config.name == self.name {
151 return true;
152 }
153 false
Jooyung Han73bac242021-07-02 10:25:49 +0900154 }
Jooyung Han21e9b922021-06-26 04:14:16 +0900155}
156
Jooyung Han5dc42172021-10-05 16:43:47 +0900157struct PackageManager {
Jooyung Han5dc42172021-10-05 16:43:47 +0900158 apex_info_list: &'static ApexInfoList,
159}
160
161impl PackageManager {
162 fn new() -> Result<Self> {
Jooyung Han5dc42172021-10-05 16:43:47 +0900163 let apex_info_list = ApexInfoList::load()?;
Jooyung Han53cf7992021-10-18 19:38:41 +0900164 Ok(Self { apex_info_list })
Jooyung Han5dc42172021-10-05 16:43:47 +0900165 }
166
Jooyung Han9d7cd7d2021-10-12 17:44:14 +0900167 fn get_apex_list(&self, prefer_staged: bool) -> Result<ApexInfoList> {
Jooyung Han53cf7992021-10-18 19:38:41 +0900168 // get the list of active apexes
Jooyung Han9d7cd7d2021-10-12 17:44:14 +0900169 let mut list = self.apex_info_list.clone();
Jooyung Han53cf7992021-10-18 19:38:41 +0900170 // When prefer_staged, we override ApexInfo by consulting "package_native"
Jooyung Han5dc42172021-10-05 16:43:47 +0900171 if prefer_staged {
Jooyung Han53cf7992021-10-18 19:38:41 +0900172 let pm =
173 wait_for_interface::<dyn IPackageManagerNative>(PACKAGE_MANAGER_NATIVE_SERVICE)
174 .context("Failed to get service when prefer_staged is set.")?;
Alan Stokes70ccf162022-07-08 11:05:03 +0100175 let staged =
176 pm.getStagedApexModuleNames().context("getStagedApexModuleNames failed")?;
Jooyung Han743e0d62022-11-07 20:57:48 +0900177 for name in staged {
178 if let Some(staged_apex_info) =
179 pm.getStagedApexInfo(&name).context("getStagedApexInfo failed")?
180 {
181 list.override_staged_apex(&staged_apex_info)?;
Jooyung Han9d7cd7d2021-10-12 17:44:14 +0900182 }
Jooyung Han5dc42172021-10-05 16:43:47 +0900183 }
184 }
Jooyung Han9d7cd7d2021-10-12 17:44:14 +0900185 Ok(list)
Jooyung Han5dc42172021-10-05 16:43:47 +0900186 }
187}
188
Andrew Walbrancc0db522021-07-12 17:03:42 +0000189fn make_metadata_file(
Alan Stokes0d1ef782022-09-27 13:46:35 +0100190 app_config: &VirtualMachineAppConfig,
Jooyung Hanec788042022-01-27 22:28:37 +0900191 apex_infos: &[&ApexInfo],
Jooyung Han21e9b922021-06-26 04:14:16 +0900192 temporary_directory: &Path,
Andrew Walbrancc0db522021-07-12 17:03:42 +0000193) -> Result<ParcelFileDescriptor> {
Alan Stokes0d1ef782022-09-27 13:46:35 +0100194 let payload_metadata = match &app_config.payload {
Ludovic Barman93ee3082023-06-20 12:18:43 +0000195 Payload::PayloadConfig(payload_config) => PayloadMetadata::Config(PayloadConfig {
Alan Stokes8f12f2b2023-01-09 09:19:20 +0000196 payload_binary_name: payload_config.payloadBinaryName.clone(),
Alan Stokesfda70842023-12-20 17:50:14 +0000197 extra_apk_count: payload_config.extraApks.len().try_into()?,
198 special_fields: Default::default(),
Alan Stokes0d1ef782022-09-27 13:46:35 +0100199 }),
200 Payload::ConfigPath(config_path) => {
Ludovic Barman93ee3082023-06-20 12:18:43 +0000201 PayloadMetadata::ConfigPath(format!("/mnt/apk/{}", config_path))
Alan Stokes0d1ef782022-09-27 13:46:35 +0100202 }
203 };
204
Jooyung Han21e9b922021-06-26 04:14:16 +0900205 let metadata = Metadata {
Andrew Walbrancc0db522021-07-12 17:03:42 +0000206 version: 1,
Jooyung Hanec788042022-01-27 22:28:37 +0900207 apexes: apex_infos
Jooyung Han21e9b922021-06-26 04:14:16 +0900208 .iter()
Jooyung Han19c1d6c2021-08-06 14:08:16 +0900209 .enumerate()
Jooyung Hanec788042022-01-27 22:28:37 +0900210 .map(|(i, apex_info)| {
Andrew Walbran40be9d52022-01-19 14:32:53 +0000211 Ok(ApexPayload {
Jooyung Hanec788042022-01-27 22:28:37 +0900212 name: apex_info.name.clone(),
Andrew Walbran40be9d52022-01-19 14:32:53 +0000213 partition_name: format!("microdroid-apex-{}", i),
Jiyong Parkd6502352022-01-27 01:07:30 +0900214 last_update_seconds: apex_info.last_update_seconds,
215 is_factory: apex_info.is_factory,
Andrew Walbran40be9d52022-01-19 14:32:53 +0000216 ..Default::default()
217 })
Jooyung Han19c1d6c2021-08-06 14:08:16 +0900218 })
Andrew Walbran40be9d52022-01-19 14:32:53 +0000219 .collect::<Result<_>>()?,
Jooyung Han21e9b922021-06-26 04:14:16 +0900220 apk: Some(ApkPayload {
Jooyung Han35edb8f2021-07-01 16:17:16 +0900221 name: "apk".to_owned(),
222 payload_partition_name: "microdroid-apk".to_owned(),
223 idsig_partition_name: "microdroid-apk-idsig".to_owned(),
Jooyung Han21e9b922021-06-26 04:14:16 +0900224 ..Default::default()
225 })
226 .into(),
Alan Stokes0d1ef782022-09-27 13:46:35 +0100227 payload: Some(payload_metadata),
Jooyung Han21e9b922021-06-26 04:14:16 +0900228 ..Default::default()
229 };
Andrew Walbrancc0db522021-07-12 17:03:42 +0000230
231 // Write metadata to file.
Alan Stokes0d1ef782022-09-27 13:46:35 +0100232 let metadata_path = temporary_directory.join("metadata");
Andrew Walbrancc0db522021-07-12 17:03:42 +0000233 let mut metadata_file = OpenOptions::new()
234 .create_new(true)
235 .read(true)
236 .write(true)
237 .open(&metadata_path)
238 .with_context(|| format!("Failed to open metadata file {:?}", metadata_path))?;
Jooyung Han21e9b922021-06-26 04:14:16 +0900239 microdroid_metadata::write_metadata(&metadata, &mut metadata_file)?;
240
Andrew Walbrancc0db522021-07-12 17:03:42 +0000241 // Re-open the metadata file as read-only.
242 open_parcel_file(&metadata_path, false)
243}
244
245/// Creates a DiskImage with partitions:
Alan Stokes53cc5ca2022-08-30 14:28:19 +0100246/// payload-metadata: metadata
Andrew Walbrancc0db522021-07-12 17:03:42 +0000247/// microdroid-apex-0: apex 0
248/// microdroid-apex-1: apex 1
249/// ..
250/// microdroid-apk: apk
251/// microdroid-apk-idsig: idsig
Inseob Kima5a262f2021-11-17 19:41:03 +0900252/// extra-apk-0: additional apk 0
253/// extra-idsig-0: additional idsig 0
254/// extra-apk-1: additional apk 1
255/// extra-idsig-1: additional idsig 1
256/// ..
Andrew Walbrancc0db522021-07-12 17:03:42 +0000257fn make_payload_disk(
Inseob Kima5a262f2021-11-17 19:41:03 +0900258 app_config: &VirtualMachineAppConfig,
Jaewan Kim61f86142023-03-28 15:12:52 +0900259 debug_config: &DebugConfig,
Andrew Walbrancc0db522021-07-12 17:03:42 +0000260 apk_file: File,
261 idsig_file: File,
Alan Stokesfda70842023-12-20 17:50:14 +0000262 extra_apk_files: Vec<File>,
Jooyung Han9d7cd7d2021-10-12 17:44:14 +0900263 vm_payload_config: &VmPayloadConfig,
Andrew Walbrancc0db522021-07-12 17:03:42 +0000264 temporary_directory: &Path,
265) -> Result<DiskImage> {
Alan Stokesfda70842023-12-20 17:50:14 +0000266 if extra_apk_files.len() != app_config.extraIdsigs.len() {
Inseob Kima5a262f2021-11-17 19:41:03 +0900267 bail!(
268 "payload config has {} apks, but app config has {} idsigs",
269 vm_payload_config.extra_apks.len(),
270 app_config.extraIdsigs.len()
271 );
272 }
273
Jooyung Han9d7cd7d2021-10-12 17:44:14 +0900274 let pm = PackageManager::new()?;
275 let apex_list = pm.get_apex_list(vm_payload_config.prefer_staged)?;
276
Jooyung Hanec788042022-01-27 22:28:37 +0900277 // collect APEXes from config
Nikita Ioffed4551e12023-07-14 16:01:03 +0100278 let mut apex_infos = collect_apex_infos(&apex_list, &vm_payload_config.apexes, debug_config)?;
Jooyung Hancaa995c2022-11-08 16:35:50 +0900279
280 // Pass sorted list of apexes. Sorting key shouldn't use `path` because it will change after
281 // reboot with prefer_staged. `last_update_seconds` is added to distinguish "samegrade"
282 // update.
283 apex_infos.sort_by_key(|info| (&info.name, &info.version, &info.last_update_seconds));
Jooyung Hanec788042022-01-27 22:28:37 +0900284 info!("Microdroid payload APEXes: {:?}", apex_infos.iter().map(|ai| &ai.name));
Jooyung Han9d7cd7d2021-10-12 17:44:14 +0900285
Alan Stokes0d1ef782022-09-27 13:46:35 +0100286 let metadata_file = make_metadata_file(app_config, &apex_infos, temporary_directory)?;
Jooyung Han21e9b922021-06-26 04:14:16 +0900287 // put metadata at the first partition
288 let mut partitions = vec![Partition {
Jooyung Han14e5a8e2021-07-06 20:48:38 +0900289 label: "payload-metadata".to_owned(),
Jooyung Han631d5882021-07-29 06:34:05 +0900290 image: Some(metadata_file),
Jooyung Han21e9b922021-06-26 04:14:16 +0900291 writable: false,
Jiyong Park3f9b5092024-07-10 13:38:29 +0900292 guid: None,
Jooyung Han21e9b922021-06-26 04:14:16 +0900293 }];
294
Jooyung Hanec788042022-01-27 22:28:37 +0900295 for (i, apex_info) in apex_infos.iter().enumerate() {
296 let apex_file = open_parcel_file(&apex_info.path, false)?;
Jooyung Han95884632021-07-06 22:27:54 +0900297 partitions.push(Partition {
298 label: format!("microdroid-apex-{}", i),
Jooyung Han631d5882021-07-29 06:34:05 +0900299 image: Some(apex_file),
Jooyung Han95884632021-07-06 22:27:54 +0900300 writable: false,
Jiyong Park3f9b5092024-07-10 13:38:29 +0900301 guid: None,
Jooyung Han95884632021-07-06 22:27:54 +0900302 });
Jooyung Han21e9b922021-06-26 04:14:16 +0900303 }
Jooyung Han95884632021-07-06 22:27:54 +0900304 partitions.push(Partition {
305 label: "microdroid-apk".to_owned(),
Jooyung Han631d5882021-07-29 06:34:05 +0900306 image: Some(ParcelFileDescriptor::new(apk_file)),
Jooyung Han95884632021-07-06 22:27:54 +0900307 writable: false,
Jiyong Park3f9b5092024-07-10 13:38:29 +0900308 guid: None,
Jooyung Han95884632021-07-06 22:27:54 +0900309 });
310 partitions.push(Partition {
311 label: "microdroid-apk-idsig".to_owned(),
Jooyung Han631d5882021-07-29 06:34:05 +0900312 image: Some(ParcelFileDescriptor::new(idsig_file)),
Jooyung Han95884632021-07-06 22:27:54 +0900313 writable: false,
Jiyong Park3f9b5092024-07-10 13:38:29 +0900314 guid: None,
Jooyung Han95884632021-07-06 22:27:54 +0900315 });
Jooyung Han21e9b922021-06-26 04:14:16 +0900316
Inseob Kima5a262f2021-11-17 19:41:03 +0900317 // we've already checked that extra_apks and extraIdsigs are in the same size.
Inseob Kima5a262f2021-11-17 19:41:03 +0900318 let extra_idsigs = &app_config.extraIdsigs;
Alan Stokesfda70842023-12-20 17:50:14 +0000319 for (i, (extra_apk_file, extra_idsig)) in
320 extra_apk_files.into_iter().zip(extra_idsigs.iter()).enumerate()
321 {
Inseob Kima5a262f2021-11-17 19:41:03 +0900322 partitions.push(Partition {
Alan Stokesfda70842023-12-20 17:50:14 +0000323 label: format!("extra-apk-{i}"),
324 image: Some(ParcelFileDescriptor::new(extra_apk_file)),
Inseob Kima5a262f2021-11-17 19:41:03 +0900325 writable: false,
Jiyong Park3f9b5092024-07-10 13:38:29 +0900326 guid: None,
Inseob Kima5a262f2021-11-17 19:41:03 +0900327 });
328
329 partitions.push(Partition {
Alan Stokesfda70842023-12-20 17:50:14 +0000330 label: format!("extra-idsig-{i}"),
Victor Hsieh14497f02022-09-21 10:10:16 -0700331 image: Some(ParcelFileDescriptor::new(
332 extra_idsig
333 .as_ref()
334 .try_clone()
Alan Stokesfda70842023-12-20 17:50:14 +0000335 .with_context(|| format!("Failed to clone the extra idsig #{i}"))?,
Victor Hsieh14497f02022-09-21 10:10:16 -0700336 )),
Inseob Kima5a262f2021-11-17 19:41:03 +0900337 writable: false,
Jiyong Park3f9b5092024-07-10 13:38:29 +0900338 guid: None,
Inseob Kima5a262f2021-11-17 19:41:03 +0900339 });
340 }
341
Jooyung Han21e9b922021-06-26 04:14:16 +0900342 Ok(DiskImage { image: None, partitions, writable: false })
343}
Andrew Walbrancc0db522021-07-12 17:03:42 +0000344
Alan Stokesbf20c6a2022-01-04 12:30:50 +0000345fn run_derive_classpath() -> Result<String> {
346 let result = Command::new("/apex/com.android.sdkext/bin/derive_classpath")
347 .arg("/proc/self/fd/1")
348 .output()
349 .context("Failed to run derive_classpath")?;
350
351 if !result.status.success() {
352 bail!("derive_classpath returned {}", result.status);
353 }
354
355 String::from_utf8(result.stdout).context("Converting derive_classpath output")
356}
357
358fn find_apex_names_in_classpath(classpath_vars: &str) -> Result<HashSet<String>> {
359 // Each line should be in the format "export <var name> <paths>", where <paths> is a
360 // colon-separated list of paths to JARs. We don't care about the var names, and we're only
361 // interested in paths that look like "/apex/<apex name>/<anything>" so we know which APEXes
362 // contribute to at least one var.
363 let mut apexes = HashSet::new();
364
365 let pattern = Regex::new(r"^export [^ ]+ ([^ ]+)$").context("Failed to construct Regex")?;
366 for line in classpath_vars.lines() {
367 if let Some(captures) = pattern.captures(line) {
368 if let Some(paths) = captures.get(1) {
369 apexes.extend(paths.as_str().split(':').filter_map(|path| {
370 let path = path.strip_prefix("/apex/")?;
371 Some(path[..path.find('/')?].to_owned())
372 }));
373 continue;
374 }
375 }
376 warn!("Malformed line from derive_classpath: {}", line);
377 }
378
379 Ok(apexes)
Jooyung Han5e0f2062021-10-12 14:00:46 +0900380}
381
Nikita Ioffed4551e12023-07-14 16:01:03 +0100382fn check_apexes_are_from_allowed_partitions(requested_apexes: &Vec<&ApexInfo>) -> Result<()> {
383 const ALLOWED_PARTITIONS: [&str; 2] = ["/system", "/system_ext"];
384 for apex in requested_apexes {
385 if !ALLOWED_PARTITIONS.iter().any(|p| apex.preinstalled_path.starts_with(p)) {
386 bail!("Non-system APEX {} is not supported in Microdroid", apex.name);
387 }
388 }
389 Ok(())
390}
391
Jooyung Hanec788042022-01-27 22:28:37 +0900392// Collect ApexInfos from VM config
393fn collect_apex_infos<'a>(
394 apex_list: &'a ApexInfoList,
395 apex_configs: &[ApexConfig],
Jaewan Kim61f86142023-03-28 15:12:52 +0900396 debug_config: &DebugConfig,
Nikita Ioffed4551e12023-07-14 16:01:03 +0100397) -> Result<Vec<&'a ApexInfo>> {
Alan Stokesf7260f12023-08-30 17:25:21 +0100398 // APEXes which any Microdroid VM needs.
399 // TODO(b/192200378) move this to microdroid.json?
400 let required_apexes: &[_] =
401 if debug_config.should_include_debug_apexes() { &["com.android.adbd"] } else { &[] };
Jooyung Hanec788042022-01-27 22:28:37 +0900402
Nikita Ioffed4551e12023-07-14 16:01:03 +0100403 let apex_infos = apex_list
Jooyung Hanec788042022-01-27 22:28:37 +0900404 .list
405 .iter()
406 .filter(|ai| {
407 apex_configs.iter().any(|cfg| ai.matches(cfg) && ai.is_active)
Alan Stokesf7260f12023-08-30 17:25:21 +0100408 || required_apexes.iter().any(|name| name == &ai.name && ai.is_active)
Jooyung Han5ce867a2022-01-28 03:18:38 +0900409 || ai.provide_shared_apex_libs
Jooyung Hanec788042022-01-27 22:28:37 +0900410 })
Nikita Ioffed4551e12023-07-14 16:01:03 +0100411 .collect();
412
413 check_apexes_are_from_allowed_partitions(&apex_infos)?;
414 Ok(apex_infos)
Jooyung Han5e0f2062021-10-12 14:00:46 +0900415}
416
Nikita Ioffe5dfddf22023-06-29 16:11:26 +0100417pub fn add_microdroid_vendor_image(vendor_image: File, vm_config: &mut VirtualMachineRawConfig) {
418 vm_config.disks.push(DiskImage {
419 image: None,
420 writable: false,
421 partitions: vec![Partition {
422 label: "microdroid-vendor".to_owned(),
423 image: Some(ParcelFileDescriptor::new(vendor_image)),
424 writable: false,
Jiyong Park3f9b5092024-07-10 13:38:29 +0900425 guid: None,
Nikita Ioffe5dfddf22023-06-29 16:11:26 +0100426 }],
427 })
428}
429
Shikha Panwar22e70452022-10-10 18:32:55 +0000430pub fn add_microdroid_system_images(
Andrew Walbrancc0db522021-07-12 17:03:42 +0000431 config: &VirtualMachineAppConfig,
Jiyong Park8d081812021-07-23 17:45:04 +0900432 instance_file: File,
Shikha Panwar22e70452022-10-10 18:32:55 +0000433 storage_image: Option<File>,
Inseob Kim172f9eb2023-11-06 17:02:08 +0900434 os_name: &str,
Andrew Walbrancc0db522021-07-12 17:03:42 +0000435 vm_config: &mut VirtualMachineRawConfig,
436) -> Result<()> {
Shikha Panwared8ace42022-09-28 12:52:16 +0000437 let debug_suffix = match config.debugLevel {
438 DebugLevel::NONE => "normal",
Seungjae Yooe85831e2022-12-12 09:34:58 +0900439 DebugLevel::FULL => "debuggable",
Shikha Panwared8ace42022-09-28 12:52:16 +0000440 _ => return Err(anyhow!("unsupported debug level: {:?}", config.debugLevel)),
441 };
Inseob Kim172f9eb2023-11-06 17:02:08 +0900442 let initrd = format!("/apex/com.android.virt/etc/{os_name}_initrd_{debug_suffix}.img");
Shikha Panwared8ace42022-09-28 12:52:16 +0000443 vm_config.initrd = Some(open_parcel_file(Path::new(&initrd), false)?);
444
Shikha Panwar22e70452022-10-10 18:32:55 +0000445 let mut writable_partitions = vec![Partition {
Shikha Panwared8ace42022-09-28 12:52:16 +0000446 label: "vm-instance".to_owned(),
447 image: Some(ParcelFileDescriptor::new(instance_file)),
448 writable: true,
Jiyong Park3f9b5092024-07-10 13:38:29 +0900449 guid: None,
Shikha Panwar22e70452022-10-10 18:32:55 +0000450 }];
451
452 if let Some(file) = storage_image {
453 writable_partitions.push(Partition {
Shikha Panwar566c9672022-11-15 14:39:58 +0000454 label: "encryptedstore".to_owned(),
Shikha Panwar22e70452022-10-10 18:32:55 +0000455 image: Some(ParcelFileDescriptor::new(file)),
456 writable: true,
Jiyong Park3f9b5092024-07-10 13:38:29 +0900457 guid: None,
Shikha Panwar22e70452022-10-10 18:32:55 +0000458 });
459 }
460
461 vm_config.disks.push(DiskImage {
462 image: None,
463 partitions: writable_partitions,
464 writable: true,
465 });
466
467 Ok(())
468}
469
Alan Stokesfda70842023-12-20 17:50:14 +0000470#[allow(clippy::too_many_arguments)] // TODO: Fewer arguments
Shikha Panwar22e70452022-10-10 18:32:55 +0000471pub fn add_microdroid_payload_images(
472 config: &VirtualMachineAppConfig,
Jaewan Kim61f86142023-03-28 15:12:52 +0900473 debug_config: &DebugConfig,
Shikha Panwar22e70452022-10-10 18:32:55 +0000474 temporary_directory: &Path,
475 apk_file: File,
476 idsig_file: File,
Alan Stokesfda70842023-12-20 17:50:14 +0000477 extra_apk_files: Vec<File>,
Shikha Panwar22e70452022-10-10 18:32:55 +0000478 vm_payload_config: &VmPayloadConfig,
479 vm_config: &mut VirtualMachineRawConfig,
480) -> Result<()> {
Andrew Walbrancc0db522021-07-12 17:03:42 +0000481 vm_config.disks.push(make_payload_disk(
Inseob Kima5a262f2021-11-17 19:41:03 +0900482 config,
Jaewan Kim61f86142023-03-28 15:12:52 +0900483 debug_config,
Andrew Walbrancc0db522021-07-12 17:03:42 +0000484 apk_file,
485 idsig_file,
Alan Stokesfda70842023-12-20 17:50:14 +0000486 extra_apk_files,
Jooyung Han9d7cd7d2021-10-12 17:44:14 +0900487 vm_payload_config,
Andrew Walbrancc0db522021-07-12 17:03:42 +0000488 temporary_directory,
489 )?);
490
Andrew Walbrancc0db522021-07-12 17:03:42 +0000491 Ok(())
492}
Jooyung Han5e0f2062021-10-12 14:00:46 +0900493
494#[cfg(test)]
495mod tests {
496 use super::*;
Alan Stokesf7260f12023-08-30 17:25:21 +0100497 use std::collections::HashMap;
Jooyung Han743e0d62022-11-07 20:57:48 +0900498 use tempfile::NamedTempFile;
Andrew Walbranc1a5f5a2022-01-19 13:38:13 +0000499
Jooyung Han5e0f2062021-10-12 14:00:46 +0900500 #[test]
Alan Stokesbf20c6a2022-01-04 12:30:50 +0000501 fn test_find_apex_names_in_classpath() {
502 let vars = r#"
503export FOO /apex/unterminated
504export BAR /apex/valid.apex/something
505wrong
506export EMPTY
507export OTHER /foo/bar:/baz:/apex/second.valid.apex/:gibberish:"#;
508 let expected = vec!["valid.apex", "second.valid.apex"];
509 let expected: HashSet<_> = expected.into_iter().map(ToString::to_string).collect();
510
511 assert_eq!(find_apex_names_in_classpath(vars).unwrap(), expected);
Jooyung Han5e0f2062021-10-12 14:00:46 +0900512 }
Andrew Walbranc1a5f5a2022-01-19 13:38:13 +0000513
514 #[test]
Nikita Ioffed4551e12023-07-14 16:01:03 +0100515 fn test_collect_apexes() -> Result<()> {
Alan Stokesf7260f12023-08-30 17:25:21 +0100516 let apex_infos_for_test = [
517 (
518 "adbd",
Andrew Walbranc1a5f5a2022-01-19 13:38:13 +0000519 ApexInfo {
Jooyung Hanec788042022-01-27 22:28:37 +0900520 name: "com.android.adbd".to_string(),
521 path: PathBuf::from("adbd"),
Nikita Ioffed4551e12023-07-14 16:01:03 +0100522 preinstalled_path: PathBuf::from("/system/adbd"),
Andrew Walbranc1a5f5a2022-01-19 13:38:13 +0000523 has_classpath_jar: false,
Andrew Walbran40be9d52022-01-19 14:32:53 +0000524 last_update_seconds: 12345678,
Jiyong Parkd6502352022-01-27 01:07:30 +0900525 is_factory: true,
Jooyung Hanec788042022-01-27 22:28:37 +0900526 is_active: false,
Jooyung Han5ce867a2022-01-28 03:18:38 +0900527 ..Default::default()
Jooyung Hanec788042022-01-27 22:28:37 +0900528 },
Alan Stokesf7260f12023-08-30 17:25:21 +0100529 ),
530 (
531 "adbd_updated",
Jooyung Hanec788042022-01-27 22:28:37 +0900532 ApexInfo {
Alan Stokesf7260f12023-08-30 17:25:21 +0100533 name: "com.android.adbd".to_string(),
534 path: PathBuf::from("adbd"),
535 preinstalled_path: PathBuf::from("/system/adbd"),
Jooyung Hanec788042022-01-27 22:28:37 +0900536 has_classpath_jar: false,
537 last_update_seconds: 12345678 + 1,
538 is_factory: false,
539 is_active: true,
Jooyung Han5ce867a2022-01-28 03:18:38 +0900540 ..Default::default()
Jooyung Hanec788042022-01-27 22:28:37 +0900541 },
Alan Stokesf7260f12023-08-30 17:25:21 +0100542 ),
543 (
544 "no_classpath",
Jooyung Hanec788042022-01-27 22:28:37 +0900545 ApexInfo {
Jooyung Hanec788042022-01-27 22:28:37 +0900546 name: "no_classpath".to_string(),
547 path: PathBuf::from("no_classpath"),
548 has_classpath_jar: false,
549 last_update_seconds: 12345678,
550 is_factory: true,
551 is_active: true,
Jooyung Han5ce867a2022-01-28 03:18:38 +0900552 ..Default::default()
Jooyung Hanec788042022-01-27 22:28:37 +0900553 },
Alan Stokesf7260f12023-08-30 17:25:21 +0100554 ),
555 (
556 "has_classpath",
Jooyung Hanec788042022-01-27 22:28:37 +0900557 ApexInfo {
Andrew Walbranc1a5f5a2022-01-19 13:38:13 +0000558 name: "has_classpath".to_string(),
Jooyung Hanec788042022-01-27 22:28:37 +0900559 path: PathBuf::from("has_classpath"),
Andrew Walbranc1a5f5a2022-01-19 13:38:13 +0000560 has_classpath_jar: true,
Andrew Walbran40be9d52022-01-19 14:32:53 +0000561 last_update_seconds: 87654321,
Jooyung Hanec788042022-01-27 22:28:37 +0900562 is_factory: true,
563 is_active: false,
Jooyung Han5ce867a2022-01-28 03:18:38 +0900564 ..Default::default()
Jooyung Hanec788042022-01-27 22:28:37 +0900565 },
Alan Stokesf7260f12023-08-30 17:25:21 +0100566 ),
567 (
568 "has_classpath_updated",
Jooyung Hanec788042022-01-27 22:28:37 +0900569 ApexInfo {
Jooyung Hanec788042022-01-27 22:28:37 +0900570 name: "has_classpath".to_string(),
571 path: PathBuf::from("has_classpath/updated"),
Nikita Ioffed4551e12023-07-14 16:01:03 +0100572 preinstalled_path: PathBuf::from("/system/has_classpath"),
Jooyung Hanec788042022-01-27 22:28:37 +0900573 has_classpath_jar: true,
574 last_update_seconds: 87654321 + 1,
Jiyong Parkd6502352022-01-27 01:07:30 +0900575 is_factory: false,
Jooyung Hanec788042022-01-27 22:28:37 +0900576 is_active: true,
Jooyung Han5ce867a2022-01-28 03:18:38 +0900577 ..Default::default()
Jooyung Hanec788042022-01-27 22:28:37 +0900578 },
Alan Stokesf7260f12023-08-30 17:25:21 +0100579 ),
580 (
581 "apex-foo",
Jooyung Hanec788042022-01-27 22:28:37 +0900582 ApexInfo {
Jooyung Hanec788042022-01-27 22:28:37 +0900583 name: "apex-foo".to_string(),
584 path: PathBuf::from("apex-foo"),
Nikita Ioffed4551e12023-07-14 16:01:03 +0100585 preinstalled_path: PathBuf::from("/system/apex-foo"),
Jooyung Hanec788042022-01-27 22:28:37 +0900586 has_classpath_jar: false,
587 last_update_seconds: 87654321,
588 is_factory: true,
589 is_active: false,
Jooyung Han5ce867a2022-01-28 03:18:38 +0900590 ..Default::default()
Jooyung Hanec788042022-01-27 22:28:37 +0900591 },
Alan Stokesf7260f12023-08-30 17:25:21 +0100592 ),
593 (
594 "apex-foo-updated",
Jooyung Hanec788042022-01-27 22:28:37 +0900595 ApexInfo {
Jooyung Hanec788042022-01-27 22:28:37 +0900596 name: "apex-foo".to_string(),
597 path: PathBuf::from("apex-foo/updated"),
Nikita Ioffed4551e12023-07-14 16:01:03 +0100598 preinstalled_path: PathBuf::from("/system/apex-foo"),
Jooyung Hanec788042022-01-27 22:28:37 +0900599 has_classpath_jar: false,
600 last_update_seconds: 87654321 + 1,
601 is_factory: false,
602 is_active: true,
Jooyung Han5ce867a2022-01-28 03:18:38 +0900603 ..Default::default()
604 },
Alan Stokesf7260f12023-08-30 17:25:21 +0100605 ),
606 (
607 "sharedlibs",
Jooyung Han5ce867a2022-01-28 03:18:38 +0900608 ApexInfo {
Jooyung Han5ce867a2022-01-28 03:18:38 +0900609 name: "sharedlibs".to_string(),
610 path: PathBuf::from("apex-foo"),
Nikita Ioffed4551e12023-07-14 16:01:03 +0100611 preinstalled_path: PathBuf::from("/system/apex-foo"),
Jooyung Han5ce867a2022-01-28 03:18:38 +0900612 last_update_seconds: 87654321,
613 is_factory: true,
614 provide_shared_apex_libs: true,
615 ..Default::default()
616 },
Alan Stokesf7260f12023-08-30 17:25:21 +0100617 ),
618 (
619 "sharedlibs-updated",
Jooyung Han5ce867a2022-01-28 03:18:38 +0900620 ApexInfo {
Jooyung Han5ce867a2022-01-28 03:18:38 +0900621 name: "sharedlibs".to_string(),
622 path: PathBuf::from("apex-foo/updated"),
Nikita Ioffed4551e12023-07-14 16:01:03 +0100623 preinstalled_path: PathBuf::from("/system/apex-foo"),
Jooyung Han5ce867a2022-01-28 03:18:38 +0900624 last_update_seconds: 87654321 + 1,
625 is_active: true,
626 provide_shared_apex_libs: true,
627 ..Default::default()
Andrew Walbranc1a5f5a2022-01-19 13:38:13 +0000628 },
Alan Stokesf7260f12023-08-30 17:25:21 +0100629 ),
630 ];
631 let apex_info_list = ApexInfoList {
632 list: apex_infos_for_test.iter().map(|(_, info)| info).cloned().collect(),
Andrew Walbranc1a5f5a2022-01-19 13:38:13 +0000633 };
Alan Stokesf7260f12023-08-30 17:25:21 +0100634 let apex_info_map = HashMap::from(apex_infos_for_test);
Jooyung Hanec788042022-01-27 22:28:37 +0900635 let apex_configs = vec![
636 ApexConfig { name: "apex-foo".to_string() },
Andrew Walbranc1a5f5a2022-01-19 13:38:13 +0000637 ApexConfig { name: "{CLASSPATH}".to_string() },
638 ];
639 assert_eq!(
Nikita Ioffed4551e12023-07-14 16:01:03 +0100640 collect_apex_infos(
641 &apex_info_list,
642 &apex_configs,
Jaewan Kimf3143242024-03-15 06:56:31 +0000643 &DebugConfig::new_with_debug_level(DebugLevel::FULL)
Nikita Ioffed4551e12023-07-14 16:01:03 +0100644 )?,
Andrew Walbranc1a5f5a2022-01-19 13:38:13 +0000645 vec![
Jooyung Han5ce867a2022-01-28 03:18:38 +0900646 // Pass active/required APEXes
Alan Stokesf7260f12023-08-30 17:25:21 +0100647 &apex_info_map["adbd_updated"],
Jooyung Han5ce867a2022-01-28 03:18:38 +0900648 // Pass active APEXes specified in the config
Alan Stokesf7260f12023-08-30 17:25:21 +0100649 &apex_info_map["has_classpath_updated"],
650 &apex_info_map["apex-foo-updated"],
Jooyung Han5ce867a2022-01-28 03:18:38 +0900651 // Pass both preinstalled(inactive) and updated(active) for "sharedlibs" APEXes
Alan Stokesf7260f12023-08-30 17:25:21 +0100652 &apex_info_map["sharedlibs"],
653 &apex_info_map["sharedlibs-updated"],
Andrew Walbranc1a5f5a2022-01-19 13:38:13 +0000654 ]
655 );
Nikita Ioffed4551e12023-07-14 16:01:03 +0100656 Ok(())
657 }
658
659 #[test]
660 fn test_check_allowed_partitions_vendor_not_allowed() -> Result<()> {
661 let apex_info_list = ApexInfoList {
662 list: vec![ApexInfo {
663 name: "apex-vendor".to_string(),
664 path: PathBuf::from("apex-vendor"),
665 preinstalled_path: PathBuf::from("/vendor/apex-vendor"),
666 is_active: true,
667 ..Default::default()
668 }],
669 };
670 let apex_configs = vec![ApexConfig { name: "apex-vendor".to_string() }];
671
Jaewan Kimf3143242024-03-15 06:56:31 +0000672 let ret = collect_apex_infos(
673 &apex_info_list,
674 &apex_configs,
675 &DebugConfig::new_with_debug_level(DebugLevel::NONE),
676 );
Nikita Ioffed4551e12023-07-14 16:01:03 +0100677 assert!(ret
678 .is_err_and(|ret| ret.to_string()
679 == "Non-system APEX apex-vendor is not supported in Microdroid"));
680
681 Ok(())
682 }
683
684 #[test]
685 fn test_check_allowed_partitions_system_ext_allowed() -> Result<()> {
686 let apex_info_list = ApexInfoList {
687 list: vec![ApexInfo {
688 name: "apex-system_ext".to_string(),
689 path: PathBuf::from("apex-system_ext"),
690 preinstalled_path: PathBuf::from("/system_ext/apex-system_ext"),
691 is_active: true,
692 ..Default::default()
693 }],
694 };
695
696 let apex_configs = vec![ApexConfig { name: "apex-system_ext".to_string() }];
697
698 assert_eq!(
699 collect_apex_infos(
700 &apex_info_list,
701 &apex_configs,
Jaewan Kimf3143242024-03-15 06:56:31 +0000702 &DebugConfig::new_with_debug_level(DebugLevel::NONE)
Nikita Ioffed4551e12023-07-14 16:01:03 +0100703 )?,
704 vec![&apex_info_list.list[0]]
705 );
706
707 Ok(())
Andrew Walbranc1a5f5a2022-01-19 13:38:13 +0000708 }
Jooyung Han743e0d62022-11-07 20:57:48 +0900709
710 #[test]
711 fn test_prefer_staged_apex_with_factory_active_apex() {
712 let single_apex = ApexInfo {
713 name: "foo".to_string(),
Jooyung Hancaa995c2022-11-08 16:35:50 +0900714 version: 1,
Jooyung Han743e0d62022-11-07 20:57:48 +0900715 path: PathBuf::from("foo.apex"),
716 is_factory: true,
717 is_active: true,
718 ..Default::default()
719 };
720 let mut apex_info_list = ApexInfoList { list: vec![single_apex.clone()] };
721
722 let staged = NamedTempFile::new().unwrap();
723 apex_info_list
724 .override_staged_apex(&StagedApexInfo {
725 moduleName: "foo".to_string(),
Jooyung Hancaa995c2022-11-08 16:35:50 +0900726 versionCode: 2,
Jooyung Han743e0d62022-11-07 20:57:48 +0900727 diskImagePath: staged.path().to_string_lossy().to_string(),
728 ..Default::default()
729 })
730 .expect("should be ok");
731
732 assert_eq!(
733 apex_info_list,
734 ApexInfoList {
735 list: vec![
736 ApexInfo {
Jooyung Hancaa995c2022-11-08 16:35:50 +0900737 version: 2,
Jooyung Han743e0d62022-11-07 20:57:48 +0900738 is_factory: false,
739 path: staged.path().to_owned(),
740 last_update_seconds: last_updated(staged.path()).unwrap(),
741 ..single_apex.clone()
742 },
743 ApexInfo { is_active: false, ..single_apex },
744 ],
745 }
746 );
747 }
748
749 #[test]
750 fn test_prefer_staged_apex_with_factory_and_inactive_apex() {
751 let factory_apex = ApexInfo {
752 name: "foo".to_string(),
Jooyung Hancaa995c2022-11-08 16:35:50 +0900753 version: 1,
Jooyung Han743e0d62022-11-07 20:57:48 +0900754 path: PathBuf::from("foo.apex"),
755 is_factory: true,
756 ..Default::default()
757 };
758 let active_apex = ApexInfo {
759 name: "foo".to_string(),
Jooyung Hancaa995c2022-11-08 16:35:50 +0900760 version: 2,
Jooyung Han743e0d62022-11-07 20:57:48 +0900761 path: PathBuf::from("foo.downloaded.apex"),
762 is_active: true,
763 ..Default::default()
764 };
765 let mut apex_info_list =
766 ApexInfoList { list: vec![factory_apex.clone(), active_apex.clone()] };
767
768 let staged = NamedTempFile::new().unwrap();
769 apex_info_list
770 .override_staged_apex(&StagedApexInfo {
771 moduleName: "foo".to_string(),
Jooyung Hancaa995c2022-11-08 16:35:50 +0900772 versionCode: 3,
Jooyung Han743e0d62022-11-07 20:57:48 +0900773 diskImagePath: staged.path().to_string_lossy().to_string(),
774 ..Default::default()
775 })
776 .expect("should be ok");
777
778 assert_eq!(
779 apex_info_list,
780 ApexInfoList {
781 list: vec![
782 // factory apex isn't touched
783 factory_apex,
784 // update active one
785 ApexInfo {
Jooyung Hancaa995c2022-11-08 16:35:50 +0900786 version: 3,
Jooyung Han743e0d62022-11-07 20:57:48 +0900787 path: staged.path().to_owned(),
788 last_update_seconds: last_updated(staged.path()).unwrap(),
789 ..active_apex
790 },
791 ],
792 }
793 );
794 }
Jooyung Han5e0f2062021-10-12 14:00:46 +0900795}