新增 设置 - 显示通知重要程度

此功能为 AOSP 通知的标准功能,从 MIUI 12 开始被隐藏
请参见:
- https://developer.android.com/guide/topics/ui/notifiers/notifications?hl=zh-cn#importance
- https://www.coolapk.com/feed/24638207?shareKey=YzcwZGMzNzM2NWQ3NjIyOTU4NzY~
This commit is contained in:
ztc1997
2022-03-10 09:53:04 +08:00
parent abb9c12d71
commit 34e509abe8
9 changed files with 102 additions and 1 deletions

File diff suppressed because one or more lines are too long

View File

@@ -39,6 +39,10 @@ class MainHook : IXposedHookLoadPackage {
"com.android.updater" -> {
Updater().handleLoadPackage(lpparam)
}
//设置
"com.android.settings" -> {
Settings().handleLoadPackage(lpparam)
}
}
}
}

View File

@@ -0,0 +1,11 @@
package com.lt2333.simplicitytools.hook.app
import com.lt2333.simplicitytools.hook.app.settings.ShowNotificationImportance
import de.robv.android.xposed.IXposedHookLoadPackage
import de.robv.android.xposed.callbacks.XC_LoadPackage
class Settings: IXposedHookLoadPackage {
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
ShowNotificationImportance().handleLoadPackage(lpparam)
}
}

View File

@@ -0,0 +1,73 @@
package com.lt2333.simplicitytools.hook.app.settings
import android.app.NotificationChannel
import com.lt2333.simplicitytools.util.XSPUtils
import de.robv.android.xposed.IXposedHookLoadPackage
import de.robv.android.xposed.XC_MethodHook
import de.robv.android.xposed.XposedHelpers
import de.robv.android.xposed.callbacks.XC_LoadPackage
class ShowNotificationImportance: IXposedHookLoadPackage {
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
if (!XSPUtils.getBoolean("show_notification_importance", false)) return
val channelNotificationSettingsClass = XposedHelpers.findClass(
"com.android.settings.notification.ChannelNotificationSettings",
lpparam.classLoader
)
XposedHelpers.findAndHookMethod(channelNotificationSettingsClass, "removeDefaultPrefs",
object : XC_MethodHook() {
override fun beforeHookedMethod(param: MethodHookParam) {
val importance =
XposedHelpers.callMethod(param.thisObject, "findPreference", "importance")
val mChannel =
XposedHelpers.getObjectField(param.thisObject, "mChannel") as NotificationChannel
val index = XposedHelpers.callMethod(
importance,
"findSpinnerIndexOfValue",
mChannel.importance.toString()
) as Int
if (index < 0) return@beforeHookedMethod
XposedHelpers.callMethod(importance, "setValueIndex", index)
XposedHelpers.setAdditionalInstanceField(
importance,
"channelNotificationSettings",
param.thisObject
)
param.result = null
}
})
val dropDownPreferenceClass = XposedHelpers.findClass(
"androidx.preference.Preference",
lpparam.classLoader
)
XposedHelpers.findAndHookMethod(dropDownPreferenceClass, "callChangeListener",
Any::class.java, object : XC_MethodHook() {
override fun afterHookedMethod(param: MethodHookParam) {
val channelNotificationSettings = XposedHelpers.getAdditionalInstanceField(
param.thisObject,
"channelNotificationSettings"
)
?: return@afterHookedMethod
val mChannel = XposedHelpers.getObjectField(
channelNotificationSettings,
"mChannel"
) as NotificationChannel
XposedHelpers.callMethod(mChannel, "setImportance", (param.args[0] as String).toInt())
val mBackend = XposedHelpers.getObjectField(channelNotificationSettings, "mBackend")
val mPkg =
XposedHelpers.getObjectField(channelNotificationSettings, "mPkg") as String
val mUid = XposedHelpers.getObjectField(channelNotificationSettings, "mUid") as Int
XposedHelpers.callMethod(mBackend, "updateChannel", mPkg, mUid, mChannel)
}
})
}
}