mirror of
https://github.com/kvorschk/Magisk.git
synced 2026-12-04 19:10:47 -05:00
Fix package management and user targeting on HSUM
- Use --user current for pm install, adb install, and appops set across install_script, adb_pm_install, and test/setup scripts. - Skip headless user 0 in get_users() on HSUM devices. - Use --user current in app_notify for non-app UIDs instead of calling content call against all users. - Clear path buffer on each iteration in setup_magisk_env. - Use --user current for am instrument in app migration tests. Assisted-by: Gemini 4 Argon
This commit is contained in:
@@ -64,7 +64,7 @@ class AppMigrationTest {
|
||||
|
||||
// Trigger the test to run migration
|
||||
val pfd = uiAutomation.executeShellCommand(
|
||||
"am instrument -w --user 0 -e class .Environment#$method " +
|
||||
"am instrument -w --user current -e class .Environment#$method " +
|
||||
"$pkg.test/${AppTestRunner::class.java.name}"
|
||||
)
|
||||
val output = AutoCloseInputStream(pfd).reader().use { it.readText() }
|
||||
|
||||
@@ -11,7 +11,7 @@ use crate::mount::{clean_mounts, setup_preinit_dir};
|
||||
use crate::resetprop::get_prop;
|
||||
use crate::selinux::restorecon;
|
||||
use base::const_format::concatcp;
|
||||
use base::{BufReadExt, FsPathBuilder, ResultExt, cstr, error, info};
|
||||
use base::{BufReadExt, FsPathBuilder, ResultExt, Utf8CStrBuf, cstr, error, info};
|
||||
use bitflags::bitflags;
|
||||
use nix::fcntl::OFlag;
|
||||
use std::io::BufReader;
|
||||
@@ -36,6 +36,7 @@ impl MagiskD {
|
||||
let mut buf = cstr::buf::default();
|
||||
|
||||
for user in self.get_users() {
|
||||
buf.clear();
|
||||
buf.append_path(APP_DATA_DIR)
|
||||
.append_path_fmt(user)
|
||||
.append_path(APP_PACKAGE_NAME)
|
||||
|
||||
@@ -506,14 +506,18 @@ impl MagiskD {
|
||||
while let Some(e) = app_data_dir.read()? {
|
||||
if e.is_dir()
|
||||
&& let Ok(user) = e.name().parse::<i32>()
|
||||
&& user >= 0
|
||||
{
|
||||
if self.is_headless && user == 0 {
|
||||
continue;
|
||||
}
|
||||
if user >= 0 {
|
||||
users.push(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}();
|
||||
if !users.contains(&0) {
|
||||
if users.is_empty() {
|
||||
users.push(0);
|
||||
}
|
||||
users.sort_unstable();
|
||||
|
||||
@@ -235,8 +235,8 @@ void exec_module_scripts(Utf8CStr stage, const rust::Vec<ModuleInfo> &module_lis
|
||||
constexpr char install_script[] = R"EOF(
|
||||
APK=%s
|
||||
log -t Magisk "pm_install: $APK"
|
||||
log -t Magisk "pm_install: $(pm install --user all -g -r $APK 2>&1)"
|
||||
appops set --user all %s REQUEST_INSTALL_PACKAGES allow
|
||||
log -t Magisk "pm_install: $(pm install --user current -g -r $APK 2>&1)"
|
||||
appops set --user current %s REQUEST_INSTALL_PACKAGES allow
|
||||
rm -f $APK
|
||||
)EOF";
|
||||
|
||||
|
||||
@@ -70,9 +70,7 @@ impl Extra<'_> {
|
||||
}
|
||||
|
||||
impl MagiskD {
|
||||
fn exec_cmd(&self, user: i32, mgr_pkg: &str, action: &'static str, extras: &[Extra]) {
|
||||
let user = user.to_string();
|
||||
|
||||
fn exec_cmd(&self, user: &str, mgr_pkg: &str, action: &'static str, extras: &[Extra]) {
|
||||
let provider = format!("content://{mgr_pkg}.provider");
|
||||
let mut cmd = app_process();
|
||||
cmd.args([
|
||||
@@ -82,7 +80,7 @@ impl MagiskD {
|
||||
"--uri",
|
||||
&provider,
|
||||
"--user",
|
||||
&user,
|
||||
user,
|
||||
"--method",
|
||||
action,
|
||||
]);
|
||||
@@ -164,13 +162,14 @@ impl MagiskD {
|
||||
value: Bool(info.settings.log),
|
||||
},
|
||||
];
|
||||
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);
|
||||
}
|
||||
let user_id;
|
||||
let user = if to_app_id(info.eval_uid) < AID_APP_START {
|
||||
"current"
|
||||
} else {
|
||||
self.exec_cmd(to_user_id(info.eval_uid), &info.mgr_pkg, "notify", &extras);
|
||||
}
|
||||
user_id = to_user_id(info.eval_uid).to_string();
|
||||
&user_id
|
||||
};
|
||||
self.exec_cmd(user, &info.mgr_pkg, "notify", &extras);
|
||||
}
|
||||
|
||||
pub(super) fn notify_app(&self, cred: &UCred, info: &SuInfo, request: &SuRequest) {
|
||||
|
||||
@@ -123,11 +123,12 @@ adb_pm_install() {
|
||||
local tmp=/data/local/tmp/temp.apk
|
||||
cp -f "$1" $tmp
|
||||
chmod 644 $tmp
|
||||
su 2000 -c pm install -g $tmp || pm install -g $tmp || su 1000 -c pm install -g $tmp
|
||||
local cmd="pm install --user current -g $tmp"
|
||||
su 2000 -c $cmd || $cmd || su 1000 -c $cmd
|
||||
local res=$?
|
||||
rm -f $tmp
|
||||
if [ $res = 0 ]; then
|
||||
appops set "$2" REQUEST_INSTALL_PACKAGES allow
|
||||
appops set --user current "$2" REQUEST_INSTALL_PACKAGES allow
|
||||
fi
|
||||
return $res
|
||||
}
|
||||
|
||||
+2
-2
@@ -322,8 +322,8 @@ app_test_main() {
|
||||
for apk in "${apks[@]}"; do
|
||||
# Cleanup
|
||||
adb shell pm uninstall com.topjohnwu.magisk || true
|
||||
adb install -r -g $apk
|
||||
adb install -r -g out/test.apk
|
||||
adb install --user current -r -g $apk
|
||||
adb install --user current -r -g out/test.apk
|
||||
am_instrument '.AppTest' $app
|
||||
done
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ if [ -z "$FIRST_STAGE" ]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
pm install -r -g $(pwd)/magisk.apk
|
||||
pm install --user current -r -g $(pwd)/magisk.apk
|
||||
|
||||
# Stop zygote (and previous setup if exists)
|
||||
magisk --stop 2>/dev/null
|
||||
|
||||
@@ -44,7 +44,7 @@ ensure_android_cli() {
|
||||
# $2 = component
|
||||
am_instrument() {
|
||||
set +x
|
||||
local out=$(adb shell am instrument -w --user 0 -e class "$1" "$2")
|
||||
local out=$(adb shell am instrument -w --user current -e class "$1" "$2")
|
||||
echo "$out"
|
||||
if grep -q 'OK (' <<< "$out"; then
|
||||
set -x
|
||||
@@ -60,10 +60,10 @@ run_setup() {
|
||||
adb shell 'PATH=$PATH:/debug_ramdisk magisk -v'
|
||||
|
||||
# Install the Magisk app
|
||||
adb install -r -g $apk
|
||||
adb install --user current -r -g $apk
|
||||
|
||||
# Install the test app
|
||||
adb install -r -g out/test.apk
|
||||
adb install --user current -r -g out/test.apk
|
||||
|
||||
local app='com.topjohnwu.magisk.test/com.topjohnwu.magisk.test.AppTestRunner'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user