Skip to content

Commit 492d0da

Browse files
Nep-Timelinefankes
andauthored
fix: block coloros 15 fixSmallIcon method (#78)
* fix: block coloros 15 fixSmallIcon method * fix: hook error * feat: complete ColorOS 15 support * docs: update README --------- Co-authored-by: fankesyooni <qzmmcn@163.com>
1 parent d26f68c commit 492d0da

File tree

6 files changed

+73
-19
lines changed

6 files changed

+73
-19
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ This project will not be adapted i18n, please stay tuned for my new projects in
3535

3636
- 建议在不低于 ColorOS 11 的版本上使用
3737

38+
## 注意事项
39+
40+
由于 ColorOS 15 版本的系统性通知图标行为变更,系统强制在通知图标初始化阶段就将图标强制替换为 APP 彩色图标进行破坏,所以目前加入了 “系统框架”
41+
作用域,如果在模块安装后没有自动勾选此作用域,请手动进行勾选并重新启动系统以修复此破坏行为,ColorOS 15 以下版本的系统无需勾选。
42+
43+
感谢 [Nep-Timeline](https://github.com/Nep-Timeline) 提供的解决方案。
44+
3845
## 历史背景
3946

4047
继 MIUI 之后的第二大系统 ColorOS 虽然支持原生通知图标,但是第三方推送五颜六色的图标系统并没有做适配,甚至系统自己的图标都是彩色的,极其不友好。

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ package com.fankes.coloros.notify.hook
2424

2525
import com.fankes.coloros.notify.const.PackageName
2626
import com.fankes.coloros.notify.data.ConfigData
27+
import com.fankes.coloros.notify.hook.entity.FrameworkHooker
2728
import com.fankes.coloros.notify.hook.entity.SystemUIHooker
2829
import com.fankes.coloros.notify.utils.factory.isNotColorOS
2930
import com.highcapable.yukihookapi.annotation.xposed.InjectYukiHookWithXposed
@@ -45,13 +46,13 @@ object HookEntry : IYukiHookXposedInit {
4546
}
4647

4748
override fun onHook() = encase {
49+
if (isNotColorOS) return@encase YLog.warn("Aborted Hook -> This System is not ColorOS")
50+
loadSystem(FrameworkHooker)
4851
loadApp(PackageName.SYSTEMUI) {
4952
ConfigData.init(instance = this)
50-
when {
51-
isNotColorOS -> YLog.warn("Aborted Hook -> This System is not ColorOS")
52-
ConfigData.isEnableModule.not() -> YLog.warn("Aborted Hook -> Hook Closed")
53-
else -> loadHooker(SystemUIHooker)
54-
}
53+
if (ConfigData.isEnableModule)
54+
loadHooker(SystemUIHooker)
55+
else YLog.warn("Aborted Hook -> Hook Closed")
5556
}
5657
}
5758
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* ColorOSNotifyIcon - Optimize notification icons for ColorOS and adapt to native notification icon specifications.
3+
* Copyright (C) 20174 Fankes Studio(qzmmcn@163.com)
4+
* https://github.com/fankes/ColorOSNotifyIcon
5+
*
6+
* This software is non-free but opensource software: you can redistribute it
7+
* and/or modify it under the terms of the GNU Affero General Public License
8+
* as published by the Free Software Foundation; either
9+
* version 3 of the License, or any later version.
10+
* <p>
11+
*
12+
* This software is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Affero General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public License
18+
* and eula along with this software. If not, see
19+
* <https://www.gnu.org/licenses/>
20+
*
21+
* This file is created by Nep-Timeline on 2025/5/27.
22+
*/
23+
package com.fankes.coloros.notify.hook.entity
24+
25+
import com.highcapable.yukihookapi.hook.entity.YukiBaseHooker
26+
import com.highcapable.yukihookapi.hook.factory.method
27+
import com.highcapable.yukihookapi.hook.type.android.NotificationClass
28+
import com.highcapable.yukihookapi.hook.type.java.BooleanType
29+
import com.highcapable.yukihookapi.hook.type.java.StringClass
30+
31+
/**
32+
* 系统框架核心 Hook 类
33+
*/
34+
object FrameworkHooker : YukiBaseHooker() {
35+
36+
/** ColorOS 存在的类 - 旧版本不存在 */
37+
private val OplusNotificationFixHelperClass by lazyClassOrNull("com.android.server.notification.OplusNotificationFixHelper")
38+
39+
override fun onHook() {
40+
/** 拦截 ColorOS 覆盖应用通知图标 */
41+
OplusNotificationFixHelperClass?.method {
42+
name = "fixSmallIcon"
43+
param(NotificationClass, StringClass, StringClass, BooleanType)
44+
}?.ignored()?.hook()?.intercept()
45+
}
46+
}

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import android.content.IntentFilter
3232
import android.content.res.ColorStateList
3333
import android.graphics.Color
3434
import android.graphics.Outline
35-
import android.graphics.drawable.BitmapDrawable
3635
import android.graphics.drawable.Drawable
3736
import android.graphics.drawable.Icon
3837
import android.os.SystemClock
@@ -43,6 +42,7 @@ import android.view.ViewGroup
4342
import android.view.ViewOutlineProvider
4443
import android.widget.ImageView
4544
import androidx.core.graphics.drawable.toBitmap
45+
import androidx.core.graphics.drawable.toDrawable
4646
import androidx.core.view.children
4747
import com.fankes.coloros.notify.R
4848
import com.fankes.coloros.notify.bean.IconDataBean
@@ -81,15 +81,14 @@ import com.highcapable.yukihookapi.hook.type.android.ContextClass
8181
import com.highcapable.yukihookapi.hook.type.android.DrawableClass
8282
import com.highcapable.yukihookapi.hook.type.android.IconClass
8383
import com.highcapable.yukihookapi.hook.type.android.ImageViewClass
84+
import com.highcapable.yukihookapi.hook.type.android.NotificationClass
8485
import com.highcapable.yukihookapi.hook.type.android.StatusBarNotificationClass
8586
import com.highcapable.yukihookapi.hook.type.defined.VagueType
8687
import com.highcapable.yukihookapi.hook.type.java.BooleanType
8788
import com.highcapable.yukihookapi.hook.type.java.FloatType
8889
import com.highcapable.yukihookapi.hook.type.java.IntType
8990
import com.highcapable.yukihookapi.hook.type.java.LongType
9091
import top.defaults.drawabletoolbox.DrawableBuilder
91-
import androidx.core.graphics.drawable.toDrawable
92-
import com.highcapable.yukihookapi.hook.type.android.NotificationClass
9392

9493
/**
9594
* 系统界面核心 Hook 类
@@ -301,15 +300,15 @@ object SystemUIHooker : YukiBaseHooker() {
301300
private fun loggerDebug(tag: String, context: Context, nf: StatusBarNotification?, isCustom: Boolean, isGrayscale: Boolean) {
302301
if (ConfigData.isEnableModuleLog) YLog.debug(
303302
msg = "(Processing $tag) ↓\n" +
304-
"[Title]: ${nf?.notification?.extras?.getString(Notification.EXTRA_TITLE)}\n" +
305-
"[Content]: ${nf?.notification?.extras?.getString(Notification.EXTRA_TEXT)}\n" +
306-
"[App Name]: ${context.appNameOf(packageName = nf?.packageName ?: "")}\n" +
307-
"[Package Name]: ${nf?.packageName}\n" +
308-
"[Sender Package Name]: ${nf?.opPkg}\n" +
309-
"[Custom Icon]: $isCustom\n" +
310-
"[Grayscale Icon]: $isGrayscale\n" +
311-
"[From System Push]: ${nf?.isOplusPush}\n" +
312-
"[String]: ${nf?.notification}"
303+
"[Title]: ${nf?.notification?.extras?.getString(Notification.EXTRA_TITLE)}\n" +
304+
"[Content]: ${nf?.notification?.extras?.getString(Notification.EXTRA_TEXT)}\n" +
305+
"[App Name]: ${context.appNameOf(packageName = nf?.packageName ?: "")}\n" +
306+
"[Package Name]: ${nf?.packageName}\n" +
307+
"[Sender Package Name]: ${nf?.opPkg}\n" +
308+
"[Custom Icon]: $isCustom\n" +
309+
"[Grayscale Icon]: $isGrayscale\n" +
310+
"[From System Push]: ${nf?.isOplusPush}\n" +
311+
"[String]: ${nf?.notification}"
313312
)
314313
}
315314

@@ -938,4 +937,4 @@ object SystemUIHooker : YukiBaseHooker() {
938937
}
939938
}
940939
}
941-
}
940+
}

app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,7 @@
12131213
android:layout_marginBottom="10dp"
12141214
android:alpha="0.8"
12151215
android:lineSpacingExtra="10dp"
1216-
android:text="Q.哪些是已知问题?\nA.以下是问题描述列表:\n(1) 由于机型有限,仅对 ColorOS 12、12.1、13 测试正常运行,根据酷友的需要云调试修复 ColorOS 11 的问题,其它版本情况未知,请自行进行测试。\n(2) OxygenOS 只支持 12、12.1、13 版本,其它类 ColorOS 魔改的 UI 理论没有问题,请自行测试。\n(3) 动态刷新系统界面为实验性功能,若动态地改变了系统深色模式,调节了分辨率和字体大小,状态栏、通知栏中的通知图标会还原或直接不起作用,或在刷新时发生图标黑白块问题,发生类似这种情况请手动重启一次系统界面即可解决。\n(4) 部分机型的 ColorOS 12、12.1 版本概率性出现通知栏的通知图标黑白块问题,属于系统强制重新设置图标问题,无法修复,建议可以更新到 ColorOS 13 的机型更新系统解决,不再负责修复这个问题。"
1216+
android:text="Q.哪些是已知问题?\nA.以下是问题描述列表:\n(1) 由于机型有限,仅对 ColorOS 12、12.1、13 测试正常运行,根据酷友的需要云调试修复 ColorOS 11 的问题,其它版本情况未知,请自行进行测试。\n(2) OxygenOS 只支持 12、12.1、13 版本,其它类 ColorOS 魔改的 UI 理论没有问题,请自行测试。\n(3) 动态刷新系统界面为实验性功能,若动态地改变了系统深色模式,调节了分辨率和字体大小,状态栏、通知栏中的通知图标会还原或直接不起作用,或在刷新时发生图标黑白块问题,发生类似这种情况请手动重启一次系统界面即可解决。\n(4) 部分机型的 ColorOS 12、12.1 版本概率性出现通知栏的通知图标黑白块问题,属于系统强制重新设置图标问题,无法修复,建议可以更新到 ColorOS 13 的机型更新系统解决,不再负责修复这个问题。\n(5) 由于 ColorOS 15 版本的系统性通知图标行为变更,系统强制在通知图标初始化阶段就将图标强制替换为 APP 彩色图标进行破坏,所以目前加入了 “系统框架” 作用域,如果在模块安装后没有自动勾选此作用域,请手动进行勾选并重新启动系统以修复此破坏行为,ColorOS 15 以下版本的系统无需勾选。"
12171217
android:textColor="@color/colorTextDark"
12181218
android:textSize="12sp" />
12191219

app/src/main/res/values/array.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
33
<string-array name="module_scope">
4+
<item>android</item>
45
<item>com.android.systemui</item>
56
</string-array>
67
</resources>

0 commit comments

Comments
 (0)