修复 MIUI 在 Android 11 上最小化优先级图标的着色问题

This commit is contained in:
2022-03-01 02:50:30 +08:00
parent c7d9b2661b
commit 8d6a05e02c
2 changed files with 101 additions and 78 deletions

View File

@@ -22,6 +22,7 @@
*/
package com.fankes.miui.notify.hook
import android.app.NotificationManager
import android.content.Context
import android.graphics.Bitmap
import android.graphics.Color
@@ -55,6 +56,7 @@ import com.highcapable.yukihookapi.hook.param.PackageParam
import com.highcapable.yukihookapi.hook.type.android.ContextClass
import com.highcapable.yukihookapi.hook.type.android.DrawableClass
import com.highcapable.yukihookapi.hook.type.android.ImageViewClass
import com.highcapable.yukihookapi.hook.type.java.BooleanType
import com.highcapable.yukihookapi.hook.type.java.IntType
import com.highcapable.yukihookapi.hook.xposed.proxy.YukiHookXposedInitProxy
@@ -334,15 +336,21 @@ class HookEntry : YukiHookXposedInitProxy {
* @param context 实例
* @param expandedNf 通知实例
* @param iconImageView 通知图标实例
* @param isExpanded 通知是否展开 - 可做最小化通知处理
*/
private fun PackageParam.hookNotifyIconOnSet(context: Context, expandedNf: StatusBarNotification?, iconImageView: ImageView) =
safeRun(msg = "AutoSetAppIconOnSet") {
private fun PackageParam.hookNotifyIconOnSet(
context: Context,
expandedNf: StatusBarNotification?,
iconImageView: ImageView,
isExpanded: Boolean
) = safeRun(msg = "AutoSetAppIconOnSet") {
/** 判断是 MIUI 样式就停止 Hook */
if (context.isMiuiNotifyStyle) return@safeRun
/** 如果没开启修复 APP 的彩色图标 */
if (!prefs.getBoolean(ENABLE_COLOR_ICON_HOOK, default = true)) return@safeRun
/** 获取通知对象 - 由于 MIUI 的版本迭代不规范性可能是空的 */
expandedNf?.let { notifyInstance ->
/** 新版风格反色 */
val newStyle = if (context.isSystemInDarkMode) 0xFF2D2D2D.toInt() else Color.WHITE
@@ -359,7 +367,7 @@ class HookEntry : YukiHookXposedInitProxy {
val supportColor = iconColor.let {
when {
isUpperOfAndroidS -> newStyle
it == 0 -> oldStyle
it == 0 || !isExpanded -> oldStyle
else -> it
}
}
@@ -377,7 +385,7 @@ class HookEntry : YukiHookXposedInitProxy {
var customIconColor: Int
compatCustomIcon(isGrayscaleIcon, notifyInstance.opPkgName).also {
customIcon = it.first
customIconColor = it.second
customIconColor = if (isUpperOfAndroidS || isExpanded) it.second else 0
}
/** 打印日志 */
printLogcat(tag = "NotifyIcon", context, notifyInstance, isCustom = customIcon != null, isGrayscaleIcon)
@@ -540,6 +548,9 @@ class HookEntry : YukiHookXposedInitProxy {
NotificationHeaderViewWrapperClass.clazz
.field { name = "mIcon" }.of<ImageView>(instance) ?: return@afterHook
/** 通知是否展开 */
var isExpanded = false
/**
* 从父类中得到 mRow 变量 - [ExpandableNotificationRowClass]
* 获取其中的得到通知方法
@@ -548,7 +559,12 @@ class HookEntry : YukiHookXposedInitProxy {
.method { name = "getEntry" }
.get(NotificationViewWrapperClass.clazz.field {
name = "mRow"
}.get(instance).self).call()?.let {
}.get(instance).self?.also {
isExpanded = ExpandableNotificationRowClass.clazz.method {
name = "isExpanded"
returnType = BooleanType
}.get(it).invoke<Boolean>() == true
}).call()?.let {
it.javaClass.method {
name = "getSbn"
}.get(it).invoke<StatusBarNotification>()
@@ -556,8 +572,15 @@ class HookEntry : YukiHookXposedInitProxy {
.method { name = "getStatusBarNotification" }
.get(NotificationViewWrapperClass.clazz.field { name = "mRow" }.get(instance).self)
.invoke<StatusBarNotification>()
/** 获取优先级 */
val importance =
(iconImageView.context.getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager?)
?.getNotificationChannel(expandedNf?.notification?.channelId)?.importance ?: 0
/** 非最小化优先级的通知全部设置为展开状态 */
if (importance != 1) isExpanded = true
/** 执行 Hook */
hookNotifyIconOnSet(iconImageView.context, expandedNf, iconImageView)
hookNotifyIconOnSet(iconImageView.context, expandedNf, iconImageView, isExpanded)
}
}
}

View File

@@ -5,8 +5,8 @@ plugins {
}
ext {
appVersionName = "1.85"
appVersionCode = 18
appVersionName = "1.86"
appVersionCode = 19
}
task clean(type: Delete) {