Skip to content

Commit 26fdbcc

Browse files
Add DisableChargingSounds
1 parent ab8608e commit 26fdbcc

File tree

5 files changed

+80
-4
lines changed

5 files changed

+80
-4
lines changed

.idea/codeStyles/Project.xml

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
com.programminghoch10.DisableSounds.DisableChargingSoundsHook
12
com.programminghoch10.DisableSounds.DisableForcedCameraSoundHook
23
com.programminghoch10.DisableSounds.DisableScreenshotSoundHook
34
com.programminghoch10.DisableSounds.DisableShutterSoundsHook
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.programminghoch10.DisableSounds
2+
3+
import android.content.ContentResolver
4+
import android.provider.Settings
5+
import de.robv.android.xposed.IXposedHookLoadPackage
6+
import de.robv.android.xposed.XC_MethodHook
7+
import de.robv.android.xposed.XC_MethodReplacement
8+
import de.robv.android.xposed.XSharedPreferences
9+
import de.robv.android.xposed.XposedHelpers
10+
import de.robv.android.xposed.callbacks.XC_LoadPackage
11+
12+
class DisableChargingSoundsHook : IXposedHookLoadPackage {
13+
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
14+
if (lpparam.packageName != "android") return
15+
val sharedPreferences = XSharedPreferences(BuildConfig.APPLICATION_ID, SHARED_PREFERENCES_NAME)
16+
if (!sharedPreferences.getBoolean("charging", false)) return
17+
val disableChargingFeedback = sharedPreferences.getBoolean("chargingFeedback", false)
18+
19+
val CHARGING_STARTED_SOUND =
20+
XposedHelpers.getStaticObjectField(Settings::class.java, "CHARGING_STARTED_SOUND") as String
21+
val WIRELESS_CHARGING_STARTED_SOUND =
22+
XposedHelpers.getStaticObjectField(Settings::class.java, "WIRELESS_CHARGING_STARTED_SOUND") as String
23+
val CHARGING_VIBRATION_ENABLED =
24+
XposedHelpers.getStaticObjectField(Settings.Secure::class.java, "CHARGING_VIBRATION_ENABLED") as String
25+
26+
XposedHelpers.findAndHookMethod(
27+
Settings.Global::class.java,
28+
"getString",
29+
ContentResolver::class.java,
30+
String::class.java,
31+
object : XC_MethodHook() {
32+
override fun beforeHookedMethod(param: MethodHookParam) {
33+
val string = param.args[1] as String
34+
if (string == CHARGING_STARTED_SOUND || string == WIRELESS_CHARGING_STARTED_SOUND) param.result =
35+
null
36+
}
37+
},
38+
)
39+
40+
if (disableChargingFeedback) {
41+
XposedHelpers.findAndHookMethod(
42+
Settings.Secure::class.java,
43+
"getIntForUser",
44+
ContentResolver::class.java,
45+
String::class.java,
46+
Int::class.java,
47+
object : XC_MethodHook() {
48+
override fun beforeHookedMethod(param: MethodHookParam) {
49+
val string = param.args[1] as String
50+
if (string == CHARGING_VIBRATION_ENABLED) param.result = 0
51+
}
52+
},
53+
)
54+
55+
val NotifierClass = XposedHelpers.findClass("com.android.server.power.Notifier", lpparam.classLoader)
56+
XposedHelpers.findAndHookMethod(
57+
NotifierClass,
58+
"isChargingFeedbackEnabled",
59+
Int::class.java,
60+
XC_MethodReplacement.returnConstant(false),
61+
)
62+
}
63+
}
64+
}

DisableSounds/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@
88
<string name="disable_shutter_sounds_description_on">Some apps using the old Camera API might not be muted. On Android 13 and older the screenshot sound might be muted too.</string>
99
<string name="disable_screenshot_sound_title">Disable screenshot sound</string>
1010
<string name="disable_screenshot_sound_description">@null</string>
11+
<string name="disable_charging_sounds">Disable charging sounds</string>
12+
<string name="disable_charging_feedback">Disable charging feedback</string>
13+
<string name="disable_charging_feedback_summary">Also disable charging vibration.</string>
1114
</resources>

DisableSounds/src/main/res/xml/root_preferences.xml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,23 @@
33
xmlns:app="http://schemas.android.com/apk/res-auto">
44
<SwitchPreference
55
app:key="shutter"
6-
app:title="@string/disable_shutter_sounds_title"
76
app:summary="@string/disable_shutter_sounds_description"
87
app:summaryOn="@string/disable_shutter_sounds_description_on"
8+
app:title="@string/disable_shutter_sounds_title"
99
/>
1010
<SwitchPreference
1111
app:key="screenshot"
12-
app:title="@string/disable_screenshot_sound_title"
1312
app:summary="@string/disable_screenshot_sound_description"
13+
app:title="@string/disable_screenshot_sound_title"
14+
/>
15+
<SwitchPreference
16+
app:key="charging"
17+
app:title="@string/disable_charging_sounds"
18+
/>
19+
<SwitchPreference
20+
app:dependency="charging"
21+
app:key="chargingFeedback"
22+
app:summary="@string/disable_charging_feedback_summary"
23+
app:title="@string/disable_charging_feedback"
1424
/>
1525
</PreferenceScreen>

0 commit comments

Comments
 (0)