From 3ed382165b85e4b99880f9c36e54db36b76ef1dc Mon Sep 17 00:00:00 2001 From: Fankesyooni Date: Fri, 18 Mar 2022 05:47:35 +0800 Subject: [PATCH] Update YukiHookAPI --- app/build.gradle | 4 +- .../com/fankes/miui/notify/hook/HookEntry.kt | 86 ++++++++----------- 2 files changed, 39 insertions(+), 51 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 71ccb2f..93b6c77 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -64,8 +64,8 @@ tasks.whenTaskAdded { dependencies { compileOnly 'de.robv.android.xposed:api:82' - implementation 'com.highcapable.yukihookapi:api:1.0.4' - ksp 'com.highcapable.yukihookapi:ksp-xposed:1.0.4' + implementation 'com.highcapable.yukihookapi:api:1.0.5-fix' + ksp 'com.highcapable.yukihookapi:ksp-xposed:1.0.5-fix' implementation "com.github.topjohnwu.libsu:core:3.1.2" implementation 'androidx.annotation:annotation:1.3.0' implementation 'com.geyifeng.immersionbar:immersionbar:3.2.0' diff --git a/app/src/main/java/com/fankes/miui/notify/hook/HookEntry.kt b/app/src/main/java/com/fankes/miui/notify/hook/HookEntry.kt index ca63ea8..0ceff7f 100644 --- a/app/src/main/java/com/fankes/miui/notify/hook/HookEntry.kt +++ b/app/src/main/java/com/fankes/miui/notify/hook/HookEntry.kt @@ -122,10 +122,6 @@ class HookEntry : YukiHookXposedInitProxy { /** 是否显示通知图标 - 跟随 Hook 保存 */ private var isShowNotificationIcons = true - /** 是否有最大图标设置功能 */ - private val PackageParam.hasMaxStaticIcons - get() = safeOfFalse { NotificationIconContainerClass.clazz.hasField(name = "MAX_STATIC_ICONS") } - /** * - 这个是修复彩色图标的关键核心代码判断 * @@ -469,19 +465,12 @@ class HookEntry : YukiHookXposedInitProxy { } else false.also { printLogcat(tag = "IconColor", context, expandedNf, isCustom = false, isGrayscale = true) } else true.also { printLogcat(tag = "IconColor", context, expandedNf, isCustom = false, isGrayscale = false) } - override fun onHook() { - runConfig() - runHook() - } - - /** 配置 Hook */ - private fun runConfig() = configs { + override fun onInit() = configs { debugTag = "MIUINativeNotifyIcon" isDebug = false } - /** 开始 Hook */ - private fun runHook() = encase { + override fun onHook() = encase { loadApp(SYSTEMUI_PACKAGE_NAME) { when { /** 不是 MIUI 系统停止 Hook */ @@ -562,42 +551,41 @@ class HookEntry : YukiHookXposedInitProxy { } } } - if (hasMaxStaticIcons) - NotificationIconContainerClass.hook { - injectMember { - method { name = "calculateIconTranslations" } - afterHook { - /** 修复最新开发版状态栏图标只能显示一个的问题 */ - instance().layoutParams.width = 9999 - } + NotificationIconContainerClass.hook { + injectMember { + method { name = "calculateIconTranslations" } + afterHook { + /** 修复最新开发版状态栏图标只能显示一个的问题 */ + instance().layoutParams.width = 9999 } - injectMember { - method { name = "updateState" } - beforeHook { - /** 解除状态栏通知图标个数限制 */ - if (isShowNotificationIcons && prefs.getBoolean(ENABLE_HOOK_STATUS_ICON_COUNT, default = true)) - field { name = "MAX_STATIC_ICONS" } - .get(instance).set(prefs.getInt(HOOK_STATUS_ICON_COUNT, default = 5) - .let { if (it in 0..100) it else 5 }) - } - } - /** 旧版方法 - 新版不存在 */ - injectMember { - method { - name = "setMaxStaticIcons" - param(IntType) - beforeHook { isShowNotificationIcons = firstArgs as Int > 0 } - } - }.ignoredHookingFailure() - /** 新版方法 - 旧版不存在 */ - injectMember { - method { - name = "miuiShowNotificationIcons" - param(BooleanType) - } - beforeHook { isShowNotificationIcons = firstArgs as Boolean } - }.ignoredHookingFailure() } + injectMember { + method { name = "updateState" } + beforeHook { + /** 解除状态栏通知图标个数限制 */ + if (isShowNotificationIcons && prefs.getBoolean(ENABLE_HOOK_STATUS_ICON_COUNT, default = true)) + field { name = "MAX_STATIC_ICONS" } + .get(instance).set(prefs.getInt(HOOK_STATUS_ICON_COUNT, default = 5) + .let { if (it in 0..100) it else 5 }) + } + } + /** 旧版方法 - 新版不存在 */ + injectMember { + method { + name = "setMaxStaticIcons" + param(IntType) + beforeHook { isShowNotificationIcons = firstArgs as Int > 0 } + } + }.ignoredNoSuchMemberFailure() + /** 新版方法 - 旧版不存在 */ + injectMember { + method { + name = "miuiShowNotificationIcons" + param(BooleanType) + } + beforeHook { isShowNotificationIcons = firstArgs as Boolean } + }.ignoredNoSuchMemberFailure() + }.by { safeOfFalse { NotificationIconContainerClass.clazz.hasField(name = "MAX_STATIC_ICONS") } } NotificationHeaderViewWrapperClass.hook { /** 修复下拉通知图标自动设置回 APP 图标的方法 */ injectMember { @@ -659,14 +647,14 @@ class HookEntry : YukiHookXposedInitProxy { } } intercept() - }.ignoredHookingFailure() + }.ignoredNoSuchMemberFailure() injectMember { method { name = "resetIconBgAndPaddings" param(ImageViewClass, ExpandedNotificationClass.clazz) } intercept() - }.ignoredHookingFailure() + }.ignoredNoSuchMemberFailure() }.ignoredHookClassNotFoundFailure() } }