Skip to content

Commit 3745438

Browse files
committed
fix: Handle icon expansion behavior
1 parent f3bbfb1 commit 3745438

1 file changed

Lines changed: 68 additions & 8 deletions

File tree

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

Lines changed: 68 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import android.graphics.Color
3434
import android.graphics.Outline
3535
import android.graphics.drawable.Drawable
3636
import android.graphics.drawable.Icon
37+
import android.os.Build
3738
import android.os.SystemClock
3839
import android.service.notification.StatusBarNotification
3940
import android.util.ArrayMap
@@ -147,6 +148,9 @@ object SystemUIHooker : YukiBaseHooker() {
147148
/** ColorOS 存在的类 - 旧版本不存在 */
148149
private val OplusNotificationGroupTemplateWrapperClass by lazyClassOrNull("com.oplus.systemui.notification.row.oplusgroup.OplusNotificationGroupTemplateWrapper")
149150

151+
/** ColorOS 存在的类 - 旧版本不存在 */
152+
private val OplusNotificationGroupExtImplClass by lazyClassOrNull("com.oplus.systemui.notification.row.oplusgroup.OplusNotificationGroupExtImpl")
153+
150154
/** 根据多个版本存在不同的包名相同的类 */
151155
private val OplusNotificationIconAreaControllerClass by lazyClass(
152156
VariousClass(
@@ -516,7 +520,8 @@ object SystemUIHooker : YukiBaseHooker() {
516520
packageName: String,
517521
drawable: Drawable,
518522
iconColor: Int,
519-
iconView: ImageView
523+
iconView: ImageView,
524+
header: Boolean = false
520525
) = runInSafe {
521526
compatCustomIcon(context, isGrayscaleIcon, packageName).also { customTriple ->
522527
when {
@@ -563,11 +568,23 @@ object SystemUIHooker : YukiBaseHooker() {
563568
.solidColor(newApplyColor)
564569
.build()
565570
setColorFilter(newStyle)
566-
setPadding(2.dp(context))
571+
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.VANILLA_ICE_CREAM)
572+
if (header)
573+
setPadding(3.2f.dp(context))
574+
else
575+
setPadding(6.dp(context))
576+
else
577+
setPadding(2.dp(context))
567578
} else {
568579
background = null
569580
setColorFilter(oldApplyColor)
570-
setPadding(0)
581+
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.VANILLA_ICE_CREAM)
582+
if (header)
583+
setPadding(2.2f.dp(context))
584+
else
585+
setPadding(4.dp(context))
586+
else
587+
setPadding(0.dp(context))
571588
}
572589
}
573590
else -> iconView.apply {
@@ -747,11 +764,6 @@ object SystemUIHooker : YukiBaseHooker() {
747764
resultFalse()
748765
}
749766
}
750-
Notification::class.java.resolve().optional().firstMethodOrNull {
751-
name = "shouldUseAppIcon"
752-
}?.hook()?.before {
753-
resultFalse()
754-
}
755767
/** 修复并替换 ColorOS 以及原生灰度图标色彩判断 */
756768
NotificationUtilsClass.resolve().optional(silent = true).apply {
757769
firstMethodOrNull {
@@ -878,6 +890,54 @@ object SystemUIHooker : YukiBaseHooker() {
878890
}
879891

880892
if (isNewNotification) {
893+
/** 阻止颜色覆盖 */
894+
OplusNotificationGroupExtImplClass?.resolve()?.optional()?.firstMethodOrNull {
895+
name = "updateExpandIconColorFilter"
896+
parameterCount = 1
897+
}?.hook()?.intercept()
898+
/** 动态处理通知展开 */
899+
ExpandableNotificationRowClass.resolve().optional().apply {
900+
firstMethodOrNull {
901+
name = "onExpansionChanged"
902+
parameterCount = 2
903+
}?.hook()?.before {
904+
ExpandableNotificationRowClass.resolve().optional()
905+
.firstFieldOrNull { name = "mChildrenContainer" }
906+
?.of(instance)?.getQuietly()?.let {
907+
it.asResolver().optional().firstFieldOrNull {
908+
name = "mCurrentHeader"
909+
superclass()
910+
}?.get()
911+
}.also { header ->
912+
header?.asResolver()?.optional()?.firstFieldOrNull {
913+
name = "mIcon"
914+
}?.get<ImageView>()?.apply {
915+
ExpandableNotificationRowClass.resolve().optional()
916+
.firstMethodOrNull { name = "getEntry" }
917+
?.of(instance)?.invokeQuietly()?.let {
918+
it.asResolver().optional().firstMethodOrNull {
919+
name = "getSbn"
920+
}?.invoke<StatusBarNotification>()
921+
}.also { nf ->
922+
nf?.notification?.also {
923+
it.smallIcon.loadDrawable(context)?.also { iconDrawable ->
924+
compatNotifyIcon(
925+
context = context,
926+
nf = nf,
927+
isGrayscaleIcon = isGrayscaleIcon(context, iconDrawable),
928+
packageName = context.packageName,
929+
drawable = iconDrawable,
930+
iconColor = it.color,
931+
iconView = this,
932+
header = true
933+
)
934+
}
935+
}
936+
}
937+
}
938+
}
939+
}
940+
}
881941
/** 替换通知图标和样式 */
882942
OplusNotificationHeaderViewWrapperExImpClass?.resolve()?.optional()?.apply {
883943
firstMethodOrNull {

0 commit comments

Comments
 (0)