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

Commit 83271bd7 authored by Jean-Michel Trivi's avatar Jean-Michel Trivi
Browse files

Do not duck AAudio streams as a result of focus loss

Not all AAudio streams support VolumeShaper, so do not have
  the framework duck AAudio players in audio focus management.

Test: play audio through AAudio and play notification
Bug: 62027849
Change-Id: Ibe7293bf2347b75c8abd2194b6863ee3f5944003
parent 8ac5a94c
Loading
Loading
Loading
Loading
+12 −4
Original line number Original line Diff line number Diff line
@@ -29,6 +29,8 @@ import android.os.IBinder;
import android.os.RemoteException;
import android.os.RemoteException;
import android.util.Log;
import android.util.Log;


import com.android.internal.util.ArrayUtils;

import java.io.PrintWriter;
import java.io.PrintWriter;
import java.text.DateFormat;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.ArrayList;
@@ -67,6 +69,12 @@ public final class PlaybackActivityMonitor
                    .createIfNeeded()
                    .createIfNeeded()
                    .build();
                    .build();


    // TODO support VolumeShaper on those players
    private static final int[] UNDUCKABLE_PLAYER_TYPES = {
            AudioPlaybackConfiguration.PLAYER_TYPE_AAUDIO,
            AudioPlaybackConfiguration.PLAYER_TYPE_JAM_SOUNDPOOL,
    };

    // like a PLAY_CREATE_IF_NEEDED operation but with a skip to the end of the ramp
    // like a PLAY_CREATE_IF_NEEDED operation but with a skip to the end of the ramp
    private static final VolumeShaper.Operation PLAY_SKIP_RAMP =
    private static final VolumeShaper.Operation PLAY_SKIP_RAMP =
            new VolumeShaper.Operation.Builder(PLAY_CREATE_IF_NEEDED).setXOffset(1.0f).build();
            new VolumeShaper.Operation.Builder(PLAY_CREATE_IF_NEEDED).setXOffset(1.0f).build();
@@ -298,12 +306,12 @@ public final class PlaybackActivityMonitor
                                + " uid:" + apc.getClientUid() + " pid:" + apc.getClientPid()
                                + " uid:" + apc.getClientUid() + " pid:" + apc.getClientPid()
                                + " - SPEECH");
                                + " - SPEECH");
                        return false;
                        return false;
                    } else if (apc.getPlayerType()
                    } else if (ArrayUtils.contains(UNDUCKABLE_PLAYER_TYPES, apc.getPlayerType())) {
                            == AudioPlaybackConfiguration.PLAYER_TYPE_JAM_SOUNDPOOL) {
                        // TODO support ducking of SoundPool players
                        Log.v(TAG, "not ducking player " + apc.getPlayerInterfaceId()
                        Log.v(TAG, "not ducking player " + apc.getPlayerInterfaceId()
                                + " uid:" + apc.getClientUid() + " pid:" + apc.getClientPid()
                                + " uid:" + apc.getClientUid() + " pid:" + apc.getClientPid()
                                + " - SoundPool");
                                + " due to type:"
                                + AudioPlaybackConfiguration.toLogFriendlyPlayerType(
                                        apc.getPlayerType()));
                        return false;
                        return false;
                    }
                    }
                    apcsToDuck.add(apc);
                    apcsToDuck.add(apc);