Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent Audio Focus #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions PreventAudioFocus/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# PreventAudioFocus

This module prevents selected apps from acquiring audio focus.

If applied to System Framework (`android`),
it will prevent every app from acquiring audio focus.
12 changes: 12 additions & 0 deletions PreventAudioFocus/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
plugins {
id("com.android.application")
}

android {
namespace = "com.programminghoch10.PreventAudioFocus"

defaultConfig {
minSdk = 23
targetSdk = 34
}
}
24 changes: 24 additions & 0 deletions PreventAudioFocus/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android">

<application android:label="PreventAudioFocus">
<meta-data
android:name="xposedmodule"
android:value="true"
/>
<meta-data
android:name="xposeddescription"
android:value="Prevent apps from acquiring audio focus"
/>
<meta-data
android:name="xposedminversion"
android:value="82"
/>
<meta-data
android:name="xposedscope"
android:resource="@array/scope"
/>
</application>

</manifest>
1 change: 1 addition & 0 deletions PreventAudioFocus/src/main/assets/xposed_init
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.programminghoch10.PreventAudioFocus.Hook
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.programminghoch10.PreventAudioFocus;

import android.media.AudioManager;

import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodReplacement;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

public class Hook implements IXposedHookLoadPackage {
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) {
Class<?> clazz = AudioManager.class;
if (lpparam.packageName.equals("android"))
clazz = XposedHelpers.findClass("com.android.server.MediaFocusControl", lpparam.classLoader);
XposedBridge.hookAllMethods(
clazz,
"requestAudioFocus",
XC_MethodReplacement.returnConstant(AudioManager.AUDIOFOCUS_REQUEST_GRANTED));
}
}
6 changes: 6 additions & 0 deletions PreventAudioFocus/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="scope">
<item>android</item>
</string-array>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This module prevents selected apps from acquiring audio focus.

If applied to System Framework (`android`),
it will prevent every app from acquiring audio focus.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prevent selected apps from acquiring audio focus.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PreventAudioFocus
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ include(":FreeNotifications")
include(":MotionEventMod")
include(":MuteSlf4jWarnings")
include(":PersistentForegroundServiceNotifications")
include(":PreventAudioFocus")
include(":ResetAllNotificationChannels")
include(":RotationControl")
include(":reflection")
Expand Down