diff --git a/compos/common/Android.bp b/compos/common/Android.bp index 35947d71..05bc093e 100644 --- a/compos/common/Android.bp +++ b/compos/common/Android.bp @@ -12,6 +12,7 @@ rust_library { "compos_aidl_interface-rust", "libanyhow", "libbinder_rs", + "libglob", "liblazy_static", "liblog_rust", "libnested_virt", diff --git a/compos/common/compos_client.rs b/compos/common/compos_client.rs index 92c9a3cb..96c81477 100644 --- a/compos/common/compos_client.rs +++ b/compos/common/compos_client.rs @@ -27,12 +27,13 @@ use android_system_virtualizationservice::aidl::android::system::virtualizations VirtualMachineAppConfig::{DebugLevel::DebugLevel, Payload::Payload, VirtualMachineAppConfig}, VirtualMachineConfig::VirtualMachineConfig, }; -use anyhow::{bail, Context, Result}; +use anyhow::{anyhow, bail, Context, Result}; use binder::{ParcelFileDescriptor, Strong}; use compos_aidl_interface::aidl::com::android::compos::ICompOsService::ICompOsService; +use glob::glob; use log::{info, warn}; use rustutils::system_properties; -use std::fs::{self, File}; +use std::fs::File; use std::path::{Path, PathBuf}; use vmclient::{DeathReason, ErrorCode, VmInstance, VmWaitError}; @@ -194,15 +195,19 @@ fn locate_config_apk(apex_dir: &Path) -> Result { // Our config APK will be in a directory under app, but the name of the directory is at the // discretion of the build system. So just look in each sub-directory until we find it. // (In practice there will be exactly one directory, so this shouldn't take long.) - let app_dir = apex_dir.join("app"); - for dir in fs::read_dir(app_dir).context("Reading app dir")? { - let apk_file = dir?.path().join("CompOSPayloadApp.apk"); - if apk_file.is_file() { - return Ok(apk_file); - } + let app_glob = apex_dir.join("app").join("**").join("CompOSPayloadApp*.apk"); + let mut entries: Vec = + glob(app_glob.to_str().ok_or_else(|| anyhow!("Invalid path: {}", app_glob.display()))?) + .context("failed to glob")? + .filter_map(|e| e.ok()) + .collect(); + if entries.len() > 1 { + bail!("Found more than one apk matching {}", app_glob.display()); + } + match entries.pop() { + Some(path) => Ok(path), + None => Err(anyhow!("No apks match {}", app_glob.display())), } - - bail!("Failed to locate CompOSPayloadApp.apk") } fn prepare_idsig( diff --git a/vm/src/run.rs b/vm/src/run.rs index 5d785de2..36edc64a 100644 --- a/vm/src/run.rs +++ b/vm/src/run.rs @@ -152,7 +152,7 @@ pub fn command_run_app( } fn find_empty_payload_apk_path() -> Result { - const GLOB_PATTERN: &str = "/apex/com.android.virt/app/**/EmptyPayloadApp.apk"; + const GLOB_PATTERN: &str = "/apex/com.android.virt/app/**/EmptyPayloadApp*.apk"; let mut entries: Vec = glob(GLOB_PATTERN).context("failed to glob")?.filter_map(|e| e.ok()).collect(); if entries.len() > 1 {