manager: clean lkm remnants

ksud: clean clippy warnings
This commit is contained in:
rifsxd
2025-05-01 16:29:16 +06:00
parent 1336996129
commit 757d20166a
9 changed files with 169 additions and 125 deletions

View File

@@ -7,6 +7,8 @@ use crate::{defs::BINARY_DIR, utils};
pub const RESETPROP_PATH: &str = concatcp!(BINARY_DIR, "resetprop");
pub const BUSYBOX_PATH: &str = concatcp!(BINARY_DIR, "busybox");
#[allow(dead_code)]
pub const BOOTCTL_PATH: &str = concatcp!(BINARY_DIR, "bootctl");
#[allow(dead_code)]

View File

@@ -19,6 +19,7 @@ use crate::defs::{KSU_BACKUP_DIR, KSU_BACKUP_FILE_PREFIX};
use crate::{assets, utils};
#[cfg(target_os = "android")]
#[allow(dead_code)]
fn ensure_gki_kernel() -> Result<()> {
let version = get_kernel_version()?;
let is_gki = version.0 == 5 && version.1 >= 10 || version.2 > 5;
@@ -27,6 +28,7 @@ fn ensure_gki_kernel() -> Result<()> {
}
#[cfg(target_os = "android")]
#[allow(dead_code)]
pub fn get_kernel_version() -> Result<(i32, i32, i32)> {
let uname = rustix::system::uname();
let version = uname.release().to_string_lossy();
@@ -92,10 +94,12 @@ pub fn get_current_kmi() -> Result<String> {
}
#[cfg(not(target_os = "android"))]
#[allow(dead_code)]
pub fn get_current_kmi() -> Result<String> {
bail!("Unsupported platform")
}
#[allow(dead_code)]
fn parse_kmi_from_kernel(kernel: &PathBuf, workdir: &Path) -> Result<String> {
use std::fs::{File, copy};
use std::io::{BufReader, Read};
@@ -129,6 +133,7 @@ fn parse_kmi_from_kernel(kernel: &PathBuf, workdir: &Path) -> Result<String> {
bail!("Try to choose LKM manually")
}
#[allow(dead_code)]
fn parse_kmi_from_boot(magiskboot: &Path, image: &PathBuf, workdir: &Path) -> Result<String> {
let image_path = workdir.join("image");
@@ -153,6 +158,7 @@ fn parse_kmi_from_boot(magiskboot: &Path, image: &PathBuf, workdir: &Path) -> Re
parse_kmi_from_kernel(&image_path, workdir)
}
#[allow(dead_code)]
fn do_cpio_cmd(magiskboot: &Path, workdir: &Path, cmd: &str) -> Result<()> {
let status = Command::new(magiskboot)
.current_dir(workdir)
@@ -167,6 +173,7 @@ fn do_cpio_cmd(magiskboot: &Path, workdir: &Path, cmd: &str) -> Result<()> {
Ok(())
}
#[allow(dead_code)]
fn is_magisk_patched(magiskboot: &Path, workdir: &Path) -> Result<bool> {
let status = Command::new(magiskboot)
.current_dir(workdir)
@@ -179,6 +186,7 @@ fn is_magisk_patched(magiskboot: &Path, workdir: &Path) -> Result<bool> {
Ok(status.code() == Some(1))
}
#[allow(dead_code)]
fn is_kernelsu_patched(magiskboot: &Path, workdir: &Path) -> Result<bool> {
let status = Command::new(magiskboot)
.current_dir(workdir)
@@ -190,6 +198,7 @@ fn is_kernelsu_patched(magiskboot: &Path, workdir: &Path) -> Result<bool> {
Ok(status.success())
}
#[allow(dead_code)]
fn dd<P: AsRef<Path>, Q: AsRef<Path>>(ifile: P, ofile: Q) -> Result<()> {
let status = Command::new("dd")
.stdout(Stdio::null())
@@ -323,6 +332,7 @@ pub fn restore(
Ok(())
}
#[allow(dead_code)]
#[allow(clippy::too_many_arguments)]
pub fn patch(
image: Option<PathBuf>,
@@ -342,6 +352,7 @@ pub fn patch(
result
}
#[allow(dead_code)]
#[allow(clippy::too_many_arguments)]
fn do_patch(
image: Option<PathBuf>,
@@ -529,6 +540,7 @@ fn do_patch(
}
#[cfg(target_os = "android")]
#[allow(dead_code)]
fn calculate_sha1(file_path: impl AsRef<Path>) -> Result<String> {
use sha1::Digest;
use std::io::Read;
@@ -549,6 +561,7 @@ fn calculate_sha1(file_path: impl AsRef<Path>) -> Result<String> {
}
#[cfg(target_os = "android")]
#[allow(dead_code)]
fn do_backup(magiskboot: &Path, workdir: &Path, image: &str) -> Result<()> {
let sha1 = calculate_sha1(image)?;
let filename = format!("{KSU_BACKUP_FILE_PREFIX}{sha1}");
@@ -569,6 +582,7 @@ fn do_backup(magiskboot: &Path, workdir: &Path, image: &str) -> Result<()> {
}
#[cfg(target_os = "android")]
#[allow(dead_code)]
fn clean_backup(sha1: &str) -> Result<()> {
println!("- Clean up backup");
let backup_name = format!("{}{}", KSU_BACKUP_FILE_PREFIX, sha1);
@@ -591,6 +605,7 @@ fn clean_backup(sha1: &str) -> Result<()> {
Ok(())
}
#[allow(dead_code)]
fn flash_boot(bootdevice: &Option<String>, new_boot: PathBuf) -> Result<()> {
let Some(bootdevice) = bootdevice else {
bail!("boot device not found")
@@ -604,6 +619,7 @@ fn flash_boot(bootdevice: &Option<String>, new_boot: PathBuf) -> Result<()> {
Ok(())
}
#[allow(dead_code)]
fn find_magiskboot(magiskboot_path: Option<PathBuf>, workdir: &Path) -> Result<PathBuf> {
let magiskboot = {
if which("magiskboot").is_ok() {
@@ -628,6 +644,7 @@ fn find_magiskboot(magiskboot_path: Option<PathBuf>, workdir: &Path) -> Result<P
Ok(magiskboot)
}
#[allow(dead_code)]
fn find_boot_image(
image: &Option<PathBuf>,
skip_init: bool,
@@ -677,6 +694,7 @@ fn find_boot_image(
Ok((bootimage, bootdevice))
}
#[allow(dead_code)]
fn post_ota() -> Result<()> {
use crate::defs::ADB_DIR;
use assets::BOOTCTL_PATH;

View File

@@ -34,11 +34,11 @@ enum Commands {
/// Trigger `boot-complete` event
BootCompleted,
// /// Install KernelSU Next userspace component to system
// Install {
// #[arg(long, default_value = None)]
// magiskboot: Option<PathBuf>,
// }, // DISBAND LKM MODE
/// Install KernelSU Next userspace component to system
Install {
#[arg(long, default_value = None)]
magiskboot: Option<PathBuf>,
},
/// Uninstall KernelSU Next modules and itself(LKM Only)
Uninstall {
@@ -327,7 +327,7 @@ pub fn run() -> Result<()> {
Module::Shrink => module::shrink_ksu_images(),
}
}
// Commands::Install { magiskboot } => utils::install(magiskboot), // DISBAND LKM MODE
Commands::Install { magiskboot } => utils::install(magiskboot), // DISBAND LKM MODE
Commands::Uninstall { magiskboot } => utils::uninstall(magiskboot),
Commands::Sepolicy { command } => match command {
Sepolicy::Patch { sepolicy } => crate::sepolicy::live_patch(&sepolicy),

View File

@@ -12,6 +12,7 @@ pub const PROFILE_TEMPLATE_DIR: &str = concatcp!(PROFILE_DIR, "templates/");
pub const KSURC_PATH: &str = concatcp!(WORKING_DIR, ".ksurc");
pub const KSU_OVERLAY_SOURCE: &str = "KSU";
pub const DAEMON_PATH: &str = concatcp!(ADB_DIR, "ksud");
#[allow(dead_code)]
pub const MAGISKBOOT_PATH: &str = concatcp!(BINARY_DIR, "magiskboot");
#[cfg(target_os = "android")]