Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 37a42cac authored by Jean-Michel Trivi's avatar Jean-Michel Trivi
Browse files

AudioManager: route hasAudioFocus() through manager

AudioService API should go through its manager, to avoid exposing
interface through AIDL.

Bug: 416963897
Flag: android.media.audio.audio_focus_desktop
Test: atest CtsPackageInstallTestCases:android.packageinstaller.install.cts.InstallConstraintsTest#testCheckInstallConstraints_AppIsInteracting
Change-Id: I4d2416b506facb77361bad7b5bba1117326db2fb
parent b7237322
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -4982,6 +4982,20 @@ public class AudioManager {
        }
    }

    /**
     * @hide
     * Returns whether a client is currently holding audio focus.
     * @param pckgName the name of the package of the client
     */
    @RequiresPermission("android.permission.QUERY_AUDIO_STATE")
    public boolean hasAudioFocus(@NonNull String pckgName) {
        try {
            return getService().hasAudioFocus(pckgName);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * @hide
     * Return the duration of the fade out applied when a player of the given AudioAttributes
+2 −5
Original line number Diff line number Diff line
@@ -25,9 +25,7 @@ import android.app.usage.NetworkStatsManager;
import android.content.Context;
import android.content.pm.PackageManagerInternal;
import android.media.AudioManager;
import android.media.IAudioService;
import android.net.ConnectivityManager;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.telecom.TelecomManager;
import android.text.TextUtils;
@@ -74,10 +72,9 @@ public class AppStateHelper {
     * True if the app owns the audio focus.
     */
    private boolean hasAudioFocus(String packageName) {
        var audioService = IAudioService.Stub.asInterface(
                ServiceManager.getService(Context.AUDIO_SERVICE));
        var audioManager = mContext.getSystemService(AudioManager.class);
        try {
            return audioService.hasAudioFocus(packageName);
            return audioManager.hasAudioFocus(packageName);
        } catch (Exception ignore) {
        }
        return false;