mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-09-13 02:54:26 +08:00
feat: 新增安卓平台支持
This commit is contained in:
@@ -49,16 +49,26 @@ pub fn ensure_libcomposite_loaded() -> Result<()> {
|
||||
}
|
||||
|
||||
pub fn find_udc() -> Option<String> {
|
||||
let udc_path = Path::new("/sys/class/udc");
|
||||
if !udc_path.exists() {
|
||||
return None;
|
||||
}
|
||||
list_udcs().into_iter().next()
|
||||
}
|
||||
|
||||
fs::read_dir(udc_path)
|
||||
.ok()?
|
||||
.filter_map(|e| e.ok())
|
||||
.map(|e| e.file_name().to_string_lossy().to_string())
|
||||
.next()
|
||||
pub fn list_udcs() -> Vec<String> {
|
||||
let mut devices = Vec::new();
|
||||
collect_dir_names(Path::new("/sys/class/udc"), &mut devices);
|
||||
devices.sort();
|
||||
devices.dedup();
|
||||
devices
|
||||
}
|
||||
|
||||
fn collect_dir_names(path: &Path, devices: &mut Vec<String>) {
|
||||
if let Ok(entries) = fs::read_dir(path) {
|
||||
for entry in entries.flatten() {
|
||||
let name = entry.file_name().to_string_lossy().trim().to_string();
|
||||
if !name.is_empty() {
|
||||
devices.push(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_low_endpoint_udc(name: &str) -> bool {
|
||||
|
||||
@@ -25,13 +25,12 @@ pub use service::{HidDevicePaths, OtgService};
|
||||
|
||||
/// List USB Device Controller names exposed by sysfs.
|
||||
pub fn list_udc_devices() -> Vec<String> {
|
||||
let mut devices: Vec<String> = std::fs::read_dir("/sys/class/udc")
|
||||
.ok()
|
||||
.into_iter()
|
||||
.flat_map(|entries| entries.filter_map(|entry| entry.ok()))
|
||||
.filter_map(|entry| entry.file_name().to_str().map(str::to_owned))
|
||||
.collect();
|
||||
|
||||
devices.sort();
|
||||
devices
|
||||
#[cfg(unix)]
|
||||
{
|
||||
configfs::list_udcs()
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
{
|
||||
Vec::new()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user