优化代码,加入适配说明

This commit is contained in:
2022-02-07 22:38:31 +08:00
parent 4914ae20b2
commit be18502fd8
3 changed files with 22 additions and 18 deletions

View File

@@ -19,6 +19,7 @@ Fix the native notification bar icon function abandoned by the MIUI development
- 此模块仅支持 LSPosed(作用域“系统界面”)、~~EdXposed(随时停止支持)~~、不支持太极无极
- 目前最低支持基于 Android 9 版本的 MIUI 12 或 MIUI 12.5(最低建议)
- 请始终保持最新版本的 LSPosed旧版本可能会出现 Hook 不生效的问题
- 在 MIUI 12 上无法对状态栏图标的 MIPUSH 图标进行通知优化适配,下拉通知栏图标无异常,由于 MIUI 乱改导致无法找到方案,考虑到系统过老,本人精力有限,不再做修复,系统 ≥ MIUI 12.5 无此问题
# 禁止任何商业用途

View File

@@ -68,6 +68,9 @@ class HookMain : IXposedHookLoadPackage {
/** 原生存在的类 */
private const val ContrastColorUtilClass = "com.android.internal.util.ContrastColorUtil"
/** 未确定是否只有旧版本存在的类 */
private const val ExpandableNotificationRowClass = "$SYSTEMUI_PACKAGE_NAME.statusbar.ExpandableNotificationRow"
/** 根据多个版本存在不同的包名相同的类 */
private val NotificationUtilClass = Pair(
"$SYSTEMUI_PACKAGE_NAME.statusbar.notification.NotificationUtil",
@@ -314,25 +317,24 @@ class HookMain : IXposedHookLoadPackage {
* 区分系统版本 - 由于每个系统版本的方法不一样这里单独拿出来进行 Hook
* @param context 实例
* @param expandedNf 通知实例
* @param param Hook Param
* @param iconDrawable 小图标 [Drawable]
* @param isLegacyWay 旧版本 Hook 方式
* @param it 回调小图标 - ([Bitmap] 小图标)
*/
private fun XC_LoadPackage.LoadPackageParam.hookSmallIconOnSet(
context: Context,
expandedNf: StatusBarNotification?,
param: XC_MethodHook.MethodHookParam,
iconDrawable: Drawable,
isLegacyWay: Boolean,
it: (Bitmap) -> Unit
) {
runWithoutError(error = "GetSmallIconOnSet") {
/** 获取通知小图标 */
val iconDrawable = (param.result as Icon).loadDrawable(context)
/** 判断是否不是灰度图标 */
val isNotGrayscaleIcon = !isGrayscaleIcon(context, iconDrawable)
/** 获取通知对象 - 由于 MIUI 的版本迭代不规范性可能是空的 */
expandedNf?.also { notifyInstance ->
/** 目标彩色通知 APP 图标 */
var customIcon: Icon? = null
var customIcon: Bitmap? = null
if (HookMedium.getBoolean(HookMedium.ENABLE_COLOR_ICON_HOOK, default = true))
run {
IconPackParams.iconDatas.forEach {
@@ -341,7 +343,7 @@ class HookMain : IXposedHookLoadPackage {
HookMedium.isAppNotifyHookOf(it)
) {
if (isNotGrayscaleIcon || HookMedium.isAppNotifyHookAllOf(it))
customIcon = Icon.createWithBitmap(it.iconBitmap)
customIcon = it.iconBitmap
return@run
}
}
@@ -354,7 +356,7 @@ class HookMain : IXposedHookLoadPackage {
"hook Custom AppIcon [pkgName] ${notifyInstance.opPkgName} " +
"[appName] ${findAppName(notifyInstance)} " +
"[legacyWay] $isLegacyWay"
) { param.result = customIcon }
) { it(customIcon!!) }
/** 若不是灰度图标自动处理为圆角 */
isNotGrayscaleIcon ->
logD(
@@ -363,9 +365,7 @@ class HookMain : IXposedHookLoadPackage {
"[appName] ${findAppName(notifyInstance)} " +
"[legacyWay] $isLegacyWay"
) {
param.result = Icon.createWithBitmap(
iconDrawable.toBitmap().round(15.dp(context))
)
it(iconDrawable.toBitmap().round(15.dp(context)))
}
}
} ?: logW(content = "GetSmallIconOnSet -> StatusBarNotification got null [legacyWay] $isLegacyWay")
@@ -680,11 +680,14 @@ class HookMain : IXposedHookLoadPackage {
/** 对于之前没有通知图标色彩判断功能的版本判断是 MIUI 样式就停止 Hook */
if (!lpparam.hasIgnoreStatusBarIconColor() && lpparam.isShowMiuiStyle()) return
runWithoutError(error = "GetSmallIconDoing") {
lpparam.hookSmallIconOnSet(
context = lpparam.globalContext ?: param.args[0] as Context,
param.args?.get(if (isTooOld) 1 else 0) as? StatusBarNotification?, param,
isLegacyWay = isTooOld
)
(lpparam.globalContext ?: param.args[0] as Context).also { context ->
lpparam.hookSmallIconOnSet(
context = context,
param.args?.get(if (isTooOld) 1 else 0) as? StatusBarNotification?,
(param.result as Icon).loadDrawable(context),
isLegacyWay = isTooOld
) { icon -> param.result = icon }
}
}
}
})
@@ -745,7 +748,7 @@ class HookMain : IXposedHookLoadPackage {
runWithoutError(error = "AutoSetAppIconOldWayOnSet") hook@{
/** 对于之前没有通知图标色彩判断功能的版本判断是 MIUI 样式就停止 Hook */
if (!lpparam.hasIgnoreStatusBarIconColor() && lpparam.isShowMiuiStyle()) return@hook
/** 从父类中得到 mRow 变量 */
/** 从父类中得到 mRow 变量 - [ExpandableNotificationRowClass] */
lpparam.findClass(NotificationViewWrapperClass).getDeclaredField("mRow")
.apply {
isAccessible = true

View File

@@ -363,7 +363,7 @@
android:layout_marginBottom="10dp"
android:alpha="0.8"
android:lineSpacingExtra="6dp"
android:text="Q.哪些是已知问题?\nA.以下是问题描述列表:\n(1) MIUI 自己的系统应用的通知图标仍然可能出现黑白块的情况,可使用通知图标优化暂时修复其图标问题,后期只能等官方修复(基本上没什么可能性)。\n(2) 动态小图标可能会在高版本系统中闪烁,这是 MIUI 的问题,后期仍在想解决办法。\n(3) 请始终保持最新版本的 LSPosed旧版本可能会出现 Hook 不生效的问题。"
android:text="Q.哪些是已知问题?\nA.以下是问题描述列表:\n(1) MIUI 12 上无法对状态栏图标的 MIPUSH 图标进行通知优化适配,下拉通知栏图标无异常,由于 MIUI 乱改导致无法找到方案,考虑到系统过老,本人精力有限,不再做修复,系统 ≥ MIUI 12.5 无此问题。\n(2) 动态小图标可能会在高版本系统中闪烁,这是 MIUI 自身就存在的问题,后期只能等官方修复。\n(3) 请始终保持最新版本的 LSPosed旧版本可能会出现 Hook 不生效的问题。"
android:textColor="@color/colorTextDark"
android:textSize="12sp" />