Merge pull request #49 from ztc1997/main

增强:显示通知重要程度:即时生效
This commit is contained in:
乌堆小透明
2022-03-11 23:03:58 +08:00
committed by GitHub
4 changed files with 47 additions and 47 deletions

View File

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