Skip to content

Commit 74eb55a

Browse files
committed
增加移除免打扰通知功能
1 parent f7e7593 commit 74eb55a

4 files changed

Lines changed: 47 additions & 6 deletions

File tree

app/src/main/java/com/fankes/coloros/notify/hook/HookConst.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ object HookConst {
3131
const val ENABLE_NOTIFY_ICON_FIX = "_notify_icon_fix"
3232
const val REMOVE_DEV_NOTIFY = "_remove_dev_notify"
3333
const val REMOVE_CHANGECP_NOTIFY = "_remove_charge_complete_notify"
34+
const val REMOVE_DNDALERT_NOTIFY = "_remove_dndalert_notify"
3435
const val NOTIFY_ICON_DATAS = "_notify_icon_datas"
3536

3637
const val SOURCE_SYNC_WAY = "_source_sync_way"

app/src/main/java/com/fankes/coloros/notify/hook/HookEntry.kt

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import com.fankes.coloros.notify.hook.HookConst.ENABLE_MODULE_LOG
3838
import com.fankes.coloros.notify.hook.HookConst.ENABLE_NOTIFY_ICON_FIX
3939
import com.fankes.coloros.notify.hook.HookConst.REMOVE_CHANGECP_NOTIFY
4040
import com.fankes.coloros.notify.hook.HookConst.REMOVE_DEV_NOTIFY
41+
import com.fankes.coloros.notify.hook.HookConst.REMOVE_DNDALERT_NOTIFY
4142
import com.fankes.coloros.notify.hook.HookConst.SYSTEMUI_PACKAGE_NAME
4243
import com.fankes.coloros.notify.hook.factory.isAppNotifyHookAllOf
4344
import com.fankes.coloros.notify.hook.factory.isAppNotifyHookOf
@@ -59,6 +60,7 @@ import com.highcapable.yukihookapi.hook.type.android.IconClass
5960
import com.highcapable.yukihookapi.hook.type.android.ImageViewClass
6061
import com.highcapable.yukihookapi.hook.type.java.BooleanType
6162
import com.highcapable.yukihookapi.hook.type.java.IntType
63+
import com.highcapable.yukihookapi.hook.type.java.LongType
6264
import com.highcapable.yukihookapi.hook.xposed.proxy.YukiHookXposedInitProxy
6365

6466
@InjectYukiHookWithXposed
@@ -90,6 +92,9 @@ class HookEntry : YukiHookXposedInitProxy {
9092
/** ColorOS 存在的类 */
9193
private const val SystemPromptControllerClass = "com.oplusos.systemui.statusbar.policy.SystemPromptController"
9294

95+
/** ColorOS 存在的类 */
96+
private const val DndAlertHelperClass = "com.oplusos.systemui.notification.helper.DndAlertHelper"
97+
9398
/** 根据多个版本存在不同的包名相同的类 */
9499
private val OplusPowerNotificationWarningsClass = VariousClass(
95100
"com.oplusos.systemui.notification.power.OplusPowerNotificationWarnings",
@@ -309,11 +314,20 @@ class HookEntry : YukiHookXposedInitProxy {
309314
}
310315
beforeHook {
311316
/** 是否移除 */
312-
if (firstArgs as Int == 7 && prefs.getBoolean(
313-
REMOVE_CHANGECP_NOTIFY,
314-
default = false
315-
)
316-
) resultNull()
317+
if (firstArgs as Int == 7 && prefs.getBoolean(REMOVE_CHANGECP_NOTIFY, default = false)) resultNull()
318+
}
319+
}
320+
}
321+
/** 移除免打扰通知 */
322+
DndAlertHelperClass.hook {
323+
injectMember {
324+
method {
325+
name = "sendNotificationWithEndtime"
326+
param(LongType)
327+
}
328+
beforeHook {
329+
/** 是否移除 */
330+
if (prefs.getBoolean(REMOVE_DNDALERT_NOTIFY, default = false)) resultNull()
317331
}
318332
}
319333
}

app/src/main/java/com/fankes/coloros/notify/ui/MainActivity.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import com.fankes.coloros.notify.hook.HookConst.ENABLE_MODULE_LOG
4343
import com.fankes.coloros.notify.hook.HookConst.ENABLE_NOTIFY_ICON_FIX
4444
import com.fankes.coloros.notify.hook.HookConst.REMOVE_CHANGECP_NOTIFY
4545
import com.fankes.coloros.notify.hook.HookConst.REMOVE_DEV_NOTIFY
46+
import com.fankes.coloros.notify.hook.HookConst.REMOVE_DNDALERT_NOTIFY
4647
import com.fankes.coloros.notify.ui.base.BaseActivity
4748
import com.fankes.coloros.notify.utils.factory.*
4849
import com.fankes.coloros.notify.utils.tool.SystemUITool
@@ -98,6 +99,7 @@ class MainActivity : BaseActivity() {
9899
val notifyIconConfigItem = findViewById<View>(R.id.config_item_notify)
99100
val devNotifyConfigSwitch = findViewById<SwitchCompat>(R.id.remove_dev_n_enable_switch)
100101
val crcpNotifyConfigSwitch = findViewById<SwitchCompat>(R.id.remove_chargecp_n_enable_switch)
102+
val dndNotifyConfigSwitch = findViewById<SwitchCompat>(R.id.remove_dndalert_n_enable_switch)
101103
val a12StyleConfigSwitch = findViewById<SwitchCompat>(R.id.a12_style_enable_switch)
102104
val hideIconInLauncherSwitch = findViewById<SwitchCompat>(R.id.hide_icon_in_launcher_switch)
103105
val notifyIconFixSwitch = findViewById<SwitchCompat>(R.id.notify_icon_fix_switch)
@@ -110,6 +112,7 @@ class MainActivity : BaseActivity() {
110112
notifyIconFixButton.isVisible = modulePrefs.getBoolean(ENABLE_NOTIFY_ICON_FIX, default = true)
111113
devNotifyConfigSwitch.isChecked = modulePrefs.getBoolean(REMOVE_DEV_NOTIFY, default = true)
112114
crcpNotifyConfigSwitch.isChecked = modulePrefs.getBoolean(REMOVE_CHANGECP_NOTIFY, default = false)
115+
dndNotifyConfigSwitch.isChecked = modulePrefs.getBoolean(REMOVE_DNDALERT_NOTIFY, default = false)
113116
a12StyleConfigSwitch.isChecked = modulePrefs.getBoolean(ENABLE_ANDROID12_STYLE, isUpperOfAndroidS)
114117
moduleEnableSwitch.isChecked = modulePrefs.getBoolean(ENABLE_MODULE, default = true)
115118
moduleEnableLogSwitch.isChecked = modulePrefs.getBoolean(ENABLE_MODULE_LOG, default = false)
@@ -154,6 +157,11 @@ class MainActivity : BaseActivity() {
154157
modulePrefs.putBoolean(REMOVE_CHANGECP_NOTIFY, b)
155158
SystemUITool.showNeedRestartSnake(context = this)
156159
}
160+
dndNotifyConfigSwitch.setOnCheckedChangeListener { btn, b ->
161+
if (!btn.isPressed) return@setOnCheckedChangeListener
162+
modulePrefs.putBoolean(REMOVE_DNDALERT_NOTIFY, b)
163+
SystemUITool.showNeedRestartSnake(context = this)
164+
}
157165
a12StyleConfigSwitch.setOnCheckedChangeListener { btn, b ->
158166
if (!btn.isPressed) return@setOnCheckedChangeListener
159167
modulePrefs.putBoolean(ENABLE_ANDROID12_STYLE, b)

app/src/main/res/layout/activity_main.xml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@
233233
android:textSize="15sp" />
234234

235235
<TextView
236-
android:id="@+id/color_icon_compat_text"
237236
android:layout_width="match_parent"
238237
android:layout_height="wrap_content"
239238
android:layout_marginBottom="10dp"
@@ -242,6 +241,25 @@
242241
android:text="充电完成后总是会推送一条通知,有时候甚至还不是静音状态,开启后将直接移除这个“你在教我做事”的通知功能。"
243242
android:textColor="@color/colorTextDark"
244243
android:textSize="12sp" />
244+
245+
<com.fankes.coloros.notify.view.MaterialSwitch
246+
android:id="@+id/remove_dndalert_n_enable_switch"
247+
android:layout_width="match_parent"
248+
android:layout_height="35dp"
249+
android:layout_marginBottom="5dp"
250+
android:text="移除免打扰通知"
251+
android:textColor="@color/colorTextGray"
252+
android:textSize="15sp" />
253+
254+
<TextView
255+
android:layout_width="match_parent"
256+
android:layout_height="wrap_content"
257+
android:layout_marginBottom="10dp"
258+
android:alpha="0.6"
259+
android:lineSpacingExtra="6dp"
260+
android:text="开启免打扰后无论任何时长,总是会推送一条通知,开启后将直接移除这个“你在教我做事”的通知功能。"
261+
android:textColor="@color/colorTextDark"
262+
android:textSize="12sp" />
245263
</LinearLayout>
246264

247265
<LinearLayout

0 commit comments

Comments
 (0)