Repository navigation
fix(redirect): 修复 HarmonyOS 上安装重定向被系统 Resolver 吞掉 - #31
Merged
Merged
Conversation
- 现象: 鸿蒙 4.2 上 InxLocker 把安装 Intent 的 package 改成目标安装器后, 系统仍无视 package 将其交给 com.huawei.android.internal.app.HwResolverActivity, 重定向完全失效(issue Chimioo#7)。 - 根因: 该 ROM 在 PMS 的 resolve 侧对安装类 Intent 强制注入自家 Resolver, 只给 package 而不给 component 的 Intent 永远到不了目标安装器;query 侧正常。 - 组件解析: 新增 ComponentResolver,先探测系统会解析到谁,仅在解析结果落在 OEM 自家 Resolver 时才从 queryIntentActivities 的候选里挑出真正的安装入口 并下发显式 component;AOSP 上解析正常时行为完全不变。 - 候选打分: 按类名关键字加权(packageinstaller/install/intercept)并对 scanner/viewer/explorer 等无关界面降权,得分不足时不擅自替用户选择。 - 性能: 按 package/action/type/scheme/categories 缓存 60 秒, 避免在持有 mGlobalLock 的 ActivityStarter.execute 里反复查询 PMS。 - action 规范化: 提前到解析之前,保证按最终的 VIEW 而非 INSTALL_PACKAGE 匹配候选。 - 缓存失效: 安装器/卸载器/强制组件配置变更与热重载时清空缓存。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
Fixes #7
在 HarmonyOS / EMUI(测试环境:DBY-W09 / HarmonyOS 4.2.0.208 / Android 12)上,InxLocker 的安装拦截看起来生效但结果被吞掉:日志显示 Intent 的
package已被改成目标安装器,但系统最终仍启动com.huawei.android.internal.app/.HwResolverActivity。补充一点:issue 里贴的
NoSuchFieldException: No field mRequest in class LcOm/android/server/wm/HwActivityStarter;是 V1.4(YukiHookAPI 时代,用getDeclaredField不回溯父类)的旧栈,V1.5 的findField递归实现已经让它不再出现。V1.5+ 在鸿蒙上的真实症状是这个 resolver 劫持。根因
该 ROM 在 PMS 的 resolve 侧对安装类 Intent 强制注入自家 Resolver。实测矩阵(adb 逐条验证):
am start -a VIEW -t application/vnd.android.package-archive -d file:///sdcard/test.apk -p io.github.muntashirakon.AppManager-p com.huawei.hinote(完全无关的包)-n io.github.muntashirakon.AppManager/.apk.installer.PackageInstallerActivity(显式 component)cmd package query-activities --brief -a VIEW -t application/vnd.android.package-archive即:只给 package 不给 component 的安装类 Intent 永远到不了目标安装器,
query侧正常、resolve侧被劫持。修改
新增
app/src/main/java/io/github/chimio/inxlocker/util/ComponentResolver.kt:resolveActivity看系统会解析到谁ResolverActivity仍交给用户选)*HwResolverActivity→ 说明被劫持,进下一步queryIntentActivities取目标包 exported 的候选,按类名关键字打分packageinstaller+100、install+50、intercept+20scanner/viewer/explorer/details/manifest/share/settings/…−100配套改动:
IntentRedirector.kt— 在只设 package 之后尝试解析;同时把normalizeAction()提到解析之前,保证按最终的VIEW而非INSTALL_PACKAGE匹配候选PrefsProvider.kt/HookEntry.kt/MainActivity.kt— 安装器/卸载器/强制组件变更与热重载时ComponentResolver.invalidate()IntentRedirector.kt日志增加- Target component:性能
ActivityStarter.execute执行时持有mGlobalLock,所以结果按package|action|type|scheme|categories缓存 60 秒(上限 128 条),配置变更立即失效。验证
release 版(
minifyEnabled+shrinkResources)装到 DBY-W09 / HarmonyOS 4.2.0.208 实测:风险
改动只在「系统会解析到 OEM 自家 Resolver」时才生效,AOSP 路径的逻辑分支没有任何变化。仍建议在 AOSP 设备上回归一次。