Skip to content

Commit

Permalink
ExternalModuleApi
Browse files Browse the repository at this point in the history
  • Loading branch information
Ylarod authored and tiann committed Oct 21, 2023
1 parent e3ad4e3 commit ada0f7a
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion userspace/ksud/src/module_api.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::Result;
use lazy_static::lazy_static;
use log::info;
use std::{process::Command, os::unix::process::CommandExt};

use crate::module::KsuModuleApi;

Expand All @@ -27,7 +28,7 @@ pub struct ModuleApiProxy {
lazy_static! {
static ref MODULE_API_PROXY: ModuleApiProxy = if should_use_external_module_api() {
ModuleApiProxy {
api: Box::new(KsuModuleApi {}),
api: Box::new(ExternalModuleApi {}),
}
} else {
ModuleApiProxy {
Expand Down Expand Up @@ -84,3 +85,35 @@ impl ModuleApi for ModuleApiProxy {
self.api.mount_modules()
}
}

struct ExternalModuleApi;

impl ModuleApi for ExternalModuleApi{
fn on_post_data_fs(&self) -> Result<()>{
Err(Command::new("/data/adb/ksu/module").args("post-fs-data").exec().into())
}
fn on_boot_completed(&self) -> Result<()>{
Err(Command::new("/data/adb/ksu/module").args("boot-completed").exec().into())
}
fn on_services(&self) -> Result<()>{
Err(Command::new("/data/adb/ksu/module").args("services").exec().into())
}
fn install_module(&self, zip: &str) -> Result<()>{
Err(Command::new("/data/adb/ksu/module").args(["install", zip]).exec().into())
}
fn uninstall_module(&self, id: &str) -> Result<()>{
Err(Command::new("/data/adb/ksu/module").args(["uninstall", id]).exec().into())
}
fn enable_module(&self, id: &str) -> Result<()>{
Err(Command::new("/data/adb/ksu/module").args(["enable", id]).exec().into())
}
fn disable_module(&self, id: &str) -> Result<()>{
Err(Command::new("/data/adb/ksu/module").args(["disable", id]).exec().into())
}
fn list_modules(&self) -> Result<()>{
Err(Command::new("/data/adb/ksu/module").args(["list"]).exec().into())
}
fn mount_modules(&self) -> Result<()>{
Err(Command::new("/data/adb/ksu/module").args(["mount"]).exec().into())
}
}

0 comments on commit ada0f7a

Please sign in to comment.