mirror of
https://github.com/kvorschk/Magisk.git
synced 2026-12-04 19:10:47 -05:00
Support Headless System User Mode (HSUM)
On Headless System User Mode (HSUM) devices (e.g. Android Automotive OS and shared tablets), user 0 is strictly a non-interactive background system user while human users operate as secondary users (user 10+). - Check ro.fw.mu.headless_system_user in daemon_entry and store it on MagiskD. - Enforce MultiuserMode::User on HSUM devices and seed the setting in magisk.db during post-fs-data, avoiding duplicate override logic. - For non-app UIDs (< AID_APP_START), scan all discovered users from /data/user_de to resolve the manager package/UID and broadcast su usage notifications across all users. - Include system UIDs (< 10000) in PolicyDao.fetchAll() so ADB shell (UID 2000) policies can be loaded on secondary users. - Hide the Multiuser Mode setting in the app on HSUM devices. Assisted-by: Gemini 3.8 Flash
This commit is contained in:
@@ -440,30 +440,32 @@ private fun SuperuserSection(
|
||||
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f)
|
||||
)
|
||||
|
||||
// Multiuser Mode
|
||||
val multiuserEntries = remember {
|
||||
resources.getStringArray(CoreR.array.multiuser_mode).toList()
|
||||
}
|
||||
val multiuserDescriptions = remember {
|
||||
resources.getStringArray(CoreR.array.multiuser_summary).toList()
|
||||
}
|
||||
var multiuserMode by remember { mutableIntStateOf(Config.suMultiuserMode) }
|
||||
SettingsDropdown(
|
||||
title = stringResource(CoreR.string.multiuser_mode),
|
||||
summary = multiuserDescriptions.getOrElse(multiuserMode) { "" },
|
||||
items = multiuserEntries,
|
||||
selectedIndex = multiuserMode,
|
||||
enabled = Const.USER_ID == 0,
|
||||
onSelectedIndexChange = {
|
||||
multiuserMode = it
|
||||
Config.suMultiuserMode = it
|
||||
if (!Info.isHeadlessSystemUser) {
|
||||
// Multiuser Mode
|
||||
val multiuserEntries = remember {
|
||||
resources.getStringArray(CoreR.array.multiuser_mode).toList()
|
||||
}
|
||||
)
|
||||
val multiuserDescriptions = remember {
|
||||
resources.getStringArray(CoreR.array.multiuser_summary).toList()
|
||||
}
|
||||
var multiuserMode by remember { mutableIntStateOf(Config.suMultiuserMode) }
|
||||
SettingsDropdown(
|
||||
title = stringResource(CoreR.string.multiuser_mode),
|
||||
summary = multiuserDescriptions.getOrElse(multiuserMode) { "" },
|
||||
items = multiuserEntries,
|
||||
selectedIndex = multiuserMode,
|
||||
enabled = Const.USER_ID == 0,
|
||||
onSelectedIndexChange = {
|
||||
multiuserMode = it
|
||||
Config.suMultiuserMode = it
|
||||
}
|
||||
)
|
||||
|
||||
HorizontalDivider(
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f)
|
||||
)
|
||||
HorizontalDivider(
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f)
|
||||
)
|
||||
}
|
||||
|
||||
// Mount Namespace Mode
|
||||
val namespaceEntries = remember {
|
||||
|
||||
@@ -60,6 +60,10 @@ object Info {
|
||||
|| getProperty("ro.kernel.qemu", "0") == "1"
|
||||
|| getProperty("ro.boot.qemu", "0") == "1"
|
||||
|
||||
val isHeadlessSystemUser by lazy {
|
||||
getProperty("ro.fw.mu.headless_system_user", "false").toBoolean()
|
||||
}
|
||||
|
||||
val isConnected = MutableLiveData(false)
|
||||
|
||||
val showSuperUser: Boolean get() {
|
||||
|
||||
@@ -35,7 +35,7 @@ class PolicyDao : MagiskDB() {
|
||||
}
|
||||
|
||||
suspend fun fetchAll(): List<SuPolicy> {
|
||||
val query = "$SELECT_QUERY FROM ${Table.POLICY} WHERE uid/100000=${Const.USER_ID}"
|
||||
val query = "$SELECT_QUERY FROM ${Table.POLICY} WHERE uid/100000=${Const.USER_ID} OR uid < 10000"
|
||||
return exec(query, ::toPolicy).filterNotNull()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::consts::{APP_PACKAGE_NAME, BBPATH, DATABIN, MODULEROOT, SECURE_DIR};
|
||||
use crate::daemon::MagiskD;
|
||||
use crate::db::MultiuserMode;
|
||||
use crate::ffi::{
|
||||
DbEntryKey, RequestCode, check_key_combo, exec_common_scripts, exec_module_scripts,
|
||||
get_magisk_tmp, initialize_denylist,
|
||||
@@ -125,6 +126,11 @@ impl MagiskD {
|
||||
|
||||
self.prune_su_access();
|
||||
|
||||
if self.is_headless {
|
||||
self.set_db_setting(DbEntryKey::SuMultiuserMode, MultiuserMode::User as i32)
|
||||
.log_ok();
|
||||
}
|
||||
|
||||
if !self.setup_magisk_env() {
|
||||
error!("* Magisk environment incomplete, abort");
|
||||
return true;
|
||||
|
||||
@@ -65,6 +65,7 @@ pub struct MagiskD {
|
||||
pub cached_su_info: AtomicArc<SuInfo>,
|
||||
pub sdk_int: i32,
|
||||
pub is_emulator: bool,
|
||||
pub is_headless: bool,
|
||||
is_recovery: bool,
|
||||
exe_attr: FileAttr,
|
||||
}
|
||||
@@ -311,6 +312,7 @@ fn daemon_entry() {
|
||||
let is_emulator = get_prop(cstr!("ro.kernel.qemu")) == "1"
|
||||
|| get_prop(cstr!("ro.boot.qemu")) == "1"
|
||||
|| get_prop(cstr!("ro.product.device")).contains("vsoc");
|
||||
let is_headless = get_prop(cstr!("ro.fw.mu.headless_system_user")) == "true";
|
||||
|
||||
// Load config status
|
||||
let magisk_tmp = get_magisk_tmp();
|
||||
@@ -395,6 +397,7 @@ fn daemon_entry() {
|
||||
let daemon = MagiskD {
|
||||
sdk_int,
|
||||
is_emulator,
|
||||
is_headless,
|
||||
is_recovery,
|
||||
exe_attr,
|
||||
..Default::default()
|
||||
|
||||
@@ -246,6 +246,9 @@ impl MagiskD {
|
||||
}
|
||||
|
||||
pub fn get_db_setting(&self, key: DbEntryKey) -> i32 {
|
||||
if self.is_headless && key == DbEntryKey::SuMultiuserMode {
|
||||
return MultiuserMode::User as i32;
|
||||
}
|
||||
// Get default values
|
||||
let mut val = match key {
|
||||
DbEntryKey::RootAccess => RootAccess::default() as i32,
|
||||
@@ -277,6 +280,9 @@ impl MagiskD {
|
||||
};
|
||||
self.db_exec_with_rows("SELECT * FROM settings", &[], &mut cfg)
|
||||
.sql_result()?;
|
||||
if self.is_headless {
|
||||
cfg.multiuser_mode = MultiuserMode::User;
|
||||
}
|
||||
Ok(cfg)
|
||||
}
|
||||
|
||||
|
||||
@@ -502,4 +502,27 @@ impl MagiskD {
|
||||
}();
|
||||
list
|
||||
}
|
||||
|
||||
pub fn get_users(&self) -> Vec<i32> {
|
||||
let mut users = Vec::new();
|
||||
let _ = || -> LoggedResult<()> {
|
||||
let mut app_data_dir = Directory::open(self.app_data_dir())?;
|
||||
while let Some(e) = app_data_dir.read()? {
|
||||
if e.is_dir()
|
||||
&& let Ok(user) = e.name().parse::<i32>()
|
||||
&& user >= 0
|
||||
{
|
||||
users.push(user);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}();
|
||||
if !users.contains(&0) {
|
||||
users.push(0);
|
||||
}
|
||||
users.sort_unstable();
|
||||
users.dedup();
|
||||
users
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::SuInfo;
|
||||
use crate::daemon::{MagiskD, to_user_id};
|
||||
use crate::daemon::{AID_APP_START, MagiskD, to_app_id, to_user_id};
|
||||
use crate::ffi::{SuRequest, fork_dont_care};
|
||||
use ExtraVal::{Bool, Int, IntList, Str};
|
||||
use base::{BytesExt, error};
|
||||
@@ -70,8 +70,8 @@ impl Extra<'_> {
|
||||
}
|
||||
|
||||
impl MagiskD {
|
||||
fn exec_cmd(&self, eval_uid: i32, mgr_pkg: &str, action: &'static str, extras: &[Extra]) {
|
||||
let user = to_user_id(eval_uid).to_string();
|
||||
fn exec_cmd(&self, user: i32, mgr_pkg: &str, action: &'static str, extras: &[Extra]) {
|
||||
let user = user.to_string();
|
||||
|
||||
let provider = format!("content://{mgr_pkg}.provider");
|
||||
let mut cmd = app_process();
|
||||
@@ -123,7 +123,13 @@ impl MagiskD {
|
||||
value: Int(info.settings.policy.repr),
|
||||
},
|
||||
];
|
||||
self.exec_cmd(info.eval_uid, &info.mgr_pkg, "notify", &extras);
|
||||
if to_app_id(info.eval_uid) < AID_APP_START {
|
||||
for user in self.get_users() {
|
||||
self.exec_cmd(user, &info.mgr_pkg, "notify", &extras);
|
||||
}
|
||||
} else {
|
||||
self.exec_cmd(to_user_id(info.eval_uid), &info.mgr_pkg, "notify", &extras);
|
||||
}
|
||||
}
|
||||
|
||||
fn app_log(&self, cred: &UCred, info: &SuInfo, request: &SuRequest) {
|
||||
@@ -170,7 +176,13 @@ impl MagiskD {
|
||||
value: Bool(info.settings.notify),
|
||||
},
|
||||
];
|
||||
self.exec_cmd(info.eval_uid, &info.mgr_pkg, "log", &extras);
|
||||
if to_app_id(info.eval_uid) < AID_APP_START {
|
||||
for user in self.get_users() {
|
||||
self.exec_cmd(user, &info.mgr_pkg, "log", &extras);
|
||||
}
|
||||
} else {
|
||||
self.exec_cmd(to_user_id(info.eval_uid), &info.mgr_pkg, "log", &extras);
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn notify_app(&self, cred: &UCred, info: &SuInfo, request: &SuRequest) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::db::RootSettings;
|
||||
use crate::daemon::{AID_ROOT, AID_SHELL, MagiskD, to_app_id, to_user_id};
|
||||
use crate::daemon::{AID_APP_START, AID_ROOT, AID_SHELL, MagiskD, to_app_id, to_user_id};
|
||||
use crate::db::{DbSettings, MultiuserMode, RootAccess};
|
||||
use crate::ffi::{SuPolicy, SuRequest, exec_root_shell};
|
||||
use crate::socket::IpcRead;
|
||||
@@ -201,7 +201,17 @@ impl MagiskD {
|
||||
let mut settings = RootSettings::default();
|
||||
self.get_root_settings(eval_uid, &mut settings)?;
|
||||
|
||||
let (mgr_uid, mgr_pkg) = self.get_manager(to_user_id(eval_uid), true);
|
||||
let (mut mgr_uid, mut mgr_pkg) = self.get_manager(to_user_id(eval_uid), true);
|
||||
if mgr_pkg.is_empty() && to_app_id(eval_uid) < AID_APP_START {
|
||||
for user in self.get_users() {
|
||||
let (id, pkg) = self.get_manager(user, true);
|
||||
if !pkg.is_empty() {
|
||||
mgr_uid = id;
|
||||
mgr_pkg = pkg;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If it's the manager, allow it silently
|
||||
if to_app_id(uid) == to_app_id(mgr_uid) {
|
||||
|
||||
Reference in New Issue
Block a user