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

Commit 952f2341 authored by Jean-Michel Trivi's avatar Jean-Michel Trivi
Browse files

Audio focus: framework enforces ducking

When an application requests audio focus with AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK
 automatically duck any active players of the current focus owner, unless:
 - the player is a SoundPool
 - the player plays content of type AudioAttributes.CONTENT_TYPE_SPEECH
 - the focus owner requested focus with an AudioFocusRequest which
    returns true for willPauseWhenDucked().
 - the focus owner and requester share the same UID

Test: cts-tradefed run cts -m CtsMediaTestCases -t android.media.cts.AudioFocusTest#testAudioFocusRequestGainLossTransient
Bug: 30258418

Change-Id: I997905089252be410d58e03b350b6aa8a0d98e61
parent 272fe5c3
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -46,9 +46,9 @@ public class MediaFocusControl implements PlayerFocusEnforcer {

    /**
     * set to true so the framework enforces ducking itself, without communicating to apps
     * that they lost focus.
     * that they lost focus for most use cases.
     */
    static final boolean ENFORCE_DUCKING = false;
    static final boolean ENFORCE_DUCKING = true;
    /**
     * set to true so the framework enforces muting media/game itself when the device is ringing
     * or in a call.
+6 −6
Original line number Diff line number Diff line
@@ -309,7 +309,7 @@ public final class PlaybackActivityMonitor
                        return false;
                    } else {
                        try {
                            if (DEBUG) { Log.v(TAG, "ducking player " + piid); }
                            Log.v(TAG, "ducking player " + piid);
                            apc.getPlayerProxy().applyVolumeShaper(
                                    DUCK_VSHAPE,
                                    PLAY_CREATE_IF_NEEDED);
@@ -339,7 +339,7 @@ public final class PlaybackActivityMonitor
                if (apc != null
                        && winner.hasSameUid(apc.getClientUid())) {
                    try {
                        if (DEBUG) { Log.v(TAG, "unducking player" + piid); }
                        Log.v(TAG, "unducking player" + piid);
                        mDuckedPlayers.remove(new Integer(piid));
                        apc.getPlayerProxy().applyVolumeShaper(
                                DUCK_ID,
@@ -381,11 +381,11 @@ public final class PlaybackActivityMonitor
                }
                if (mute) {
                    try {
                        if (DEBUG) { Log.v(TAG, "muting player" + piid); }
                        Log.v(TAG, "call: muting player" + piid);
                        apc.getPlayerProxy().setVolume(0.0f);
                        mMutedPlayers.add(piid);
                    } catch (Exception e) {
                        Log.e(TAG, "Error muting player " + piid, e);
                        Log.e(TAG, "call: error muting player " + piid, e);
                    }
                }
            }
@@ -405,10 +405,10 @@ public final class PlaybackActivityMonitor
                final AudioPlaybackConfiguration apc = mPlayers.get(piid);
                if (apc != null) {
                    try {
                        if (DEBUG) { Log.v(TAG, "unmuting player" + piid); }
                        Log.v(TAG, "call: unmuting player" + piid);
                        apc.getPlayerProxy().setVolume(1.0f);
                    } catch (Exception e) {
                        Log.e(TAG, "Error unmuting player " + piid, e);
                        Log.e(TAG, "call: error unmuting player " + piid, e);
                    }
                }
            }