Skip to content

Commit ba86226

Browse files
programminghoch10binarynoise
authored andcommitted
implement PreventAudioFocus
1 parent 8502cf3 commit ba86226

File tree

10 files changed

+78
-0
lines changed

10 files changed

+78
-0
lines changed

PreventAudioFocus/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# PreventAudioFocus
2+
3+
This module prevents selected apps from acquiring audio focus.
4+
5+
If applied to System Framework (`android`),
6+
it will prevent every app from acquiring audio focus.

PreventAudioFocus/build.gradle.kts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
plugins {
2+
alias(libs.plugins.buildlogic.android.application)
3+
}
4+
5+
android {
6+
namespace = "com.programminghoch10.PreventAudioFocus"
7+
8+
defaultConfig {
9+
minSdk = 23
10+
targetSdk = 35
11+
}
12+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest
3+
xmlns:android="http://schemas.android.com/apk/res/android">
4+
5+
<application android:label="PreventAudioFocus">
6+
<meta-data
7+
android:name="xposedmodule"
8+
android:value="true"
9+
/>
10+
<meta-data
11+
android:name="xposeddescription"
12+
android:value="Prevent apps from acquiring audio focus"
13+
/>
14+
<meta-data
15+
android:name="xposedminversion"
16+
android:value="82"
17+
/>
18+
<meta-data
19+
android:name="xposedscope"
20+
android:resource="@array/scope"
21+
/>
22+
</application>
23+
24+
</manifest>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
com.programminghoch10.PreventAudioFocus.Hook
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.programminghoch10.PreventAudioFocus;
2+
3+
import android.media.AudioManager;
4+
5+
import de.robv.android.xposed.IXposedHookLoadPackage;
6+
import de.robv.android.xposed.XC_MethodReplacement;
7+
import de.robv.android.xposed.XposedBridge;
8+
import de.robv.android.xposed.XposedHelpers;
9+
import de.robv.android.xposed.callbacks.XC_LoadPackage;
10+
11+
public class Hook implements IXposedHookLoadPackage {
12+
@Override
13+
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) {
14+
Class<?> clazz = AudioManager.class;
15+
if (lpparam.packageName.equals("android"))
16+
clazz = XposedHelpers.findClass("com.android.server.audio.MediaFocusControl", lpparam.classLoader);
17+
XposedBridge.hookAllMethods(
18+
clazz,
19+
"requestAudioFocus",
20+
XC_MethodReplacement.returnConstant(AudioManager.AUDIOFOCUS_REQUEST_GRANTED));
21+
}
22+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<string-array name="scope">
4+
<item>android</item>
5+
</string-array>
6+
</resources>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This module prevents selected apps from acquiring audio focus.
2+
3+
If applied to System Framework (`android`),
4+
it will prevent every app from acquiring audio focus.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Prevent selected apps from acquiring audio focus.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PreventAudioFocus

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ include(":MotionEventMod")
5050
include(":MuteSlf4jWarnings")
5151
include(":OpenWifiOnTop")
5252
include(":PersistentForegroundServiceNotifications")
53+
include(":PreventAudioFocus")
5354
include(":ResetAllNotificationChannels")
5455
include(":RotationControl")
5556
include(":reflection")

0 commit comments

Comments
 (0)