Skip to content

Commit d0b71b5

Browse files
programminghoch10binarynoise
authored andcommitted
Add DisableShutterSounds
1 parent 0c27807 commit d0b71b5

File tree

7 files changed

+49
-0
lines changed

7 files changed

+49
-0
lines changed

DisableSounds/Readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Disable various system sounds.
44

55
- Disable (regionally) forced camera sound
6+
- Disable shutter sound
67
- Disable screenshot sound
78

89
## Forced camera sound
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
com.programminghoch10.DisableSounds.DisableForcedCameraSoundsHook
22
com.programminghoch10.DisableSounds.DisableScreenshotSoundsHook
3+
com.programminghoch10.DisableSounds.DisableShutterSoundsHook
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.programminghoch10.DisableSounds
2+
3+
import android.media.MediaActionSound
4+
import android.os.Build
5+
import com.programminghoch10.DisableSounds.BuildConfig.SHARED_PREFERENCES_NAME
6+
import de.robv.android.xposed.IXposedHookLoadPackage
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 DisableShutterSoundsHook : IXposedHookLoadPackage {
13+
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam?) {
14+
val sharedPreferences = XSharedPreferences(BuildConfig.APPLICATION_ID, SHARED_PREFERENCES_NAME)
15+
if (!sharedPreferences.getBoolean("shutter", false)) return
16+
17+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
18+
for (methodName in listOf("load", "play")) {
19+
XposedHelpers.findAndHookMethod(
20+
MediaActionSound::class.java,
21+
methodName,
22+
Int::class.java,
23+
XC_MethodReplacement.DO_NOTHING,
24+
)
25+
}
26+
}
27+
28+
// TODO: need a native hook for old Camera API methods
29+
// https://cs.android.com/android/platform/superproject/main/+/main:frameworks/av/services/camera/libcameraservice/CameraService.cpp;l=4097?q=camera_click.ogg
30+
// then the "might not work" warning can be removed from @string/disable_shutter_sounds_description_on
31+
}
32+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<string name="disable_shutter_sounds_description_on">Some apps using the old Camera API might not be muted.</string>
4+
</resources>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@
55
<string name="description">Disable various system sounds</string>
66
<string name="disable_screenshot_sounds_title">Disable screenshot sounds</string>
77
<string name="disable_screenshot_sounds_description">Disable screenshot and screen recording sounds.</string>
8+
<string name="disable_shutter_sounds_title">Disable shutter sounds</string>
9+
<string name="disable_shutter_sounds_description">Disable shutter, focus and video recording sounds.</string>
10+
<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>
811
</resources>

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<PreferenceScreen
33
xmlns:app="http://schemas.android.com/apk/res-auto">
4+
<SwitchPreference
5+
app:iconSpaceReserved="false"
6+
app:key="shutter"
7+
app:summary="@string/disable_shutter_sounds_description"
8+
app:summaryOn="@string/disable_shutter_sounds_description_on"
9+
app:title="@string/disable_shutter_sounds_title"
10+
/>
411
<SwitchPreference
512
app:iconSpaceReserved="false"
613
app:key="screenshot"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Disable various system sounds.
22

33
- Disable (regionally) forced camera sound
4+
- Disable shutter sound
45
- Disable screenshot sound

0 commit comments

Comments
 (0)