From d70d01cf6c8b1a8ea06bd443202566f11e2ee241 Mon Sep 17 00:00:00 2001 From: fankesyooni Date: Sun, 27 Aug 2023 14:38:05 +0800 Subject: [PATCH] Fix SystemUI crashed when StatusBarNotification's tag is null by NotificationStat method "isUnimportantEntry" in SystemUIHooker --- .../miui/notify/hook/entity/SystemUIHooker.kt | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/app/src/main/java/com/fankes/miui/notify/hook/entity/SystemUIHooker.kt b/app/src/main/java/com/fankes/miui/notify/hook/entity/SystemUIHooker.kt index c17bb87..7a35134 100644 --- a/app/src/main/java/com/fankes/miui/notify/hook/entity/SystemUIHooker.kt +++ b/app/src/main/java/com/fankes/miui/notify/hook/entity/SystemUIHooker.kt @@ -87,6 +87,9 @@ object SystemUIHooker : YukiBaseHooker() { private const val NotificationHeaderViewWrapperInjectorClass = "${PackageName.SYSTEMUI}.statusbar.notification.row.wrapper.NotificationHeaderViewWrapperInjector" + /** MIUI 新版本存在的类 */ + private const val NotificationStatClass = "${PackageName.SYSTEMUI}.statusbar.notification.analytics.NotificationStat" + /** 原生存在的类 */ private const val NotificationChildrenContainerClass = "${PackageName.SYSTEMUI}.statusbar.notification.stack.NotificationChildrenContainer" @@ -969,5 +972,32 @@ object SystemUIHooker : YukiBaseHooker() { intercept() }.ignoredNoSuchMemberFailure() }.ignoredHookClassNotFoundFailure() + /** + * 尝试修复从 MIUI 14 开始出现的一个崩溃问题 + * 由于模块注入推送的通知没有对 [StatusBarNotification] 设置 TAG 会导致其空指针 + * 直接替换掉它自己的实现方法 - 使用自己的方式实现这个功能 + * ```java + * public final boolean isUnimportantEntry(NotificationEntry notificationEntry) { + * return notificationEntry.getSbn().getPackageName().equals("com.android.systemui") && + * notificationEntry.getSbn().getTag().equals("UNIMPORTANT"); + * } + * ``` + */ + NotificationStatClass.hook { + injectMember { + method { + name = "isUnimportantEntry" + paramCount = 1 + } + replaceAny { + args().first().current(ignored = true).method { + name = "getSbn" + superClass() + }.invoke()?.let { sbn -> + sbn.packageName == PackageName.SYSTEMUI && sbn.tag == "UNIMPORTANT" + } ?: false + } + }.ignoredNoSuchMemberFailure() + }.ignoredHookClassNotFoundFailure() } } \ No newline at end of file