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,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)
}
})
}
}

View File

@@ -145,7 +145,7 @@
<string name="remove_ota_validate">*移除OTA验证 [实验性]</string>
<string name="remove_ota_validate_summary">- 仅支持VAB系列使用其余系列请不要开启。\n- 无需内测试资格即可刷入完整内测包。\n- 拥有内测权限的用户将无法接收内测更新\n可用于屏蔽系统更新。\n- 跨版本类型升级后,建议清空数据。\n- 不支持非官方ROM使用。</string>
<string name="settings">设置</string>
<string name="show_notification_importance_summary">显示 MIUI12 及之后版本被隐藏的通知重要程度设置</string>
<string name="show_notification_importance_summary">显示 MIUI 12 及之后版本被隐藏的通知重要程度设置</string>
<string name="show_notification_importance">显示通知重要程度</string>
<string name="remove_ad">去广告</string>
<string name="remove_thememanager_ads">移除主题壁纸的广告</string>

View File

@@ -144,7 +144,7 @@
<string name="updater">系統更新</string>
<string name="remove_ota_validate">*移除OTA驗證 [實驗性]</string>
<string name="remove_ota_validate_summary">- 僅支持VAB系列使用其餘系列請不要開啟。\n- 無需內測試資格即可刷入完整內測包。\n- 擁有內測權限的用戶將無法接收內測更新\n可用於屏蔽系統更新。\n- 跨版本類型升級後,建議清空數據。\n- 不支持非官方ROM使用。</string>
<string name="show_notification_importance_summary">顯示 MIUI12 及之後版本被隱藏的通知重要程度設定</string>
<string name="show_notification_importance_summary">顯示 MIUI 12 及之後版本被隱藏的通知重要程度設定</string>
<string name="show_notification_importance">顯示通知重要程度</string>
<string name="settings">設定</string>
<string name="remove_ad">去廣告</string>

View File

@@ -145,7 +145,7 @@
<string name="remove_ota_validate">*移除OTA驗證 [實驗性]</string>
<string name="remove_ota_validate_summary">- 僅支持VAB系列使用其餘系列請不要開啟。\n- 無需內測試資格即可刷入完整內測包。\n- 擁有內測權限的用戶將無法接收內測更新\n可用於屏蔽系統更新。\n- 跨版本類型升級後,建議清空數據。\n- 不支持非官方ROM使用。</string>
<string name="show_notification_importance">顯示通知重要程度</string>
<string name="show_notification_importance_summary">顯示 MIUI12 及之後版本被隱藏的通知重要程度設定</string>
<string name="show_notification_importance_summary">顯示 MIUI 12 及之後版本被隱藏的通知重要程度設定</string>
<string name="settings">設定</string>
<string name="remove_ad">去廣告</string>
<string name="remove_thememanager_ads">拿掉主題壁紙的廣告</string>