增强:显示通知重要程度:即时生效

This commit is contained in:
ztc1997
2022-03-11 22:26:10 +08:00
parent 3e7cab9376
commit 4190f41980

View File

@@ -1,73 +1,73 @@
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
import de.robv.android.xposed.callbacks.XC_LoadPackage 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) {
val importance = if (!XSPUtils.getBoolean("show_notification_importance", false)) return
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) val importance =
param.thisObject.callMethod("findPreference", "importance") ?: return
val mChannel =
param.thisObject.getObjectField("mChannel") as NotificationChannel
val index = importance.callMethod(
"findSpinnerIndexOfValue",
mChannel.importance.toString()
) as Int
if (index < 0) return
XposedHelpers.setAdditionalInstanceField( importance.callMethod("setValueIndex", index)
importance,
"channelNotificationSettings",
param.thisObject
)
param.result = null XposedHelpers.setAdditionalInstanceField(
} importance,
}) "channelNotificationSettings",
param.thisObject
)
param.result = null
}
})
val dropDownPreferenceClass = XposedHelpers.findClass( val dropDownPreferenceClass = XposedHelpers.findClass(
"androidx.preference.Preference", "androidx.preference.Preference",
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)
}
})
} }
} }