Skip to content

Commit e10e4a5

Browse files
Add DisableScreenshotSounds
1 parent c62b2de commit e10e4a5

File tree

14 files changed

+171
-3
lines changed

14 files changed

+171
-3
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 screenshot sound
67

78
## Forced camera sound
89

DisableSounds/build.gradle.kts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,15 @@ android {
99
defaultConfig {
1010
minSdk = 17
1111
targetSdk = 36
12+
buildConfigField("String", "SHARED_PREFERENCES_NAME", "\"disable_sounds\"")
1213
}
1314
}
15+
16+
dependencies {
17+
// fragment-ktx is included as transitive dependency through preference-ktx
18+
// the transitive dependency is a lower version though, which allows minSdk 17,
19+
// while explicit mention with the latest version forced minSdk 21
20+
//implementation(libs.androidx.fragment.ktx)
21+
implementation(libs.androidx.preference.ktx)
22+
implementation(libs.kotlinx.coroutines.guava)
23+
}

DisableSounds/src/main/AndroidManifest.xml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,31 @@
22
<manifest
33
xmlns:android="http://schemas.android.com/apk/res/android">
44

5-
<application android:label="DisableSounds">
5+
<application android:label="@string/app_name">
6+
<activity
7+
android:name=".SettingsActivity"
8+
android:excludeFromRecents="true"
9+
android:exported="true"
10+
android:label="@string/title_activity_settings"
11+
android:theme="@style/AppTheme"
12+
>
13+
<intent-filter>
14+
<action android:name="android.intent.action.MAIN" />
15+
<category android:name="de.robv.android.xposed.category.MODULE_SETTINGS" />
16+
</intent-filter>
17+
</activity>
18+
619
<meta-data
720
android:name="xposedmodule"
821
android:value="true"
922
/>
1023
<meta-data
1124
android:name="xposeddescription"
12-
android:value="Disable various system sounds"
25+
android:value="@string/description"
1326
/>
1427
<meta-data
1528
android:name="xposedminversion"
16-
android:value="53"
29+
android:value="93"
1730
/>
1831
<meta-data
1932
android:name="xposedscope"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
com.programminghoch10.DisableSounds.DisableForcedCameraSoundsHook
2+
com.programminghoch10.DisableSounds.DisableScreenshotSoundsHook
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.Context
4+
import android.media.MediaActionSound
5+
import android.os.Build
6+
import com.google.common.util.concurrent.Futures
7+
import com.programminghoch10.DisableSounds.BuildConfig.SHARED_PREFERENCES_NAME
8+
import de.robv.android.xposed.IXposedHookLoadPackage
9+
import de.robv.android.xposed.XC_MethodHook
10+
import de.robv.android.xposed.XC_MethodReplacement
11+
import de.robv.android.xposed.XSharedPreferences
12+
import de.robv.android.xposed.XposedHelpers
13+
import de.robv.android.xposed.callbacks.XC_LoadPackage
14+
15+
class DisableScreenshotSoundsHook : IXposedHookLoadPackage {
16+
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
17+
if (lpparam.packageName != "com.android.systemui") return
18+
val sharedPreferences = XSharedPreferences(BuildConfig.APPLICATION_ID, SHARED_PREFERENCES_NAME)
19+
if (!sharedPreferences.getBoolean("screenshot", false)) return
20+
21+
when {
22+
Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE -> XposedHelpers.findAndHookMethod(
23+
"com.android.systemui.screenshot.ScreenshotSoundControllerImpl",
24+
lpparam.classLoader,
25+
"playScreenshotSoundAsync",
26+
XC_MethodReplacement.DO_NOTHING,
27+
)
28+
Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ->
29+
// TODO: check if inlined by r8 on 33
30+
XposedHelpers.findAndHookMethod(
31+
"com.android.systemui.screenshot.ScreenshotController",
32+
lpparam.classLoader,
33+
"playCameraSound",
34+
XC_MethodReplacement.DO_NOTHING,
35+
)
36+
37+
}
38+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && Build.VERSION.SDK_INT <= Build.VERSION_CODES.TIRAMISU) {
39+
val ScreenshotControllerClass = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
40+
XposedHelpers.findClass("com.android.systemui.screenshot.ScreenshotController", lpparam.classLoader)
41+
} else {
42+
XposedHelpers.findClass("com.android.systemui.screenshot.GlobalScreenshot", lpparam.classLoader)
43+
}
44+
45+
var replacementDummy: Any = MediaActionSoundDummy()
46+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) replacementDummy = Futures.immediateFuture(replacementDummy)
47+
48+
XposedHelpers.findAndHookConstructor(
49+
ScreenshotControllerClass, Context::class.java, object : XC_MethodHook() {
50+
override fun afterHookedMethod(param: MethodHookParam) {
51+
XposedHelpers.setObjectField(
52+
param.thisObject, "mCameraSound", replacementDummy
53+
)
54+
}
55+
})
56+
}
57+
}
58+
59+
class MediaActionSoundDummy : MediaActionSound() {
60+
override fun load(soundName: Int) {}
61+
override fun play(soundName: Int) {}
62+
override fun release() {}
63+
}
64+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.programminghoch10.DisableSounds
2+
3+
import android.os.Bundle
4+
import androidx.fragment.app.FragmentActivity
5+
import androidx.preference.PreferenceFragmentCompat
6+
import com.programminghoch10.DisableSounds.BuildConfig.SHARED_PREFERENCES_NAME
7+
8+
class SettingsActivity : FragmentActivity() {
9+
override fun onCreate(savedInstanceState: Bundle?) {
10+
super.onCreate(savedInstanceState)
11+
setContentView(R.layout.settings_activity)
12+
if (savedInstanceState == null) {
13+
supportFragmentManager.beginTransaction().replace(R.id.settings, SettingsFragment()).commit()
14+
}
15+
actionBar?.setDisplayHomeAsUpEnabled(true)
16+
}
17+
18+
override fun onNavigateUp(): Boolean {
19+
finish()
20+
return true
21+
}
22+
23+
class SettingsFragment : PreferenceFragmentCompat() {
24+
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
25+
preferenceManager.sharedPreferencesName = SHARED_PREFERENCES_NAME
26+
preferenceManager.sharedPreferencesMode = MODE_WORLD_READABLE
27+
setPreferencesFromResource(R.xml.root_preferences, rootKey)
28+
}
29+
}
30+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<LinearLayout
2+
xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:theme="@style/AppTheme.Edge2EdgeFix"
6+
>
7+
8+
<FrameLayout
9+
android:id="@+id/settings"
10+
android:layout_width="match_parent"
11+
android:layout_height="match_parent"
12+
/>
13+
</LinearLayout>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
4+
<style name="AppTheme" parent="@android:style/Theme.DeviceDefault.Settings" />
5+
</resources>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<resources>
33
<string-array name="scope">
44
<item>android</item>
5+
<item>com.android.systemui</item>
56
<item>org.lineageos.aperture</item>
67
</string-array>
78
</resources>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<string name="title_activity_settings">DisableSounds Configuration</string>
4+
<string name="app_name">DisableSounds</string>
5+
<string name="description">Disable various system sounds</string>
6+
<string name="disable_screenshot_sounds_title">Disable screenshot sounds</string>
7+
<string name="disable_screenshot_sounds_description">Disable screenshot and screen recording sounds.</string>
8+
</resources>

0 commit comments

Comments
 (0)