mirror of
https://github.com/Universal-Debloater-Alliance/universal-android-debloater-next-generation.git
synced 2026-08-24 06:24:19 +02:00
refactor: user_id: u16 not u: User
This commit is contained in:
parent
4ec1acd769
commit
9aeba115a6
4 changed files with 22 additions and 27 deletions
|
|
@ -37,7 +37,6 @@
|
|||
//! For comprehensive info about ADB,
|
||||
//! [see this](https://android.googlesource.com/platform/packages/modules/adb/+/refs/heads/master/docs/)
|
||||
|
||||
use crate::core::sync::User;
|
||||
use regex::Regex;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use static_init::dynamic;
|
||||
|
|
@ -200,11 +199,8 @@ impl ToString for PmLsPackFlag {
|
|||
}
|
||||
}
|
||||
|
||||
pub const PACK_PREFIX: &str = "package:";
|
||||
#[expect(clippy::cast_possible_truncation, reason = "")]
|
||||
pub const PACK_URI_LEN: u8 = PACK_PREFIX.len() as _;
|
||||
const PACK_PREFIX: &str = "package:";
|
||||
|
||||
pub const PM_LIST_PACKS: &str = "pm list packages";
|
||||
pub const PM_CLEAR_PACK: &str = "pm clear";
|
||||
|
||||
/// Builder for an Android Package Manager command.
|
||||
|
|
@ -224,23 +220,23 @@ impl PmCmd {
|
|||
pub fn ls_packs(
|
||||
mut self,
|
||||
f: Option<PmLsPackFlag>,
|
||||
u: Option<User>,
|
||||
user_id: Option<u16>,
|
||||
) -> Result<Vec<String>, String> {
|
||||
let cmd = &mut self.0 .0 .0;
|
||||
cmd.args(["list", "packages", "-s"]);
|
||||
if let Some(s) = f {
|
||||
cmd.arg(s.to_str());
|
||||
};
|
||||
if let Some(u) = u {
|
||||
if let Some(u) = user_id {
|
||||
cmd.arg("--user");
|
||||
cmd.arg(u.id.to_string());
|
||||
cmd.arg(u.to_string());
|
||||
};
|
||||
self.0 .0.run().map(|pack_ls| {
|
||||
pack_ls
|
||||
.lines()
|
||||
.map(|p_ln| {
|
||||
debug_assert!(p_ln.starts_with(PACK_PREFIX));
|
||||
String::from(&p_ln[PACK_URI_LEN as usize..])
|
||||
String::from(&p_ln[PACK_PREFIX.len()..])
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
|
|
@ -252,9 +248,9 @@ impl PmCmd {
|
|||
pub fn ls_packs_valid(
|
||||
self,
|
||||
f: Option<PmLsPackFlag>,
|
||||
u: Option<User>,
|
||||
user_id: Option<u16>,
|
||||
) -> Result<HashSet<PackId>, String> {
|
||||
Ok(self.ls_packs(f, u)?
|
||||
Ok(self.ls_packs(f, user_id)?
|
||||
.into_iter()
|
||||
.map(|p| PackId::new(p).expect("One of these is wrong: `PackId` regex, ADB implementation. Or the spec now allows a wider char-set")).collect())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::core::{
|
||||
adb::{to_trimmed_utf8, Cmd as AdbCmd, PACK_URI_LEN, PM_CLEAR_PACK, PM_LIST_PACKS},
|
||||
adb::{to_trimmed_utf8, Cmd as AdbCmd, PM_CLEAR_PACK},
|
||||
uad_lists::PackageState,
|
||||
};
|
||||
use crate::gui::{views::list::PackageInfo, widgets::package_row::PackageRow};
|
||||
|
|
@ -7,7 +7,7 @@ use regex::Regex;
|
|||
use retry::{delay::Fixed, retry, OperationResult};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use static_init::dynamic;
|
||||
use std::{collections::HashSet, process::Command};
|
||||
use std::process::Command;
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
use std::os::windows::process::CommandExt;
|
||||
|
|
@ -293,13 +293,12 @@ pub const fn supports_multi_user(dev: &Device) -> bool {
|
|||
/// to list associated packages.
|
||||
///
|
||||
/// If `device_serial` is empty, it lets ADB choose the default device.
|
||||
pub fn is_protected_user(user_id: &str, device_serial: &str) -> bool {
|
||||
adb_cmd(
|
||||
true,
|
||||
device_serial,
|
||||
&format!("{PM_LIST_PACKS} -s --user {user_id}"),
|
||||
)
|
||||
.is_err()
|
||||
pub fn is_protected_user<S: AsRef<str>>(user_id: u16, device_serial: S) -> bool {
|
||||
AdbCmd::new()
|
||||
.sh(device_serial)
|
||||
.pm()
|
||||
.ls_packs(None, Some(user_id))
|
||||
.is_err()
|
||||
}
|
||||
|
||||
/// `pm list users` parsed into a vec with extra info.
|
||||
|
|
@ -319,11 +318,11 @@ pub fn ls_users_parsed(device_serial: &str) -> Vec<User> {
|
|||
// It seems each line is a user,
|
||||
// optionally associated with a work-profile.
|
||||
// This will ignore the work-profiles!
|
||||
let u = &RE.captures(&user).expect("Each user should have an ID")[1];
|
||||
let u = RE.captures(&user).expect("Each user should have an ID")[1]
|
||||
.parse()
|
||||
.unwrap_or_else(|_| unreachable!("User ID must be valid `u16`"));
|
||||
User {
|
||||
id: u
|
||||
.parse()
|
||||
.unwrap_or_else(|_| unreachable!("User ID must be valid `u16`")),
|
||||
id: u,
|
||||
index: i,
|
||||
protected: is_protected_user(u, device_serial),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::core::{
|
||||
adb::{Cmd as AdbCmd, PmLsPackFlag},
|
||||
sync::{hashset_system_packages, User},
|
||||
sync::User,
|
||||
theme::Theme,
|
||||
uad_lists::{PackageHashMap, PackageState, Removal, UadList},
|
||||
};
|
||||
|
|
@ -27,7 +27,7 @@ pub enum Error {
|
|||
pub fn fetch_packages(
|
||||
uad_lists: &PackageHashMap,
|
||||
device_serial: &str,
|
||||
user_id: Option<User>,
|
||||
user_id: Option<u16>,
|
||||
) -> Vec<PackageRow> {
|
||||
let all_sys_packs = AdbCmd::new()
|
||||
.sh(device_serial)
|
||||
|
|
|
|||
|
|
@ -868,7 +868,7 @@ impl List {
|
|||
} else {
|
||||
user_list
|
||||
.iter()
|
||||
.map(|user| fetch_packages(&uad_list, serial, Some(*user)))
|
||||
.map(|user| fetch_packages(&uad_list, serial, Some(user.id)))
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue