|
20 | 20 | * |
21 | 21 | * This file is created by fankes on 2022/3/25. |
22 | 22 | */ |
23 | | -@file:Suppress("StaticFieldLeak", "ConstPropertyName") |
| 23 | +@file:Suppress("ConstPropertyName") |
24 | 24 |
|
25 | 25 | package com.fankes.miui.notify.hook.entity |
26 | 26 |
|
| 27 | +import android.annotation.SuppressLint |
27 | 28 | import android.app.Notification |
28 | 29 | import android.app.NotificationManager |
29 | 30 | import android.app.WallpaperManager |
@@ -67,6 +68,7 @@ import com.fankes.miui.notify.utils.factory.isMIOS |
67 | 68 | import com.fankes.miui.notify.utils.factory.isNotSystemInDarkMode |
68 | 69 | import com.fankes.miui.notify.utils.factory.isSystemInDarkMode |
69 | 70 | import com.fankes.miui.notify.utils.factory.isUpperOfAndroidS |
| 71 | +import com.fankes.miui.notify.utils.factory.miosVersionCode |
70 | 72 | import com.fankes.miui.notify.utils.factory.miuiIncrementalVersion |
71 | 73 | import com.fankes.miui.notify.utils.factory.round |
72 | 74 | import com.fankes.miui.notify.utils.factory.runInSafe |
@@ -215,6 +217,7 @@ object SystemUIHooker : YukiBaseHooker() { |
215 | 217 | private var isUsingCachingMethod = false |
216 | 218 |
|
217 | 219 | /** 状态栏通知图标容器 */ |
| 220 | + @SuppressLint("StaticFieldLeak") |
218 | 221 | private var notificationIconContainer: ViewGroup? = null |
219 | 222 |
|
220 | 223 | /** 通知栏通知控制器 */ |
@@ -659,8 +662,10 @@ object SystemUIHooker : YukiBaseHooker() { |
659 | 662 | /** 获取 [StatusBarNotification] 实例 */ |
660 | 663 | val notifyInstance = asResolver().optional().firstFieldOrNull { name = "mNotification" }?.get<StatusBarNotification>() ?: return false |
661 | 664 |
|
| 665 | + val appContext = context.createPackageContext(notifyInstance.nfPkgName, Context.CONTEXT_IGNORE_SECURITY) |
| 666 | + |
662 | 667 | /** 获取通知小图标 */ |
663 | | - val iconDrawable = notifyInstance.notification?.smallIcon?.loadDrawable(context) ?: return false |
| 668 | + val iconDrawable = notifyInstance.notification?.smallIcon?.loadDrawable(appContext) ?: return false |
664 | 669 |
|
665 | 670 | /** 判断是否不是灰度图标 */ |
666 | 671 | val isGrayscaleIcon = notifyInstance.isXmsf.not() && isGrayscaleIcon(context, iconDrawable) |
@@ -693,6 +698,7 @@ object SystemUIHooker : YukiBaseHooker() { |
693 | 698 | * @param animColor 动画过渡颜色 |
694 | 699 | */ |
695 | 700 | private fun updateStatusBarIconColor(iconView: ImageView, isDarkIconMode: Boolean = this.isDarkIconMode, animColor: Int? = null) { |
| 701 | + if (miosVersionCode >= 3) return |
696 | 702 | if (iconView.isGrayscaleIcon()) { |
697 | 703 | /** |
698 | 704 | * 防止图标不是纯黑的问题 |
@@ -947,11 +953,15 @@ object SystemUIHooker : YukiBaseHooker() { |
947 | 953 | parameters(Notification::class, Context::class) |
948 | 954 | }?.hook()?.after { |
949 | 955 | val nf = args().first().cast<Notification>() |
| 956 | + val appname = nf?.extras?.getString("miui.opPkg") |
950 | 957 | val context = args(index = 1).cast<Context>() |
951 | | - val iconBitmap = nf?.smallIcon?.loadDrawable(context)?.toBitmap() |
952 | | - result = if (context != null && iconBitmap != null && !iconBitmap.isRecycled) |
953 | | - iconBitmap.toDrawable(context.resources) |
954 | | - else null |
| 958 | + if (appname != null) { |
| 959 | + val appContext = context?.createPackageContext(appname, Context.CONTEXT_IGNORE_SECURITY) |
| 960 | + val iconBitmap = nf.smallIcon?.loadDrawable(appContext)?.toBitmap() |
| 961 | + result = if (context != null && iconBitmap != null && !iconBitmap.isRecycled) |
| 962 | + iconBitmap.toDrawable(context.resources) |
| 963 | + else null |
| 964 | + } |
955 | 965 | } |
956 | 966 | /** |
957 | 967 | * 强制回写系统的状态栏图标样式为原生 |
@@ -986,59 +996,61 @@ object SystemUIHooker : YukiBaseHooker() { |
986 | 996 | } |
987 | 997 | } |
988 | 998 | } |
989 | | - /** 焦点通知深色模式切换点 */ |
990 | | - FocusedNotifPromptViewClass?.resolve()?.optional()?.apply { |
991 | | - firstMethodOrNull { |
992 | | - name = "onDarkChanged" |
993 | | - parameters(ArrayList::class, Float::class, Int::class, Int::class, Int::class, Boolean::class) |
994 | | - }?.hook()?.after { |
995 | | - val isDark = args(index = 1).float() |
996 | | - val mIcon = firstFieldOrNull { name = "mIcon" }?.of(instance)?.get() |
997 | | - if (ConfigData.isEnableModuleLog) |
998 | | - YLog.debug("FocusedNotifPromptView DEBUG $isDark $mIcon") |
999 | | - if (focusedIcon || ConfigData.isEnableFocusNotificationFix) |
1000 | | - mIcon?.asResolver()?.optional()?.firstMethodOrNull { |
1001 | | - name = "setColorFilter" |
1002 | | - superclass() |
1003 | | - }?.invoke(if (isDark <= 0.5f) Color.WHITE else Color.BLACK) |
| 999 | + if (miosVersionCode < 3) { |
| 1000 | + /** 焦点通知深色模式切换点 */ |
| 1001 | + FocusedNotifPromptViewClass?.resolve()?.optional()?.apply { |
| 1002 | + firstMethodOrNull { |
| 1003 | + name = "onDarkChanged" |
| 1004 | + parameters(ArrayList::class, Float::class, Int::class, Int::class, Int::class, Boolean::class) |
| 1005 | + }?.hook()?.after { |
| 1006 | + val isDark = args(index = 1).float() |
| 1007 | + val mIcon = firstFieldOrNull { name = "mIcon" }?.of(instance)?.get() |
| 1008 | + if (ConfigData.isEnableModuleLog) |
| 1009 | + YLog.debug("FocusedNotifPromptView DEBUG $isDark $mIcon") |
| 1010 | + if (focusedIcon || ConfigData.isEnableFocusNotificationFix) |
| 1011 | + mIcon?.asResolver()?.optional()?.firstMethodOrNull { |
| 1012 | + name = "setColorFilter" |
| 1013 | + superclass() |
| 1014 | + }?.invoke(if (isDark <= 0.5f) Color.WHITE else Color.BLACK) |
| 1015 | + } |
1004 | 1016 | } |
1005 | | - } |
1006 | | - /** 去他妈的焦点通知彩色图标 */ |
1007 | | - FocusUtilsClass?.resolve()?.optional()?.apply { |
1008 | | - fun HookParam.hookTickerDarkIcon(isDark: Boolean) { |
1009 | | - (globalContext ?: args().first().cast())?.also { context -> |
1010 | | - val expandedNf = args().first().cast<StatusBarNotification?>() |
1011 | | - val small = expandedNf?.notification?.smallIcon |
1012 | | - /** Hook 状态栏小图标 */ |
1013 | | - compatStatusIcon( |
1014 | | - context = context, |
1015 | | - nf = expandedNf, |
1016 | | - iconDrawable = small?.loadDrawable(context) |
1017 | | - ).also { pair -> |
1018 | | - focusedIcon = pair.second |
1019 | | - val originalBitmap = pair.first?.toBitmap() |
1020 | | - val bitmap = originalBitmap?.scale(50, 50) |
1021 | | - result = Icon.createWithBitmap(bitmap).apply { |
1022 | | - if (pair.second || ConfigData.isEnableFocusNotificationFix) |
1023 | | - setTint(if (isDark) Color.BLACK else Color.WHITE) |
| 1017 | + /** 去他妈的焦点通知彩色图标 */ |
| 1018 | + FocusUtilsClass?.resolve()?.optional()?.apply { |
| 1019 | + fun HookParam.hookTickerDarkIcon(isDark: Boolean) { |
| 1020 | + (globalContext ?: args().first().cast())?.also { context -> |
| 1021 | + val expandedNf = args().first().cast<StatusBarNotification?>() |
| 1022 | + val small = expandedNf?.notification?.smallIcon |
| 1023 | + /** Hook 状态栏小图标 */ |
| 1024 | + compatStatusIcon( |
| 1025 | + context = context, |
| 1026 | + nf = expandedNf, |
| 1027 | + iconDrawable = small?.loadDrawable(context) |
| 1028 | + ).also { pair -> |
| 1029 | + focusedIcon = pair.second |
| 1030 | + val originalBitmap = pair.first?.toBitmap() |
| 1031 | + val bitmap = originalBitmap?.scale(50, 50) |
| 1032 | + result = Icon.createWithBitmap(bitmap).apply { |
| 1033 | + if (pair.second || ConfigData.isEnableFocusNotificationFix) |
| 1034 | + setTint(if (isDark) Color.BLACK else Color.WHITE) |
| 1035 | + } |
1024 | 1036 | } |
1025 | 1037 | } |
1026 | 1038 | } |
| 1039 | + firstMethodOrNull { |
| 1040 | + name = "getStatusBarTickerDarkIcon" |
| 1041 | + parameters { |
| 1042 | + (it.first() == classOf<StatusBarNotification>() || |
| 1043 | + it.first() == ExpandedNotificationClass) && it.size == 1 |
| 1044 | + } |
| 1045 | + }?.hook()?.after { hookTickerDarkIcon(isDark = true) } |
| 1046 | + firstMethodOrNull { |
| 1047 | + name = "getStatusBarTickerIcon" |
| 1048 | + parameters { |
| 1049 | + (it.first() == classOf<StatusBarNotification>() || |
| 1050 | + it.first() == ExpandedNotificationClass) && it.size == 1 |
| 1051 | + } |
| 1052 | + }?.hook()?.after { hookTickerDarkIcon(isDark = false) } |
1027 | 1053 | } |
1028 | | - firstMethodOrNull { |
1029 | | - name = "getStatusBarTickerDarkIcon" |
1030 | | - parameters { |
1031 | | - (it.first() == classOf<StatusBarNotification>() || |
1032 | | - it.first() == ExpandedNotificationClass) && it.size == 1 |
1033 | | - } |
1034 | | - }?.hook()?.after { hookTickerDarkIcon(isDark = true) } |
1035 | | - firstMethodOrNull { |
1036 | | - name = "getStatusBarTickerIcon" |
1037 | | - parameters { |
1038 | | - (it.first() == classOf<StatusBarNotification>() || |
1039 | | - it.first() == ExpandedNotificationClass) && it.size == 1 |
1040 | | - } |
1041 | | - }?.hook()?.after { hookTickerDarkIcon(isDark = false) } |
1042 | 1054 | } |
1043 | 1055 | /** 注入状态栏通知图标实例 */ |
1044 | 1056 | StatusBarIconViewClass.resolve().optional().firstMethodOrNull { |
|
0 commit comments