适配最低基于 Android 9 的 MIUI

This commit is contained in:
2022-01-30 21:14:40 +08:00
parent 755570c00e
commit a72cbe01c8
4 changed files with 49 additions and 31 deletions

View File

@@ -19,7 +19,7 @@ android {
defaultConfig { defaultConfig {
applicationId "com.fankes.miui.notify" applicationId "com.fankes.miui.notify"
minSdk 29 minSdk 26
targetSdk 26 targetSdk 26
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"

View File

@@ -25,7 +25,6 @@ package com.fankes.miui.notify.hook
import android.content.Context import android.content.Context
import android.graphics.Color import android.graphics.Color
import android.graphics.Outline import android.graphics.Outline
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.graphics.drawable.Icon import android.graphics.drawable.Icon
import android.service.notification.StatusBarNotification import android.service.notification.StatusBarNotification
@@ -34,6 +33,7 @@ import android.view.View
import android.view.ViewOutlineProvider import android.view.ViewOutlineProvider
import android.widget.ImageView import android.widget.ImageView
import androidx.annotation.Keep import androidx.annotation.Keep
import androidx.core.app.NotificationCompat
import androidx.core.graphics.drawable.toBitmap import androidx.core.graphics.drawable.toBitmap
import com.fankes.miui.notify.hook.HookMedium.QQ_PACKAGE_NAME import com.fankes.miui.notify.hook.HookMedium.QQ_PACKAGE_NAME
import com.fankes.miui.notify.hook.HookMedium.SELF_PACKAGE_NAME import com.fankes.miui.notify.hook.HookMedium.SELF_PACKAGE_NAME
@@ -165,7 +165,7 @@ class HookMain : IXposedHookLoadPackage {
/** 判断要设置的图标 */ /** 判断要设置的图标 */
when { when {
/** 如果开启了修复聊天 APP 的图标 */ /** 如果开启了修复聊天 APP 的图标 */
notifyInstance.opPkg == QQ_PACKAGE_NAME && notifyInstance.packageName == QQ_PACKAGE_NAME &&
XPrefUtils.getBoolean( XPrefUtils.getBoolean(
HookMedium.ENABLE_CHAT_ICON_HOOK, HookMedium.ENABLE_CHAT_ICON_HOOK,
default = true default = true
@@ -206,14 +206,14 @@ class HookMain : IXposedHookLoadPackage {
val iconDrawable = notifyInstance.notification.smallIcon.loadDrawable(context) val iconDrawable = notifyInstance.notification.smallIcon.loadDrawable(context)
/** 获取发送通知的 APP */ /** 获取发送通知的 APP */
val packageName = notifyInstance.opPkg val packageName = notifyInstance.packageName
/** 如果开启了修复聊天 APP 的图标 */ /** 如果开启了修复聊天 APP 的图标 */
if (packageName == QQ_PACKAGE_NAME && if (packageName == QQ_PACKAGE_NAME &&
XPrefUtils.getBoolean(HookMedium.ENABLE_CHAT_ICON_HOOK, default = true) XPrefUtils.getBoolean(HookMedium.ENABLE_CHAT_ICON_HOOK, default = true)
) )
iconImageView.apply { iconImageView.apply {
/** 设置自定义小图标 */ /** 设置自定义小图标 */
setImageDrawable(BitmapDrawable(IconPackParams.qqSmallIcon)) setImageBitmap(IconPackParams.qqSmallIcon)
/** 上色 */ /** 上色 */
setColorFilter(if (isUpperOfAndroidS) newStyle else oldStyle) setColorFilter(if (isUpperOfAndroidS) newStyle else oldStyle)
} }
@@ -262,6 +262,8 @@ class HookMain : IXposedHookLoadPackage {
SYSTEMUI_PACKAGE_NAME -> { SYSTEMUI_PACKAGE_NAME -> {
/** 若不是 MIUI 系统直接停止 Hook */ /** 若不是 MIUI 系统直接停止 Hook */
if (isNotMIUI) return if (isNotMIUI) return
/** 系统版本过低直接停止 Hook */
if (isLowerAndroidP) return
/** 若没开启模块直接停止 Hook */ /** 若没开启模块直接停止 Hook */
if (!XPrefUtils.getBoolean(HookMedium.ENABLE_MODULE, default = true)) return if (!XPrefUtils.getBoolean(HookMedium.ENABLE_MODULE, default = true)) return
/** 强制回写系统的状态栏图标样式为原生 */ /** 强制回写系统的状态栏图标样式为原生 */
@@ -288,8 +290,8 @@ class HookMain : IXposedHookLoadPackage {
/** 获取通知对象 - 由于 MIUI 的版本迭代不规范性可能是空的 */ /** 获取通知对象 - 由于 MIUI 的版本迭代不规范性可能是空的 */
(param.args?.get(0) as? StatusBarNotification?)?.let { notifyInstance -> (param.args?.get(0) as? StatusBarNotification?)?.let { notifyInstance ->
/** 获取发送通知的 APP */ /** 获取发送通知的 APP */
val packageName = notifyInstance.opPkg val packageName = notifyInstance.packageName
NotificationCompat()
/** 获取通知小图标 */ /** 获取通知小图标 */
val iconDrawable = val iconDrawable =
notifyInstance.notification.smallIcon.loadDrawable(lpparam.globalContext) notifyInstance.notification.smallIcon.loadDrawable(lpparam.globalContext)

View File

@@ -76,32 +76,42 @@ class MainActivity : AppCompatActivity() {
/** 设置文本 */ /** 设置文本 */
findViewById<TextView>(R.id.main_text_version).text = "当前版本:$moduleVersion" findViewById<TextView>(R.id.main_text_version).text = "当前版本:$moduleVersion"
findViewById<TextView>(R.id.main_text_miui_version).text = "MIUI 版本:$miuiVersion" findViewById<TextView>(R.id.main_text_miui_version).text = "MIUI 版本:$miuiVersion"
/** 判断是否为 MIUI 系统 */ when {
if (isNotMIUI) { /** 判断是否为 MIUI 系统 */
showDialog { isNotMIUI ->
title = "不是 MIUI 系统" showDialog {
msg = "此模块专为 MIUI 系统打造,当前无法识别你的系统为 MIUI所以模块无法工作。\n" + title = "不是 MIUI 系统"
"如有问题请联系 酷安 @星夜不荟" msg = "此模块专为 MIUI 系统打造,当前无法识别你的系统为 MIUI所以模块无法工作。\n" +
confirmButton(text = "退出") { finish() } "如有问题请联系 酷安 @星夜不荟"
noCancelable() confirmButton(text = "退出") { finish() }
noCancelable()
}
/** 判断最低系统版本 */
isLowerAndroidP ->
showDialog {
title = "系统版本过低"
msg = "此模块最低支持基于 Android 9 的 MIUI 系统,你的系统版本过低不再进行适配。\n" +
"如有问题请联系 酷安 @星夜不荟"
confirmButton(text = "退出") { finish() }
noCancelable()
}
/** 判断是否 Hook */
isHooked() -> {
findViewById<LinearLayout>(R.id.main_lin_status).setBackgroundResource(R.drawable.green_round)
findViewById<ImageFilterView>(R.id.main_img_status).setImageResource(R.mipmap.succcess)
findViewById<TextView>(R.id.main_text_status).text = "模块已激活"
} }
return else ->
showDialog {
title = "模块没有激活"
msg = "检测到模块没有激活,模块需要 Xposed 环境依赖," +
"同时需要系统拥有 Root 权限," +
"请自行查看本页面使用帮助与说明第二条。\n" +
"由于需要修改系统应用达到效果,模块不支持太极阴、应用转生。"
confirmButton(text = "我知道了")
noCancelable()
}
} }
/** 判断 Hook 状态 */
if (isHooked()) {
findViewById<LinearLayout>(R.id.main_lin_status).setBackgroundResource(R.drawable.green_round)
findViewById<ImageFilterView>(R.id.main_img_status).setImageResource(R.mipmap.succcess)
findViewById<TextView>(R.id.main_text_status).text = "模块已激活"
} else
showDialog {
title = "模块没有激活"
msg = "检测到模块没有激活,模块需要 Xposed 环境依赖," +
"同时需要系统拥有 Root 权限," +
"请自行查看本页面使用帮助与说明第二条。\n" +
"由于需要修改系统应用达到效果,模块不支持太极阴、应用转生。"
confirmButton(text = "我知道了")
noCancelable()
}
/** 初始化 View */ /** 初始化 View */
val moduleEnableSwitch = findViewById<SwitchCompat>(R.id.module_enable_switch) val moduleEnableSwitch = findViewById<SwitchCompat>(R.id.module_enable_switch)
val hideIconInLauncherSwitch = findViewById<SwitchCompat>(R.id.hide_icon_in_launcher_switch) val hideIconInLauncherSwitch = findViewById<SwitchCompat>(R.id.hide_icon_in_launcher_switch)

View File

@@ -65,6 +65,12 @@ inline val Context.isNotSystemInDarkMode get() = !isSystemInDarkMode
*/ */
inline val isUpperOfAndroidS get() = Build.VERSION.SDK_INT > Build.VERSION_CODES.R inline val isUpperOfAndroidS get() = Build.VERSION.SDK_INT > Build.VERSION_CODES.R
/**
* 系统版本是否低于 Android 9
* @return [Boolean] 是否符合条件
*/
inline val isLowerAndroidP get() = Build.VERSION.SDK_INT < Build.VERSION_CODES.P
/** /**
* 当前设备是否是 MIUI 定制 Android 系统 * 当前设备是否是 MIUI 定制 Android 系统
* @return [Boolean] 是否符合条件 * @return [Boolean] 是否符合条件