Skip to content

Commit 0e099dc

Browse files
authored
fix: block coloros 15 useAppIconForSmallIcon method (#77)
1 parent 3819db4 commit 0e099dc

File tree

1 file changed

+64
-52
lines changed

1 file changed

+64
-52
lines changed

app/src/main/java/com/fankes/coloros/notify/hook/entity/SystemUIHooker.kt

Lines changed: 64 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ import com.highcapable.yukihookapi.hook.type.java.FloatType
8888
import com.highcapable.yukihookapi.hook.type.java.IntType
8989
import com.highcapable.yukihookapi.hook.type.java.LongType
9090
import top.defaults.drawabletoolbox.DrawableBuilder
91+
import androidx.core.graphics.drawable.toDrawable
92+
import com.highcapable.yukihookapi.hook.type.android.NotificationClass
9193

9294
/**
9395
* 系统界面核心 Hook 类
@@ -143,6 +145,9 @@ object SystemUIHooker : YukiBaseHooker() {
143145
/** ColorOS 存在的类 - 旧版本不存在 */
144146
private val BasePlayViewHolderClass by lazyClassOrNull("com.oplusos.systemui.media.base.BasePlayViewHolder")
145147

148+
/** ColorOS 存在的类 - 旧版本不存在 */
149+
private val OplusNotificationSmallIconUtilClass by lazyClassOrNull("com.oplus.systemui.statusbar.notification.util.OplusNotificationSmallIconUtil")
150+
146151
/** 根据多个版本存在不同的包名相同的类 */
147152
private val OplusNotificationIconAreaControllerClass by lazyClass(
148153
VariousClass(
@@ -293,15 +298,15 @@ object SystemUIHooker : YukiBaseHooker() {
293298
private fun loggerDebug(tag: String, context: Context, nf: StatusBarNotification?, isCustom: Boolean, isGrayscale: Boolean) {
294299
if (ConfigData.isEnableModuleLog) YLog.debug(
295300
msg = "(Processing $tag) ↓\n" +
296-
"[Title]: ${nf?.notification?.extras?.getString(Notification.EXTRA_TITLE)}\n" +
297-
"[Content]: ${nf?.notification?.extras?.getString(Notification.EXTRA_TEXT)}\n" +
298-
"[App Name]: ${context.appNameOf(packageName = nf?.packageName ?: "")}\n" +
299-
"[Package Name]: ${nf?.packageName}\n" +
300-
"[Sender Package Name]: ${nf?.opPkg}\n" +
301-
"[Custom Icon]: $isCustom\n" +
302-
"[Grayscale Icon]: $isGrayscale\n" +
303-
"[From System Push]: ${nf?.isOplusPush}\n" +
304-
"[String]: ${nf?.notification}"
301+
"[Title]: ${nf?.notification?.extras?.getString(Notification.EXTRA_TITLE)}\n" +
302+
"[Content]: ${nf?.notification?.extras?.getString(Notification.EXTRA_TEXT)}\n" +
303+
"[App Name]: ${context.appNameOf(packageName = nf?.packageName ?: "")}\n" +
304+
"[Package Name]: ${nf?.packageName}\n" +
305+
"[Sender Package Name]: ${nf?.opPkg}\n" +
306+
"[Custom Icon]: $isCustom\n" +
307+
"[Grayscale Icon]: $isGrayscale\n" +
308+
"[From System Push]: ${nf?.isOplusPush}\n" +
309+
"[String]: ${nf?.notification}"
305310
)
306311
}
307312

@@ -434,7 +439,7 @@ object SystemUIHooker : YukiBaseHooker() {
434439
iconDatas.takeIf { it.isNotEmpty() }?.forEach {
435440
if (packageName == it.packageName && isAppNotifyHookOf(it)) {
436441
if (isGrayscaleIcon.not() || isAppNotifyHookAllOf(it))
437-
customPair = Triple(BitmapDrawable(context.resources, it.iconBitmap), it.iconColor, false)
442+
customPair = Triple(it.iconBitmap.toDrawable(context.resources), it.iconColor, false)
438443
return@run
439444
}
440445
}
@@ -696,6 +701,13 @@ object SystemUIHooker : YukiBaseHooker() {
696701
/** 是否移除 */
697702
if (ConfigData.isEnableRemoveDndAlertNotify) resultNull()
698703
}
704+
/** 拦截ColorOS使用应用图标判断 */
705+
OplusNotificationSmallIconUtilClass?.method {
706+
name = "useAppIconForSmallIcon"
707+
param(NotificationClass)
708+
}?.hook()?.before {
709+
resultFalse()
710+
}
699711
/** 修复并替换 ColorOS 以及原生灰度图标色彩判断 */
700712
NotificationUtilsClass.apply {
701713
method {
@@ -714,28 +726,28 @@ object SystemUIHooker : YukiBaseHooker() {
714726
}.hook().after {
715727
IconBuilderClass.field { name = "context" }
716728
.get(IconManagerClass.field { name = "iconBuilder" }.get(instance).cast()).cast<Context>()?.also { context ->
717-
NotificationEntryClass.method {
718-
name = "getSbn"
719-
}.get(args().first().any()).invoke<StatusBarNotification>()?.also { nf ->
720-
nf.notification.smallIcon.loadDrawable(context)?.also { iconDrawable ->
721-
compatStatusIcon(
722-
context = context,
723-
nf = nf,
724-
isGrayscaleIcon = isGrayscaleIcon(context, iconDrawable).also {
725-
/** 缓存第一次的 APP 小图标 */
726-
if (it.not()) context.appIconOf(nf.packageName)?.also { e -> appIcons[nf.packageName] = e }
727-
},
728-
packageName = nf.packageName,
729-
drawable = iconDrawable
730-
).also { pair ->
731-
if (pair.second) StatusBarIconClass.field {
732-
name = "icon"
733-
type = IconClass
734-
}.get(result).set(Icon.createWithBitmap(pair.first.toBitmap()))
729+
NotificationEntryClass.method {
730+
name = "getSbn"
731+
}.get(args().first().any()).invoke<StatusBarNotification>()?.also { nf ->
732+
nf.notification.smallIcon.loadDrawable(context)?.also { iconDrawable ->
733+
compatStatusIcon(
734+
context = context,
735+
nf = nf,
736+
isGrayscaleIcon = isGrayscaleIcon(context, iconDrawable).also {
737+
/** 缓存第一次的 APP 小图标 */
738+
if (it.not()) context.appIconOf(nf.packageName)?.also { e -> appIcons[nf.packageName] = e }
739+
},
740+
packageName = nf.packageName,
741+
drawable = iconDrawable
742+
).also { pair ->
743+
if (pair.second) StatusBarIconClass.field {
744+
name = "icon"
745+
type = IconClass
746+
}.get(result).set(Icon.createWithBitmap(pair.first.toBitmap()))
747+
}
735748
}
736749
}
737750
}
738-
}
739751
}
740752
/** 得到状态栏图标实例 */
741753
StatusBarIconViewClass.method {
@@ -768,8 +780,8 @@ object SystemUIHooker : YukiBaseHooker() {
768780
}.onFind { way = 2 }
769781
}.hook().after {
770782
when (way) {
771-
1 -> notificationIconContainer = OplusNotificationIconAreaControllerClass.method { name = "getNotificationIcons" }.get(instance).invoke()
772-
2 -> {
783+
2 -> notificationIconContainer = OplusNotificationIconAreaControllerClass.method { name = "getNotificationIcons" }.get(instance).invoke()
784+
1 -> {
773785
notificationIconInstances.clear()
774786
field { name = "mLastToShow" }.get(instance).list<View>()
775787
.takeIf { it.isNotEmpty() }?.forEach { notificationIconInstances.add(it) }
@@ -875,30 +887,30 @@ object SystemUIHooker : YukiBaseHooker() {
875887
.get(NotificationViewWrapperClass.field {
876888
name = "mRow"
877889
}.get(instance).any()).call()?.let {
878-
it.javaClass.method {
879-
name = "getSbn"
880-
}.get(it).invoke<StatusBarNotification>()
881-
}.also { nf ->
882-
nf?.notification?.also {
883-
it.smallIcon.loadDrawable(context)?.also { iconDrawable ->
884-
/** 执行替换 */
885-
fun doParse() {
886-
compatNotifyIcon(
887-
context = context,
888-
nf = nf,
889-
isGrayscaleIcon = isGrayscaleIcon(context, iconDrawable),
890-
packageName = context.packageName,
891-
drawable = iconDrawable,
892-
iconColor = it.color,
893-
iconView = this
894-
)
890+
it.javaClass.method {
891+
name = "getSbn"
892+
}.get(it).invoke<StatusBarNotification>()
893+
}.also { nf ->
894+
nf?.notification?.also {
895+
it.smallIcon.loadDrawable(context)?.also { iconDrawable ->
896+
/** 执行替换 */
897+
fun doParse() {
898+
compatNotifyIcon(
899+
context = context,
900+
nf = nf,
901+
isGrayscaleIcon = isGrayscaleIcon(context, iconDrawable),
902+
packageName = context.packageName,
903+
drawable = iconDrawable,
904+
iconColor = it.color,
905+
iconView = this
906+
)
907+
}
908+
doParse()
909+
/** 延迟重新设置防止部分机型的系统重新设置图标出现图标着色后黑白块问题 */
910+
delayedRun(ms = 1500) { doParse() }
895911
}
896-
doParse()
897-
/** 延迟重新设置防止部分机型的系统重新设置图标出现图标着色后黑白块问题 */
898-
delayedRun(ms = 1500) { doParse() }
899912
}
900913
}
901-
}
902914
}
903915
}
904916
}

0 commit comments

Comments
 (0)