From cabadbc24401a55d359978ddaaabc5095afc504b Mon Sep 17 00:00:00 2001 From: Timeline <53483352+Nep-Timeline@users.noreply.github.com> Date: Thu, 9 Apr 2026 14:33:09 +0800 Subject: [PATCH 1/3] fix: skip media notifications to avoid systemui lag --- .../notify/hook/entity/SystemUIHooker.kt | 45 ++++++++++++++++--- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/fankes/coloros/notify/hook/entity/SystemUIHooker.kt b/app/src/main/java/com/fankes/coloros/notify/hook/entity/SystemUIHooker.kt index 21eddca..971c3ab 100644 --- a/app/src/main/java/com/fankes/coloros/notify/hook/entity/SystemUIHooker.kt +++ b/app/src/main/java/com/fankes/coloros/notify/hook/entity/SystemUIHooker.kt @@ -256,6 +256,9 @@ object SystemUIHooker : YukiBaseHooker() { /** 状态栏通知图标数组 */ private var notificationIconInstances = ArrayList() + /** 媒体会话管理器 */ + private var mediaSessionManager: MediaSessionManager? = null + /** 媒体通知 [View] */ private var notificationPlayerView: View? = null @@ -699,6 +702,34 @@ object SystemUIHooker : YukiBaseHooker() { iconDatas.clear() IconPackParams(param = this).iconDatas.apply { if (isNotEmpty()) forEach { iconDatas.add(it) } } } + + /** 获取媒体会话管理器 */ + fun getMediaSessionManager(context: Context): MediaSessionManager { + if (mediaSessionManager == null) + mediaSessionManager = context.getSystemService(Context.MEDIA_SESSION_SERVICE) as MediaSessionManager + + return mediaSessionManager!! + } + + /** 判断是否为媒体通知 */ + fun isMediaNotificationAOSP(notification: Notification?): Boolean { + if (notification == null) return false + + return notification.javaClass.resolve().firstMethod { name = "isMediaNotification" }.of(notification).invoke() == true + } + + /** 通过媒体会话和AOSP方法判断是否为媒体通知 */ + fun isMediaNotification(context: Context, notification: Notification, packageName: String): Boolean { + if (isMediaNotificationVanilla(notification)) return true + + val mediaSessionManager: MediaSessionManager = getMediaSessionManager(context) + + for (mediaController in mediaSessionManager.getActiveSessions(null)) + if (packageName == mediaController.getPackageName() && notification.contentView != null) + return true + + return false + } /** * 刷新缓存数据 @@ -786,7 +817,7 @@ object SystemUIHooker : YukiBaseHooker() { NotificationEntryClass.resolve().optional().firstMethodOrNull { name = "getSbn" }?.of(args().first().any())?.invokeQuietly()?.also { nf -> - nf.notification.smallIcon.loadDrawable(context)?.also { iconDrawable -> + if (!isMediaNotification(context, nf.notification, context.packageName)) nf.notification.smallIcon.loadDrawable(context)?.also { iconDrawable -> compatStatusIcon( context = context, nf = nf, @@ -920,7 +951,7 @@ object SystemUIHooker : YukiBaseHooker() { }?.invoke() }.also { nf -> nf?.notification?.also { - it.smallIcon.loadDrawable(context)?.also { iconDrawable -> + if (!isMediaNotification(context, it, context.packageName)) it.smallIcon.loadDrawable(context)?.also { iconDrawable -> compatNotifyIcon( context = context, nf = nf, @@ -954,7 +985,7 @@ object SystemUIHooker : YukiBaseHooker() { }?.invoke() }.also { nf -> nf?.notification?.also { - it.smallIcon.loadDrawable(context)?.also { iconDrawable -> + if (!isMediaNotification(context, it, context.packageName)) it.smallIcon.loadDrawable(context)?.also { iconDrawable -> compatNotifyIcon( context = context, nf = nf, @@ -997,7 +1028,7 @@ object SystemUIHooker : YukiBaseHooker() { if (context == null) return@also nf?.notification?.also { - it.smallIcon.loadDrawable(context)?.also { iconDrawable -> + if (!isMediaNotification(context, it, context.packageName)) it.smallIcon.loadDrawable(context)?.also { iconDrawable -> compatNotifyIcon( context = context, nf = nf, @@ -1071,7 +1102,7 @@ object SystemUIHooker : YukiBaseHooker() { }?.invoke() }.also { nf -> nf?.notification?.also { - it.smallIcon.loadDrawable(context)?.also { iconDrawable -> + if (!isMediaNotification(context, it, context.packageName)) it.smallIcon.loadDrawable(context)?.also { iconDrawable -> /** 执行替换 */ compatNotifyIcon( context = context, @@ -1102,7 +1133,7 @@ object SystemUIHooker : YukiBaseHooker() { }?.invoke() }.also { nf -> nf?.notification?.also { - it.smallIcon.loadDrawable(context)?.also { iconDrawable -> + if (!isMediaNotification(context, it, context.packageName)) it.smallIcon.loadDrawable(context)?.also { iconDrawable -> /** 执行替换 */ fun doParse() { compatNotifyIcon( @@ -1126,4 +1157,4 @@ object SystemUIHooker : YukiBaseHooker() { } } } -} \ No newline at end of file +} From 5b70245982bdb431e0d35ee7793472b9f0073a16 Mon Sep 17 00:00:00 2001 From: Timeline <53483352+Nep-Timeline@users.noreply.github.com> Date: Thu, 9 Apr 2026 14:34:47 +0800 Subject: [PATCH 2/3] fix: packageName --- .../com/fankes/coloros/notify/hook/entity/SystemUIHooker.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/fankes/coloros/notify/hook/entity/SystemUIHooker.kt b/app/src/main/java/com/fankes/coloros/notify/hook/entity/SystemUIHooker.kt index 971c3ab..a476c89 100644 --- a/app/src/main/java/com/fankes/coloros/notify/hook/entity/SystemUIHooker.kt +++ b/app/src/main/java/com/fankes/coloros/notify/hook/entity/SystemUIHooker.kt @@ -720,7 +720,7 @@ object SystemUIHooker : YukiBaseHooker() { /** 通过媒体会话和AOSP方法判断是否为媒体通知 */ fun isMediaNotification(context: Context, notification: Notification, packageName: String): Boolean { - if (isMediaNotificationVanilla(notification)) return true + if (isMediaNotificationAOSP(notification)) return true val mediaSessionManager: MediaSessionManager = getMediaSessionManager(context) @@ -817,7 +817,7 @@ object SystemUIHooker : YukiBaseHooker() { NotificationEntryClass.resolve().optional().firstMethodOrNull { name = "getSbn" }?.of(args().first().any())?.invokeQuietly()?.also { nf -> - if (!isMediaNotification(context, nf.notification, context.packageName)) nf.notification.smallIcon.loadDrawable(context)?.also { iconDrawable -> + if (!isMediaNotification(context, nf.notification, nf.packageName)) nf.notification.smallIcon.loadDrawable(context)?.also { iconDrawable -> compatStatusIcon( context = context, nf = nf, From 3690dba266f629eb0b1046885b220a3e1ee3cd25 Mon Sep 17 00:00:00 2001 From: Timeline <53483352+Nep-Timeline@users.noreply.github.com> Date: Thu, 9 Apr 2026 14:38:42 +0800 Subject: [PATCH 3/3] fix: import --- .../fankes/coloros/notify/hook/entity/SystemUIHooker.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/fankes/coloros/notify/hook/entity/SystemUIHooker.kt b/app/src/main/java/com/fankes/coloros/notify/hook/entity/SystemUIHooker.kt index a476c89..6745dcf 100644 --- a/app/src/main/java/com/fankes/coloros/notify/hook/entity/SystemUIHooker.kt +++ b/app/src/main/java/com/fankes/coloros/notify/hook/entity/SystemUIHooker.kt @@ -1,3 +1,4 @@ + /* * ColorOSNotifyIcon - Optimize notification icons for ColorOS and adapt to native notification icon specifications. * Copyright (C) 20174 Fankes Studio(qzmmcn@163.com) @@ -34,6 +35,7 @@ import android.graphics.Color import android.graphics.Outline import android.graphics.drawable.Drawable import android.graphics.drawable.Icon +import android.media.session.MediaSessionManager import android.os.Build import android.os.SystemClock import android.service.notification.StatusBarNotification @@ -258,7 +260,7 @@ object SystemUIHooker : YukiBaseHooker() { /** 媒体会话管理器 */ private var mediaSessionManager: MediaSessionManager? = null - + /** 媒体通知 [View] */ private var notificationPlayerView: View? = null @@ -702,7 +704,7 @@ object SystemUIHooker : YukiBaseHooker() { iconDatas.clear() IconPackParams(param = this).iconDatas.apply { if (isNotEmpty()) forEach { iconDatas.add(it) } } } - + /** 获取媒体会话管理器 */ fun getMediaSessionManager(context: Context): MediaSessionManager { if (mediaSessionManager == null) @@ -717,7 +719,7 @@ object SystemUIHooker : YukiBaseHooker() { return notification.javaClass.resolve().firstMethod { name = "isMediaNotification" }.of(notification).invoke() == true } - + /** 通过媒体会话和AOSP方法判断是否为媒体通知 */ fun isMediaNotification(context: Context, notification: Notification, packageName: String): Boolean { if (isMediaNotificationAOSP(notification)) return true