Skip to content

Commit b3ab3ff

Browse files
programminghoch10binarynoise
authored andcommitted
Add DisableChargingSounds
1 parent 7720751 commit b3ab3ff

File tree

6 files changed

+79
-0
lines changed

6 files changed

+79
-0
lines changed

DisableSounds/Readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Disable various system sounds.
55
- Disable (regionally) forced camera sound
66
- Disable shutter sound
77
- Disable screenshot sound
8+
- Disable charging sound and vibration
89

910
## Forced camera sound
1011

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

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_title">Disable shutter sounds</string>
99
<string name="disable_shutter_sounds_description">Disable shutter, focus and video recording sounds.</string>
1010
<string name="disable_shutter_sounds_description_on">Some apps using the old Camera API might not be muted. The screenshot sound might be muted too.</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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,16 @@
1414
app:summary="@string/disable_screenshot_sounds_description"
1515
app:title="@string/disable_screenshot_sounds_title"
1616
/>
17+
<SwitchPreference
18+
app:iconSpaceReserved="false"
19+
app:key="charging"
20+
app:title="@string/disable_charging_sounds"
21+
/>
22+
<SwitchPreference
23+
app:dependency="charging"
24+
app:iconSpaceReserved="false"
25+
app:key="chargingFeedback"
26+
app:summary="@string/disable_charging_feedback_summary"
27+
app:title="@string/disable_charging_feedback"
28+
/>
1729
</PreferenceScreen>

metadata/com.programminghoch10.DisableSounds/en-US/full_description.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ Disable various system sounds.
33
- Disable (regionally) forced camera sound
44
- Disable shutter sound
55
- Disable screenshot sound
6+
- Disable charging sound and vibration

0 commit comments

Comments
 (0)