From ae65e2a1f4c36ff42016feccbbc4eae5aa04f9f5 Mon Sep 17 00:00:00 2001 From: frknkrc44 Date: Mon, 11 Aug 2025 16:35:56 +0300 Subject: [PATCH] Fix pre-Q support for ActivityHook --- .../hidemyapplist/xposed/hook/ActivityHook.kt | 81 ++++++++++++++----- 1 file changed, 59 insertions(+), 22 deletions(-) diff --git a/xposed/src/main/java/icu/nullptr/hidemyapplist/xposed/hook/ActivityHook.kt b/xposed/src/main/java/icu/nullptr/hidemyapplist/xposed/hook/ActivityHook.kt index 7b2d1ed..2c737b6 100644 --- a/xposed/src/main/java/icu/nullptr/hidemyapplist/xposed/hook/ActivityHook.kt +++ b/xposed/src/main/java/icu/nullptr/hidemyapplist/xposed/hook/ActivityHook.kt @@ -1,6 +1,7 @@ package icu.nullptr.hidemyapplist.xposed.hook import android.content.Intent +import android.os.Build import com.github.kyuubiran.ezxhelper.init.InitFields import com.github.kyuubiran.ezxhelper.utils.findMethod import com.github.kyuubiran.ezxhelper.utils.hookBefore @@ -21,30 +22,66 @@ class ActivityHook(private val service: HMAService) : IFrameworkHook { override fun load() { logI(TAG, "Load hook") - hook = findMethod( - "com.android.server.wm.ActivityStarter" - ) { - name == "executeRequest" - }.hookBefore { param -> - runCatching { - val request = param.args[0] - val caller = getObjectField(request, "callingPackage") as String? - val intent = getObjectField(request, "intent") as Intent? - val targetApp = intent?.component?.packageName - if (service.shouldHide(caller, targetApp)) { - logI(TAG, "@executeRequest: insecure query from $caller, target: ${intent?.component}") - param.result = getStaticIntField( - findClass( - "android.app.ActivityManager", - InitFields.ezXClassLoader - ), - "START_INTENT_NOT_RESOLVED" - ) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + hook = findMethod( + "com.android.server.wm.ActivityStarter" + ) { + name == "executeRequest" + }.hookBefore { param -> + runCatching { + val request = param.args[0] + val caller = getObjectField(request, "callingPackage") as String? + val intent = getObjectField(request, "intent") as Intent? + val targetApp = intent?.component?.packageName + + if (service.shouldHide(caller, targetApp)) { + logI( + TAG, + "@executeRequest: insecure query from $caller, target: ${intent?.component}" + ) + param.result = getStaticIntField( + findClass( + "android.app.ActivityManager", + InitFields.ezXClassLoader + ), + "START_INTENT_NOT_RESOLVED" + ) + } + }.onFailure { + logE(TAG, "Fatal error occurred, ignore hook\n", it) + // unload() + } + } + } else { + hook = findMethod( + "com.android.server.am.ActivityStarter" + ) { + name == "execute" + }.hookBefore { param -> + runCatching { + val request = getObjectField(param.thisObject, "mRequest") + val caller = getObjectField(request, "callingPackage") as String? + val intent = getObjectField(request, "intent") as Intent? + val targetApp = intent?.component?.packageName + + if (service.shouldHide(caller, targetApp)) { + logI( + TAG, + "@executeRequest: insecure query from $caller, target: ${intent?.component}" + ) + param.result = getStaticIntField( + findClass( + "android.app.ActivityManager", + InitFields.ezXClassLoader + ), + "START_INTENT_NOT_RESOLVED" + ) + } + }.onFailure { + logE(TAG, "Fatal error occurred, ignore hook\n", it) + // unload() } - }.onFailure { - logE(TAG, "Fatal error occurred, ignore hook\n", it) - // unload() } } }