Skip to content

Commit 6ff5479

Browse files
Add disable camera sounds
1 parent 524cc45 commit 6ff5479

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
com.programminghoch10.DisableSounds.DisableForcedCameraSoundHook
2+
com.programminghoch10.DisableSounds.DisableShutterSoundsHook
23
com.programminghoch10.DisableSounds.DisableScreenshotSoundHook
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.programminghoch10.DisableSounds
2+
3+
import android.annotation.SuppressLint
4+
import android.media.MediaActionSound
5+
import android.os.Build
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+
@SuppressLint("ObsoleteSdkInt")
14+
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam?) {
15+
val sharedPreferences = XSharedPreferences(BuildConfig.APPLICATION_ID, SHARED_PREFERENCES_NAME)
16+
if (!sharedPreferences.getBoolean("shutter", false))
17+
return
18+
19+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
20+
for (methodName in listOf("load", "play"))
21+
XposedHelpers.findAndHookMethod(MediaActionSound::class.java, methodName, Int::class.java, XC_MethodReplacement.DO_NOTHING)
22+
23+
// TODO: need a native hook for old Camera API methods
24+
// https://cs.android.com/android/platform/superproject/main/+/main:frameworks/av/services/camera/libcameraservice/CameraService.cpp;l=4097?q=camera_click.ogg
25+
// then the "might not work" warning can be removed from @string/disable_shutter_sounds_description_on
26+
}
27+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
<string name="title_activity_settings">DisableSounds Configuration</string>
44
<string name="app_name">DisableSounds</string>
55
<string name="description">Disable various system sounds</string>
6+
<string name="disable_shutter_sounds_title">Disable shutter sounds</string>
7+
<string name="disable_shutter_sounds_description">Disable shutter, focus and video recording sounds.</string>
8+
<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>
69
<string name="disable_screenshot_sound_title">Disable screenshot sound</string>
710
<string name="disable_screenshot_sound_description">@null</string>
811
</resources>

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
3+
<SwitchPreference
4+
app:key="shutter"
5+
app:title="@string/disable_shutter_sounds_title"
6+
app:summary="@string/disable_shutter_sounds_description"
7+
app:summaryOn="@string/disable_shutter_sounds_description_on"/>
38
<SwitchPreference
49
app:key="screenshot"
510
app:title="@string/disable_screenshot_sound_title"

0 commit comments

Comments
 (0)