fix: block coloros 15 useAppIconForSmallIcon method (#77)

This commit is contained in:
YuSaki丶Kanade
2025-04-22 02:15:08 +08:00
committed by GitHub
parent 9aae48c785
commit 51e52f3eba

View File

@@ -88,6 +88,8 @@ import com.highcapable.yukihookapi.hook.type.java.FloatType
import com.highcapable.yukihookapi.hook.type.java.IntType import com.highcapable.yukihookapi.hook.type.java.IntType
import com.highcapable.yukihookapi.hook.type.java.LongType import com.highcapable.yukihookapi.hook.type.java.LongType
import top.defaults.drawabletoolbox.DrawableBuilder import top.defaults.drawabletoolbox.DrawableBuilder
import androidx.core.graphics.drawable.toDrawable
import com.highcapable.yukihookapi.hook.type.android.NotificationClass
/** /**
* 系统界面核心 Hook 类 * 系统界面核心 Hook 类
@@ -143,6 +145,9 @@ object SystemUIHooker : YukiBaseHooker() {
/** ColorOS 存在的类 - 旧版本不存在 */ /** ColorOS 存在的类 - 旧版本不存在 */
private val BasePlayViewHolderClass by lazyClassOrNull("com.oplusos.systemui.media.base.BasePlayViewHolder") private val BasePlayViewHolderClass by lazyClassOrNull("com.oplusos.systemui.media.base.BasePlayViewHolder")
/** ColorOS 存在的类 - 旧版本不存在 */
private val OplusNotificationSmallIconUtilClass by lazyClassOrNull("com.oplus.systemui.statusbar.notification.util.OplusNotificationSmallIconUtil")
/** 根据多个版本存在不同的包名相同的类 */ /** 根据多个版本存在不同的包名相同的类 */
private val OplusNotificationIconAreaControllerClass by lazyClass( private val OplusNotificationIconAreaControllerClass by lazyClass(
VariousClass( VariousClass(
@@ -293,15 +298,15 @@ object SystemUIHooker : YukiBaseHooker() {
private fun loggerDebug(tag: String, context: Context, nf: StatusBarNotification?, isCustom: Boolean, isGrayscale: Boolean) { private fun loggerDebug(tag: String, context: Context, nf: StatusBarNotification?, isCustom: Boolean, isGrayscale: Boolean) {
if (ConfigData.isEnableModuleLog) YLog.debug( if (ConfigData.isEnableModuleLog) YLog.debug(
msg = "(Processing $tag) ↓\n" + msg = "(Processing $tag) ↓\n" +
"[Title]: ${nf?.notification?.extras?.getString(Notification.EXTRA_TITLE)}\n" + "[Title]: ${nf?.notification?.extras?.getString(Notification.EXTRA_TITLE)}\n" +
"[Content]: ${nf?.notification?.extras?.getString(Notification.EXTRA_TEXT)}\n" + "[Content]: ${nf?.notification?.extras?.getString(Notification.EXTRA_TEXT)}\n" +
"[App Name]: ${context.appNameOf(packageName = nf?.packageName ?: "")}\n" + "[App Name]: ${context.appNameOf(packageName = nf?.packageName ?: "")}\n" +
"[Package Name]: ${nf?.packageName}\n" + "[Package Name]: ${nf?.packageName}\n" +
"[Sender Package Name]: ${nf?.opPkg}\n" + "[Sender Package Name]: ${nf?.opPkg}\n" +
"[Custom Icon]: $isCustom\n" + "[Custom Icon]: $isCustom\n" +
"[Grayscale Icon]: $isGrayscale\n" + "[Grayscale Icon]: $isGrayscale\n" +
"[From System Push]: ${nf?.isOplusPush}\n" + "[From System Push]: ${nf?.isOplusPush}\n" +
"[String]: ${nf?.notification}" "[String]: ${nf?.notification}"
) )
} }
@@ -434,7 +439,7 @@ object SystemUIHooker : YukiBaseHooker() {
iconDatas.takeIf { it.isNotEmpty() }?.forEach { iconDatas.takeIf { it.isNotEmpty() }?.forEach {
if (packageName == it.packageName && isAppNotifyHookOf(it)) { if (packageName == it.packageName && isAppNotifyHookOf(it)) {
if (isGrayscaleIcon.not() || isAppNotifyHookAllOf(it)) if (isGrayscaleIcon.not() || isAppNotifyHookAllOf(it))
customPair = Triple(BitmapDrawable(context.resources, it.iconBitmap), it.iconColor, false) customPair = Triple(it.iconBitmap.toDrawable(context.resources), it.iconColor, false)
return@run return@run
} }
} }
@@ -696,6 +701,13 @@ object SystemUIHooker : YukiBaseHooker() {
/** 是否移除 */ /** 是否移除 */
if (ConfigData.isEnableRemoveDndAlertNotify) resultNull() if (ConfigData.isEnableRemoveDndAlertNotify) resultNull()
} }
/** 拦截ColorOS使用应用图标判断 */
OplusNotificationSmallIconUtilClass?.method {
name = "useAppIconForSmallIcon"
param(NotificationClass)
}?.hook()?.before {
resultFalse()
}
/** 修复并替换 ColorOS 以及原生灰度图标色彩判断 */ /** 修复并替换 ColorOS 以及原生灰度图标色彩判断 */
NotificationUtilsClass.apply { NotificationUtilsClass.apply {
method { method {
@@ -714,28 +726,28 @@ object SystemUIHooker : YukiBaseHooker() {
}.hook().after { }.hook().after {
IconBuilderClass.field { name = "context" } IconBuilderClass.field { name = "context" }
.get(IconManagerClass.field { name = "iconBuilder" }.get(instance).cast()).cast<Context>()?.also { context -> .get(IconManagerClass.field { name = "iconBuilder" }.get(instance).cast()).cast<Context>()?.also { context ->
NotificationEntryClass.method { NotificationEntryClass.method {
name = "getSbn" name = "getSbn"
}.get(args().first().any()).invoke<StatusBarNotification>()?.also { nf -> }.get(args().first().any()).invoke<StatusBarNotification>()?.also { nf ->
nf.notification.smallIcon.loadDrawable(context)?.also { iconDrawable -> nf.notification.smallIcon.loadDrawable(context)?.also { iconDrawable ->
compatStatusIcon( compatStatusIcon(
context = context, context = context,
nf = nf, nf = nf,
isGrayscaleIcon = isGrayscaleIcon(context, iconDrawable).also { isGrayscaleIcon = isGrayscaleIcon(context, iconDrawable).also {
/** 缓存第一次的 APP 小图标 */ /** 缓存第一次的 APP 小图标 */
if (it.not()) context.appIconOf(nf.packageName)?.also { e -> appIcons[nf.packageName] = e } if (it.not()) context.appIconOf(nf.packageName)?.also { e -> appIcons[nf.packageName] = e }
}, },
packageName = nf.packageName, packageName = nf.packageName,
drawable = iconDrawable drawable = iconDrawable
).also { pair -> ).also { pair ->
if (pair.second) StatusBarIconClass.field { if (pair.second) StatusBarIconClass.field {
name = "icon" name = "icon"
type = IconClass type = IconClass
}.get(result).set(Icon.createWithBitmap(pair.first.toBitmap())) }.get(result).set(Icon.createWithBitmap(pair.first.toBitmap()))
}
} }
} }
} }
}
} }
/** 得到状态栏图标实例 */ /** 得到状态栏图标实例 */
StatusBarIconViewClass.method { StatusBarIconViewClass.method {
@@ -768,8 +780,8 @@ object SystemUIHooker : YukiBaseHooker() {
}.onFind { way = 2 } }.onFind { way = 2 }
}.hook().after { }.hook().after {
when (way) { when (way) {
1 -> notificationIconContainer = OplusNotificationIconAreaControllerClass.method { name = "getNotificationIcons" }.get(instance).invoke() 2 -> notificationIconContainer = OplusNotificationIconAreaControllerClass.method { name = "getNotificationIcons" }.get(instance).invoke()
2 -> { 1 -> {
notificationIconInstances.clear() notificationIconInstances.clear()
field { name = "mLastToShow" }.get(instance).list<View>() field { name = "mLastToShow" }.get(instance).list<View>()
.takeIf { it.isNotEmpty() }?.forEach { notificationIconInstances.add(it) } .takeIf { it.isNotEmpty() }?.forEach { notificationIconInstances.add(it) }
@@ -875,30 +887,30 @@ object SystemUIHooker : YukiBaseHooker() {
.get(NotificationViewWrapperClass.field { .get(NotificationViewWrapperClass.field {
name = "mRow" name = "mRow"
}.get(instance).any()).call()?.let { }.get(instance).any()).call()?.let {
it.javaClass.method { it.javaClass.method {
name = "getSbn" name = "getSbn"
}.get(it).invoke<StatusBarNotification>() }.get(it).invoke<StatusBarNotification>()
}.also { nf -> }.also { nf ->
nf?.notification?.also { nf?.notification?.also {
it.smallIcon.loadDrawable(context)?.also { iconDrawable -> it.smallIcon.loadDrawable(context)?.also { iconDrawable ->
/** 执行替换 */ /** 执行替换 */
fun doParse() { fun doParse() {
compatNotifyIcon( compatNotifyIcon(
context = context, context = context,
nf = nf, nf = nf,
isGrayscaleIcon = isGrayscaleIcon(context, iconDrawable), isGrayscaleIcon = isGrayscaleIcon(context, iconDrawable),
packageName = context.packageName, packageName = context.packageName,
drawable = iconDrawable, drawable = iconDrawable,
iconColor = it.color, iconColor = it.color,
iconView = this iconView = this
) )
}
doParse()
/** 延迟重新设置防止部分机型的系统重新设置图标出现图标着色后黑白块问题 */
delayedRun(ms = 1500) { doParse() }
} }
doParse()
/** 延迟重新设置防止部分机型的系统重新设置图标出现图标着色后黑白块问题 */
delayedRun(ms = 1500) { doParse() }
} }
} }
}
} }
} }
} }