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

Commit e1b8376c authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "AudioManager: route hasAudioFocus() through manager" into main

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