diff --git a/app/src/main/java/com/lt2333/simplicitytools/hook/app/settings/ShowNotificationImportance.kt b/app/src/main/java/com/lt2333/simplicitytools/hook/app/settings/ShowNotificationImportance.kt index 352cc548..cc1a9faa 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/hook/app/settings/ShowNotificationImportance.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/hook/app/settings/ShowNotificationImportance.kt @@ -1,73 +1,73 @@ package com.lt2333.simplicitytools.hook.app.settings 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.XC_MethodHook import de.robv.android.xposed.XposedHelpers import de.robv.android.xposed.callbacks.XC_LoadPackage -class ShowNotificationImportance: IXposedHookLoadPackage { +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", + channelNotificationSettingsClass.hookMethod("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 + override fun beforeHookedMethod(param: MethodHookParam) { + if (!XSPUtils.getBoolean("show_notification_importance", false)) return - 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, - "channelNotificationSettings", - param.thisObject - ) + importance.callMethod("setValueIndex", index) - param.result = null - } - }) + XposedHelpers.setAdditionalInstanceField( + importance, + "channelNotificationSettings", + param.thisObject + ) + + param.result = null + } + }) val dropDownPreferenceClass = XposedHelpers.findClass( "androidx.preference.Preference", lpparam.classLoader ) - XposedHelpers.findAndHookMethod(dropDownPreferenceClass, "callChangeListener", + dropDownPreferenceClass.hookMethod("callChangeListener", Any::class.java, object : XC_MethodHook() { - override fun afterHookedMethod(param: MethodHookParam) { - val channelNotificationSettings = XposedHelpers.getAdditionalInstanceField( - param.thisObject, - "channelNotificationSettings" - ) - ?: return@afterHookedMethod + 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 mChannel = XposedHelpers.getObjectField( + channelNotificationSettings, + "mChannel" + ) as NotificationChannel - 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) - } - }) + mChannel.callMethod( + "setImportance", (param.args[0] as String).toInt() + ) + + val mBackend = channelNotificationSettings.getObjectField("mBackend") ?: return + val mPkg = channelNotificationSettings.getObjectField("mPkg") as String + val mUid = channelNotificationSettings.getIntField("mUid") + mBackend.callMethod("updateChannel", mPkg, mUid, mChannel) + } + }) } } \ No newline at end of file