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

Commit 5bbd8ea6 authored by Vlad Popa's avatar Vlad Popa Committed by Android (Google) Code Review
Browse files

Merge "LEA index range consistent with SCO" into main

parents 81ee0274 31751337
Loading
Loading
Loading
Loading
+23 −4
Original line number Diff line number Diff line
@@ -17,6 +17,11 @@ package com.android.server.audio;

import static android.media.audio.Flags.scoManagedByAudio;

import static com.android.media.audio.Flags.equalScoLeaVcIndexRange;
import static com.android.server.audio.AudioService.BT_COMM_DEVICE_ACTIVE_BLE_HEADSET;
import static com.android.server.audio.AudioService.BT_COMM_DEVICE_ACTIVE_BLE_SPEAKER;
import static com.android.server.audio.AudioService.BT_COMM_DEVICE_ACTIVE_SCO;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.compat.CompatChanges;
@@ -64,6 +69,7 @@ import android.util.Pair;
import android.util.PrintWriterPrinter;

import com.android.internal.annotations.GuardedBy;
import com.android.server.audio.AudioService.BtCommDeviceActiveType;
import com.android.server.utils.EventLogger;

import java.io.PrintWriter;
@@ -835,15 +841,15 @@ public class AudioDeviceBroker {
        return isDeviceOnForCommunication(AudioDeviceInfo.TYPE_BLUETOOTH_SCO);
    }

    /*package*/ boolean isBluetoothScoActive() {
    private boolean isBluetoothScoActive() {
        return isDeviceActiveForCommunication(AudioDeviceInfo.TYPE_BLUETOOTH_SCO);
    }

    /*package*/ boolean isBluetoothBleHeadsetActive() {
    private boolean isBluetoothBleHeadsetActive() {
        return isDeviceActiveForCommunication(AudioDeviceInfo.TYPE_BLE_HEADSET);
    }

    /*package*/ boolean isBluetoothBleSpeakerActive() {
    private boolean isBluetoothBleSpeakerActive() {
        return isDeviceActiveForCommunication(AudioDeviceInfo.TYPE_BLE_SPEAKER);
    }

@@ -1437,7 +1443,20 @@ public class AudioDeviceBroker {
        }
        mCurCommunicationPortId = portId;

        mAudioService.postScoDeviceActive(isBluetoothScoActive());
        @BtCommDeviceActiveType int btCommDeviceActiveType = 0;
        if (equalScoLeaVcIndexRange()) {
            if (isBluetoothScoActive()) {
                btCommDeviceActiveType = BT_COMM_DEVICE_ACTIVE_SCO;
            } else if (isBluetoothBleHeadsetActive()) {
                btCommDeviceActiveType = BT_COMM_DEVICE_ACTIVE_BLE_HEADSET;
            } else if (isBluetoothBleSpeakerActive()) {
                btCommDeviceActiveType = BT_COMM_DEVICE_ACTIVE_BLE_SPEAKER;
            }
            mAudioService.postBtCommDeviceActive(btCommDeviceActiveType);
        } else {
            mAudioService.postBtCommDeviceActive(
                    isBluetoothScoActive() ? BT_COMM_DEVICE_ACTIVE_SCO : btCommDeviceActiveType);
        }

        final int nbDispatchers = mCommDevDispatchers.beginBroadcast();
        for (int i = 0; i < nbDispatchers; i++) {
+54 −21
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ import static com.android.media.audio.Flags.alarmMinVolumeZero;
import static com.android.media.audio.Flags.asDeviceConnectionFailure;
import static com.android.media.audio.Flags.audioserverPermissions;
import static com.android.media.audio.Flags.disablePrescaleAbsoluteVolume;
import static com.android.media.audio.Flags.equalScoLeaVcIndexRange;
import static com.android.media.audio.Flags.replaceStreamBtSco;
import static com.android.media.audio.Flags.ringerModeAffectsAlarm;
import static com.android.media.audio.Flags.setStreamVolumeOrder;
@@ -470,7 +471,7 @@ public class AudioService extends IAudioService.Stub
    private static final int MSG_CONFIGURATION_CHANGED = 54;
    private static final int MSG_BROADCAST_MASTER_MUTE = 55;
    private static final int MSG_UPDATE_CONTEXTUAL_VOLUMES = 56;
    private static final int MSG_SCO_DEVICE_ACTIVE_UPDATE = 57;
    private static final int MSG_BT_COMM_DEVICE_ACTIVE_UPDATE = 57;
    /**
     * Messages handled by the {@link SoundDoseHelper}, do not exceed
@@ -766,7 +767,21 @@ public class AudioService extends IAudioService.Stub
     * @see System#MUTE_STREAMS_AFFECTED */
    private int mUserMutableStreams;
    private final AtomicBoolean mScoDeviceActive = new AtomicBoolean(false);
    /** The active bluetooth device type used for communication is sco. */
    /*package*/ static final int BT_COMM_DEVICE_ACTIVE_SCO = 1;
    /** The active bluetooth device type used for communication is ble headset. */
    /*package*/ static final int BT_COMM_DEVICE_ACTIVE_BLE_HEADSET = 1 << 1;
    /** The active bluetooth device type used for communication is ble speaker. */
    /*package*/ static final int BT_COMM_DEVICE_ACTIVE_BLE_SPEAKER = 1 << 2;
    @IntDef({
            BT_COMM_DEVICE_ACTIVE_SCO, BT_COMM_DEVICE_ACTIVE_BLE_HEADSET,
            BT_COMM_DEVICE_ACTIVE_BLE_SPEAKER
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface BtCommDeviceActiveType {
    }
    private final AtomicInteger mBtCommDeviceActive = new AtomicInteger(0);
    @NonNull
    private SoundEffectsHelper mSfxHelper;
@@ -2522,12 +2537,18 @@ public class AudioService extends IAudioService.Stub
                // this should not happen, throwing exception
                throw new IllegalArgumentException("STREAM_BLUETOOTH_SCO is deprecated");
            }
            return streamType == AudioSystem.STREAM_VOICE_CALL && mScoDeviceActive.get();
            return streamType == AudioSystem.STREAM_VOICE_CALL
                    && mBtCommDeviceActive.get() == BT_COMM_DEVICE_ACTIVE_SCO;
        } else {
            return streamType == AudioSystem.STREAM_BLUETOOTH_SCO;
        }
    }
    private boolean isStreamBluetoothComm(int streamType) {
        return (streamType == AudioSystem.STREAM_VOICE_CALL && mBtCommDeviceActive.get() != 0)
                || streamType == AudioSystem.STREAM_BLUETOOTH_SCO;
    }
    private void dumpStreamStates(PrintWriter pw) {
        pw.println("\nStream volumes (device: index)");
        int numStreamTypes = AudioSystem.getNumStreamTypes();
@@ -4761,7 +4782,7 @@ public class AudioService extends IAudioService.Stub
                + asDeviceConnectionFailure());
        pw.println("\tandroid.media.audio.autoPublicVolumeApiHardening:"
                + autoPublicVolumeApiHardening());
        pw.println("\tandroid.media.audio.Flags.automaticBtDeviceType:"
        pw.println("\tandroid.media.audio.automaticBtDeviceType:"
                + automaticBtDeviceType());
        pw.println("\tandroid.media.audio.featureSpatialAudioHeadtrackingLowLatency:"
                + featureSpatialAudioHeadtrackingLowLatency());
@@ -4783,6 +4804,8 @@ public class AudioService extends IAudioService.Stub
                + absVolumeIndexFix());
        pw.println("\tcom.android.media.audio.replaceStreamBtSco:"
                + replaceStreamBtSco());
        pw.println("\tcom.android.media.audio.equalScoLeaVcIndexRange:"
                + equalScoLeaVcIndexRange());
    }
    private void dumpAudioMode(PrintWriter pw) {
@@ -4896,7 +4919,7 @@ public class AudioService extends IAudioService.Stub
        final VolumeStreamState streamState = getVssForStreamOrDefault(streamTypeAlias);
        if (!replaceStreamBtSco() && (streamType == AudioManager.STREAM_VOICE_CALL)
                && isInCommunication() && mDeviceBroker.isBluetoothScoActive()) {
                && isInCommunication() && mBtCommDeviceActive.get() == BT_COMM_DEVICE_ACTIVE_SCO) {
            Log.i(TAG, "setStreamVolume for STREAM_VOICE_CALL, switching to STREAM_BLUETOOTH_SCO");
            streamType = AudioManager.STREAM_BLUETOOTH_SCO;
        }
@@ -5947,10 +5970,10 @@ public class AudioService extends IAudioService.Stub
        final boolean ringerModeMute = ringerMode == AudioManager.RINGER_MODE_VIBRATE
                || ringerMode == AudioManager.RINGER_MODE_SILENT;
        final boolean shouldRingSco = ringerMode == AudioManager.RINGER_MODE_VIBRATE
                && mDeviceBroker.isBluetoothScoActive();
                && mBtCommDeviceActive.get() == BT_COMM_DEVICE_ACTIVE_SCO;
        final boolean shouldRingBle = ringerMode == AudioManager.RINGER_MODE_VIBRATE
                && (mDeviceBroker.isBluetoothBleHeadsetActive()
                || mDeviceBroker.isBluetoothBleSpeakerActive());
                && (mBtCommDeviceActive.get() == BT_COMM_DEVICE_ACTIVE_BLE_HEADSET
                || mBtCommDeviceActive.get() == BT_COMM_DEVICE_ACTIVE_BLE_SPEAKER);
        // Ask audio policy engine to force use Bluetooth SCO/BLE channel if needed
        final String eventSource = "muteRingerModeStreams() from u/pid:" + Binder.getCallingUid()
                + "/" + Binder.getCallingPid();
@@ -7419,7 +7442,8 @@ public class AudioService extends IAudioService.Stub
        case AudioSystem.PLATFORM_VOICE:
            if (isInCommunication()
                    || mAudioSystem.isStreamActive(AudioManager.STREAM_VOICE_CALL, 0)) {
                if (!replaceStreamBtSco() && mDeviceBroker.isBluetoothScoActive()) {
                if (!replaceStreamBtSco()
                        && mBtCommDeviceActive.get() == BT_COMM_DEVICE_ACTIVE_SCO) {
                    if (DEBUG_VOL) {
                        Log.v(TAG, "getActiveStreamType: Forcing STREAM_BLUETOOTH_SCO...");
                    }
@@ -7463,7 +7487,8 @@ public class AudioService extends IAudioService.Stub
            }
        default:
            if (isInCommunication()) {
                if (!replaceStreamBtSco() && mDeviceBroker.isBluetoothScoActive()) {
                if (!replaceStreamBtSco()
                        && mBtCommDeviceActive.get() == BT_COMM_DEVICE_ACTIVE_SCO) {
                    if (DEBUG_VOL) Log.v(TAG, "getActiveStreamType: Forcing STREAM_BLUETOOTH_SCO");
                    return AudioSystem.STREAM_BLUETOOTH_SCO;
                } else {
@@ -7788,15 +7813,15 @@ public class AudioService extends IAudioService.Stub
                0 /*delay*/);
    }
    /*package*/ void postScoDeviceActive(boolean scoDeviceActive) {
    /*package*/ void postBtCommDeviceActive(@BtCommDeviceActiveType int btCommDeviceActive) {
        sendMsg(mAudioHandler,
                MSG_SCO_DEVICE_ACTIVE_UPDATE,
                SENDMSG_QUEUE, scoDeviceActive ? 1 : 0 /*arg1*/, 0 /*arg2*/, null /*obj*/,
                MSG_BT_COMM_DEVICE_ACTIVE_UPDATE,
                SENDMSG_QUEUE, btCommDeviceActive /*arg1*/, 0 /*arg2*/, null /*obj*/,
                0 /*delay*/);
    }
    private void onUpdateScoDeviceActive(boolean scoDeviceActive) {
        if (mScoDeviceActive.compareAndSet(!scoDeviceActive, scoDeviceActive)) {
    private void onUpdateBtCommDeviceActive(@BtCommDeviceActiveType int btCommDeviceActive) {
        if (mBtCommDeviceActive.getAndSet(btCommDeviceActive) != btCommDeviceActive) {
            getVssForStreamOrDefault(AudioSystem.STREAM_VOICE_CALL).updateIndexFactors();
        }
    }
@@ -8997,7 +9022,7 @@ public class AudioService extends IAudioService.Stub
        }
        public void updateIndexFactors() {
            if (!replaceStreamBtSco()) {
            if (!replaceStreamBtSco() && !equalScoLeaVcIndexRange()) {
                return;
            }
@@ -9008,10 +9033,18 @@ public class AudioService extends IAudioService.Stub
                        mIndexMax = MAX_STREAM_VOLUME[AudioSystem.STREAM_BLUETOOTH_SCO] * 10;
                    }
                    if (!equalScoLeaVcIndexRange() && isStreamBluetoothSco(mStreamType)) {
                        // SCO devices have a different min index
                    if (isStreamBluetoothSco(mStreamType)) {
                        mIndexMin = MIN_STREAM_VOLUME[AudioSystem.STREAM_BLUETOOTH_SCO] * 10;
                        mIndexStepFactor = 1.f;
                    } else if (equalScoLeaVcIndexRange() && isStreamBluetoothComm(mStreamType)) {
                        // For non SCO devices the stream state does not change the min index
                        if (mBtCommDeviceActive.get() == BT_COMM_DEVICE_ACTIVE_SCO) {
                            mIndexMin = MIN_STREAM_VOLUME[AudioSystem.STREAM_BLUETOOTH_SCO] * 10;
                        } else {
                            mIndexMin = MIN_STREAM_VOLUME[mStreamType] * 10;
                        }
                        mIndexStepFactor = 1.f;
                    } else {
                        mIndexMin = MIN_STREAM_VOLUME[AudioSystem.STREAM_VOICE_CALL] * 10;
                        mIndexStepFactor = (float) (mIndexMax - mIndexMin) / (float) (
@@ -9207,7 +9240,7 @@ public class AudioService extends IAudioService.Stub
        private void setStreamVolumeIndex(int index, int device) {
            // Only set audio policy BT SCO stream volume to 0 when the stream is actually muted.
            // This allows RX path muting by the audio HAL only when explicitly muted but not when
            // index is just set to 0 to repect BT requirements
            // index is just set to 0 to respect BT requirements
            if (isStreamBluetoothSco(mStreamType) && index == 0 && !isFullyMuted()) {
                index = 1;
            }
@@ -10217,8 +10250,8 @@ public class AudioService extends IAudioService.Stub
                    onUpdateContextualVolumes();
                    break;
                case MSG_SCO_DEVICE_ACTIVE_UPDATE:
                    onUpdateScoDeviceActive(msg.arg1 != 0);
                case MSG_BT_COMM_DEVICE_ACTIVE_UPDATE:
                    onUpdateBtCommDeviceActive(msg.arg1);
                    break;
                case MusicFxHelper.MSG_EFFECT_CLIENT_GONE: