Skip to content

Commit 7760519

Browse files
committed
apd: add new method to skip useless mount
use touch /data/adb/.litemode_enable to enable ,notice:it will skip all mount cause some module not work,it can effectively target garbage detection
1 parent 6f4341e commit 7760519

File tree

2 files changed

+54
-43
lines changed

2 files changed

+54
-43
lines changed

apd/src/defs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub const APATCH_LOG_FOLDER: &str = concatcp!(WORKING_DIR, "log/");
77

88
pub const AP_RC_PATH: &str = concatcp!(WORKING_DIR, ".aprc");
99
pub const GLOBAL_NAMESPACE_FILE: &str = concatcp!(ADB_DIR,".global_namespace_enable");
10-
pub const BIND_MOUNT_FILE: &str = concatcp!(ADB_DIR,".bind_mount_enable");
10+
pub const LITEMODE_FILE: &str = concatcp!(ADB_DIR,".litemode_enable");
1111
pub const OVERLAY_FILE: &str = concatcp!(ADB_DIR,".overlay_enable");
1212
pub const AP_OVERLAY_SOURCE: &str = "APatch";
1313
pub const DAEMON_PATH: &str = concatcp!(ADB_DIR, "apd");

apd/src/event.rs

Lines changed: 53 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -333,15 +333,13 @@ pub fn on_post_data_fs(superkey: Option<String>) -> Result<()> {
333333
let tmp_module_img = defs::MODULE_UPDATE_TMP_IMG;
334334
let tmp_module_path = Path::new(tmp_module_img);
335335
move_file(module_update_dir,module_dir)?;
336-
337-
338-
339336
info!("remove update flag");
340337
let _ = fs::remove_file(module_update_flag);
341338
if tmp_module_path.exists() { //if it have update,remove tmp file
342339
std::fs::remove_file(tmp_module_path)?;
343340
}
344341

342+
let lite_file = Path::new(defs::LITEMODE_FILE);
345343

346344

347345
if safe_mode {
@@ -364,10 +362,15 @@ pub fn on_post_data_fs(superkey: Option<String>) -> Result<()> {
364362
if crate::module::load_sepolicy_rule().is_err() {
365363
warn!("load sepolicy.rule failed");
366364
}
365+
if lite_file.exists() {
366+
info!("litemode runing skip mount tempfs")
367+
}else{
368+
if let Err(e) = mount::mount_tmpfs(utils::get_tmp_path()) {
369+
warn!("do temp dir mount failed: {}", e);
370+
}
367371

368-
if let Err(e) = mount::mount_tmpfs(utils::get_tmp_path()) {
369-
warn!("do temp dir mount failed: {}", e);
370372
}
373+
371374

372375
// exec modules post-fs-data scripts
373376
// TODO: Add timeout
@@ -379,50 +382,58 @@ pub fn on_post_data_fs(superkey: Option<String>) -> Result<()> {
379382
if let Err(e) = crate::module::load_system_prop() {
380383
warn!("load system.prop failed: {}", e);
381384
}
382-
if utils::should_enable_overlay()? {
383-
// mount module systemlessly by overlay
384-
let work_dir = get_work_dir();
385-
let tmp_dir = PathBuf::from(work_dir.clone());
386-
ensure_dir_exists(&tmp_dir)?;
387-
mount(defs::AP_OVERLAY_SOURCE, &tmp_dir, "tmpfs", MountFlags::empty(), "").context("mount tmp")?;
388-
mount_change(&tmp_dir, MountPropagationFlags::PRIVATE).context("make tmp private")?;
389-
let dir_names = vec!["vendor", "product", "system_ext", "odm", "oem", "system"];
390-
let dir = fs::read_dir(module_dir)?;
391-
for entry in dir.flatten() {
392-
let module_path = entry.path();
393-
let disabled = module_path.join(defs::DISABLE_FILE_NAME).exists();
394-
if disabled {
395-
info!("module: {} is disabled, ignore!", module_path.display());
396-
continue;
397-
}
398-
if module_path.is_dir() {
399-
let module_name = module_path.file_name().unwrap().to_string_lossy();
400-
let module_dest = Path::new(&work_dir).join(module_name.as_ref());
401385

402-
for sub_dir in dir_names.iter() {
403-
let sub_dir_path = module_path.join(sub_dir);
404-
if sub_dir_path.exists() && sub_dir_path.is_dir() {
405-
let sub_dir_dest = module_dest.join(sub_dir);
406-
fs::create_dir_all(&sub_dir_dest)?;
386+
387+
if lite_file.exists() {
388+
info!("litemode runing skip mount state")
389+
}else{
407390

408-
copy_dir_with_xattr(&sub_dir_path, &sub_dir_dest)?;
391+
if utils::should_enable_overlay()? {
392+
// mount module systemlessly by overlay
393+
let work_dir = get_work_dir();
394+
let tmp_dir = PathBuf::from(work_dir.clone());
395+
ensure_dir_exists(&tmp_dir)?;
396+
mount(defs::AP_OVERLAY_SOURCE, &tmp_dir, "tmpfs", MountFlags::empty(), "").context("mount tmp")?;
397+
mount_change(&tmp_dir, MountPropagationFlags::PRIVATE).context("make tmp private")?;
398+
let dir_names = vec!["vendor", "product", "system_ext", "odm", "oem", "system"];
399+
let dir = fs::read_dir(module_dir)?;
400+
for entry in dir.flatten() {
401+
let module_path = entry.path();
402+
let disabled = module_path.join(defs::DISABLE_FILE_NAME).exists();
403+
if disabled {
404+
info!("module: {} is disabled, ignore!", module_path.display());
405+
continue;
406+
}
407+
if module_path.is_dir() {
408+
let module_name = module_path.file_name().unwrap().to_string_lossy();
409+
let module_dest = Path::new(&work_dir).join(module_name.as_ref());
410+
411+
for sub_dir in dir_names.iter() {
412+
let sub_dir_path = module_path.join(sub_dir);
413+
if sub_dir_path.exists() && sub_dir_path.is_dir() {
414+
let sub_dir_dest = module_dest.join(sub_dir);
415+
fs::create_dir_all(&sub_dir_dest)?;
416+
417+
copy_dir_with_xattr(&sub_dir_path, &sub_dir_dest)?;
418+
}
409419
}
410420
}
411421
}
422+
if let Err(e) = mount_systemlessly(&get_work_dir(),false) {
423+
warn!("do systemless mount failed: {}", e);
424+
}
425+
if let Err(e) = unmount(&tmp_dir, UnmountFlags::DETACH) {
426+
log::error!("failed to unmount tmp {}", e);
427+
}
428+
}else{
429+
if let Err(e) = systemless_bind_mount(module_dir) {
430+
warn!("do systemless bind_mount failed: {}", e);
431+
}
432+
433+
412434
}
413-
if let Err(e) = mount_systemlessly(&get_work_dir(),false) {
414-
warn!("do systemless mount failed: {}", e);
415-
}
416-
if let Err(e) = unmount(&tmp_dir, UnmountFlags::DETACH) {
417-
log::error!("failed to unmount tmp {}", e);
418-
}
419-
}else{
420-
if let Err(e) = systemless_bind_mount(module_dir) {
421-
warn!("do systemless bind_mount failed: {}", e);
422-
}
423-
424-
425435
}
436+
426437

427438
run_stage("post-mount", superkey, true);
428439

0 commit comments

Comments
 (0)