fix multiuser owner_managed mode

This commit is contained in:
vvb2060 2019-01-29 04:41:51 +08:00 committed by John Wu
parent 1a38f25bd9
commit 817cdf7113
2 changed files with 5 additions and 9 deletions

View File

@ -38,7 +38,7 @@ fun MagiskPolicy.toMap() = mapOf(
fun Map<String, String>.toPolicy(pm: PackageManager): MagiskPolicy { fun Map<String, String>.toPolicy(pm: PackageManager): MagiskPolicy {
val uid = get("uid")?.toIntOrNull() ?: -1 val uid = get("uid")?.toIntOrNull() ?: -1
val packageName = get("package_name").orEmpty() val packageName = get("package_name").orEmpty()
val info = pm.getApplicationInfo(packageName, 0) val info = pm.getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES)
if (info.uid != uid) if (info.uid != uid)
throw PackageManager.NameNotFoundException() throw PackageManager.NameNotFoundException()
@ -59,9 +59,9 @@ fun Map<String, String>.toPolicy(pm: PackageManager): MagiskPolicy {
fun Int.toPolicy(pm: PackageManager, policy: Int = INTERACTIVE): MagiskPolicy { fun Int.toPolicy(pm: PackageManager, policy: Int = INTERACTIVE): MagiskPolicy {
val pkg = pm.getPackagesForUid(this)?.firstOrNull() val pkg = pm.getPackagesForUid(this)?.firstOrNull()
?: throw PackageManager.NameNotFoundException() ?: throw PackageManager.NameNotFoundException()
val info = pm.getApplicationInfo(pkg, 0) val info = pm.getApplicationInfo(pkg, PackageManager.GET_UNINSTALLED_PACKAGES)
return MagiskPolicy( return MagiskPolicy(
uid = this, uid = info.uid,
packageName = pkg, packageName = pkg,
policy = policy, policy = policy,
applicationInfo = info, applicationInfo = info,

View File

@ -34,10 +34,6 @@ enum {
(info->cfg[SU_MULTIUSER_MODE] == MULTIUSER_MODE_USER \ (info->cfg[SU_MULTIUSER_MODE] == MULTIUSER_MODE_USER \
? info->uid / 100000 : 0) ? info->uid / 100000 : 0)
#define get_uid(info) \
(info->cfg[SU_MULTIUSER_MODE] == MULTIUSER_MODE_OWNER_MANAGED \
? info->uid % 100000 : info->uid)
#define get_cmd(to) \ #define get_cmd(to) \
(to.command[0] ? to.command : to.shell[0] ? to.shell : DEFAULT_SHELL) (to.command[0] ? to.command : to.shell[0] ? to.shell : DEFAULT_SHELL)
@ -165,7 +161,7 @@ void app_log(const su_context &ctx) {
if (fork_dont_care() == 0) { if (fork_dont_care() == 0) {
vector<Extra> extras; vector<Extra> extras;
extras.reserve(6); extras.reserve(6);
extras.emplace_back("from.uid", get_uid(ctx.info)); extras.emplace_back("from.uid", ctx.info->uid);
extras.emplace_back("to.uid", ctx.req.uid); extras.emplace_back("to.uid", ctx.req.uid);
extras.emplace_back("pid", ctx.pid); extras.emplace_back("pid", ctx.pid);
extras.emplace_back("policy", ctx.info->access.policy); extras.emplace_back("policy", ctx.info->access.policy);
@ -181,7 +177,7 @@ void app_notify(const su_context &ctx) {
if (fork_dont_care() == 0) { if (fork_dont_care() == 0) {
vector<Extra> extras; vector<Extra> extras;
extras.reserve(2); extras.reserve(2);
extras.emplace_back("from.uid", get_uid(ctx.info)); extras.emplace_back("from.uid", ctx.info->uid);
extras.emplace_back("policy", ctx.info->access.policy); extras.emplace_back("policy", ctx.info->access.policy);
exec_cmd("notify", extras, ctx.info); exec_cmd("notify", extras, ctx.info);