mirror of
https://github.com/fankes/MIUINativeNotifyIcon.git
synced 2025-09-06 10:45:20 +08:00
完全修改 Hook 方案,加入新的日志打印方式
This commit is contained in:
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -6,6 +6,8 @@
|
|||||||
<entry key="app/src/main/res/drawable-night/dark_round.xml" value="0.256" />
|
<entry key="app/src/main/res/drawable-night/dark_round.xml" value="0.256" />
|
||||||
<entry key="app/src/main/res/drawable-night/permotion_round.xml" value="0.256" />
|
<entry key="app/src/main/res/drawable-night/permotion_round.xml" value="0.256" />
|
||||||
<entry key="app/src/main/res/drawable-v24/ic_launcher_foreground.xml" value="0.44871794871794873" />
|
<entry key="app/src/main/res/drawable-v24/ic_launcher_foreground.xml" value="0.44871794871794873" />
|
||||||
|
<entry key="app/src/main/res/drawable/bg_green_round.xml" value="0.255" />
|
||||||
|
<entry key="app/src/main/res/drawable/bg_yellow_round.xml" value="0.255" />
|
||||||
<entry key="app/src/main/res/drawable/permotion_round.xml" value="0.256" />
|
<entry key="app/src/main/res/drawable/permotion_round.xml" value="0.256" />
|
||||||
<entry key="app/src/main/res/drawable/white_round.xml" value="0.256" />
|
<entry key="app/src/main/res/drawable/white_round.xml" value="0.256" />
|
||||||
<entry key="app/src/main/res/layout/activity_config.xml" value="0.42168674698795183" />
|
<entry key="app/src/main/res/layout/activity_config.xml" value="0.42168674698795183" />
|
||||||
|
@@ -30,7 +30,7 @@ android {
|
|||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
minifyEnabled true
|
minifyEnabled false
|
||||||
signingConfig signingConfigs.debug
|
signingConfig signingConfigs.debug
|
||||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||||
}
|
}
|
||||||
|
@@ -28,7 +28,7 @@ import java.io.Serializable
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 通知栏小图标 bean
|
* 通知栏小图标 bean
|
||||||
* @param appName APP 名称 - 仅限默认语言区域
|
* @param appName APP 名称
|
||||||
* @param packageName 包名
|
* @param packageName 包名
|
||||||
* @param iconBitmap 图标位图
|
* @param iconBitmap 图标位图
|
||||||
* @param iconColor 通知栏中显示的图标颜色 - 设置为 0 使用系统默认颜色
|
* @param iconColor 通知栏中显示的图标颜色 - 设置为 0 使用系统默认颜色
|
||||||
|
@@ -70,20 +70,27 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
private const val NotificationHeaderViewWrapperInjectorClass =
|
private const val NotificationHeaderViewWrapperInjectorClass =
|
||||||
"$SYSTEMUI_PACKAGE_NAME.statusbar.notification.row.wrapper.NotificationHeaderViewWrapperInjector"
|
"$SYSTEMUI_PACKAGE_NAME.statusbar.notification.row.wrapper.NotificationHeaderViewWrapperInjector"
|
||||||
|
|
||||||
/** MIUI 新版本存在的类 */
|
|
||||||
private const val NotificationHeaderViewWrapperClass =
|
|
||||||
"$SYSTEMUI_PACKAGE_NAME.statusbar.notification.NotificationHeaderViewWrapper"
|
|
||||||
|
|
||||||
/** MIUI 新版本存在的类 */
|
|
||||||
private const val NotificationViewWrapperClass =
|
|
||||||
"$SYSTEMUI_PACKAGE_NAME.statusbar.notification.NotificationViewWrapper"
|
|
||||||
|
|
||||||
/** 未确定是否只有旧版本存在的类 */
|
|
||||||
private const val ExpandableNotificationRowClass = "$SYSTEMUI_PACKAGE_NAME.statusbar.ExpandableNotificationRow"
|
|
||||||
|
|
||||||
/** 原生存在的类 */
|
/** 原生存在的类 */
|
||||||
private const val ContrastColorUtilClass = "com.android.internal.util.ContrastColorUtil"
|
private const val ContrastColorUtilClass = "com.android.internal.util.ContrastColorUtil"
|
||||||
|
|
||||||
|
/** 根据多个版本存在不同的包名相同的类 */
|
||||||
|
private val ExpandableNotificationRowClass = VariousClass(
|
||||||
|
"$SYSTEMUI_PACKAGE_NAME.statusbar.notification.row.ExpandableNotificationRow",
|
||||||
|
"$SYSTEMUI_PACKAGE_NAME.statusbar.ExpandableNotificationRow"
|
||||||
|
)
|
||||||
|
|
||||||
|
/** 根据多个版本存在不同的包名相同的类 */
|
||||||
|
private val NotificationViewWrapperClass = VariousClass(
|
||||||
|
"$SYSTEMUI_PACKAGE_NAME.statusbar.notification.row.wrapper.NotificationViewWrapper",
|
||||||
|
"$SYSTEMUI_PACKAGE_NAME.statusbar.notification.NotificationViewWrapper"
|
||||||
|
)
|
||||||
|
|
||||||
|
/** 根据多个版本存在不同的包名相同的类 */
|
||||||
|
private val NotificationHeaderViewWrapperClass = VariousClass(
|
||||||
|
"$SYSTEMUI_PACKAGE_NAME.statusbar.notification.row.wrapper.NotificationHeaderViewWrapper",
|
||||||
|
"$SYSTEMUI_PACKAGE_NAME.statusbar.notification.NotificationHeaderViewWrapper"
|
||||||
|
)
|
||||||
|
|
||||||
/** 根据多个版本存在不同的包名相同的类 */
|
/** 根据多个版本存在不同的包名相同的类 */
|
||||||
private val NotificationUtilClass = VariousClass(
|
private val NotificationUtilClass = VariousClass(
|
||||||
"$SYSTEMUI_PACKAGE_NAME.statusbar.notification.NotificationUtil",
|
"$SYSTEMUI_PACKAGE_NAME.statusbar.notification.NotificationUtil",
|
||||||
@@ -132,8 +139,21 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
NotificationUtilClass.clazz.hasMethod(name = "ignoreStatusBarIconColor", ExpandedNotificationClass.clazz)
|
NotificationUtilClass.clazz.hasMethod(name = "ignoreStatusBarIconColor", ExpandedNotificationClass.clazz)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否为旧版本 MIUI 方案
|
||||||
|
*
|
||||||
|
* 拥有 “handleHeaderViews” 方法
|
||||||
|
* @return [Boolean]
|
||||||
|
*/
|
||||||
|
private val PackageParam.hasHandleHeaderViews
|
||||||
|
get() = safeOfFalse {
|
||||||
|
NotificationHeaderViewWrapperClass.clazz.hasMethod(name = "handleHeaderViews")
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前通知栏的样式
|
* 获取当前通知栏的样式
|
||||||
|
*
|
||||||
|
* - ❗新版本可能不存在这个方法
|
||||||
* @return [Boolean]
|
* @return [Boolean]
|
||||||
*/
|
*/
|
||||||
private val PackageParam.isShowMiuiStyle
|
private val PackageParam.isShowMiuiStyle
|
||||||
@@ -141,15 +161,6 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
NotificationUtilClass.clazz.method { name = "showMiuiStyle" }.get().invoke() ?: false
|
NotificationUtilClass.clazz.method { name = "showMiuiStyle" }.get().invoke() ?: false
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取 [ExpandedNotificationClass] 的应用名称
|
|
||||||
* @param instance 通知实例
|
|
||||||
* @return [String]
|
|
||||||
*/
|
|
||||||
private fun PackageParam.findAppName(instance: Any?) = safeOf(default = "<unknown>") {
|
|
||||||
ExpandedNotificationClass.clazz.method { name = "getAppName" }.get(instance).invoke() ?: "<empty>"
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 适配通知栏、状态栏图标
|
* 适配通知栏、状态栏图标
|
||||||
*
|
*
|
||||||
@@ -163,10 +174,51 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
private fun StatusBarNotification.compatNotifyIcon(context: Context, iconDrawable: Drawable) = safeOf(iconDrawable) {
|
private fun StatusBarNotification.compatNotifyIcon(context: Context, iconDrawable: Drawable) = safeOf(iconDrawable) {
|
||||||
/** 给 MIPUSH 设置 APP 自己的图标 */
|
/** 给 MIPUSH 设置 APP 自己的图标 */
|
||||||
if (isXmsf && opPkgName.isNotBlank())
|
if (isXmsf && opPkgName.isNotBlank())
|
||||||
context.packageManager.getPackageInfo(opPkgName, 0).applicationInfo.loadIcon(context.packageManager)
|
findAppIcon(context)
|
||||||
else iconDrawable
|
else iconDrawable
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取推送通知的应用名称
|
||||||
|
* @param context 实例
|
||||||
|
* @return [String]
|
||||||
|
*/
|
||||||
|
private fun StatusBarNotification.findAppName(context: Context) = safeOf(default = "<unknown>") {
|
||||||
|
context.packageManager.getPackageInfo(opPkgName, 0).applicationInfo.loadLabel(context.packageManager)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取通知栏、状态栏 APP 图标
|
||||||
|
* @param context 实例
|
||||||
|
* @return [Drawable] 适配的图标
|
||||||
|
*/
|
||||||
|
private fun StatusBarNotification.findAppIcon(context: Context) = safeOf(notification.smallIcon.loadDrawable(context)) {
|
||||||
|
context.packageManager.getPackageInfo(opPkgName, 0).applicationInfo.loadIcon(context.packageManager)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打印日志
|
||||||
|
* @param tag 标识
|
||||||
|
* @param context 实例
|
||||||
|
* @param expandedNf 通知实例
|
||||||
|
* @param isCustom 是否为通知优化生效图标
|
||||||
|
* @param isGrayscale 是否为灰度图标
|
||||||
|
*/
|
||||||
|
private fun PackageParam.printLogcat(
|
||||||
|
tag: String,
|
||||||
|
context: Context,
|
||||||
|
expandedNf: StatusBarNotification?,
|
||||||
|
isCustom: Boolean,
|
||||||
|
isGrayscale: Boolean
|
||||||
|
) {
|
||||||
|
if (prefs.getBoolean(ENABLE_MODULE_LOG)) loggerD(
|
||||||
|
msg = "$tag --> [${expandedNf?.findAppName(context)}][${expandedNf?.opPkgName}] " +
|
||||||
|
"custom [$isCustom] " +
|
||||||
|
"grayscale [$isGrayscale] " +
|
||||||
|
"xmsf [${expandedNf?.isXmsf}]"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取推送通知的包名
|
* 获取推送通知的包名
|
||||||
*
|
*
|
||||||
@@ -232,6 +284,11 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
if (!prefs.getBoolean(ENABLE_COLOR_ICON_HOOK, default = true)) return@safeRun
|
if (!prefs.getBoolean(ENABLE_COLOR_ICON_HOOK, default = true)) return@safeRun
|
||||||
/** 获取通知对象 - 由于 MIUI 的版本迭代不规范性可能是空的 */
|
/** 获取通知对象 - 由于 MIUI 的版本迭代不规范性可能是空的 */
|
||||||
expandedNf?.also { notifyInstance ->
|
expandedNf?.also { notifyInstance ->
|
||||||
|
/** 判断是 MIUI 样式就停止 Hook */
|
||||||
|
if (context.isMiuiNotifyStyle) {
|
||||||
|
it(notifyInstance.findAppIcon(context).toBitmap())
|
||||||
|
return@safeRun
|
||||||
|
}
|
||||||
/** 判断是否不是灰度图标 */
|
/** 判断是否不是灰度图标 */
|
||||||
val isNotGrayscaleIcon = notifyInstance.isXmsf || !isGrayscaleIcon(context, iconDrawable)
|
val isNotGrayscaleIcon = notifyInstance.isXmsf || !isGrayscaleIcon(context, iconDrawable)
|
||||||
|
|
||||||
@@ -241,10 +298,7 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
run {
|
run {
|
||||||
if (iconDatas.isNotEmpty())
|
if (iconDatas.isNotEmpty())
|
||||||
iconDatas.forEach {
|
iconDatas.forEach {
|
||||||
if ((notifyInstance.opPkgName == it.packageName ||
|
if (notifyInstance.opPkgName == it.packageName && isAppNotifyHookOf(it)) {
|
||||||
findAppName(notifyInstance) == it.appName) &&
|
|
||||||
isAppNotifyHookOf(it)
|
|
||||||
) {
|
|
||||||
if (isNotGrayscaleIcon || isAppNotifyHookAllOf(it))
|
if (isNotGrayscaleIcon || isAppNotifyHookAllOf(it))
|
||||||
customIcon = it.iconBitmap
|
customIcon = it.iconBitmap
|
||||||
return@run
|
return@run
|
||||||
@@ -252,8 +306,7 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/** 打印日志 */
|
/** 打印日志 */
|
||||||
if (prefs.getBoolean(ENABLE_MODULE_LOG))
|
printLogcat(tag = "StatusIcon", context, notifyInstance, isCustom = customIcon != null, !isNotGrayscaleIcon)
|
||||||
loggerD(msg = "Icon --> [${findAppName(notifyInstance)}][${notifyInstance.opPkgName}] custom [${customIcon != null}] grayscale [${!isNotGrayscaleIcon}] xmsf [${notifyInstance.isXmsf}]")
|
|
||||||
when {
|
when {
|
||||||
/** 处理自定义通知图标优化 */
|
/** 处理自定义通知图标优化 */
|
||||||
customIcon != null -> it(customIcon!!)
|
customIcon != null -> it(customIcon!!)
|
||||||
@@ -273,6 +326,8 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
*/
|
*/
|
||||||
private fun PackageParam.hookNotifyIconOnSet(context: Context, expandedNf: StatusBarNotification?, iconImageView: ImageView) =
|
private fun PackageParam.hookNotifyIconOnSet(context: Context, expandedNf: StatusBarNotification?, iconImageView: ImageView) =
|
||||||
safeRun(msg = "AutoSetAppIconOnSet") {
|
safeRun(msg = "AutoSetAppIconOnSet") {
|
||||||
|
/** 判断是 MIUI 样式就停止 Hook */
|
||||||
|
if (context.isMiuiNotifyStyle) return@safeRun
|
||||||
/** 如果没开启修复 APP 的彩色图标 */
|
/** 如果没开启修复 APP 的彩色图标 */
|
||||||
if (!prefs.getBoolean(ENABLE_COLOR_ICON_HOOK, default = true)) return@safeRun
|
if (!prefs.getBoolean(ENABLE_COLOR_ICON_HOOK, default = true)) return@safeRun
|
||||||
/** 获取通知对象 - 由于 MIUI 的版本迭代不规范性可能是空的 */
|
/** 获取通知对象 - 由于 MIUI 的版本迭代不规范性可能是空的 */
|
||||||
@@ -316,10 +371,7 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
if (isNotifyIconFix) run {
|
if (isNotifyIconFix) run {
|
||||||
if (iconDatas.isNotEmpty())
|
if (iconDatas.isNotEmpty())
|
||||||
iconDatas.forEach {
|
iconDatas.forEach {
|
||||||
if ((notifyInstance.opPkgName == it.packageName ||
|
if (notifyInstance.opPkgName == it.packageName && isAppNotifyHookOf(it)) {
|
||||||
findAppName(notifyInstance) == it.appName) &&
|
|
||||||
isAppNotifyHookOf(it)
|
|
||||||
) {
|
|
||||||
if (!isGrayscaleIcon || isAppNotifyHookAllOf(it)) {
|
if (!isGrayscaleIcon || isAppNotifyHookAllOf(it)) {
|
||||||
customIcon = it.iconBitmap
|
customIcon = it.iconBitmap
|
||||||
customIconColor = it.iconColor
|
customIconColor = it.iconColor
|
||||||
@@ -328,6 +380,8 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/** 打印日志 */
|
||||||
|
printLogcat(tag = "NotifyIcon", context, notifyInstance, isCustom = customIcon != null, isGrayscaleIcon)
|
||||||
/** 处理自定义通知图标优化 */
|
/** 处理自定义通知图标优化 */
|
||||||
if (customIcon != null)
|
if (customIcon != null)
|
||||||
iconImageView.apply {
|
iconImageView.apply {
|
||||||
@@ -381,39 +435,37 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
* @return [Boolean] 是否忽略通知图标颜色
|
* @return [Boolean] 是否忽略通知图标颜色
|
||||||
*/
|
*/
|
||||||
private fun PackageParam.hookIgnoreStatusBarIconColor(context: Context, expandedNf: StatusBarNotification?) =
|
private fun PackageParam.hookIgnoreStatusBarIconColor(context: Context, expandedNf: StatusBarNotification?) =
|
||||||
if (prefs.getBoolean(ENABLE_COLOR_ICON_HOOK, default = true)) safeOfFalse {
|
if (!context.isMiuiNotifyStyle)
|
||||||
/** 获取通知对象 - 由于 MIUI 的版本迭代不规范性可能是空的 */
|
if (prefs.getBoolean(ENABLE_COLOR_ICON_HOOK, default = true)) safeOfFalse {
|
||||||
expandedNf?.let { notifyInstance ->
|
/** 获取通知对象 - 由于 MIUI 的版本迭代不规范性可能是空的 */
|
||||||
/** 获取通知小图标 */
|
expandedNf?.let { notifyInstance ->
|
||||||
val iconDrawable =
|
/** 获取通知小图标 */
|
||||||
notifyInstance.notification.smallIcon.loadDrawable(context)
|
val iconDrawable = notifyInstance.notification.smallIcon.loadDrawable(context)
|
||||||
|
|
||||||
/** 判断是否不是灰度图标 */
|
/** 判断是否不是灰度图标 */
|
||||||
val isNotGrayscaleIcon = notifyInstance.isXmsf || !isGrayscaleIcon(context, iconDrawable)
|
val isNotGrayscaleIcon = notifyInstance.isXmsf || !isGrayscaleIcon(context, iconDrawable)
|
||||||
|
|
||||||
/** 获取目标修复彩色图标的 APP */
|
/** 获取目标修复彩色图标的 APP */
|
||||||
var isTargetFixApp = false
|
var isTargetFixApp = false
|
||||||
/** 如果开启了自定义通知图标优化 */
|
/** 如果开启了自定义通知图标优化 */
|
||||||
if (prefs.getBoolean(ENABLE_NOTIFY_ICON_FIX, default = true))
|
if (prefs.getBoolean(ENABLE_NOTIFY_ICON_FIX, default = true))
|
||||||
run {
|
run {
|
||||||
if (iconDatas.isNotEmpty())
|
if (iconDatas.isNotEmpty())
|
||||||
iconDatas.forEach {
|
iconDatas.forEach {
|
||||||
if ((notifyInstance.opPkgName == it.packageName ||
|
if (notifyInstance.opPkgName == it.packageName && isAppNotifyHookOf(it)) {
|
||||||
findAppName(notifyInstance) == it.appName) &&
|
if (isNotGrayscaleIcon || isAppNotifyHookAllOf(it)) isTargetFixApp = true
|
||||||
isAppNotifyHookOf(it)
|
return@run
|
||||||
) {
|
}
|
||||||
if (isNotGrayscaleIcon || isAppNotifyHookAllOf(it)) isTargetFixApp = true
|
|
||||||
return@run
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
/**
|
||||||
/**
|
* 只要不是灰度就返回彩色图标
|
||||||
* 只要不是灰度就返回彩色图标
|
* 否则不对颜色进行反色处理防止一些系统图标出现异常
|
||||||
* 否则不对颜色进行反色处理防止一些系统图标出现异常
|
*/
|
||||||
*/
|
if (isTargetFixApp) false else isNotGrayscaleIcon
|
||||||
if (isTargetFixApp) false else isNotGrayscaleIcon
|
} ?: true
|
||||||
} ?: true
|
} else false
|
||||||
} else false
|
else true
|
||||||
|
|
||||||
override fun onHook() = encase {
|
override fun onHook() = encase {
|
||||||
configs {
|
configs {
|
||||||
@@ -443,10 +495,10 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
param(ExpandedNotificationClass.clazz)
|
param(ExpandedNotificationClass.clazz)
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 因为之前的 MIUI 版本的状态栏图标颜色会全部设置为白色的 - 找不到修复的地方就直接判断版本了
|
* 为了防止 MIUI 自身的版本不同造成的各种 BUG
|
||||||
* 对于之前没有通知图标色彩判断功能的版本判断是 MIUI 样式就停止 Hook
|
* 判断是 MIUI 样式就停止 Hook
|
||||||
*/
|
*/
|
||||||
replaceAny { if (hasIgnoreStatusBarIconColor) false else isShowMiuiStyle }
|
replaceAny { globalContext?.isMiuiNotifyStyle ?: isShowMiuiStyle }
|
||||||
}
|
}
|
||||||
if (hasIgnoreStatusBarIconColor)
|
if (hasIgnoreStatusBarIconColor)
|
||||||
injectMember {
|
injectMember {
|
||||||
@@ -478,86 +530,71 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
}.onFind { isUseLegacy = true }
|
}.onFind { isUseLegacy = true }
|
||||||
}
|
}
|
||||||
afterHook {
|
afterHook {
|
||||||
/** 对于之前没有通知图标色彩判断功能的版本判断是 MIUI 样式就停止 Hook */
|
(globalContext ?: args[0] as Context).also { context ->
|
||||||
if (hasIgnoreStatusBarIconColor || !isShowMiuiStyle)
|
hookSmallIconOnSet(
|
||||||
(globalContext ?: args[0] as Context).also { context ->
|
context = context,
|
||||||
hookSmallIconOnSet(
|
args[if (isUseLegacy) 1 else 0] as? StatusBarNotification?,
|
||||||
context = context,
|
(result as Icon).loadDrawable(context)
|
||||||
args[if (isUseLegacy) 1 else 0] as? StatusBarNotification?,
|
) { icon -> result = Icon.createWithBitmap(icon) }
|
||||||
(result as Icon).loadDrawable(context)
|
}
|
||||||
) { icon -> result = Icon.createWithBitmap(icon) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (NotificationHeaderViewWrapperInjectorClass.hasClass)
|
NotificationHeaderViewWrapperClass.hook {
|
||||||
NotificationHeaderViewWrapperInjectorClass.hook {
|
/** 修复下拉通知图标自动设置回 APP 图标的方法 */
|
||||||
/** 修复下拉通知图标自动设置回 APP 图标的方法 */
|
injectMember {
|
||||||
injectMember {
|
if (hasHandleHeaderViews)
|
||||||
var isUseLegacy = false
|
method { name = "handleHeaderViews" }
|
||||||
|
else method { name = "resolveHeaderViews" }
|
||||||
|
afterHook {
|
||||||
|
/** 获取小图标 */
|
||||||
|
val iconImageView =
|
||||||
|
NotificationHeaderViewWrapperClass.clazz
|
||||||
|
.field { name = "mIcon" }.of<ImageView>(instance) ?: return@afterHook
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从父类中得到 mRow 变量 - [ExpandableNotificationRowClass]
|
||||||
|
* 获取其中的得到通知方法
|
||||||
|
*/
|
||||||
|
val expandedNf = ExpandableNotificationRowClass.clazz
|
||||||
|
.method { name = "getEntry" }
|
||||||
|
.get(NotificationViewWrapperClass.clazz.field {
|
||||||
|
name = "mRow"
|
||||||
|
}.get(instance).self).call()?.let {
|
||||||
|
it.javaClass.method {
|
||||||
|
name = "getSbn"
|
||||||
|
}.get(it).invoke<StatusBarNotification>()
|
||||||
|
} ?: ExpandableNotificationRowClass.clazz
|
||||||
|
.method { name = "getStatusBarNotification" }
|
||||||
|
.get(NotificationViewWrapperClass.clazz.field { name = "mRow" }.get(instance).self)
|
||||||
|
.invoke<StatusBarNotification>()
|
||||||
|
/** 执行 Hook */
|
||||||
|
hookNotifyIconOnSet(iconImageView.context, expandedNf, iconImageView)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/** 干掉下拉通知图标自动设置回 APP 图标的方法 */
|
||||||
|
NotificationHeaderViewWrapperInjectorClass.hook {
|
||||||
|
injectMember {
|
||||||
|
method {
|
||||||
|
name = "setAppIcon"
|
||||||
|
param(ContextClass, ImageViewClass, ExpandedNotificationClass.clazz)
|
||||||
|
}.remedys {
|
||||||
method {
|
method {
|
||||||
name = "setAppIcon"
|
name = "setAppIcon"
|
||||||
param(ContextClass, ImageViewClass, ExpandedNotificationClass.clazz)
|
param(ImageViewClass, ExpandedNotificationClass.clazz)
|
||||||
}.remedys {
|
|
||||||
method {
|
|
||||||
name = "setAppIcon"
|
|
||||||
param(ImageViewClass, ExpandedNotificationClass.clazz)
|
|
||||||
}.onFind { isUseLegacy = true }
|
|
||||||
}
|
|
||||||
replaceUnit {
|
|
||||||
if (isUseLegacy)
|
|
||||||
hookNotifyIconOnSet(
|
|
||||||
context = globalContext ?: error("GlobalContext got null"),
|
|
||||||
args[1] as? StatusBarNotification?,
|
|
||||||
args[0] as ImageView
|
|
||||||
)
|
|
||||||
else
|
|
||||||
hookNotifyIconOnSet(
|
|
||||||
context = args[0] as? Context ?: globalContext ?: error("GlobalContext got null"),
|
|
||||||
args[2] as? StatusBarNotification?,
|
|
||||||
args[1] as ImageView
|
|
||||||
)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/** 干掉下拉通知图标自动设置回 APP 图标的方法 - Android 12 */
|
intercept()
|
||||||
if (isUpperOfAndroidS)
|
}.ignoredAllFailure()
|
||||||
injectMember {
|
injectMember {
|
||||||
method {
|
method {
|
||||||
name = "resetIconBgAndPaddings"
|
name = "resetIconBgAndPaddings"
|
||||||
param(ImageViewClass, ExpandedNotificationClass.clazz)
|
param(ImageViewClass, ExpandedNotificationClass.clazz)
|
||||||
}
|
|
||||||
intercept()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
NotificationHeaderViewWrapperClass.hook {
|
|
||||||
/** 之前的版本解决方案 */
|
|
||||||
injectMember {
|
|
||||||
method { name = "handleHeaderViews" }
|
|
||||||
afterHook {
|
|
||||||
/** 对于之前没有通知图标色彩判断功能的版本判断是 MIUI 样式就停止 Hook */
|
|
||||||
if (!hasIgnoreStatusBarIconColor && isShowMiuiStyle) return@afterHook
|
|
||||||
|
|
||||||
/** 获取小图标 */
|
|
||||||
val iconImageView =
|
|
||||||
NotificationHeaderViewWrapperClass.clazz
|
|
||||||
.field { name = "mIcon" }.of<ImageView>(instance) ?: return@afterHook
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 从父类中得到 mRow 变量 - [ExpandableNotificationRowClass]
|
|
||||||
* 获取其中的得到通知方法
|
|
||||||
*/
|
|
||||||
val expandedNf =
|
|
||||||
ExpandableNotificationRowClass.clazz
|
|
||||||
.method { name = "getStatusBarNotification" }
|
|
||||||
.get(NotificationViewWrapperClass.clazz.field { name = "mRow" }.get(instance).self)
|
|
||||||
.invoke<StatusBarNotification>()
|
|
||||||
/** 执行 Hook */
|
|
||||||
hookNotifyIconOnSet(iconImageView.context, expandedNf, iconImageView)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
intercept()
|
||||||
|
}.ignoredAllFailure()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -50,11 +50,7 @@ class IconPackParams(private val context: Context? = null, private val param: Pa
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取图标数据
|
* 获取图标数据
|
||||||
*
|
* @return [Array] 通知栏小图标数组
|
||||||
* 通知栏小图标数组
|
|
||||||
*
|
|
||||||
* 默认使用包名进行匹配 - 若失败则使用 APP 名称进行匹配
|
|
||||||
* @return [Array]
|
|
||||||
*/
|
*/
|
||||||
val iconDatas
|
val iconDatas
|
||||||
get() = ArrayList<IconDataBean>().apply {
|
get() = ArrayList<IconDataBean>().apply {
|
||||||
|
@@ -93,11 +93,7 @@ class MainActivity : BaseActivity() {
|
|||||||
noCancelable()
|
noCancelable()
|
||||||
}
|
}
|
||||||
/** 判断是否 Hook */
|
/** 判断是否 Hook */
|
||||||
YukiHookModuleStatus.isActive() -> {
|
YukiHookModuleStatus.isActive() -> {}
|
||||||
findViewById<LinearLayout>(R.id.main_lin_status).setBackgroundResource(R.drawable.bg_green_round)
|
|
||||||
findViewById<ImageFilterView>(R.id.main_img_status).setImageResource(R.mipmap.ic_success)
|
|
||||||
findViewById<TextView>(R.id.main_text_status).text = "模块已激活"
|
|
||||||
}
|
|
||||||
else ->
|
else ->
|
||||||
showDialog {
|
showDialog {
|
||||||
title = "模块没有激活"
|
title = "模块没有激活"
|
||||||
@@ -208,16 +204,56 @@ class MainActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 刷新模块状态 */
|
||||||
|
private fun refreshModuleStatus() {
|
||||||
|
findViewById<LinearLayout>(R.id.main_lin_status).setBackgroundResource(
|
||||||
|
when {
|
||||||
|
YukiHookModuleStatus.isActive() && isMiuiNotifyStyle -> R.drawable.bg_yellow_round
|
||||||
|
YukiHookModuleStatus.isActive() -> R.drawable.bg_green_round
|
||||||
|
else -> R.drawable.bg_dark_round
|
||||||
|
}
|
||||||
|
)
|
||||||
|
findViewById<ImageFilterView>(R.id.main_img_status).setImageResource(
|
||||||
|
when {
|
||||||
|
YukiHookModuleStatus.isActive() && !isMiuiNotifyStyle -> R.mipmap.ic_success
|
||||||
|
else -> R.mipmap.ic_warn
|
||||||
|
}
|
||||||
|
)
|
||||||
|
findViewById<TextView>(R.id.main_text_status).text =
|
||||||
|
when {
|
||||||
|
YukiHookModuleStatus.isActive() && isMiuiNotifyStyle -> "模块已激活,但未在工作"
|
||||||
|
YukiHookModuleStatus.isActive() -> "模块已激活"
|
||||||
|
else -> "模块未激活"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
/** MIUI 12 的版本特殊 - 所以给出提示 */
|
/** 刷新模块状态 */
|
||||||
if (!isWarnDialogShowing && YukiHookModuleStatus.isActive() && miuiVersion == "12" && isMiuiNotifyStyle)
|
refreshModuleStatus()
|
||||||
|
/** 经典样式启用后给出警告 */
|
||||||
|
if (!isWarnDialogShowing && YukiHookModuleStatus.isActive() && isMiuiNotifyStyle)
|
||||||
showDialog {
|
showDialog {
|
||||||
isWarnDialogShowing = true
|
isWarnDialogShowing = true
|
||||||
title = "经典通知栏样式已启用"
|
title = "经典通知栏样式已启用"
|
||||||
msg = "在 MIUI 12 中启用了经典通知栏样式后状态栏图标将不再做原生处理,模块停止工作," +
|
msg = "当你启用了经典通知栏样式后,为防止 MIUI 自身不规范 APP 图标被破坏,状态栏图标将不再做原生处理。\n\n" +
|
||||||
"这取决于系统设置,你应当在 设置>通知管理>通知显示设置 中将样式设置为“原生样式”。"
|
"若要使用原生样式,请前往 设置>通知管理>通知显示设置 中将样式设置为“原生样式”,新版本为 设置>通知与控制中心>通知显示设置。"
|
||||||
confirmButton(text = "我知道了") { isWarnDialogShowing = false }
|
confirmButton(text = "去设置") {
|
||||||
|
runCatching {
|
||||||
|
startActivity(Intent().apply {
|
||||||
|
component = ComponentName(
|
||||||
|
"com.miui.notification",
|
||||||
|
"miui.notification.management.activity.NotificationDisplaySettingsActivity"
|
||||||
|
)
|
||||||
|
/** 防止顶栈一样重叠在自己的 APP 中 */
|
||||||
|
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
|
})
|
||||||
|
}.onFailure {
|
||||||
|
toast(msg = "启动失败,请手动调整设置")
|
||||||
|
}
|
||||||
|
isWarnDialogShowing = false
|
||||||
|
}
|
||||||
|
cancelButton { isWarnDialogShowing = false }
|
||||||
noCancelable()
|
noCancelable()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
6
app/src/main/res/drawable/bg_yellow_round.xml
Executable file
6
app/src/main/res/drawable/bg_yellow_round.xml
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:shape="rectangle">
|
||||||
|
<solid android:color="#FF9800" />
|
||||||
|
<corners android:radius="15dp" />
|
||||||
|
</shape>
|
@@ -76,7 +76,7 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="5dp"
|
android:layout_marginBottom="5dp"
|
||||||
android:text="模块未激活"
|
android:text="模块状态未知"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
android:textSize="18sp" />
|
android:textSize="18sp" />
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user